Skip to content

Instantly share code, notes, and snippets.

require 'bcrypt'
module EasyAuth
# http://techspeak.plainlystated.com/2010/03/drop-dead-simple-authentication-for.html
# To generate a crypted password (in irb):
# require 'easy_auth'
# EasyAuth.encrypt_password('my_password') # Put returned array in AUTHORIZED_USERS
AUTHORIZED_USERS = {
helpers do
def protected!
response = callcc do |cont|
auth = Rack::Auth::Digest::MD5.new(cont, "Administrator only") do |username|
"password" # username is ignored, or Password is always 'password' in this example.
end
auth.opaque = $$.to_s
auth.call(request.env)
end
@squarism
squarism / mongodb_sharding.txt
Created August 26, 2011 18:36
MongoDB sharded cluster install
OS Setup
- Install VMs (base OS = Ubuntu 11.04)
- 6GB disk is not enough. Probably 20-40GB would be good. Mongo has a lot of compression and cleanup features coming.
- Create user to run MongoDB as
- Get DNS or Hosts file set up so all nodes in the cluster can talk to each other
- Generate ssh-keygen -t rsa
- Copy ssh public keys from each node to node01. Then cat all keys to authorized_keys. Then copy that file to each node. Each node will have ssh key trust now. You will also want to ssh from node01 to 02,03,04; from node02 to 01,03,04 etc to test it out.
- Create an initial architecture:
node01: master (replica set 1)
node02: slave (replica set 1)
db.getSiblingDB("admin");
var databases = null;
databases = db.runCommand("listDatabases");
if(databases){
for(var i=0;i<databases.databases.length;i++){
//TODO skip if it's the admin database
@havenwood
havenwood / mac-app.rb
Created September 5, 2012 21:53
Create an OS X .app Executable With Your Choice Of Language For Script
require 'builder'
module MacApp
class << self
def new
ask_name
ask_file_extension
ask_language
create_directories
@TylerBrock
TylerBrock / gist:3761635
Created September 21, 2012 14:03 — forked from olistik/gist:2627011
Ubuntu 12.04 setup (rbenv, janus, postgres)

Basic pre-requisites

  • Some utilities:
sudo apt-get install vim tmux git
  • Copy/paste from the command line:
sudo apt-get install xclip
@rogernolan
rogernolan / gist:95ea615164e343b3bc54
Last active November 6, 2015 19:57
Parse.com Cloudcode to Loggly logger
///
/// A very simple Loggly client for Parse.com cloudcode.
/// Usage:
/// logger = require('cloud/libs/logger');
/// logger.setToken('your-loggly-token', 'appname'); // Appname is optional.
///
/// logger.log("A String to Log", {'key': 'Extra fields to add to loggly entry'});
/// /// The logger will add a few fields replicating the iOS client fields to help filtering and setting up a grid view on Loggly.
///
/// logger.setConsoleLogging(false); // Stop the logger exhoing to Parse's console.

ruby-1.9.3-p362 cumulative performance patch for rbenv

This installs a patched ruby 1.9.3-p362 with the railsexpress patchsets: https://github.com/skaes/rvm-patchsets

Requirements

You will also need a C Compiler. If you're on Linux, you probably already have one or know how to install one. On OS X, you should install XCode, and brew install autoconf using homebrew.

@bpierre
bpierre / Makefile
Created November 5, 2011 17:34
A Makefile to concatenate / minify my JS Scripts and convert/compress my Stylus (CSS preprocessor) files
# JS files
JS_FINAL = js/project-name-all.js
JS_TARGETS = js/file1.js \
js/file2.js \
js/file3.js
# CSS files
CSS_FINAL = css/project-name-all.css
STYLUS_TARGETS = css/file1.styl \
@m0n5t3r
m0n5t3r / gunicorn-upstart.conf.template
Created July 30, 2010 12:27
template for a gunicorn upstart job that can run several instances of a django application
# %(mysite)s - run %(mysite)s instances (default is the main production instance)
#
# This runs gunicorn-django for %(mysite)s; to install:
# * sudo ln -s <this file> /etc/init/%(mysite)s
# * sudo initctl reload-configuration
#
# it expects the following directory layout:
#
# /home/%(mysite)s/public_html
# \-env -> virtualenv