Skip to content

Instantly share code, notes, and snippets.

@andersonsp
andersonsp / setup_load_paths.rb
Created November 18, 2010 22:26
fork of the darcy's setup_load_paths.rb from http://bit.ly/rvm-passenger-slp
if ENV['MY_RUBY_HOME'] && ENV['MY_RUBY_HOME'].include?('rvm')
begin
rvm_path = File.dirname(File.dirname(ENV['MY_RUBY_HOME']))
rvm_lib_path = File.join(rvm_path, 'lib')
$LOAD_PATH.unshift rvm_lib_path
require 'rvm'
dir = File.dirname(File.dirname(__FILE__))
rvmrc = File.join(dir, ".rvmrc")
if File.exists? rvmrc
@andersonsp
andersonsp / dup_mysql_db.sh
Created January 26, 2011 20:32
duplicate a mysql database
mysqladmin create DB_name -u DB_user --password=DB_pass && \
mysqldump -u DB_user --password=DB_pass DB_name | mysql -u DB_user --password=DB_pass -h DB_host DB_name
@andersonsp
andersonsp / README
Created March 18, 2011 19:08
Rails 3 custom form builder implementing a simple color picker based on JQuery and CaryonBox plugin
INSTALLATION
the rails application must have support for JQuery
get JQuery.Crayonbox.js at http://gelform.com/crayonbox-jquery-plugin/
add the plugin JQuery.Crayonbox.js to /public/javascript folder
add the crayonbox css to /public/stylesheets folder
add color_picker_form_builder.rb to the /lib folder
add to the view or layout file:
var Rufus = {
Mnemo: {
/** CONSTANTS **/
V: [ 'a', 'e', 'i', 'o', 'u' ],
C: [ 'b', 'd', 'g', 'h', 'j', 'k', 'm', 'n', 'p', 'r', 's', 't', 'z' ],
SYL: [], // This is populated later on. [1]
SPECIAL: [
@andersonsp
andersonsp / git_svn_bash_prompt.sh
Created October 18, 2011 16:07 — forked from sammyd/git_svn_bash_prompt.sh
Set color bash prompt according to ruby version and git/svn branch, and return status of last command
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the ruby version
# * the branch/status of the current git repository
# * the branch of the current subversion repository
# * the return value of the previous command
#
@andersonsp
andersonsp / android_ics_tones.gpl
Created September 28, 2012 13:55
Gimp palette for Android ICS tones (including all 14 shades of each color as listed here http://developer.android.com/design/style/color.html)
GIMP Palette
Name: Android ICS
Columns: 8
#
51 181 229 33B5E5
170 102 204 AA66CC
153 204 0 99CC00
255 187 51 FFBB33
255 68 68 FF4444
0 153 204 0099CC
@andersonsp
andersonsp / triangle-collision.js
Created October 15, 2012 15:44 — forked from toji/triangle-collision.js
Javascript Swept-Sphere/Triangle Collision Detection
/*
* Copyright (c) 2012 Brandon Jones
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
#
#add this to ApplicationController
#
def set_no_cache
response.headers["Cache-Control"] = "no-cache, no-store, must-revalidate"
response.headers["Pragma"] = "no-cache"
response.headers["Expires"] = "0"
end
#
@andersonsp
andersonsp / markdown.parse.js
Created February 25, 2014 18:27
A Markdown parser in under 100 JS LoC, taken from http://pzxc.com/simple-javascript-markdown-parsing-function
if (typeof markdown === 'undefined') var markdown = {
parse: function (s) {
var r = s, ii, pre1 = [], pre2 = [];
// detect newline format
var newline = r.indexOf('\r\n') != -1 ? '\r\n' : r.indexOf('\n') != -1 ? '\n' : ''
// store {{{ unformatted blocks }}} and <pre> pre-formatted blocks </pre>
r = r.replace(/{{{([\s\S]*?)}}}/g, function (x) { pre1.push(x.substring(3, x.length - 3)); return '{{{}}}'; });
r = r.replace(new RegExp('<pre>([\\s\\S]*?)</pre>', 'gi'), function (x) { pre2.push(x.substring(5, x.length - 6)); return '<pre></pre>'; });
@andersonsp
andersonsp / pratt-parser.py
Last active August 29, 2015 13:57
Parser examples in python
# see http://effbot.org/zone/simple-top-down-parsing.htm
import sys
import re
try:
# test binding for python's built-in tokenizer; see
# http://svn.effbot.org/public/stuff/sandbox/pytoken
import pytoken
except ImportError: