This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class JsonController < ApplicationController | |
rescue_from ActiveRecord::RecordNotFound do |exception| | |
render :json => { :success => false }, :status => :not_found | |
end | |
before_filter :find_record, :only => [ :get, :update, :destroy ] | |
layout 'base' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ModelDiscovery | |
def self.models_hash | |
@active_record_classes ||= valid_active_record_classes.index_by do |model| | |
model.table_name | |
end | |
end | |
def self.model_file_names | |
@model_file_names ||= Dir['app/models/*.rb'].map {|f| | |
File.basename(f, '.*') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Represents a string that isn't surrounded by quotes when converted to JSON. | |
# Originally created to be able to create ruby hashes containing javascript | |
# function definitions that could be converted to JSON easily. | |
# | |
# Use it like this: | |
# {:number = > 10, | |
# :date => Time.now, | |
# :regular_string => "Some Quoted Text", | |
# :unquoted_string => UnQuotedString("function(){ alert('you can create a function'); }") | |
# }.to_json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var util = exports || {}; | |
util.mergeDeep = function (A, B, depth) { | |
var forever = depth == null; | |
for (var p in B) { | |
if (B[p] != null && B[p].constructor==Object && (forever || depth > 0)) { | |
A[p] = util.mergeDeep( | |
A.hasOwnProperty(p) ? A[p] : {}, | |
B[p], |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Adds .previous and .next class methods to your model treating the records in your database like a sequential list | |
# | |
# Put this in your model definition: | |
# acts_as_sequential :column => :created_at # you can also use the :dir => 'DESC' option (ASC is the default) | |
# | |
# Then use it like this: | |
# Model.next(current_record) -> next record in sequence | |
# Model.other_named_scope.previous(current_record) -> previous record in sequence | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* Provides a simple interface to the gzip executable found on the system, should work in all *nix environments. | |
* Keep in mind that this spawns a process, so don't go using for every request, only use it in non-time-sensitive places | |
* Thanks mostly go to 3Rd-Eden who created the original code in a pull-request to Socket.IO-node | |
*/ | |
var child_process = require('child_process'); | |
module.exports.gzip = function(buffer, callback){ | |
var gzip = child_process.spawn('gzip', ['-9']) | |
, buffers = [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Usage: | |
// express_app.register('html', htmlRenderer({stripNewlines: true})); | |
// ... | |
// express_app.get('/plain', function(req, res){ | |
// res.render('./path_to_html_file'); | |
// }) | |
function htmlRenderer(opt){ | |
var stripNewlines = opt && opt.stripNewlines; | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Allows easy composition of a chain of connect.js-style middlewares in node.js | |
// given: | |
// function A(req,res,next){} | |
// function B(req,res,next){} | |
// composeMiddleware(A,B) will return a function(req,res,next) that passes the request | |
// through both handlers, just like Connect. If a next() is called with an error | |
// the call chain is stopped and the error is passed to the topmost next() | |
// If next() is called with the second parameter set to 'break' "next(null, 'break')" | |
// The chain is halted and route control is passed back to the original next() | |
function composeMiddleware(){ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
SEARCH=$1 | |
REPLACE=$2 | |
function ConfirmOrExit() { | |
echo -n "Continue? (y / n) :" | |
read CONFIRM | |
if [ $CONFIRM != 'y' ] | |
then | |
exit |
OlderNewer