Skip to content

Instantly share code, notes, and snippets.

@mrkurt
mrkurt / Gemfile
Created August 21, 2011 19:10
The magical document eating has_many assignment
source :rubygems
gem 'mongoid'
@mrkurt
mrkurt / map.coffee
Created August 20, 2011 06:04
Testing Mongo map/reduce functions in isolation
map = ()->
return unless @a? #skip things with no actions array
return unless @i?
time = @_id.getTimestamp().getTime()
hour = time / 1000 / 3600
cst = hour - 6
key = parseInt(cst / 24).toString() + "-" + hex_md5(@i.join('-'))
val = {actions : {}, ids : @i, time : time}
for a in @a
val.actions[a] = 1
class TrackingMiddleware
attr_accessor :app
def initialize(app)
self.app = app
end
def call(env)
if env["PATH_INFO"] == '/tracker'
req = Rack::Request.new(env)
p = req.params.select{|k,v| TrackingWorker::FIELDS.has_key?(k) }
#!/bin/bash
SHADOW_FILE="/etc/shadow"
DATE=$(( $(date -u '+%s') / 60 / 60 / 24 ))
REPLACEMENT=$(echo "account-$1:$2:$DATE:0:99999:7:::" | sed -e 's/\(\/\|\\\|&\)/\\&/g')
sed -i "s/^account-$1:.*$/$REPLACEMENT/" $SHADOW_FILE \
&& echo "success"
@mrkurt
mrkurt / deploy.rake
Created February 22, 2011 23:19
an ugly task for processing compass and whatnot, then deploying them to heroku
namespace :credibles do
desc "Pre compiles assets"
task :deploy => ['credibles:prep_heroku', 'assets:compile', 'credibles:push_heroku']
task :prep_heroku do
puts "Switching to staging branch...\n"
system "git checkout -b staging || git checkout staging"
puts "Checking heroku remote...\n"
system 'git remote add heroku git@heroku.com:credibles.git || echo "remote exists"'
puts "Pulling down heroku changes...\n"
system 'git pull heroku master'
var stitch = require('stitch');
var express = require('express');
var package = stitch.createPackage({
paths: [__dirname + '/lib'],
identifier : 'credibles'
});
var app = express.createServer();
app.configure(function(){
var credibles = (function(modules) {
var exportCache = {};
return function require(name) {
var module = exportCache[name];
var fn;
if (module) {
return module;
} else if (fn = modules[name]) {
module = { id: name, exports: {} };
fn(module.exports, require, module);
.button, input[type=submit], input[type=button]{
border: 0px;
margin: 0px;
color: white;
font-size: 12px;
padding: 5px 12px;
vertical-align: middle;
text-align: center;
text-decoration: none;
font-weight: bold;
copypasta.locate_text_container = function() {
var biggest, biggest_count, p, parent, parent_count, _i, _len, _ref;
parent = false;
biggest = false;
biggest_count = 0;
parent_count = 0;
_ref = document.getElementsByTagName('p');
for (_i = 0, _len = _ref.length; _i < _len; _i++) {
p = _ref[_i];
if (p != null) {
copypasta.locate_text_container = ()->
parent = false
biggest = false
biggest_count = 0
parent_count = 0
for p in document.getElementsByTagName('p') when p?
if parent != p.parentElement
if parent_count > biggest_count
biggest_count = parent_count
biggest = parent