Skip to content

Instantly share code, notes, and snippets.

@joshcutler
joshcutler / gist:1293829
Created October 17, 2011 21:09
Resource consumption graph
rm(list = ls()) #Clear the workspace
library(ggplot2)
time = seq(1:1000)
starting_population = 2
reproduction_rate = 1.0192
population = cbind(time, starting_population*reproduction_rate^time)
starting_resources = population[time==length(time)-1][2]
@joshcutler
joshcutler / gist:1185291
Created September 1, 2011 02:22 — forked from ahankinson/gist:985173
Install WxPython 2.9 64-bit with Homebrew Python Framework install
# These instructions work for OS X 10.6 with homebrew pre-installed.
brew install python --framework
brew install gfortran
# install other dependencies through pip:
pip install numpy
# the regular pip build for matplotlib is b0rken, and it can't find the built-in libraries for OSX
export LDFLAGS="-L/usr/X11/lib"
@joshcutler
joshcutler / gist:1051435
Created June 28, 2011 15:46
Pusher controller
class PusherController < ApplicationController
def auth
if current_user
response = Pusher[params[:channel_name]].authenticate(params[:socket_id], {
:user_id => current_user.id,
:user_info => {
:username => current_user.username,
:status => Point.user_status(current_user),
:list_html => render_to_string(:partial => "chat_messages/user", :locals => {:user => current_user})
}
@joshcutler
joshcutler / node-and-npm-in-30-seconds.sh
Created May 20, 2011 23:03 — forked from isaacs/node-and-npm-in-30-seconds.sh
Use one of these techniques to install node and npm without having to sudo. Discussed in more detail at http://joyeur.com/2010/12/10/installing-node-and-npm/ Note: npm >=0.3 is *safer* when using sudo.
echo 'export PATH=$HOME/local/bin:$PATH' >> ~/.bashrc
. ~/.bashrc
mkdir ~/local
mkdir ~/node-latest-install
cd ~/node-latest-install
curl http://nodejs.org/dist/node-latest.tar.gz | tar xz --strip-components=1
./configure --prefix=~/local
make install # ok, fine, this step probably takes more than 30 seconds...
curl http://npmjs.org/install.sh | sh
@joshcutler
joshcutler / Item Code for Mongoid
Created January 19, 2011 01:06
This is gist to show the mongoid group
class Item
include Mongoid::Document
field :fulltext, :type => String, :default => ""
field :_keywords, :type => Array
index :_keywords
field :created_by_id, :type => Integer
index :created_by_id
@joshcutler
joshcutler / Loading Div
Created October 18, 2010 19:16
This adds a loading screen for an ajax call
/* Some CSS */
.loading_div {
background: white;
opacity: 0.7;
filter: alpha(opacity=70);
width: 100%;
height: 100%;
position: absolute;
top: 0px;
@joshcutler
joshcutler / Ruby NL2BR
Created August 30, 2010 03:46
Ruby snippet to simulate nl2br
def nl2br(string)
if string
string.gsub("\n\r","<br />").gsub("\r", "").gsub("\n", "<br />")
end
end
@joshcutler
joshcutler / Debug HTTP connections
Created May 18, 2010 21:32
Debug Ruby HTTP connections
# DEBUG HTTP Connection
class ActiveResource::Connection
# Creates new Net::HTTP instance for communication with
# remote service and resources.
def http
http = Net::HTTP.new(@site.host, @site.port)
http.use_ssl = @site.is_a?(URI::HTTPS)
http.verify_mode = OpenSSL::SSL::VERIFY_NONE if http.use_ssl
http.read_timeout = @timeout if @timeout
#Here's the addition that allows you to see the output
function change_filter(input, accept_blank, query_string_var)
{
var accept_blank = (accept_blank) ? accept_blank : false;
if ((input && input.value) || (input && accept_blank))
{
filter_name = (query_string_var) ? query_string_var : "filter";
url = add_or_update_query_param(filter_name, input.value)
window.location.href = url
}
}
@joshcutler
joshcutler / Javascript: Update query param
Created November 13, 2009 16:57
Javascript snippet for taking a url and updating query string paramters
function add_or_update_query_param(name, value, starter_url)
{
url = starter_url || window.location.href;
query_string_chunks = url.split("?");
base_url = query_string_chunks[0];
query_string = (query_string_chunks.length == 2) ? query_string_chunks[1] : null;
chunks = [];
new_value_updated = false;
if (query_string)
{