Skip to content

Instantly share code, notes, and snippets.

# routes.rb
# You can do this:
map.connect '/something/*email', :controller => 'something', :action=> 'some_action'
# ...to get the email parameter as an array.
# Then you can do this in your controller:
# something_controller.rb
email_address = params[:email][0]
Anders-Norass-MacBook-Pro:.ssh anders$ which pbcopy
/usr/bin/pbcopy
Anders-Norass-MacBook-Pro:.ssh anders$ cat id_rsa.pub | pbcopy
-bash:  pbcopy: command not found
Anders-Norass-MacBook-Pro:.ssh anders$
@anoras
anoras / demo.html
Created July 2, 2010 22:25
Code for my screencast at http://vimeo.com/13043828
<!doctype html>
<html>
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script src="client/socket.io.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript" charset="utf-8">
var socket = new io.Socket(null, {rememberTransport: false, port: 8080});
socket.connect();
socket.addEvent('message', function(data) {
$('body').append('<p>' + $.map(data, function(e,i) {
@anoras
anoras / Inheritance.js
Created July 12, 2010 20:28
Example of too clever JavaScript code for my JavaZone 2010 talk.
Object.prototype.inherits = function(base, args) {
if (arguments.length > 1) {
base.apply(this, Array.prototype.slice.call(arguments, 1));
} else {
base.call(this);
}
};
Function.prototype.inherits = function(base){
this.prototype = new base();
@anoras
anoras / LivingWithBugs.rb
Created July 30, 2010 20:28
It's been a while since I've written code like this :-)
# It's been a while since I've written code like this :-)
def encoding_error_fucks_up_html_length?(node)
# Are we experiencing this Nokogiri issue: http://github.com/tenderlove/nokogiri/issues/#issue/215
node.inner_html.length < node.inner_text.length
end
@anoras
anoras / mongo_paperclip.rb
Created August 3, 2010 12:14 — forked from anlek/mongo_paperclip.rb
Patching Paperclip to work with MongoMapper
module Paperclip
class << self
def logger #:nodoc:
# Paperclip depends on having a logger available, so let's create a nice fallback chain...
MongoMapper.logger || Rails.logger || Logger.new(STDOUT)
end
end
module ClassMethods
def has_attached_file name, options = {}
snehvit:~ anders$ gem install toto
Building native extensions. This could take a while...
Successfully installed rdiscount-1.6.5
Successfully installed toto-0.4.6
2 gems installed
Installing ri documentation for rdiscount-1.6.5...
Installing ri documentation for toto-0.4.6...
Installing RDoc documentation for rdiscount-1.6.5...
Installing RDoc documentation for toto-0.4.6...
snehvit:~ anders$ ruby -v
Function.prototype.memoize = function() {
var fn=this;
var args = Array.prototype.slice.call(arguments);
var target = args.length > 0 ? args[0] : null;
fn._vals = fn._vals || {};
return function() {
var call_args = Array.prototype.slice.call(arguments);
if (fn._vals[call_args] !== undefined) return fn._vals[call_args];
fn._vals[call_args] = fn.apply(target, arguments);
return fn._vals[call_args];
Del Close & John Brent - Basic Hip
Reuben Bell - Superjock
Archaeopterix - Samstag Abend, Sonntag Morgen
Les Maledictus Sound - Kriminal Theme
Joe Cogra Group - Darkness
Googoosh - Talagh
Lord Cobra Y Los Hnos. Duncan - Love Letters
Lonnie Mack - Too Much Trouble
Boobpa Saichol - Seng Rabird
Colosseum - The Kettle
@anoras
anoras / gist:741250
Created December 14, 2010 22:39
LOC kata
puts %q(
/*****
* This is a test program with 5 lines of code
* \/* no nesting allowed!
//*****//***/// Slightly pathological comment ending...
public class Hello {
public static final void main(String [] args) { // gotta love Java
// Say hello
System./*wait*/out./*for*/println/*it*/("Hello/*");
}