Skip to content

Instantly share code, notes, and snippets.

# Usage:
#
# class Mail
# include SimpleStateMachine
#
# self.initial_state = 'unread'
# self.transitions_map = {
# read: {from: 'unread', to: 'read'},
# unread: {from: 'any', to: 'unread'},
# delete: {from: 'any', to: 'deleted'},
@EdwardDiehl
EdwardDiehl / Intro to Common Table Expressions.md
Created November 19, 2018 07:38 — forked from felixyz/Intro to Common Table Expressions.md
Introduction to transitive closure / Common Table Expressions / iterative queries in SQL

Teh Social Netswork!

CREATE TABLE users (
 id SERIAL PRIMARY KEY,
 name VARCHAR(10) NOT NULL
);

INSERT into users VALUES

@EdwardDiehl
EdwardDiehl / geoip.rb
Created July 24, 2018 20:53 — forked from zarqman/geoip.rb
Benchmark various GeoIP gems
# Related blog post: https://iprog.com/posting/2017/10/benchmarking-geoip-gems
require 'benchmark'
PASS = 1 # 1 or 2
### libraries for C extensions
# brew install geoip
# brew install libmaxminddb
@EdwardDiehl
EdwardDiehl / Bracket Terminology.md
Created May 28, 2018 13:16 — forked from Integralist/Bracket Terminology.md
[Bracket Terminology] #bracket #terminology
parentheses:     ( ) 
braces:          { } 
brackets:        < > 
square-brackets: [ ]
@EdwardDiehl
EdwardDiehl / ruby-blocks-procs-lambdas.md
Created February 22, 2018 11:34 — forked from cflee/ruby-blocks-procs-lambdas.md
Discoveries about Ruby Blocks, Procs and Lambdas

Ruby: Blocks, Procs, Lambdas

Note that for blocks, {} and do ... end are interchangeable. For brevity, only the former will be listed here.

Version differences

Pre-1.9, lambda and proc are synonyms. Essentially the difference is between proc and block.

def method(&block) p block.class; p block.inspect; end
l = lambda { 5 }
@EdwardDiehl
EdwardDiehl / poly_to_osm.rb
Created February 3, 2018 21:43 — forked from JamesChevalier/poly_to_osm.rb
This is my script to generate OSMs out of all of a country's POLY files.
#!/usr/bin/env ruby
Dir.glob('poly/*.poly').each_slice(50) do |group|
bp_wx = ''
group.each do |poly_file|
file = File.basename(poly_file, '.poly')
city, region = file.split('_')
bp_wx << "--buffer bufferCapacity=50000"\
" --bp file='poly/#{city}_#{region}.poly'"\
@EdwardDiehl
EdwardDiehl / 1-sleep-es7.js
Created December 21, 2017 13:02 — forked from danharper/1-sleep-es7.js
ES7's async/await syntax.
// ES7, async/await
function sleep(ms = 0) {
return new Promise(r => setTimeout(r, ms));
}
(async () => {
console.log('a');
await sleep(1000);
console.log('b');
})()
@EdwardDiehl
EdwardDiehl / mocha_vs_jasmine.md
Created August 27, 2017 06:57 — forked from monolithed/mocha_vs_jasmine.md
Mocha vs. Jasmine

Почему Mocha, а не Jasmine?

Ниже будут приведены аргументы в пользу выбора Mocha

  • Высокая популярность:
    — 4m против 400k загузок в месяц

  • Высокая активность:
    — 1 890 против 1400 коммитов (всего)
    — 171 против 101 коммитов (последний год)

@EdwardDiehl
EdwardDiehl / 000_postgresql_fancy_datatypes
Created January 15, 2017 09:20 — forked from pcreux/000_postgresql_fancy_datatypes
Postgresql fancy datatypes with Rails / ActiveRecord. Run it with `rake`!
# Postgresql fancy datatypes!
* array
* hstore (=~ hash)
* json
* jsonb
Philippe Creux - [@pcreux](http://twitter.com/pcreux)
@EdwardDiehl
EdwardDiehl / reseed.rake
Created January 7, 2017 19:26 — forked from nithinbekal/reseed.rake
Rake task to reset and seed Rails database
# Originally written by Justin French (2008):
# http://justinfrench.com/notebook/a-custom-rake-task-to-reset-and-seed-your-database
#
# Modified to work with Rails 4.
desc 'Raise an error unless development environment'
task :safety_check do
raise "You can only use this in dev!" unless Rails.env.development?
end