Skip to content

Instantly share code, notes, and snippets.

View muloka's full-sized avatar
💖
I may be slow to respond.

Muloka muloka

💖
I may be slow to respond.
View GitHub Profile
@muloka
muloka / webapp.rb
Created November 16, 2010 21:41 — forked from igrigorik/webapp.rb
require 'rubygems'
require 'rack'
class Object
def webapp
class << self
define_method :call do |env|
func, *attrs = env['PATH_INFO'].split('/').reject(&:empty?)
[200, {}, send(func, *attrs)]
end
# layout_helper.rb
module LayoutHelper
def headjs
["/javascripts/jquery.js","/javascripts/rails.js","/javascripts/application.js"]
end
def headjs_show
"<script type='text/javascript'>
head.js('#{headjs.join('\',\'')}');
</script>"
// An Unobtrusive Javascript (UJS) driver based on explicit behavior definitions. Just
// put a "data-behaviors" attribute on your view elements, and then assign callbacks
// for those named behaviors via Behaviors.add.
var Behaviors = {
add: function(trigger, behavior, handler) {
document.observe(trigger, function(event) {
var element = event.findElement("*[data-behaviors~=" + behavior + "]");
if (element) handler(element, event);
});
@muloka
muloka / Super Simple Chat Server
Created January 17, 2011 20:46
Taken from Introduction to Node: Ryan Dahl
// source: http://camp.nodejs.org/videos/session-01_introduction_to_node-ryan_dahl.html
// Handles TCP connections
net = require('net');
// define global variables
people = []
// create tcp server
s = net.createServer(function(socket) {
@muloka
muloka / gist:809637
Created February 3, 2011 15:41
Reducing Friction by Chris Wanstrath
"...if there's one thing I've learned from Rails, it's to get the hell out of
the way and let people focus on the task at hand.
Reduce friction.
Newton's first law of motion, as commonly written, makes two statements: an
object at rest tends to stay at rest and an object in motion tends to stay in
motion. It's often referred to as the Law of Inertia.
And inertia, for those who don't remember or didn't take high school physics,
@muloka
muloka / gist:809640
Created February 3, 2011 15:41
Code, create, and share
Code, create, and share
- create solutions to sore points
- reduce friction, stream line processes
- create projects that scratch an itch or ease some pain
- start contributing to official documentation efforts
- focus more on community and less on yourself
Remember, Code talks.
- Talk (and read) less, Code More
- If you want to run your own business, code is the perfect way to find cofounders and employees
@muloka
muloka / gist:853425
Created March 3, 2011 20:09
JSMC Exercise 2 - Closures
(function (functionName, container){
var index;
function log(){
console.log(index);
}
function iterate(){
log();
if(index>1) setTimeout(iterate, 1000);
@muloka
muloka / gist:853572
Created March 3, 2011 21:09
JSMC Exercise 3
// functional
var logCar = function (obj){
return function(){
"I'm a" + obj.color + " " + obj.make;
}
}
// Example call for functional version:
logCar({ color: 'blue', make: 'BMW' });
var logCar = function (obj){ return "I'm a" + obj.color + " " + obj.make; }
// 1. Write a class to support the following code:
var Person = function(name) { this.name = name; }
var thomas = new Person('Thomas');
var amy = new Person('Amy');
thomas.name // --> "Thomas"
// 2. Add a getName() method to all Person objects, that outputs