Tutorial by Examples

Person = Struct.new :name do def greet(someone) "Hello #{someone}! I am #{name}!" end end Person.new('Alice').greet 'Bob' # => "Hello Bob! I am Alice!"
Attributes can be accessed strings and symbols as keys. Numerical indexes also work. Person = Struct.new :name alice = Person.new 'Alice' alice['name'] # => "Alice" alice[:name] # => "Alice" alice[0] # => "Alice"
The first thing to do is to add the service to AndroidManifest.xml, inside the <application> tag: <application ...> ... <service android:name=".RecordingService" <!--"enabled" tag specifies Whether or not the service can ...
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...
Any list comprehension can be correspondingly coded with list monad's do notation. [f x | x <- xs] f <$> xs do { x <- xs ; return (f x) } [f x | f <- fs, x <- xs] fs <*> xs do { f <- fs ; x <- xs ; return (f x) } [y | x &...
filter returns a list of each item in the given list for which the given predicate returns a non-#f value. ;; Get only even numbers in a list > (filter even? '(1 2 3 4)) '(2 4) ;; Get all square numbers from 1 to 100 > (filter (lambda (n) (integer? (sqrt n))) (range 1 100)) '(1 4 9 16 ...
// circle objects: { x:, y:, radius: } // return true if the 2 circles are colliding // c1 and c2 are circles as defined above function CirclesColliding(c1,c2){ var dx=c2.x-c1.x; var dy=c2.y-c1.y; var rSum=c1.radius+c2.radius; return(dx*dx+dy*dy<=rSum*rSum); }
// rectangle objects { x:, y:, width:, height: } // return true if the 2 rectangles are colliding // r1 and r2 are rectangles as defined above function RectsColliding(r1,r2){ return !( r1.x>r2.x+r2.width || r1.x+r1.width<r2.x || r1.y>r2.y+r2.height || ...
// rectangle object: { x:, y:, width:, height: } // circle object: { x:, y:, radius: } // return true if the rectangle and circle are colliding function RectCircleColliding(rect,circle){ var dx=Math.abs(circle.x-(rect.x+rect.width/2)); var dy=Math.abs(circle.y-(rect.y+rect.height/2));...
The function in this example returns true if two line segments are intersecting and false if not. The example is designed for performance and uses closure to hold working variables // point object: {x:, y:} // p0 & p1 form one segment, p2 & p3 form the second segment // Retur...
// [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...
// var rect={x:,y:,width:,height:}; // var line={x1:,y1:,x2:,y2:}; // Get interseting point of line segment & rectangle (if any) function lineRectCollide(line,rect){ // p=line startpoint, p2=line endpoint var p={x:line.x1,y:line.y1}; var p2={x:line.x2,y:line.y2}; // to...
Use the Separating Axis Theorem to determine if 2 convex polygons are intersecting THE POLYGONS MUST BE CONVEX Attribution: Markus Jarderot @ How to check intersection between 2 rotated rectangles? // polygon objects are an array of vertices forming the polygon // var polygon1=[{x:100,y:100}...
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 ...
Tests if the [x,y] point is inside a closed arc. var arc={ cx:150, cy:150, innerRadius:75, outerRadius:100, startAngle:0, endAngle:Math.PI } function isPointInArc(x,y,arc){ var dx=x-arc.cx; var dy=y-arc.cy; var dxy=dx*dx+dy*dy; var rrOuter=arc.outerRadiu...
Tests if the [x,y] point is inside a wedge. // wedge objects: {cx:,cy:,radius:,startAngle:,endAngle:} // var wedge={ // cx:150, cy:150, // centerpoint // radius:100, // startAngle:0, endAngle:Math.PI // } // Return true if the x,y point is inside the closed wedge function is...
Tests if an [x,y] point is inside a circle. // circle objects: {cx:,cy:,radius:,startAngle:,endAngle:} // var circle={ // cx:150, cy:150, // centerpoint // radius:100, // } // Return true if the x,y point is inside the circle function isPointInCircle(x,y,circle){ var dx=x-circ...
Tests if an [x,y] point is inside a rectangle. // rectangle objects: {x:, y:, width:, height: } // var rect={x:10, y:15, width:25, height:20} // Return true if the x,y point is inside the rectangle function isPointInRectangle(x,y,rect){ return(x>rect.x && x<rect.x+rect.width...
Let us first create a simple .proto file person.proto package Protocol; message Person { required string firstName = 1; required string lastName = 2; optional int32 age = 3; } After saving we can now create the Haskell files which we can use in our project by running ...
Here the steps required to create a Firebase project and to connect it with an Android app. Add Firebase to your app Create a Firebase project in the Firebase console and click Create New Project. Click Add Firebase to your Android app and follow the setup steps. When prompted, enter...

Page 688 of 1336