Skip to content

Instantly share code, notes, and snippets.

View mindscratch's full-sized avatar

Craig Wickesser mindscratch

View GitHub Profile
@mindscratch
mindscratch / config.ru
Created January 29, 2013 14:13
Run puma with control server for a Sinatra app
# Usage: rackup config.ru
require 'gollum'
require 'gollum/frontend/app'
require 'puma'
Precious::App.set(:gollum_path, Dir.pwd)
Precious::App.set(:server, :puma)
@mindscratch
mindscratch / restore_rollback.rb
Created January 23, 2013 13:27
mongo replicaset rollback data
# http://docs.mongodb.org/manual/reference/bsondump/
fh = File.open("somefile.bson", "rb")
while not fh.eof? do
obj = BSON.read_bson_document fh
id = obj.delete "_id"
# assume Thing is a Mongoid::Document
thing = Thing.new obj
thing["_id"] = id.to_s
thing.save
var AutocompleteView = Backbone.View.extend({
initialize: function() {
this.availableTags = [
"ActionScript",
"AppleScript",
"Asp",
"BASIC",
"C",
"C++",
@mindscratch
mindscratch / html-escape.js
Created December 7, 2012 17:56
un/escape HTML in Javascript
// Use the browser's built-in functionality to quickly and safely escape the
// string
function escapeHtml(str) {
var div = document.createElement('div');
div.appendChild(document.createTextNode(str));
return div.innerHTML;
};
// UNSAFE with unsafe strings; only use on previously-escaped ones!
function unescapeHtml(escapedStr) {
@mindscratch
mindscratch / ruby-gc-profiling.rb
Created November 6, 2012 02:25
ruby "complex" stuff - from Matt Aimonetti presentation
GC::Profiler.enable
# your code
puts GC::Profiler.result
# GC.disable
puts ObjectSpace.count_objects.inspect
@mindscratch
mindscratch / rails31init.md
Created August 16, 2012 12:48 — forked from samnang/rails31init.md
Rails 3.1 with Rspec, Factory Girl, Haml, Simple Form, Database Cleaner, Spork, and Guard

Install Rails 3.1

gem install rails

generate new app, skipping Test::Unit file generation

rails new my_app -T

Set up Gemfile

#!/bin/sh
set -e
if [ -d "generated" ] ; then
echo >&2 "error: 'generated' directory already exists. Delete it first."
exit 1
fi
mkdir generated
@mindscratch
mindscratch / aop.rb
Created August 2, 2012 01:44
Aquarium DSL #after_raising
require 'aquarium'
module Gizmo
class ExceptionHandling
include Aquarium::DSL
types = ['Gizmo::FindAll', 'Gizmo::Find', 'Gizmo::Make', 'Gizmo::Modify', 'Gizmo::Delete']
around :calls_to => [:call], :in_types => types do |jp, operation, *args|
puts "inside around advice..
jp.proceed
# usage:
# $ chrome index.html
function chrome() {
open $@ --args --allow-file-access-from-files
}
# usage:
# $ server
alias server='open http://localhost:8000 && python -m SimpleHTTPServer'
@mindscratch
mindscratch / self_signed_cert.rb
Created June 7, 2012 14:30 — forked from nickyp/self_signed_cert.rb
create a self-signed certificate using ruby-openssl
We couldn’t find that file to show.