This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Taken from passenger_memory_stats script | |
# Returns the private dirty RSS for the given process, in KB. | |
def determine_private_dirty_rss(pid) | |
total = 0 | |
File.read("/proc/#{pid}/smaps").split("\n").each do |line| | |
line =~ /^(Private)_Dirty: +(\d+)/ | |
if $2 | |
total += $2.to_i | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Factory girl, relaxed. | |
# | |
# Factory.define :user do |f| | |
# f.login 'johndoe%d' # Sequence. | |
# f.email '%{login}@example.com' # Interpolate. | |
# f.password f.password_confirmation('foobar') # Chain. | |
# end | |
# | |
# Factory.define :post do |f| | |
# f.user { Factory :user } # Blocks, if you must. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# More "proper" than a miniskirt (http://gist.github.com/273579). | |
class Minidress | |
@@factories = {} | |
class << self | |
def define(name, &block) | |
@@factories[name.to_s] = block | |
end | |
def build(name, attrs = {}) | |
new(name.to_s.classify.constantize.new, &@@factories[name.to_s]).record |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'open-uri' | |
require 'nokogiri' | |
class Array | |
module RegexpIndexing | |
def [] a | |
a.is_a?(Regexp) ? select {|b| b.is_a?(String) && b[a]} : super |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'rubygems' | |
require 'eventmachine' | |
require 'em-http' # gem install em-http-request | |
require 'yajl' # gem install yajl-ruby | |
module ChatClient | |
def post_init | |
@name = "anonymous_#{ChatClient.client_num+=1}" | |
@sid = ChatClient.channel.subscribe(method(:send_msg)) | |
@buf = '' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Author: Pieter Noordhuis | |
# Description: Simple demo to showcase Redis PubSub with EventMachine | |
# | |
# Requirements: | |
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby | |
# - a browser with WebSocket support | |
# | |
# Usage: | |
# ruby redis_pubsub_demo.rb | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module NokogiriUtils | |
extend self | |
# http://gist.github.com/370755 | |
def hash_from_node(node) | |
{ node.root.name.to_sym => xml_node_to_hash(node.root) } | |
end | |
def xml_node_to_hash(node) | |
return to_value(node.content.to_s) unless node.element? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
run "rm public/index.html" | |
file "Isolate", <<-END | |
gem "rails", "3.0.0" | |
gem "haml", "3.0.18" | |
gem "sqlite3-ruby", "1.3.1" | |
env :development do | |
gem "thin", "1.2.7" | |
gem "haml-rails", "0.2" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var setTextMeasure = function (contentElement, targetMeasure, maxSize, minSize) { | |
if (!contentElement) contentElement = document.createElement('p'); | |
if (!targetMeasure) targetMeasure = 66; | |
if (!maxSize) maxSize = 16; | |
if (!minSize) minSize = 9; | |
var sizer = contentElement.cloneNode(); | |
sizer.style.cssText = 'margin: 0; padding: 0; color: transparent; background-color: transparent; position: absolute;'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
cmd = %Q{curl https://gist.github.com/gists -s -L -o /dev/null -w "%{url_effective} " } | |
files = ARGV.empty? ? Dir["**/*"] : Dir[*ARGV].uniq | |
files.select { |f| File.file?(f) }.each_with_index do |path, i| | |
cmd << %Q{-F "file_ext[gistfile#{i}]=#{File.extname(path)[1..-1]}" } | |
cmd << %Q{-F "file_name[gistfile#{i}]=#{File.basename(path)}" } | |
cmd << %Q{-F "file_contents[gistfile#{i}]=<#{path}" } |
OlderNewer