Skip to content

Instantly share code, notes, and snippets.

Factory.define :application do |factory|
factory.attachment(:sample, "public/samples/sample.doc", "application/msword")
end
@mscottford
mscottford / watir_wait.rb
Created January 7, 2010 13:43
Dynamically adds "wait_to_" variants for common watir methods. Calling these variants will force the browser to first wait for the browser to finish, and then to wait for the specified element to exist before performing the desired action.
require 'watir'
require 'watir/container'
require 'watir/element'
require 'watir/input_elements'
require 'watir/link'
def support_wait_to_methods
timeout_in_seconds = 30
original_method_missing = self.instance_method(:method_missing)
@rustyio
rustyio / subhg
Created January 24, 2010 18:54
subhg
#!/usr/bin/env sh
# subhg
#
# A tiny wrapper around hg to help you manage
# Mercurial sub-projects easily, safely, and simply.
#
# Created by Rusty Klophaus (@rklophaus)
#
# See http://rklophaus.com/subhg for usage.
@jeffrafter
jeffrafter / factory_girl attachments for paperclip
Created May 30, 2010 13:26
factory_girl attachments for paperclip
require 'action_controller/test_process'
# Paperclip attachments in factories, made easy based on technicalpickles
Factory.class_eval do
def attach(name, path, content_type = nil)
if content_type
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}", content_type)
else
add_attribute name, ActionController::TestUploadedFile.new("#{RAILS_ROOT}/#{path}")
end
var dashes = ""; var num = 20; while(--num) dashes += "-"; setInterval(function() { window.history.pushState("", "", '/sticky-history?' + dashes.slice(0, num % 20) + "foo" + dashes.slice(num % 20)); num++;}, 100);
## /config/initializers/dynamic_job.rb
require 'heroku'
# base class for all jobs that you wish to automatically scale and go down in Heroku
class DynamicJob
#set a cap on maximum number of users ever - just in case.
MAX_CONCURRENT_WORKERS = 100
def initialize
@jarib
jarib / file.rb
Created October 6, 2010 11:27
watir page objects
require "rubygems"
require "watir-webdriver"
class BrowserContainer
def initialize(browser)
@browser = browser
end
end
#
@fcalderan
fcalderan / inception-javascript.js
Created November 2, 2010 09:42
inception explained as a 4 nested javascript closures
/*
* Fabrizio Calderan, twitter @fcalderan, 2010.11.02
* I had an idea: could Inception movie be explained by a few javascript closures
* and variable resolution scope (just for fun)?
*
* Activate javascript console =)
*/
<script>
console.group("inception movie");
@tlrobinson
tlrobinson / google-translate-drums.js
Created November 30, 2010 06:19
A drum machine for the German Google Translate. See instructions in comments below.
(function() {
// Notes from http://news.ycombinator.com/item?id=1952531
var notes = {
"suspended cymbal":"zk",
"snare":"bschk",
"brush":"pv",
"bass":"bk",
"flam1":"tk",
"roll tap":"vk",
"flam2":"kt",
@pgriess
pgriess / demo.py
Created December 19, 2011 01:12
Script to stream audio from Rdio
#!/bin/env python
#
# Demo tool to generate the rtmpdump(1) command for streaming a song from Rdio.
import httplib
from optparse import OptionParser
from os.path import basename
from pprint import pprint
from pyamf.remoting.client import RemotingService
from rdioapi import Rdio