Skip to content

Instantly share code, notes, and snippets.

var calculator = {
add: function (a, b) {
return a + b
},
subtract: function (a, b) {
return a - b
},
multiply: function (a, b) {
return a * b
},
// bookmarklet to introspect the source of current page
javascript:(function(d,h){h=d.documentElement.innerHTML;d.open();d.write('<pre>'+('<!DOCTYPE html><html>'+h+'</html>').replace(/[<>]/g,function(m){return{'<':'&lt;','>':'&gt;'}[m]})+'</pre>')})(document);
@chrismytton
chrismytton / ideas_generator.rb
Created May 16, 2010 23:10
For when you just don't know what to do
module Idea
class Generator
def actions
@actions ||= %w{read write design contemplate}
end
def objects
@objects ||= ['code', 'books', 'art', 'poetry', 'blogs']
end
window.onload = function () {
if (! document.querySelectorAll) { // Quick & Dirty way to tell the good browsers from the bad ones.
alert("Please upgrade your browser to view this site.");
}
};
[/Users/chris/Code/Ruby/gist-550144 (master)] ruby-1.9.2-p0
$ time php php_string.php > /dev/null
real 0m0.237s
user 0m0.218s
sys 0m0.017s
[/Users/chris/Code/Ruby/gist-550144 (master)] ruby-1.9.2-p0
$ time php php_array.php > /dev/null
real 0m0.249s
# Author: Pieter Noordhuis
# Description: Simple demo to showcase Redis PubSub with EventMachine
#
# Requirements:
# - rubygems: eventmachine, thin, cramp, sinatra, yajl-ruby
# - a browser with WebSocket support
#
# Usage:
# ruby redis_pubsub_demo.rb
#
@chrismytton
chrismytton / gist:603122
Created September 29, 2010 17:07
`gitify(1)` your remote repository
#!/bin/sh
# Get a website ready to deploy with git
REPO_HOST='example.com'
REPO_PATH=$HOME/repos
# Check that the user has provided a directory to use and it exists
if [ ! "$1" ]; then
echo "Usage: $0 DIRECTORY"
echo "Where DIRECTORY is the folder that you want to contain the working copy"
@chrismytton
chrismytton / config.ru
Created November 2, 2010 16:41
Running gollum with passenger
require 'rubygems'
require 'gollum/frontend/app'
Precious::App.set(:gollum_path, Dir.pwd)
run Precious::App
<?php
/**
* Simple twitter stream function
*
* Usage: $tweets = userTimeline("hecticjeff");
*/
function userTimeline($screenName)
{
// Create a remote connection
$twitter = curl_init("http://api.twitter.com/1/statuses/user_timeline.json?screen_name={$screenName}");
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<style type="text/css">
html { height: 100% }
body { height: 100%; margin: 0px; padding: 0px }
#map_canvas { height: 600px; width: 800px; }
.hidden { display: none; }
</style>