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
@midwire
midwire / Fix_Linkedin.user.js
Last active June 1, 2016 14:44
Remove the extremely annoying prompt to update your profile on Linkedin.
// ==UserScript==
// @name Fix_Linkedin
// @namespace linkedin.com
// @description Remove the extremely annoying prompt to update your profile.
// @include https://*.linkedin.com/*
// @include http://*.linkedin.com/*
// @version 0.0.5
// @grant GM_addStyle
// ==/UserScript==
@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)
@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
#
@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.)

@rgreenjr
rgreenjr / postgres_queries_and_commands.sql
Last active May 10, 2024 17:12
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%'
@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/

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:

@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
@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
@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