Tutorial by Examples: al

ActionMailer supports three callbacks before_action after_action around_action Provide these in your Mailer class class UserMailer < ApplicationMailer after_action :set_delivery_options, :prevent_delivery_to_guests, :set_business_headers Then create these methods under the private ...
A string can be either single or multiline. Single line strings are written using matching single or double quotes, and multiline strings are written using triple quotes. The following are all valid Dart strings: 'Single quotes'; "Double quotes"; 'Double quotes in "single" quo...
for arg; do echo arg=$arg done A for loop without a list of words parameter will iterate over the positional parameters instead. In other words, the above example is equivalent to this code: for arg in "$@"; do echo arg=$arg done In other words, if you catch yourself wri...
git log --pretty=format:"%Cgreen%ci %Cblue%cn %Cgreen%cr%Creset %s" This will give a nice overview of all commits (1 per line) with date, user and commit message. The --pretty option has many placeholders, each starting with %. All options can be found here
Arrow functions are lexically scoped; this means that their this Binding is bound to the context of the surrounding scope. That is to say, whatever this refers to can be preserved by using an arrow function. Take a look at the following example. The class Cow has a method that allows for it to pr...
To initialize a static final fields that require using more than a single expression, a static initializer can be used to assign the value. The following example initializes a unmodifiable set of Strings: public class MyClass { public static final Set<String> WORDS; static {...
List comprehensions can introduce local bindings for variables to hold some interim values: [(x,y) | x <- [1..4], let y=x*x+1, even y] -- [(1,2),(3,10)] Same effect can be achieved with a trick, [(x,y) | x <- [1..4], y <- [x*x+1], even y] -- [(1,2),(3,10)] The let in list compr...
// [x0,y0] to [x1,y1] define a line segment // [cx,cy] is circle centerpoint, cr is circle radius function isCircleSegmentColliding(x0,y0,x1,y1,cx,cy,cr){ // calc delta distance: source point to line start var dx=cx-x0; var dy=cy-y0; // calc delta distance: line start to e...
Tests all polygon sides for intersections to determine if 2 polygons are colliding. // polygon objects are an array of vertices forming the polygon // var polygon1=[{x:100,y:100},{x:150,y:150},{x:50,y:150},...]; // The polygons can be both concave and convex // return true if the 2 polygons ...
Sometimes you want an installation without anything except the bare minimum phoenix setup. The follow command will give you that. mix phoenix.new web --no-brunch --no-ecto Note: You must have installed Elixir, Erlang, Hex, Mix and the Phoenix archive for skeleton installation
propreties { $isOk = $false } # By default the Build task won't run, unless there is a param $true Task Build -precondition { return $isOk } { "Build" } Task Clean { "Clean" } Task default -Depends Build
The instance_eval method is available on all objects. It evaluates code in the context of the receiver: object = Object.new object.instance_eval do @variable = :value end object.instance_variable_get :@variable # => :value instance_eval sets self to object for the duration of the c...
Many languages feature a with statement that allows programmers to omit the receiver of method calls. with can be easily emulated in Ruby using instance_eval: def with(object, &block) object.instance_eval &block end The with method can be used to seamlessly execute methods on object...
JSON_VALUE function enables you to take a data from JSON text on the path specified as the second argument, and use this value in any part of the select query: select ProductID, Name, Color, Size, Price, JSON_VALUE(Data, '$.Type') as Type from Product where JSON_VALUE(Data, '$.Type') = 'part' ...
Once JSON values are extracted from JSON text, you can use them ina any part of the query. You can create some kind of report on JSON data with grouping aggregations, etc: select JSON_VALUE(Data, '$.Type') as type, AVG( cast(JSON_VALUE(Data, '$.ManufacturingCost') as float) ) as cost from...
JSON_MODIFY function can be used to update value on some path. You can use this function to modify original value of JSON cell in UPDATE statement: update Product set Data = JSON_MODIFY(Data, '$.Price', 24.99) where ProductID = 17; JSON_MODIFY function will update or create Price key (if it do...
JSON_MODIFY function can be used to append new value to some array inside JSON: update Product set Data = JSON_MODIFY(Data, 'append $.tags', "sales") where ProductID = 17; New value will be appended at the end of the array, or a new array with value ["sales"] will be create...
In this example, Tags array may contain various keywords like ["promo", "sales"], so we can open this array and filter values: select ProductID, Name, Color, Size, Price, Quantity from Product CROSS APPLY OPENJSON(Data, '$.Tags') where value = 'sales' OPENJSON will op...
You can expose values from JSON column as computed columns: CREATE TABLE ProductCollection ( Id int identity primary key, Data nvarchar(max), Price AS JSON_VALUE(Data, '$.Price'), Color JSON_VALUE(Data, '$.Color') PERSISTED ) If you add PERSISTED computed column, value from JSON tex...
OPENJSON function parse JSON text and returns all key:value pairs at the first level of JSON: declare @json NVARCHAR(4000) = N'{"Name":"Joe","age":27,"skills":["C#","SQL"]}'; SELECT * FROM OPENJSON(@json); keyvaluetypeNameJoe1age272ski...

Page 134 of 269