Skip to content

Instantly share code, notes, and snippets.

View razorcd's full-sized avatar

Cristian Dugacicu razorcd

View GitHub Profile
# Returns a User instance that's not saved (does not write to DB)
user = build(:user)
# Returns a saved User instance (writes to DB)
user = create(:user)
# Returns a hash of attributes that can be used to build a User instance
attrs = attributes_for(:user)
# Returns an object with all defined attributes stubbed out
== - returns true only if the two compared entities are the same object
=== - is the Case Equality Operator (Case Subsumption Operator) (fits in drawer?)
eql? - method returns true if obj and other have the same value.
equal? - determines object identitfy. Compares pointers
@razorcd
razorcd / ruby_shell.md
Created June 8, 2016 17:03
ways to run shell commands in Ruby
exec("echo 'hello world'") # exits from ruby, then runs the command
system('echo', 'hello world') # returns the status code
sh('echo', 'hello world') # returns the status code
`echo "hello world"` # returns stdout
%x[echo 'hello world'] # returns stdout
1. Codebase
One codebase tracked in revision control, many deploys
2. Dependencies
Explicitly declare and isolate dependencies
3. Config
Store config in the environment
4. Backing services
@razorcd
razorcd / gist:ccaf14eb319be6ba1e80b7605683b6e7
Last active June 12, 2016 23:15
SOLID Class Principles
- Single Responsability - classes and methods should handle/do only one thing. Methods max 5 lines long, classes max 100 lines long.
- Open Closed - classes should be open for extension and closed for change
- Liskov Substitution - Having a main class and a subclass. Anywhere we use the main we should get same result by using the subclass.
- Interface Segragation - no client should be forced to depend on methods it does not use. Maybe class does not do only one thing? Split the class in more classes (and maybe add a facade).
- Dependency Inversion - Dont tight couple the classes by creating one instance inside another class. Inject them as dependencies when calling the method outside the class.
Use `A.new(b: B.new(5))` instead of `A.new(5)` where `class A; def initialize(i); @b= B.new(i); end`
- Law of Demeter - don't chain methods that could be changed in future. (except when methods returns self)
- Don't repeat yourself - reuse code
//simple
var var1 = 1;
var func1 = function(input) {
//var var2 = 2;
return input + var1; // + var2;
}
console.log(func1(1));
console.dir(func1);
1. install openjdk
`sudo apt-get install openjdk-7-jdk`
2. install `android sdk`
# download android sdk
wget http://dl.google.com/android/android-sdk_r24.2-linux.tgz
tar -xvf android-sdk_r24.2-linux.tgz
cd android-sdk-linux/tools
@razorcd
razorcd / gist:a5d803b4b4abd55edfba
Created September 7, 2015 18:27
Swap on ubuntu
Check free mem:
free -m
Add swap:
```
sudo dd if=/dev/zero of=/swap bs=1M count=1024
sudo mkswap /swap
sudo swapon /swap
```
@razorcd
razorcd / gist:3722a9e8683f416c0aed
Last active August 29, 2015 14:20
Class Specialisations (Composition + Dependency injection) by Sandi Metz
# Class Specialisations (Composition + Dependency injection)
class House
DATA = [1,2,3,4,5,6]
attr_reader :data
def initialize(orderer: DefaultOrderer.new, formatter: DefaultFormatter.new)
# @data = formatter.format(orderer.order(DATA))
formatted_data = formatter.format(DATA)
@data = orderer.order(formatted_data)