Skip to content

Instantly share code, notes, and snippets.

@jstorimer
jstorimer / 016_session_store.rb
Created November 17, 2010 21:14
Multiple session store implementation
RedisSessionStore.logger = Rails.logger
session_options = {:expire_after => 1.day, :key_prefix => 'sessions'}
MultiSessionStore.stores[:plain] = [RedisSessionStore, session_options.merge(:key => '_session_id')]
MultiSessionStore.stores[:secure] = [RedisSessionStore, session_options.merge(:key => '_secure_session_id', :secure => ['production', 'staging'].include?(Rails.env))]
MultiSessionStore.default_store = :plain
MultiSessionStore.routes = [
['/admin', :secure],
]

This is a proof-of-concept of a couple of concurrent data structures written in Ruby.

The implementations are heavily commented for those interested. There are benchmarks (with results) included below. The results are interesting, but, as always, take with a grain of salt.

Data structures

AtomicLinkedQueue is a lock-free queue, built on atomic CAS operations.

set imap_user = 'user@gmail.com'
set imap_pass = 'pass'
set spoolfile = imaps://imap.gmail.com:993/INBOX
set folder = imaps://imap.gmail.com:993
set record="imaps://imap.gmail.com/[Gmail]/Sent Mail"
set postponed=”imaps://imap.gmail.com/[Gmail]/Drafts”
set message_cachedir=”~/.mutt/cache/bodies”
set certificate_file=~/.mutt/certificates
set smtp_url = "smtp://user@smtp.gmail.com:587/"
@jstorimer
jstorimer / hilong.rb
Last active July 30, 2020 06:52
hilong -- A simply utility to show character counts for each line of input and highlight lines longer than 80 characters.
#!/usr/bin/env ruby
# A simply utility to show character counts for each line of input and
# highlight lines longer than 80 characters.
#
# Written as an example for http://jstorimer.com/2011/12/12/writing-ruby-scripts-that-respect-pipelines.html
#
# Examples:
#
# $ hilong Gemfile
@jstorimer
jstorimer / tclient.rb
Created June 25, 2013 21:09
These scripts were the result of the "Faster Rails test runs...with Unix!" screencast at https://www.youtube.com/watch?v=RSehcT4MnRM.
#!/usr/bin/env ruby
require 'socket'
test_file = ARGV[0]
socket = UNIXSocket.new('testing.sock')
socket.write(test_file)
socket.close_write
class Sheep
def initialize
@shorn = false
# Here the sheep owns the mutex. But now the
# shearing logic is muddied up by synchronization
# logic. This doesn't seem like the right place for
# this.
@mutex = Mutex.new
end
@jstorimer
jstorimer / port_scanner.rb
Created August 30, 2012 03:40
Simple, parallel port scanner in Ruby built with connect_nonblock and IO.select.
require 'socket'
# Set up the parameters.
PORT_RANGE = 1..512
HOST = 'archive.org'
TIME_TO_WAIT = 5 # seconds
# Create a socket for each port and initiate the nonblocking
# connect.
sockets = PORT_RANGE.map do |port|
@jstorimer
jstorimer / gist:364295
Created April 13, 2010 03:55
Most used shell aliases from dotfiles repos
alias ls='ls --color=auto' [230]
alias ll='ls -l' [226]
alias ..='cd ..' [151]
alias la='ls -A' [147]
alias grep='grep --color=auto' [144]
alias l='ls -CF' [101]
alias gb='git branch' [95]
alias ls='ls -G' [95]
alias gd='git diff' [92]
alias egrep='egrep --color=auto' [91]
@jstorimer
jstorimer / -
Last active December 25, 2015 04:29
Vim plugins + vimrc
git_bundles = [
"git://github.com/ervandew/supertab.git",
"git://github.com/godlygeek/tabular.git",
"git://github.com/hallison/vim-rdoc.git",
"git://github.com/pangloss/vim-javascript.git",
"git://github.com/timcharper/textile.vim.git",
"git://github.com/tpope/vim-cucumber.git",
"git://github.com/tpope/vim-fugitive.git",
"git://github.com/tpope/vim-git.git",
"git://github.com/tpope/vim-haml.git",
require 'socket'
client = TCPSocket.new('localhost', 4481)
payload = "Lorem ipsum" * 100_000
total_bytes_written = 0
remaining_payload = payload
begin
puts 'looping'