This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 '/' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# html_encode.rb | |
# convert commandline input to html entities | |
$*.join(' ').each_char {|c| print "&##{c[0]};"} | |
puts |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# sdc - svn diff in colour | |
# Steven Wilkin @stevebiscuit | |
cleanup_exit() { | |
rm -rf "$SVNTMP" | |
} | |
# Remove temporary files even if we get interrupted |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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) { |
OlderNewer