Skip to content

Instantly share code, notes, and snippets.

# Rails example
recipe :ignore
ignore(/(^tmp|jpg|png|gif|css|\.DS_Store)$/)
recipe :rails
process do |files|
Ruby.run_tests(files.take_and_map do |file|
case file
@raggi
raggi / eventmachine_is_web_scale.rb
Created September 1, 2010 01:34
the secrets of the web scale sauce
require 'eventmachine'
EM.run do
SEKRET_SAUCE = EM.attach(
open(RUBY_PLATFORM =~ /mswin|mingw/ ? 'NUL:' : '/dev/null', 'w')
)
EM.start_server('0.0.0.0', 80, Module.new do
def post_init; proxy_incoming_to(SEKRET_SAUCE); end
end)
end
@foca
foca / job.rb
Created July 22, 2011 18:29
I don't really care for running Resque in dev or test environments.
class Job
LAZY_ENVIRONMENTS = %w(development test)
# Add a job to the queue. If we're currently running in any of the
# environments listed in +LAZY_ENVIRONMENTS+ then it automatically performs
# the job.
def self.enqueue(*args)
if LAZY_ENVIRONMENTS.include? Rails.env
Rails.logger.debug "Performing job instead of enqueuing: #{name}"
perform(*args)
Make a keyboard shortcut to run a shell script with Alfred or Quicksilver, and point it at
/System/Library/CoreServices/Menu\ Extras/User.menu/Contents/Resources/CGSession -suspend
@garth
garth / Jakefile.js
Created December 1, 2011 12:06
Example Jakefile from ViennaJS meetup
// Jake is like Rake for nodejs https://github.com/mde/jake
//
// Assumes that Jake will be run in the root of the web app with coffee files in /js/ and
// a single app.less file in /css/ that can include references to other .less files
//
//requires
var sys = require('util');
var execute = require('child_process').exec;
var fs = require('fs');
@krzysztofzablocki
krzysztofzablocki / gist:4396302
Last active November 24, 2021 19:17
Set symbol breakpoint on objc_msgSend then setup this debug command to log all methods called in iOS Simulator. If you want to do device debugging change esp+4 register to r0, esp+8 to r1 Found long ago somewhere on stackoverflow.
expr -- (void)printf("[%s, %s]\n",(char *) object_getClassName(*(long*)($esp+4)), (char *) *(long *)($esp+8) )
@kommen
kommen / postgres-bloat.sql
Created March 1, 2013 15:32
How much space is wasted by your Postgres database due to table and index bloat.
-- Based on http://pgsql.tapoueh.org/site/html/news/20080131.bloat.html
-- see that linked version for detailed table and index listings on where that bloat is
SELECT pg_size_pretty(SUM(bs*(relpages-otta))::bigint) AS wastedsize,
pg_size_pretty(SUM(CASE WHEN ipages < iotta THEN 0 ELSE bs*(ipages-iotta) END)::bigint) AS wastedisize
FROM (
SELECT
schemaname, tablename, cc.reltuples, cc.relpages, bs,
CEIL((cc.reltuples*((datahdr+ma-
(CASE WHEN datahdr%ma=0 THEN ma ELSE datahdr%ma END))+nullhdr2+4))/(bs-20::float)) AS otta,
COALESCE(c2.relname,'?') AS iname, COALESCE(c2.reltuples,0) AS ituples, COALESCE(c2.relpages,0) AS ipages,
div.description a.autolink
{
display: inline-block;
max-width: 250px;
text-overflow: ellipsis;
overflow: hidden;
}
@alloy
alloy / Rakefile
Last active March 23, 2016 10:36
A Rakefile that standardises program env installation and guides the user, as opposed to crashing with Ruby exceptions such as `LoadError`. The only case where this will *never* work reliably is if you use the `rubygems-bundler` (NOEXEC) plugin, which introduces chicken-and-egg problems.
# Do *not* load any libs here that are *not* part of Ruby’s standard-lib. Ever.
desc "Install all dependencies"
task :bootstrap do
if system('which bundle')
sh "bundle install"
sh "git submodule update --init"
# etc
else
$stderr.puts "\033[0;31m[!] Please install the bundler gem manually: $ [sudo] gem install bundler\e[0m"
@kmikael
kmikael / dispatch_async
Created June 13, 2014 15:06
Update `dispatch_async` to take a default `queue`
import Dispatch
func dispatch_async(queue: dispatch_queue_t = dispatch_get_main_queue(), block: dispatch_block_t) {
Dispatch.dispatch_async(queue, block)
}
dispatch_async {
// Update the UI
}