Skip to content

Instantly share code, notes, and snippets.

Avatar

James Tucker raggi

View GitHub Profile
@raggi
raggi / eventmachine_is_web_scale.rb
Created Sep 1, 2010
the secrets of the web scale sauce
View eventmachine_is_web_scale.rb
require 'eventmachine'
EM.run do
SEKRET_SAUCE = EM.attach(
open(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w')
)
EM.start_server('0.0.0.0', 80, Module.new do
def post_init; proxy_incoming_to(SEKRET_SAUCE); end
end)
end
@raggi
raggi / mysql2_column_cache.rb
Created Mar 16, 2012
Mysql2 Column Cache for Rails 3.0.12
View mysql2_column_cache.rb
# = MONKEY PATCH: Memoize Mysql2 Columns
#
# Reduces SHOW FIELDS selects in production to essentially 0 calls.
#
# == Reason:
#
# * We have some pages that are (with rails 3.0.12) generating nearly 1200 SHOW
# FIELDS sql statements.
# * These come from ActiveRecord::Associations during complex join semantics.
# * Esentially, through some relations, Arel::Table instances don't have
@raggi
raggi / opt.service
Created Jan 20, 2020
service unit file sample
View opt.service
[Unit]
Description=/opt/bin/%N
After=network.target
[Service]
SecureBits=no-setuid-fixup-locked noroot-locked keep-caps
RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
AmbientCapabilities=CAP_NET_BIND_SERVICE
CapabilityBoundingSet=CAP_NET_BIND_SERVICE
SystemCallFilter=@basic-io @network-io @io-event
@raggi
raggi / rack_sse.ru
Last active Nov 11, 2019
Rack SSE Example
View rack_sse.ru
# rack_sse.ru
#
# An example of basic real-time, single-room broadcast chat using Server Sent
# Events in plain old Rack. This example does NOT use hijack, or the async
# hacks, it just relies on a well implemented threaded Rack server (at time of
# writing this will therefore only work with puma!). Other servers should be
# fixed to support this, as it is pretty critical to how Rack *should* work on
# most servers. The only spec-acceptable failure in this case is not flushing
# the content stream on each yield (for which the rack spec has no workaround
# today).
View config.ru
#!/usr/bin/env rackup
require 'forward'
run Rack::Forwarder.new('google.com')
@raggi
raggi / zmq_push
Created May 18, 2012
ZeroMQ push in ZSH
View zmq_push
#!/usr/bin/env zsh
set -e
autoload -U tcp_open
tcp_open $1 $2 zmq
msg=$(cat -)
tcp_send -s zmq $(print -nf '\x01\x00\x%02x\x00%s' $((1 + ${#msg})) "$msg")
tcp_close zmq
View safeware.rb
class Safeware
def initialize(app)
@app = app
end
# This dup pattern is used frequently to avoid race conditions on state stored
# inside this middleware. It's not foolproof, but if you're just using
# single-reference instance variables (instance variables with primitive
# values (not data structures)) then it works well.
@raggi
raggi / .gitignore
Last active Mar 30, 2017
Example plain text gem indexer
View .gitignore
specs.4.8
prerelease_specs.4.8
versions.list
names.list
specs
deps
gems
@raggi
raggi / cloudbleed.md
Created Feb 25, 2017
Some advice on appropriate cloudbleed response
View cloudbleed.md

Cloudbleed: Users can't fix themselves

TL;DR

Site-owners MUST invalidate all their users sessions and tokens now, and might want to consider doing so again in the not distant future.

Cloudflare domain lists

There has been a great deal of discussion about the Cloudflare domain lists that are being constructed. These lists are not really all that useful for cleaning up this mess. Let me explain.

@raggi
raggi / bm_dci_pounding.rb
Last active Sep 22, 2016
Show the effects of method cache damage from runtime extend, as it relates to extend vs. delegate for DCI.
View bm_dci_pounding.rb
require 'benchmark'
number_of_rails_methods = 300
@rails = Class.new do
number_of_rails_methods.times do |i|
class_eval <<-RUBY
def call#{"%02d" % i} # def call01
end # end
RUBY