Tutorial by Examples

This example assumes that you have experience in creating Rails applications. To create an API-only app in Rails 5, run rails new name-of-app --api Add active_model_serializers in Gemfile gem 'active_model_serializers' install bundle in terminal bundle install Set the ActiveModelSeriali...
Installing Rails on Ubuntu On a clean ubuntu, installation of Rails should be straight forward Upgrading ubuntu packages sudo apt-get update sudo apt-get upgrade Install Ruby and Rails dependecies sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyam...
The observer pattern lets users of a class subscribe to events that happen when this class processes data etc. and be notified when these event occur. In the following example we create a processing class and an observer class which will be notified while processing a phrase - if it finds words that...
Corner radius for all 4 edges: UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRoundedRect: CGRectMake(x,y,width,height) cornerRadius: 11]; [UIColor.grayColor setFill]; [rectanglePath fill]; Corner radius for top-left edge: UIBezierPath* rectanglePath = [UIBezierPath bezierPat...
For a simple circle: UIBezierPath* ovalPath = [UIBezierPath bezierPathWithOvalInRect: CGRectMake(0,0,50,50)]; [UIColor.grayColor setFill]; [ovalPath fill]; Swift: let ovalPath = UIBezierPath(ovalInRect: CGRect(x: 0, y: 0, width: 50, height: 50)) UIColor.grayColor().setFill() ovalPath.fill...
For bezier path to get resized based on the view frame, override the drawRect of view that you are drawing the bezier path : - (void)drawRect:(CGRect)frame { UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(CGRectGetMinX(frame), CGRectGetMinY(frame), CGRectGetWidth(f...
Consider a simple rectangle that is drawn by the bezier path. UIBezierPath* rectanglePath = [UIBezierPath bezierPathWithRect: CGRectMake(x,y,width,height)]; [UIColor.grayColor setFill]; [rectanglePath fill]; Basic Outer-fill shadow: CGContextRef context = UIGraphicsGetCurrentContext();...
Add the following dependency to your project level build.gradle file. dependencies { classpath "io.realm:realm-gradle-plugin:3.1.2" } Add the following right at the top of your app level build.gradle file. apply plugin: 'realm-android' Complete a gradle sync and you now have ...
Realm models must extend the RealmObject base class, they define the schema of the underlying database. Supported field types are boolean, byte, short, int, long, float, double, String, Date, byte[], links to other RealmObjects, and RealmList<T extends RealmModel>. public class Person extend...
Realm currently does not support storing a list of primitives. It is on their todo list (GitHub issue #575), but for the meantime, here is a workaround. Create a new class for your primitive type, this uses Integer, but change it for whatever you want to store. public class RealmInteger extends Re...
Detailed instructions on getting unicode set up or installed.
In C, all function parameters are passed by value, so modifying what is passed in callee functions won't affect caller functions' local variables. #include <stdio.h> void modify(int v) { printf("modify 1: %d\n", v); /* 0 is printed */ v = 42; printf("modify 2:...
(defun fn (x) (cond (test-condition1 the-value1) (test-condition2 the-value2) ... ... ... (t (fn reduced-argument-x)))) CL-USER 2788 > (defun my-fib (n) (cond ((= n 1) 1) ((= n...
(defun fn (x) (cond (test-condition the-value) (t (fn reduced-argument-x))))
Quicksort is a common sorting algorithm with an average case complexity of O(n log n) and a worst case complexity of O(n^2). Its advantage over other O(n log n) methods is that it can be executed in-place. Quicksort splits the input on a chosen pivot value, separating the list into those values tha...
Merge Sort is a common sorting algorithm with an average case complexity of O(n log n) and a worst case complexity of O(n log n). Although it cannot be executed in-place, it guarantees O(n log n) complexity in all cases. Merge Sort repeatedly splits the input in two, until an empty list or single-e...
Ruby has an or-equals operator that allows a value to be assigned to a variable if and only if that variable evaluates to either nil or false. ||= # this is the operator that achieves this. this operator with the double pipes representing or and the equals sign representing assigning of a valu...
Given a string, strspn calculates the length of the initial substring (span) consisting solely of a specific list of characters. strcspn is similar, except it calculates the length of the initial substring consisting of any characters except those listed: /* Provided a string of "tokens&quo...
Ruby has a ternary operator (?:), which returns one of two value based on if a condition evaluates as truthy: conditional ? value_if_truthy : value_if_falsy value = true value ? "true" : "false" #=> "true" value = false value ? "true" : "fals...
This method just returns the first argument. var res1 = _.identity(10, 20); // res1 now is 10 var res2 = _.identity("hello", "world"); // res2 now is "hello" What does _.identity mean in lodash documentation? This method is used throughout lodash documentation...

Page 416 of 1336