Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
Each of these commands will run an ad hoc http static server in your current (or specified) directory, available at http://localhost:8000. Use this power wisely.
$ python -m SimpleHTTPServer 8000
# first install pgsql with home brew | |
brew install postgresql | |
# at this point, you need to be sure you have /usr/local/bin before /usr/bin on your $PATH | |
# to see, run: | |
brew doctor | |
# if doctor does not complain about this issue you can pass this step. | |
# prepend /usr/local/bin to your PATH in your ~/.bash_profile |
curl -s https://api.github.com/orgs/twitter/repos?per_page=200 | ruby -rubygems -e 'require "json"; JSON.load(STDIN.read).each { |repo| %x[git clone #{repo["ssh_url"]} ]}' |
-- show running queries (pre 9.2) | |
SELECT procpid, age(clock_timestamp(), query_start), usename, current_query | |
FROM pg_stat_activity | |
WHERE current_query != '<IDLE>' AND current_query NOT ILIKE '%pg_stat_activity%' | |
ORDER BY query_start desc; | |
-- show running queries (9.2) | |
SELECT pid, age(clock_timestamp(), query_start), usename, query | |
FROM pg_stat_activity | |
WHERE query != '<IDLE>' AND query NOT ILIKE '%pg_stat_activity%' |
require 'webrick' | |
require 'erb' | |
template = <<TEMPLATE | |
<html> | |
<head> | |
<title>Ruby as PHP</title> | |
</head> | |
<body> | |
<h1>Loop</h1> |
// You create your bookmarklet by instantiating | |
// a new Bookmarklet function, then pass in the options like so. | |
// This example checks to see if the var is already defined, and makes | |
// sure not to overwrite it. This could happen if the user clicks on | |
// the bookmarklet more than once. | |
MyBookmarklet = MyBookmarklet || (MyBookmarklet = new Bookmarklet({ | |
// debug: true, // use debug to bust the cache on your resources | |
css: ['/my/style.css'], | |
js: [], |
# Chained comparisons in Ruby | |
# inspired by http://coffeescript.org/#comparisons | |
# as well as http://refactormycode.com/codes/1284 | |
[:<, :>, :<=, :>=].each do |operator| | |
[Float, Fixnum, Rational, Comparable].each do |klass| | |
klass.class_eval do | |
alias_method "_#{operator}", operator | |
define_method operator do |rhs| | |
send("_#{operator}", rhs) && rhs |
An introduction to curl
using GitHub's API.
Makes a basic GET request to the specifed URI
curl https://api.github.com/users/caspyin
/* | |
* Euler's totient function phi(n). | |
* http://en.wikipedia.org/wiki/Euler%27s_totient_function | |
* | |
* This is an *EXTREMELY* fast function and uses | |
* several tricks to recurse. | |
* | |
* It assumes you have a list of primes and a fast | |
* isprime() function. Typically, you use a bitset | |
* to implement the sieve of Eratosthenes and use |