Skip to content

Instantly share code, notes, and snippets.

const foo = (_ = 'default') => _.toString();
foo(); // 'default'
foo(null); // throws a null pointer exception
@joegaudet
joegaudet / some_method.scala
Created June 13, 2018 00:45
optional-interfaces.
class Foo {
def doIt(foo:Int, bar:Option[Foo] = None):Int {
foo + bar.getOrElse(0)
}
}
// returns 1
new Foo().doIt(1)
@joegaudet
joegaudet / client_controlls.rb
Last active June 10, 2018 06:39
Every . b ut the last should be treated as a file system '/'
class ClientController
dependency :assign_user, Clients::AssignUser
def assign_user
assign_user.(params[:user_id], params[:client_id])
end
end
// factory-registry.js
export default FactoryRegistry {
static register(name, klass) {
this._factories = this._factories || {};
this._factories[name] = klass;
}
}
// factory instance
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;
import DS from 'ember-data';
export default Model.extend({
billingLocation: attr('location'),
billingContact: attr('contact'),
});
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]
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
-- 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)
[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"]},