This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const foo = (_ = 'default') => _.toString(); | |
foo(); // 'default' | |
foo(null); // throws a null pointer exception |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Foo { | |
def doIt(foo:Int, bar:Option[Foo] = None):Int { | |
foo + bar.getOrElse(0) | |
} | |
} | |
// returns 1 | |
new Foo().doIt(1) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ClientController | |
dependency :assign_user, Clients::AssignUser | |
def assign_user | |
assign_user.(params[:user_id], params[:client_id]) | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// factory-registry.js | |
export default FactoryRegistry { | |
static register(name, klass) { | |
this._factories = this._factories || {}; | |
this._factories[name] = klass; | |
} | |
} | |
// factory instance |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
SELECT | |
"orders"."id" as orders_id, | |
"clients"."id" as clients_id, | |
"users"."id" as users_id, | |
"users"."updated_at" as users_updated_at FROM "orders" | |
INNER JOIN "clients" ON "clients"."id" = "orders"."client_id" AND "clients"."deleted_at" IS NULL | |
INNER JOIN "clients_admins" ON "clients_admins"."client_id" = "clients"."id" | |
INNER JOIN "users" ON "users"."id" = "clients_admins"."user_id" WHERE "orders"."id" = 149784; | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import DS from 'ember-data'; | |
export default Model.extend({ | |
billingLocation: attr('location'), | |
billingContact: attr('contact'), | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
has_many :teams | |
has_many :team_users, class_name: 'User', throught: :teams | |
has_many :order_users | |
has_many :users, throught: :order_users | |
has_many :total_users, union: [:useres, :team_users] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def redis_queued_mutex(type, key, options ={}) | |
# our tests are single threaded so | |
if Rails.env.test? | |
yield | |
else | |
# define the maximum number of times we will wait to prevent starvation | |
max_waits = options[:max_waits] || 500 | |
# amount of time we will sleep waiting for the mutex to clear |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- You'll need the post GIS extensions installed on your Postgres instance | |
-- https://postgis.net/ | |
CREATE TABLE rentals ( | |
id INTEGER UNIQUE, | |
price_in_cents INTEGER, | |
url TEXT, | |
-- Used to determine uniqueness of the posting, perform a SHA hash of the content | |
hash TEXT, | |
-- This instructs PG to make location a geographic point on the 4326 sphere (The appromiximation of the earth used by GIS systems) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[3] pry(main)> Geocoder.search('159 West 2nd Avenue, #221 Vancouver') | |
=> [#<Geocoder::Result::Google:0x0000000006aa9b68 | |
@cache_hit=nil, | |
@data= | |
{"address_components"=> | |
[{"long_name"=>"221", "short_name"=>"221", "types"=>["subpremise"]}, | |
{"long_name"=>"159", "short_name"=>"159", "types"=>["street_number"]}, | |
{"long_name"=>"West 2nd Avenue", "short_name"=>"W 2nd Ave", "types"=>["route"]}, | |
{"long_name"=>"East Side", "short_name"=>"East Side", "types"=>["neighborhood", "political"]}, | |
{"long_name"=>"Vancouver", "short_name"=>"Vancouver", "types"=>["locality", "political"]}, |