Skip to content

Instantly share code, notes, and snippets.

View atnan's full-sized avatar

Nathan de Vries atnan

View GitHub Profile
require 'rubygems' rescue nil
require 'gosu'
require 'chipmunk'
class Array
# e.g. [1,2,3].each_link yields [1,2], [2,3]
def each_link
prev = first
self[1, size].each do |item|
yield prev, item
(function(){
if (typeof boilerplate_bookmarklet == 'undefined') {
var stylesheet_url = 'http://example.com/bookmarklet.css';
var script_url = 'http://example.com/bookmarklet.js';
var head = document.getElementsByTagName('head')[0] || document.documentElement;
var stylesheet = document.createElement('link');
stylesheet.setAttribute('rel', 'stylesheet');
stylesheet.setAttribute('type', 'text/css');
(function(){
function l(u,i,t,b){
var d = document;
if (!d.getElementById(i)) {
var s = d.createElement('script');
s.src = u;
s.id = i;
d.body.appendChild(s);
}
# http://pivots.pivotallabs.com/users/nick/blog/articles/359-alias-method-chain-validates-associated-informative-error-message
# http://pastie.caboo.se/142774
module ActiveRecord::Validations::ClassMethods
def validates_associated(*associations)
associations.each do |association|
class_eval do
validates_each(associations) do |record, associate_name, value|
associates = record.send(associate_name)
associates = [associates] unless associates.respond_to?('each')
// http://jqueryjs.googlecode.com/svn/trunk/jquery/build/runtest/env.js
load('env.js');
// Could do window.location = 'http://...', but I'm lazy
window.document = new DOMDocument(new java.io.ByteArrayInputStream((new java.lang.String('<pewp />')).getBytes("UTF8")));
//Bring forth the convenience
load('prototype-1.6.0.2.js');
var Person = Class.create({
<VirtualHost *:80>
ServerName www.example.com
DocumentRoot /path/to/rails/app/public
RailsEnv production
RewriteEngine On
RewriteCond %{DOCUMENT_ROOT}/system/maintenance.html -f
RewriteCond %{SCRIPT_FILENAME} !maintenance.html
def rounded_block(options={}, &block)
raise ArgumentError, 'Missing block' unless block_given?
options.symbolize_keys!
concat(content_tag(:div, :id => options[:id], :class => ["rounded", options[:class]].compact.join(" ")) do
content_tag(:div, :class => "rounded-top") do
content_tag(:div, '', :class => "rounded-top-left") +
content_tag(:div, '', :class => "rounded-top-right") +
content_tag(:div, '', :class => "rounded-top-center")
end +
#!/usr/bin/env ruby
unless (urls = DATA.read.strip).empty?
puts urls
exit
end
require 'rubygems'
require 'hpricot'
require 'open-uri'
#!/usr/bin/env ruby
File.open(__FILE__, File::WRONLY) do |file|
file.truncate(DATA.pos)
file.seek(DATA.pos)
file.write('In your __FILE__, editing your datas')
end
__END__
Example POST of multiple resources:
POST http://example.com/users?
users[0][first_name]=John
users[0][last_name]=Doe
users[1][first_name]=Jane
users[1][last_name]=Doe
=====