Skip to content

Instantly share code, notes, and snippets.

@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 / ruby_version.rb
Last active February 26, 2022 11:02
Read and specify ruby version in Gemfile from asdf-vm .tool-versions file.
# 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')
@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 / slow_query_logger.rb
Created March 30, 2018 16:56
Ruby on Rails – your own slow query log, no sql configuration required
# 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
@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 / 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
# 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.)
@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

# 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'},
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