Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env ruby
# random_password.rb
# generate a random string of 12 alphanumeric characters
# Steven Wilkin @stevebiscuit
chars = ('0'..'9').to_a + ('A'..'Z').to_a + ('a'..'z').to_a
12.times {print chars[rand(chars.length)]}
puts
I have a strange problem with a Sinatra app.
When I request http://MYAPP.heroku.com/http://google.com
This is in the log:
$ heroku logs
82.24.100.136, 10.250.31.111 - - [27/Oct/2009 13:18:41] "GET /http:/google.com HTTP/1.1" 200 17 0.0005
The '//' in my GET request is being converted to '/'
#!/usr/bin/env python
for x in range(1, 101):
if not(x % 3 or x % 5):
print 'FizzBuzz'
elif not x % 3:
print 'Fizz'
elif not x % 5:
print 'Buzz'
else:
#!/usr/bin/env python
# sort this list of random numbers using bubble sort algorithm
nums = [35, 59, 30, 95, 97, 45, 44, 41, 80, 78, 14, 58, 2, 41, 6, 68, 18, 13, 69, 12]
# test if the list is sorted
def sorted(arr):
prev = arr[0]
for x in arr:
if x < prev:
/**
* initialise Google Analytics without having to slow down page load with adding script tags in layout
*/
function initAnalytics(){
var accountId = 'UA-XXXXXXX-X';
jQuery.getScript('http://www.google-analytics.com/ga.js', function(){
try {
var pageTracker = _gat._getTracker(accountId);
pageTracker._trackPageview();
} catch(err) {}
#!/usr/bin/env ruby
# html_encode.rb
# convert commandline input to html entities
$*.join(' ').each_char {|c| print "&##{c[0]};"}
puts
# list all domains apache is configured to listen for on a Fedora Core box
grep -hE 'ServerName|ServerAlias' /etc/httpd/conf/* | grep -v '#' | sed -r -e 's/^\s+//' -e 's/\w+\b //' | tr ' ' '\n' | sort | uniq
@stevenwilkin
stevenwilkin / sdc
Created December 9, 2010 10:43
svn diff in colour
#!/bin/bash
#
# sdc - svn diff in colour
# Steven Wilkin @stevebiscuit
cleanup_exit() {
rm -rf "$SVNTMP"
}
# Remove temporary files even if we get interrupted
@stevenwilkin
stevenwilkin / redirect_to_tld.rb
Created February 22, 2011 00:30
Rack middleware to ensure all traffic is served from a canonical domain
# ensure all requests are served from a canonical top-level-domain
#
# the following in your config.ru will cause all traffic to stevenwilkin.co.uk to
# be redirected to stevenwilkin.com if both domains are served by the same app
#
# require 'redirect_to_tld'
# use RedirectToTLD, 'stevenwilkin.com'
#
class RedirectToTLD
@stevenwilkin
stevenwilkin / fizz_buzz.scala
Created August 1, 2011 21:30
FizzBuzz implemented in Scala
// http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html
//
// run with `scala fizz_buzz.scala`
for(i <- 1 until 101) {
if(((i % 3) == 0) && ((i %5) == 0)) {
println("FizzBuzz")
} else if((i % 3) == 0) {
println("Fizz")
} else if((i % 5) == 0) {