Skip to content

Instantly share code, notes, and snippets.

#
# Converts a number into a column name like in Excel. For example,
#
# index_to_column(0) = 'A'
# index_to_column(1) = 'B'
# index_to_column(2) = 'C'
# ...
# index_to_column(25) = 'Z'
# index_to_column(26) = 'AA'
# index_to_column(27) = 'AB'
@mnmldave
mnmldave / Rakefile
Created June 8, 2011 21:22
Simple rack PHP server rake task
#
# Sample rake task for starting a Thin rack server for a PHP application (like
# Wordpress or Drupal or whatever).
#
# Requires php-cgi be available on path (I used homebrew on my mac to install
# php since it doesn't come pre-installed) and gems 'thin', 'rack' and
# 'rack-legacy'.
#
BASE_PATH = File.expand_path(File.dirname(__FILE__))
SRC_PATH = File.join(BASE_PATH, 'src')
// Adds click event handlers to all the pager links within some content element, c.
function prepareContent(c) {
$('ul.pager a', c).each(function(i,e) {
var $e = $(e),
path = $e.attr('href'),
base = Drupal.settings.basePath,
regex = '^' + base.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
if (path && path.match(regex)) {
$e.click(function() {
@mnmldave
mnmldave / reverse-nav-menu.php
Created October 17, 2011 03:59
Reverse wordpress nav menu
/**
* Enables a 'reverse' option for wp_nav_menu to reverse the order of menu
* items. Usage:
*
* wp_nav_menu(array('reverse' => TRUE, ...));
*/
function my_reverse_nav_menu($menu, $args) {
if (isset($args->reverse) && $args->reverse) {
return array_reverse($menu);
}
@mnmldave
mnmldave / gist:1463847
Created December 12, 2011 00:45
Resize browser windows with Selenium WebDriver in Ruby
driver = WebDriver.for(:remote, :url => Helper.grid, :desired_capabilities => caps)
width = 1024
height = 768
# Resize window. In Firefox and Chrome, must create a new window to do this.
# http://groups.google.com/group/webdriver/browse_thread/thread/e4e987eeedfdb586
case driver.capabilities[:browser_name]
when 'firefox', 'chrome'
handles = driver.window_handles
@mnmldave
mnmldave / gist:2979219
Created June 23, 2012 17:52
Generate random characters, base64 encoded
openssl rand -base64 40
@mnmldave
mnmldave / ec2env.sh
Created June 25, 2012 17:29
EC2 environment switcher script
#!/bin/sh
#
# ec2env.sh
# mnmldave
#
# Switch between EC2_PRIVATE_KEY and EC2_CERT environment variables. Licensed under
# WTFPL v2.0.
#
# Installation (you'll have to open a new terminal after installing):