Skip to content

Instantly share code, notes, and snippets.

gem "rails", "~> 3.2.0"
require "active_record"
require "logger"
ActiveRecord::Base.establish_connection(
adapter: "sqlite3",
database: ":memory:"
)
puts ActiveRecord::VERSION::STRING
# Download file from URL + Upload to your server + Copy short URL to your clipboard
# Use it like this:
# gi http://25.media.tumblr.com/tumblr_md2j4a4Eot1rddgbmo1_1280.png
# And get something like this:
# tumblr_md2j4a4Eot1rddgbmo1_1280.png 100% 41KB 41.4KB/s 00:00
# Copied to the clipboard: http://goo.gl/ITEIG
@txus
txus / Readme.md
Created June 18, 2012 21:36
Vimcov runs a Ruby script and opens Vim marking the lines that were actually run

vimcov

Vimcov runs a Ruby script and opens Vim marking the lines that were actually run.

This could be useful when debugging long methods with lots of branching -- instead of abusing puts, you can just use Vimcov and you're good to go.

It runs only in Ruby 1.9.x.

Future versions will include more tight integration with test runs or Rails or whatever.

@foca
foca / singleton.coffee
Created January 18, 2012 22:39
Small implementation of Singletons for Backbone
# Public: generates a mixable singleton implementation dependent on a model key.
# Once you mix it into a model, your model gains an .instance method that will
# generate an object and cache it. Further calls to the .instance methods will
# return the same object.
#
# key - The name of the attribute we use to index instances. Defaults to "id".
#
# Example
#
# # Called without arguments uses the "id" as key.
@felixge
felixge / command.sh
Created October 29, 2011 13:43
Bash stuff for fighting a weak DOS attack
# Here a few bash one-liners that helped me analyze / fight a weak DOS attack against debuggable.com. Mostly for future reference.
# The attacker was opening lots of tcp connections without sending data, I believe it's called a SYN flood, see: http://tools.ietf.org/html/rfc4987#section-3.2
# Step 0: Check what is going on at port 80
$ netstat -tan | grep ':80 ' | awk '{print $6}' | sort | uniq -c
# Step 1: Increase the number of available fds
$ ulimit -n 32000
# Step 2: Restart your webserver, for me:
@jamesu
jamesu / Capfile.rb
Created June 23, 2011 21:47
Deploying chef with capistrano
# Deploying chef with capistrano
# Requires a typical chef config layout, i.e.
# cookbooks/
# nodes/
# roles/
#
# Commands:
# configure:<node> - Upload chef cookbooks, run chef-solo
#
# Roles will automatically be added from nodes/*.json. e.g. if you have
@calavera
calavera / gist:790579
Created January 21, 2011 22:41
Kata de api fluida
class User
attr_reader :name, :age
def initialize(name, age)
@name, @age = name, age
end
end
class Filter
attr_reader :method, :value
def initialize(method, value)
@BugRoger
BugRoger / ssh-background
Created January 21, 2011 16:02
Changes iTerm2's background color based on host configuration
#!/bin/bash
# Installation:
# 1. Save this script to /some/bin/ssh-background
# 2. chmod 755 /some/bin/ssh-background
# 3. alias ssh=/some/bin/ssh-background
# 4. Configure your host colors below.
set_color() {
local HEX_FG=$1
local HEX_BG=$2
@rgo
rgo / .rvmrc
Created October 21, 2010 09:57
.rvmrc example
rvm_gemset_create_on_use_flag=1
rvm gemset use project_name