Skip to content

Instantly share code, notes, and snippets.

View Orion98MC's full-sized avatar

Thierry Passeron Orion98MC

View GitHub Profile
class Notification < ActiveRecord::Base
serialize :device_ids # weak reference to devices
validates_presence_of :message
default_scope order("created_at DESC")
scope :ready, where("ready == ?", true)
scope :sent, where("sent_at IS NOT NULL")
scope :not_sent, where("sent_at IS NULL")
scope :sendable, not_sent.ready
scope :old, lambda{ where("updated_at < ?", 10.days.ago) }
@Orion98MC
Orion98MC / gist:840596
Created February 23, 2011 15:56
restful route spec query intereface
match '/restful_spec/:controller', :via => :get, :to => proc {|env|
routes = Rails.application.routes.routes.select{ |route| route.defaults[:controller] == env["action_dispatch.request.path_parameters"][:controller] }.collect {|route| {:verb => route.verb.to_s, :path => route.path}}
[
200,
{"Content-Type" => "text/html"},
[routes.to_json]
]
}
var Db = require('mongodb').Db,
Connection = require('mongodb').Connection,
Server = require('mongodb').Server;
var db = new Db('mongo-test', new Server("localhost", Connection.DEFAULT_PORT, {}), {native_parser:false});
var collection; // Global collection
var onConnect = function(err, db) {
db.dropDatabase(function() {
var fs = require('fs'), vm = require('vm'), path = require('path');
var repl = require('repl');
// Add source ability
repl.REPLServer.prototype.source = function (file) {
if (!~file.indexOf('.')) file += '.js';
if (path.existsSync(file)) {
vm.runInContext(fs.readFileSync(file).toString(), this.context);
} else {
this.outputStream.write('ERROR: file not found "' + file + '"\n');
}
var http = require('http'),
sys = require('sys');
var options = {
host: 'graph.facebook.com',
port: 443,
path: '/me'
};
http.get(options, function(response) {
var socket = io.connect(host, {port: port});
socket.on('route', function (data) { // data = "host:port"
console.log("routed to new host " + data);
socket.disconnect();
socket.socket.options.host = data.split(":")[0];
socket.socket.options.port = data.split(":")[1];
socket.socket.connect();
});
(function() {
// Module scope
var global = this;
// Helper functions
function foo() {
}
var Widget = function (elementId, options) {
this.scope = "bar";
(function() {
// Module scope
var global = this;
// Helper functions
function foo() {
return "module foo";
}
(function() {
// Module scope
var global = this;
// Helper functions
function foo() {
return "module foo";
}
(function() {
// Module scope
var global = this;
// Private methods hook
var private = {};
// Helper functions
function foo() {
return "Helper foo";