Skip to content

Instantly share code, notes, and snippets.

View brettbuddin's full-sized avatar
🤖
Arguing with computers.

Brett Buddin brettbuddin

🤖
Arguing with computers.
View GitHub Profile
server {
listen 80;
server_name intraspirit.net;
root /path/to/public/;
index index.php;
access_log /path/to/access.log;
error_log /path/to/error.log;
location / {
@brettbuddin
brettbuddin / gist:225334
Created November 3, 2009 19:14
Fetches the tracks that your friends are currently listening to from Last.fm. Written for use with GeekTool.
#!/usr/bin/ruby
require 'rubygems'
require 'open-uri'
require 'xml'
USERNAME = 'brettbuddin'
USE_REAL_NAMES = true # if available
ALLOWED_USERS = [] # enter the usernames of those you'd like to see displayed
def fetch(url)
@brettbuddin
brettbuddin / gist:239547
Created November 20, 2009 14:58
Duplicates a group of form fields and makes their attributes unique (great for nested_attributes in Rails)
jQuery.fn.make_attr_unique = function(attr) {
var value = $(this).attr(attr);
if (value !== undefined) {
var value_pieces = value.split(/[0-9]+/);
if (value_pieces.length > 1) {
$(this).attr(attr, value_pieces[0] + Number(new Date()) + value_pieces[1]);
}
}
};
module AcceptsNestedAttributesFor
def should_accept_nested_attributes_for(*models)
klass = self.name.gsub(/Test$/, '').constantize
models.each do |model|
should "accept nested attributes for #{model}" do
assert(klass.instance_methods.include?("#{model}_attributes="),
"#{klass} does not accept nested attributes for #{model}")
end
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description: Start and stop php-cgi in external FASTCGI mode
### END INIT INFO
" ============================================================================
" File: image_dimensions_menuitem.vim
" Description: Menu item plugin for NERD Tree that returns image dimensions
" Maintainer: Brett Buddin <brett at intraspirit dot net>
" Last Change: 13 October, 2009
" ============================================================================
if exists("g:loaded_nerdtree_image_dimensions_menuitem")
finish
endif
@brettbuddin
brettbuddin / ssh_tunnel.rake
Created April 7, 2010 21:03
Creates a tunnel between a remote server and your local machine. I use this for showing off what's currently in development to outside users. It could also be used for testing against APIs that need to see your machine.
TUNNEL_USERNAME = "deploy"
TUNNEL_HOST = "255.255.255.255"
TUNNEL_PORT = 3000
LOCAL_PORT = 3000
desc "Tunnel to a remote host"
task :tunnel => :environment do
puts "Tunnel established from #{TUNNEL_HOST}:#{TUNNEL_PORT} to 127.0.0.1:#{LOCAL_PORT}"
system "ssh -nNT -g -R *:#{TUNNEL_PORT}:127.0.0.1:#{LOCAL_PORT} #{TUNNEL_USERNAME}@#{TUNNEL_HOST}"
end
@brettbuddin
brettbuddin / application_job.rb
Created April 23, 2010 16:08
I needed to assign priority dynamically (at the time the job is queued up) with Resque.
class ApplicationJob
def self.set_priority(queue, priority)
if [:high, :medium, :low].include?(priority)
self.instance_eval do
@queue = "#{queue}_#{priority}".to_sym
end
end
end
end
conn = new Socket;
while (true) {
// listen on port 80
if (conn.listen (8000)) {
// wait forever for a connection
var incoming;
#! /bin/sh
### BEGIN INIT INFO
# Provides: php-fastcgi
# Required-Start: $all
# Required-Stop: $all
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Start and stop php-cgi in external FASTCGI mode
# Description: Start and stop php-cgi in external FASTCGI mode
### END INIT INFO