Skip to content

Instantly share code, notes, and snippets.

j-manu / fizzbuzz.rb
Created Aug 3, 2012 — forked from judofyr/fizzbuzz.rb
Writing FizzBuzz with flip-flops
View fizzbuzz.rb
a=b=c=(1..100).each do |num|
print num, ?\r,
("Fizz" unless (a = !a) .. (a = !a)),
("Buzz" unless (b = !b) ... !((c = !c) .. (c = !c))),
View .vimrc
"" Thanks:
"" Gary Bernhardt <>
"" Drew Neil <>
"" Tim Pope <>
"" Janus <>
set nocompatible
j-manu /
Created Jun 30, 2012 — forked from ljos/
Showing how to listen to all keypresses in OS X through the Cocoa API using Python and PyObjC
# by Bjarte Johansen is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
from AppKit import NSApplication, NSApp
from Foundation import NSObject, NSLog
from Cocoa import NSEvent, NSKeyDownMask
from PyObjCTools import AppHelper
class AppDelegate(NSObject):
def applicationDidFinishLaunching_(self, notification):
mask = NSKeyDownMask
j-manu / rails_routing_invalid_chars_fix.rb
Created May 30, 2012 — forked from bensomers/rails_routing_invalid_chars_fix.rb
3.0.x monkeypatch for fixing Invalid Char 500s
View rails_routing_invalid_chars_fix.rb
# Fix for a Rails - Ruby 1.9 bug
# Rails Router, now that it's UTF-8 default, blows up when routing requests
# with invalid chars in the URL; it should properly return a 400 error
# Have to monkey-patch the fix in, since it's not scheduled for release until
# Rails 4.0.
# Adapted Andrew White (pixeltrix)'s fix at
# but edited to work in 3.0.x.
# 3.1.x, 3.2.x compatibility unknown
require 'action_dispatch/routing/route_set'
j-manu / gist:2762570
Created May 21, 2012 — forked from jpallen/gist:2762417
Add a .findOrBuild() method to Backbone Models
View gist:2762570
// keep models fetched in different views in sync
// Finding and creating models
// ===========================
// We might need to get a reference to a model from anywhere in our code
// and we want to make sure that these references all point to the same model.
// Otherwise updates to one copy of the model won't affect another.
// The methods here let you get models through a wrapper that will either
// create the model if it doesn't exist anywhere, or return a reference to
View gist:2645620
class UserRegistrationService
def initialize(params)
@params = params
def register
user =
# send_email
j-manu / uri.js
Created Apr 21, 2012 — forked from jlong/uri.js
URI Parsing with Javascript
View uri.js
var parser = document.createElement('a');
parser.href = "";
parser.protocol; // => "http:"; // => ""
parser.port; // => "3000"
parser.pathname; // => "/pathname/"; // => "?search=test"
parser.hash; // => "#hash"
j-manu / gist:2246085
Created Mar 30, 2012 — forked from iwinux/gist:1529093
View gist:2246085
def compile_asset?(path)
# ignores any filename that begins with '_' (e.g. sass partials)
# all other css/js/sass/image files are processed
if File.basename(path) =~ /^[^_].*\.\w+$/
puts "Compiling: #{path}"
puts "Ignoring: #{path}"
View admin.rb
# Let's assume these models Department, Subject, User, Allotment, Test
# Allotment table has department_id, subject_id, user_id
# Test table has department_id, :subject_id
# Problem: allow the user to edit a test if he is alloted the subject
# for that department OR if he is special (dean) OR if the number of allotments
# of that user in that department exceeds 3
class Ability
j-manu / gist:1559754
Created Jan 4, 2012 — forked from dx7/gist:1333785
Installing ruby-debug with ruby-1.9.3-p125
View gist:1559754
# Install with:
# bash < <(curl -L
# Reference:
echo "Installing ruby-debug with ruby-1.9.3-p125 ..."
curl -OL
curl -OL