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
class A | |
def with(&block) | |
instance_eval(&block) | |
end | |
private | |
def private_blarg | |
puts 'this is from a private method' | |
end | |
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
#!/usr/bin/env ruby | |
# Contrived example of self-pipe preventing signal race condition prior to select() | |
# @see http://cr.yp.to/docs/selfpipe.html | |
# @author Paul Annesley | |
SELF_READ, SELF_WRITE = IO.pipe | |
@run = true | |
trap :INT do |
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 | |
# | |
# Are you one of the 10% of programmers who can write a binary search? | |
# http://reprog.wordpress.com/2010/04/19/are-you-one-of-the-10-percent/ | |
def bin_search(search, subject) | |
discarded_left = 0 | |
while subject.any? |
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
#!/bin/bash | |
# Attempts to fast-forward the current local branch to its remote tracked branch. | |
# Safely refuses if there is no remote tracking, or if a fast-forward is not possible. | |
# @author Paul Annesley | |
if [ -n "$(git merge --ff-only 2>&1 | grep 'unknown option')" ]; then | |
echo "Your git doesn't seem to support --ff-only... try git 1.7+" | |
exit 1 | |
fi |
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
-- bundlua: a css/javascript bundler written in LUA for lighttpd's mod_magnet | |
-- Paul Annesley : paul@annesley.cc : 2007-02-12 | |
-- URL format: /bundle/file1.css,file2.css | |
-- include trailing slash for directories | |
local urlPrefix = '/bundle/' | |
local basedir = '/path/to/htdocs/' | |
local cssDir = basedir .. 'css/' | |
local jsDir = basedir .. 'js/' | |
local cacheDir = '/path/to/cache/dir/' |
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 StoresIpAddress | |
extend ActiveSupport::Concern | |
included do | |
def self.stores_ip_address(attr) | |
define_method(attr) do | |
require "ipaddr" |
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
## | |
# spec/support/garbage_collection.rb | |
# | |
# Inspired by: | |
# http://www.rubyinside.com/careful-cutting-to-get-faster-rspec-runs-with-rails-5207.html | |
# | |
# At time of writing: | |
# reduces duration from ~16.7sec to ~15.7sec (6% improvement) | |
# increases peak memory usage from 150mb to 200mb (33% increase) |
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
## | |
# Aggregation | |
# http://ar.rubyonrails.org/classes/ActiveRecord/Aggregations/ClassMethods.html | |
module ComposableOfMoney | |
extend ActiveSupport::Concern | |
included do |
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
#include <stdlib.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include "fat.h" | |
#define FS_PATH "sample.fat16" | |
int main() { | |
print_boot_sector(); |
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
namespace :unicorn do | |
## | |
# Tasks | |
desc "Start unicorn" | |
task(:start) { | |
config = rails_root + "config/unicorn.rb" | |
sh "bundle exec unicorn --daemonize --config-file #{config}" | |
} |
OlderNewer