Teh Social Netswork!
CREATE TABLE users (
id SERIAL PRIMARY KEY,
name VARCHAR(10) NOT NULL
);
INSERT into users VALUES
module SimpleRailway | |
class Result | |
attr_accessor :success, :data | |
def initialize(success, data) | |
@success = success | |
@data = data | |
end | |
def success?; !!success; end | |
def failure?; !success?; end |
# 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
# CLOSURES IN RUBY Paul Cantrell https://innig.net | |
# Email: username "paul", domain name "innig.net" | |
# I recommend executing this file, then reading it alongside its output. | |
# | |
# Alteratively, you can give yourself an unreasonable Ruby test by deleting all | |
# the comments, then trying to guess the output of the code! | |
# | |
# (Naive HR departments, please do not use that idea as a hiring quiz.) |
# 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: [ ]
# http://pdabrowski.com/blog/ruby-on-rails/slow-query-log/ | |
# config/initializer/slow_query_logger.rb | |
class SlowQueryLogger | |
MAX_DURATION = 3.0 | |
def self.initialize! | |
ActiveSupport::Notifications.subscribe('sql.active_record') do |name, start, finish, id, payload| | |
duration = finish.to_f - start.to_f |
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 }
# https://gist.github.com/EdwardDiehl/9c660b59d0fb2e936774ee2c4fcfc792 | |
# Read and specify ruby version in Gemfile from asdf-vm .tool-versions file. | |
# Copy the file to your your project root. | |
# Add these lines at the top of your project Gemfile: | |
# require './ruby_version.rb' | |
# ruby ruby_version | |
def ruby_version(ruby_default_version = '2.5.0') | |
tool_versions_file = File.join(File.expand_path('..', __FILE__), '.tool-versions') |
#!/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'"\ |