Teh Social Netswork!
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(10) NOT NULL
);
INSERT into users VALUES
# 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'}, |
Teh Social Netswork!
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(10) NOT NULL
);
INSERT into users VALUES
# 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 |
parentheses: ( )
braces: { }
brackets: < >
square-brackets: [ ]
Note that for blocks, {}
and do ... end
are interchangeable. For brevity, only the former will be listed here.
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 }
#!/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'"\ |
// ES7, async/await | |
function sleep(ms = 0) { | |
return new Promise(r => setTimeout(r, ms)); | |
} | |
(async () => { | |
console.log('a'); | |
await sleep(1000); | |
console.log('b'); | |
})() |
# Postgresql fancy datatypes! | |
* array | |
* hstore (=~ hash) | |
* json | |
* jsonb | |
Philippe Creux - [@pcreux](http://twitter.com/pcreux) |
# 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 |