Skip to content

Instantly share code, notes, and snippets.

View liufengyun's full-sized avatar

Fengyun Liu liufengyun

View GitHub Profile
@mcantelon
mcantelon / Mongoose example
Created April 1, 2011 05:15
Mongoose example
// from Horofox in #node.js
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/mydb');
function allowPosts(mongoose) {
var Schema = mongoose.Schema;
var Posts = new Schema({
name : String,
subject: String,
comment : String,
@jonastemplestein
jonastemplestein / EventEmitter.coffee
Created February 6, 2011 09:37
A CoffeeScript port of the nodejs EventEmitter
isArray = Array.isArray or (obj) ->
obj.constructor.toString().indexOf("Array") isnt -1
default_max_listeners = 10
class EventEmitter
setMaxListeners: (n) ->
@_events.maxListeners = n
emit: (type) ->
@shripadk
shripadk / gist:652819
Created October 29, 2010 03:10
Express authentication using Redis for session store and Couchdb for database (in coffeescript!)
###
Module dependencies
###
require.paths.unshift "#{__dirname}/lib/support/express-csrf/"
require.paths.unshift "#{__dirname}/lib/support/node_hash/lib/"
express = require 'express'
app = module.exports = express.createServer()
RedisStore = require 'connect-redis'
@nijitaro
nijitaro / .autotest
Created September 7, 2010 18:06 — forked from ukstudio/Gemfile
Rails 3 + rspec2 + mongoid + Factory_girl + autotest(growl)
# Include plugins
require 'autotest/fsevent'
require 'autotest/growl'
# Skip some paths
Autotest.add_hook :initialize do |autotest|
%w{.git .DS_Store ._* vendor}.each { |exception| autotest.add_exception(exception) }
false
end
@ismasan
ismasan / gist:464257
Created July 5, 2010 11:30
Event-emitter module for Javascript objects
/* Abstract event binding
Example:
var MyEventEmitter = function(){};
MyEventEmitter.prototype = new AbstractEventsDispatcher;
var emitter = new MyEventEmitter();
// Bind to single event
emitter.bind('foo_event', function(data){ alert(data)} );
@zhengjia
zhengjia / capybara cheat sheet
Created June 7, 2010 01:35
capybara cheat sheet
=Navigating=
visit('/projects')
visit(post_comments_path(post))
=Clicking links and buttons=
click_link('id-of-link')
click_link('Link Text')
click_button('Save')
click('Link Text') # Click either a link or a button
click('Button Value')
Model.define('User',{
collection : 'test_user', // (optional) if not present uses the model name instead.
// defines your data structure
types: {
_id : Object, // if not defined, Mongoose automatically defines for you.
username: String,
first : String,
last : String,
// Released under MIT license: http://www.opensource.org/licenses/mit-license.php
$('[placeholder]').focus(function() {
var input = $(this);
if (input.val() == input.attr('placeholder')) {
input.val('');
input.removeClass('placeholder');
}
}).blur(function() {
var input = $(this);
@tarao
tarao / primes.java
Created April 15, 2010 16:08
Enumerating prime numbers in Featherweight Java
////////////////////////////////////////////////
// Lazy evaluation
class Obj extends Object {
Obj(){ super(); } Obj eval(){ return this; }
}
////////////////////////////////////////////////
// Error indicator
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Update 7 Oct 2010:
# - This example does *not* appear to work with Chrome >=6.0. Apparently,
# the WebSocket protocol implementation in the cramp gem does not work
# well with Chrome's (newer) WebSocket implementation.
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby