Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
# create a txt file to write today's notes
DIRNAME="${HOME}/Documents/stuff_i_did/`date +%Y`/`date +%m`/"
FILENAME="${DIRNAME}`date +%Y-%m-%d`.txt"
mkdir -p $DIRNAME
if [ ! -f $FILENAME ]; then
echo "---
# `whoami` did stuff today
- `date +%Y-%m-%d`
@abriening
abriening / spinner.rb
Created January 21, 2012 18:13
Simple ruby spinner
class Spinner
def initialize printer=nil
@spinner = %w[| / - \\]
@count = 0
@printer ||= $stderr
end
def print
@printer.print "\r"+@spinner[@count]
@count += 1
task :test => "test:javascript"
namespace :test do
task :javascript, :expresso_args do |t, args|
node = `/usr/bin/env which node`
if node == ""
puts "Skipping JavaScript unit tests: no 'node' executable found."
puts "Please install node.js v0.4.0 or newer."
else
puts "Running JavaScript unit tests:"
@abriening
abriening / encryption.rb
Created October 30, 2011 01:58
Blowfish encryption wrapper
require 'rubygems'
require 'crypt/blowfish'
require 'base64'
# simple wrapper for blowfish encryption. Assumes all string IO in base64.
module Encryption
extend self
class NilKey < StandardError; end
#!/usr/bin/env ruby
filename = ARGV.pop
urls = []
processing_method = {}
File.open filename do |f|
while l = f.gets
if l =~ /.* prism rails\[([0-9]+)\]: .* Processing .* \[([A-Z]+)\]/
processing_method[$1] = $2
end
@abriening
abriening / application_controller.rb
Created September 30, 2011 21:42
Add support for handling 405 Method Not Allowed & 501 Not Implemented
# As used with CanCan and Devise
class ApplicationController < ActionController::Base
protect_from_forgery
include ErrorResponseActions
rescue_from CanCan::AccessDenied, :with => :authorization_error
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
before_filter :authenticate!
class ApplicationController < ActionController::Base
rescue_from ActiveRecord::RecordNotFound, :with => :resource_not_found
rescue_from ActionController::RoutingError, :with => :check_request_uri_and_method
rescue_from AbstractController::ActionNotFound, :with => :page_not_found
rescue_from ActionController::MethodNotAllowed, :with => :method_not_allowed
@abriening
abriening / bash
Created September 10, 2011 14:40
Hijack a running nack_worker ( Pow server )
gem install hijack
ps aux | grep ruby
# andrew 10879 0.0 2.4 2538948 100668 ?? S 10:30AM 0:03.09 ruby .../node_modules/nack/bin/nack_worker .../config.ru /tmp/nack.56823.5122799426.sock
hijack 10879
@abriening
abriening / connection_fix.rb
Created May 17, 2011 19:26 — forked from defunkt/connection_fix.rb
MySQL server has gone away fix
## https://gist.github.com/977188
#
# If your workers are inactive for a long period of time, they'll
# lose their MySQL connection.
#
# This hack ensures we re-connect whenever a connection is lost.
#
# From: https://gist.github.com/238999
#
# Added retrying to prevent infinite loop.
@abriening
abriening / default.rb
Created May 4, 2011 13:17
Gem Install Chef Recipe
bash "install #{name} gems" do
cwd "/tmp/#{name}"
code <<-end_code
for gem_file in `ls *.gem`
do
gem install ./$gem_file
done
end_code
end