Skip to content

Instantly share code, notes, and snippets.

View joshprice's full-sized avatar
⚗️
Alembic is hiring!

Josh Price joshprice

⚗️
Alembic is hiring!
View GitHub Profile
String.prototype.reverse = function() {
return this.split("").reverse().join("");
}
Number.prototype.formatAsCurrency = function() {
return this.toString()
.replace(/^(\d)$/, "00$1") // pad 1 digit
.replace(/^(\d{2})$/, "0$1") // pad 2 digits
.reverse()
.replace(/(\d{2}(?=\d))/, "$1.") // place decimal point
IO.read("testfile") # reads testfile in as a string
IO.readlines("testfile") # reads testfile in as an array
IO.read("testfile") # reads testfile in as a string
IO.readlines("testfile") # reads testfile in as an array
//
// Define this.constructor.name so we can introspect an object for it's constructor's name
// (equivalent to the 'Class' name if there were classes...)
// This is necessary because IE does not define this constructor property but FF does.
//
Function.prototype.getName = function() {
var matches = this.toString().match(/function\s+([\w\$]+)\s*\(/);
return matches ? matches[1] : '';
};
(function() {
var controlPanel = (<r><![CDATA[
<div id='controlpanel'>
<h1>First</h1>
<ul>
<li>HappyPath</li>
</ul>
<h1>Second</h1>
@joshprice
joshprice / MultiplexingProxy.rb
Created August 1, 2009 05:45
Multiplexing Proxy
require "rubygems"
require "webrick/httpproxy"
module WEBrick
class HTTPRequest
attr_writer :host, :port, :request_uri, :unparsed_uri, :request_line, :path
end
end
class MultiplexingProxy < WEBrick::HTTPProxyServer
@joshprice
joshprice / jQuerify bookmarklet
Created October 3, 2009 01:49
jQuerify a webpage so you can interact with it using jQuery. Save as a bookmark with the contents as the URL. There's a Firebug plugin to do this, but this works in more browsers.
javascript:(function(){var%20j=document.createElement('script');j.setAttribute('type','text/javascript');j.setAttribute('src','http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js');document.body.appendChild(j);})();
@joshprice
joshprice / IE6 and 7 header float bug [FIXED]
Created October 22, 2009 05:35
zoom:1 is a hack for IE to recognise floating children and we use a margin-top of -1em to realign
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<style>
.wrapper { border: 1px solid black; }
.wrapper h3 a { float: right; }
</style>
<!--[if lte IE 7]>
<style>
helpers do
def mobile_request?
[ /AppleWebKit.*Mobile/, /Android.*AppleWebKit/ ].any? {|r| request.env['HTTP_USER_AGENT'] =~ r}
end
def mobile_file(name)
File.exist?("#{options.views}/#{name}#{@mobile}.haml") ? :"#{name}#{@mobile}" : name.to_sym
end
def partial(name)
haml mobile_file("_#{name}"), :layout => false
end
@joshprice
joshprice / josh.zsh-theme
Created July 13, 2010 14:46 — forked from pat/pat.zsh-theme
Pat's theme but minus the time, home as ~ and on one line (and particularly hardcoded to my setup tsk tsk)
grey='\e[0;90m'
ZSH_THEME_GIT_PROMPT_PREFIX="%{$grey%}("
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$grey%}) %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$grey%})"
function pat_prompt {
(( spare_width = ${COLUMNS} ))
prompt=" "