Skip to content

Instantly share code, notes, and snippets.

View midwire's full-sized avatar
🏠
Working from home

Chris Blackburn midwire

🏠
Working from home
View GitHub Profile
@kch
kch / 0-tm-align-assignments.rb
Created December 19, 2009 12:33
fancier align assignments command for textmate
#!/usr/bin/env ruby1.9
# encoding: UTF-8
# Copyright © 2009 Caio Chassot
# Licensed under the WTFPL
def alternation(*s); s.map(&Regexp.method(:escape)).join("|") end
# All input is read here.
LINES = $stdin.readlines
IS_SELECTION = ENV.key?("TM_SELECTED_TEXT")
@waseem
waseem / easy_tunnel.rake
Created July 11, 2010 05:12
A Rake interface to creating a tunnel using ssh.
##
# A Rake interface to creating a tunnel using ssh.
# This file originally comes with the facebooker gem for Ruby on Rails: http://github.com/mmangino/facebooker
#
# How to use:
# 1. Simply put it at a proper place. e.g. lib/tasks/ in your Rails application
# 2. Create a config file 'easy_tunnel.yml' like following:
#
# development:
# public_host_username: host_user_name
@chrisyour
chrisyour / Folder Preferences
Created December 4, 2010 20:05
Show hidden files and hidden folders (except .git) in your TextMate project drawer
# Want to show hidden files and folders in your TextMate project drawer? Simple, just modify the file and folder patterns in TextMate's preferences.
# Instructions:
# Go to TextMate > Preferences...
# Click Advanced
# Select Folder References
# Replace the following:
# File Pattern
@avdi
avdi / exception_tester.rb
Created January 10, 2011 04:28
A proof of concept for exception testing in Ruby
require 'set'
class ExceptionTester
class TestException < Exception
end
# Accepts a block containing the code you want to make exception safety
# assertions about.
def initialize(&exercise)
@exercise = exercise

Fibur

Fibur is a library that allows concurrency during Ruby I/O operations without needing to make use of callback systems. Traditionally in Ruby, to achieve concurrency during blocking I/O operations, programmers would make use of Fibers and callbacks. Fibur eliminates the need for wrapping your I/O calls with Fibers and a callback. It allows you to write your blocking I/O calls the way you normally would, and still have concurrent execution during those I/O calls.

Example

Say you have a method that fetches data from a network resource:

@alexbevi
alexbevi / pre-commit.sh
Created August 23, 2012 12:05
Git pre-commit hook that checks ruby source files for Pry breakpoints
# Git pre-commit hook to check all staged Ruby (*.rb/haml/coffee) files
# for Pry binding references
#
# Installation
#
# ln -s /path/to/pre-commit.sh /path/to/project/.git/hooks/pre-commit
#
# Based on
#
# http://codeinthehole.com/writing/tips-for-using-a-git-pre-commit-hook/
@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 22, 2024 05:53
Useful PostgreSQL Queries and Commands
-- show running queries (pre 9.2)
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query
FROM pg_stat_activity
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%'
ORDER BY query_start desc;
-- show running queries (9.2)
SELECT pid, age(clock_timestamp(), query_start), usename, query
FROM pg_stat_activity
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%'
@jjb
jjb / gist:7389552
Last active March 16, 2024 18:48
Ruby 2.1 memory configuration

This all applies to Ruby 2.1. In some cases a setting is not available in 2.0, this is noted. There is also a different with 1.9, 1.8, and REE --- these are not noted.

All the relevant code is in https://github.com/ruby/ruby/blob/master/gc.c

RUBY_HEAP_MIN_SLOTS

default: 10000

The number of heap slots to start out with. This should be set high enough so that your app has enough or almost enough memory after loading so that it doesn't have to allocate more memory on the first request (althogh this probably isn't such a big deal for most apps).

(todo: figure out how big a slot is. i think the answer can be infered from this code.)

@midwire
midwire / Guardfile
Last active December 31, 2015 07:09
DRY Guardfile with defined groups for running in focused mode or default mode. Switch at the Guard prompt using scope focus, or scope default.
# Run Guard normally. This Guardfile defines 2 groups:
# 1) default: This is the default group and will run all appropriate specs when anything changes.
# 2) focus: This is the group you want when you are focusing on a specific spec or context of specs. When in this
# scope Guard will only run specs tagged with :focus.
#
# Example:
# context "GET on :index, /", focus: true do
# ...
# end
#
@midwire
midwire / string.rb
Created January 20, 2014 16:16
String extension class
class String
class << self
def random(count = 6, ranges = [('a'..'z'),('A'..'Z'),('0'..'9')])
o = ranges.map{|i| i.to_a}.flatten;
string = (0..(count-1)).map{ o[rand(o.length)] }.join;
end
end
def left(count)