Skip to content

Instantly share code, notes, and snippets.

View larsthegeek's full-sized avatar

James Peterson larsthegeek

  • Total Tech Shop
View GitHub Profile
Parameters: {"group"=>{"enable_publisher_tab"=>"0", "title"=>"frogs", "feedback_visibility"=>"open", "is_private"=>"false", "locations_attributes"=>{"0"=>{"url"=>"http://frogs.totaltechshop.com", "selector"=>"body p"}, "1"=>{"url"=>"", "selector"=>"body p"}}, "allow_member_invite"=>"0", "group_type"=>"open", "allow_join_requests"=>"0", "short_name"=>"frogs", "publisher_logo_name"=>"", "description"=>"all about frogs"}, "commit"=>"Create Group", "authenticity_token"=>"wsRBrcH0Q1lWBBiCDvWRtceOpabF2ph7Sabmsd0zA+o="}
@larsthegeek
larsthegeek / hex2rgb.js
Created April 30, 2010 20:11 — forked from duncanbeevers/hex2rgb.js
nice little block of code
function hex2rgb(hex) {
var c, o = [], k = 0, m = hex.match(
/^#(([0-9a-f]{2})([0-9a-f]{2})([0-9a-f]{2})|([0-9a-f])([0-9a-f])([0-9a-f]))$/i);
if (!m) return {r:0,g:0,b:0};
for (var i = 2, s = m.length; i < s; i++) {
if (undefined === m[i]) continue;
c = parseInt(m[i], 16);
o[k++] = c + (i > 4 ? c * 16 : 0);
}
@larsthegeek
larsthegeek / bundles.sh
Created July 17, 2011 16:33 — forked from butaji/bundles.sh
This is how I manage my textmate bundles.
#
# This script will install the following Textmate bundles
#
# Languages
# - c https://github.com/textmate/c.tmbundle
# - coffeescript https://github.com/jashkenas/coffee-script-tmbundle
# - context free https://github.com/textmate/context-free.tmbundle
# - erlang https://github.com/textmate/erlang.tmbundle
# - haskell https://github.com/textmate/haskell.tmbundle.git
# - html https://github.com/textmate/html.tmbundle
@larsthegeek
larsthegeek / pick.lisp
Created August 23, 2011 00:24 — forked from timm/pick.lisp
LISP: selecting with bias from a set of options
#|
for both proj2 and proj3 you'll have to select "things" weighted by some
bias on how much we like "things" (e.g. stinky roads we do *not* like)
it uses a set of useful techniques that i'll walk us through on thursday
the following code is my generic "pick with bias code". here's the output
of the !pick1 and !pick2 demo. each demo is 10000 picks, biased by
the weights within the bias
CL-USER> (!pick1)
@larsthegeek
larsthegeek / devise.rb
Created September 15, 2011 17:37 — forked from kulbirsaini/devise.rb
Devise configuration to allow username or email address for sign_in, confirmation, unlock, forgot password instructions.
################################################################
# For views/migrations etc. check http://tinyurl.com/3xfx3zm #
################################################################
# File : RAILS_APP/config/initializers/devise.rb
# Change the following only. Rest can stay same
# NOTE : You must use devise master or any version released after Mar 13, 2011 to get everything mentioned here working.
config.authentication_keys = [ :login ]
config.confirmation_keys = [ :login ]
config.unlock_keys = [ :login ]
@larsthegeek
larsthegeek / bitly.rb
Created October 5, 2011 18:36 — forked from richardtifelt/bitly.rb
Simple bit.ly API class in Ruby
require 'httparty'
class Api::Bitly
include HTTParty
base_uri 'api.bit.ly'
basic_auth 'username', 'password'
format :json
def self.shorten(url)
response = get('/shorten', :query => required_params.merge(:longUrl => url))
@larsthegeek
larsthegeek / capistrano_memcached_tasks.rb
Created October 24, 2011 06:24 — forked from jamiew/capistrano_memcached_tasks.rb
Some handy Capistrano tasks for handling memcached. Assumes memcached runs locally on your app servers, YMMV
# This goes in config/deploy.rb
namespace :memcached do
desc "Flush memcached"
task :flush, :roles => [:app] do
run("cd #{current_release} && RAILS_ENV=#{rails_env} /usr/bin/rake memcached:flush")
end
desc "Flush memcached if there are any pending migrations (hook this before db:migrate)"
task :flush_if_pending_migrations, :roles => [:app] do
output = capture("cd #{current_release} && RAILS_ENV=#{rails_env} /usr/bin/rake db:pending_migration_count"
@larsthegeek
larsthegeek / gist:1315094
Created October 26, 2011 01:02
Fixing the red light coming from the audio port on a MacBook Pro running Linux
The red LED indicates the digital audio is switched on.
To toggle it off, simply run:
amixer set IEC958 off
@larsthegeek
larsthegeek / config_initializers_mongoid.rb
Created November 27, 2011 17:40 — forked from earlonrails/config_initializers_mongoid.rb
Use a replicaSet with Ruby Ree, Rails 2.3.4, Mongoid 1.9.2 and Mongo 1.0.9. Mongoid.database= Errors needs admin, so connect to admin then swap db after 2 seconds.
require 'mongoid'
# MongoDB ENV vars
File.open(File.join(RAILS_ROOT, 'config/mongodb.yml'), 'r') do |f|
@settings = YAML.load(f)[RAILS_ENV]
end
port = @settings["port"].nil? ? Mongo::Connection::DEFAULT_PORT : @settings["port"]
host_arr = @settings["host"]
connect = Mongo::Connection.multi([[host_arr[0], 27017], [host_arr[1], 27017], [host_arr[2], 27017]], :read_secondary => true)
db = connect.db(@settings["database"])
@larsthegeek
larsthegeek / sudoku-test.lisp
Created January 13, 2012 16:24 — forked from hanshuebner/sudoku-test.lisp
Ruby book Sudoku solver in Common Lisp
(defmacro deftestpackage (package-name for-package &optional (test-library-package-name :unit-test))
"Define a new package PACKAGE-NAME used to test the package
designated by FOR-PACKAGE. The new package will import all symbols
from FOR-PACKAGE and :USE the package designated by
TEST-LIBRARY-PACKAGE-NAME which supposedly contains unit testing
functions and macros."
`(defpackage ,package-name
(:use ,test-library-package-name ,@(mapcar #'package-name (package-use-list for-package)))
(:import-from ,for-package
,@(let (symbols)