Skip to content

Instantly share code, notes, and snippets.

@coderberry
coderberry / static-proxy.js
Created August 15, 2014 14:21
Proxy express app which allows passthrough requests (in order to maintain static IP)
// BASE SETUP
// =============================================================================
// call the packages we need
var express = require('express'); // call express
var app = express(); // define our app using express
var bodyParser = require('body-parser'); // allows parsing of post params
var request = require('request'); // enable performing http requests
// configure app to use bodyParser()
@mashpie
mashpie / i18n-express4-cookie-example.js
Last active August 12, 2021 15:48
i18n-express4-cookie-example
@tlowrimore
tlowrimore / union_scope.rb
Last active January 13, 2023 21:12
Unions multiple scopes on a model, and returns an instance of ActiveRecord::Relation.
module ActiveRecord::UnionScope
def self.included(base)
base.send :extend, ClassMethods
end
module ClassMethods
def union_scope(*scopes)
id_column = "#{table_name}.#{primary_key}"
sub_query = scopes.map { |s| s.select(id_column).to_sql }.join(" UNION ")
where "#{id_column} IN (#{sub_query})"
@joshed-io
joshed-io / example_group.rb
Created July 14, 2011 01:16
Easiest possible RSpec Performance Test w/ Scenarios
# here's a quick recipe to run a performance test
# with this method, you can:
#-> easily choose the examples you want included from your existing specs
#-> define the target number of total iterations you'd like, no limit
#-> tune the transaction mix by specifying frequency metadata for each example
#-> be happy that the transaction mix is fairly homogeneous over the test interval
# (ideally you'd run this with acceptance (webrat/capybara) specs, but you
# could employ this technique for any rspec test)