Skip to content

Instantly share code, notes, and snippets.

Avatar

James Tucker raggi

View GitHub Profile
View unsure.rb
$sure = false
t = Thread.new {
begin
# nada
ensure
sleep
$sure = true
# cleanup all the things
end
@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 / 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
@raggi
raggi / validate_local_cache.sh
Last active Dec 11, 2015
A script to validate your local gem cache against the public s3 repositories. If you find mismatches that contain both local and remote values, please post them in comments.
View validate_local_cache.sh
#!/usr/bin/env sh
if ! which md5sum > /dev/null; then
echo Install md5sum
exit 1
fi
if ! which curl > /dev/null; then
echo Install curl
exit 1
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 / v.zsh
Created May 29, 2012
Vim server per-directory
View v.zsh
#!/usr/bin/env zsh
which -s vim > /dev/null && VIM=vim
which -s gvim > /dev/null && VIM=gvim
which -s mvim > /dev/null && VIM=mvim
[[ -e /Applications/MacVim.app/Contents/MacOS/Vim ]] && VIM="/Applications/MacVim.app/Contents/MacOS/Vim"
[[ -z "${VIM}" ]] && echo "No vim found" && exit 1
# Console vim just gets a straight pass through, as there's no quick way to
View ramfs
#!/bin/bash
ramfs_size_mb=1024
mount_point=~/volatile
ramfs_size_sectors=$((${ramfs_size_mb}*1024*1024/512))
ramdisk_dev=`hdid -nomount ram://${ramfs_size_sectors}`
newfs_hfs -v 'Volatile' ${ramdisk_dev}
mkdir -p ${mount_point}
mount -o noatime -t hfs ${ramdisk_dev} ${mount_point}
echo "remove with:"
@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
@raggi
raggi / tsc.rb
Created May 14, 2012
Thread safe counter
View tsc.rb
class ThreadsafeCounter
include Comparable
def initialize(initial = 0)
@mutex = Mutex.new
@count = initial + 0
end
def incr
@mutex.synchronize { @count += 1 }
@raggi
raggi / encode_io.rb
Created May 9, 2012
csv generation, conversion, with utf16le - example
View encode_io.rb
require 'iconv' unless "".respond_to?(:encode)
require 'active_support/basic_object'
# = EncodeIo
#
# This is essentially a basic delegation class. The reason it isn't
# using the delegate library from stdlib is that FasterCSV has special
# casing for io classes. In order to keep using this, we need #kind_of?
# and #class to pretend that this is the original class.
#