Skip to content

Instantly share code, notes, and snippets.

View avdgaag's full-sized avatar

Arjan van der Gaag avdgaag

View GitHub Profile
@avdgaag
avdgaag / .gitignore
Created February 13, 2012 14:46 — forked from karmi/.gitignore
Script to generate PDF cards suitable for planning poker from Pivotal Tracker [http://www.pivotaltracker.com/] CSV export. Inspired by Bryan Helmkamp's http://github.com/brynary/features2cards/
.DS_Store
*.csv
*.pdf
@avdgaag
avdgaag / gist:1446606
Created December 8, 2011 09:56
Test simple page designs in a Rails app
# app/controllers/pages_controller.rb
class PagesController < ApplicationController
def login
end
def forgot_password
end
end
# app/views/pages/login.html.haml
# quick hacky class to make #111 + #456 possible.
# Make it a textmate command by adding "#!/usr/bin/env ruby -w" to the top
# and "print Color.parse(STDIN.read)" to the bottom.
class Color
OPERATORS = [:+, :-, :*, :/]
def initialize(*args)
if [*args].size == 3
@r, @g, @b = *args
@avdgaag
avdgaag / lines-to-html-list.rb
Created October 23, 2009 12:22
Mark up plain text lines as HTML lists
def to_list(text)
ol_prefix = /^\d+\.?\s*/
dl_prefix = /^(.+):\s*/
ul_prefix = /^[^\s]+\s*/
lines = text.split("\n").map { |line| line.strip }
if lines.any?
tag, pattern = if lines.first =~ ol_prefix
['ol', ol_prefix]
elsif lines.first =~ dl_prefix
@avdgaag
avdgaag / gist:202868
Created October 6, 2009 08:41
Convert plain text lists to HTML lists
# Simple function that takes a text list and creates an HTML list
# from it. This is useful as a textmate command when marking up
# plain text.
#
# This will take the following text:
#
# 1. line 1
# 2. line 2
#
# And output:
@avdgaag
avdgaag / gist:202835
Created October 6, 2009 07:39
Simple ruby function to prevent widows in a piece of HTML
# Simple widow prevention in ruby
# given a piece of HTML (not just text) this will look for ending
# tags to common block-level elements that should not have widows
#
# This can be used as a TextMate command -- I've got it mapped
# to option-w. Simply put this in there, working on selected text or entire
# document.
def widont(text)
tags = %w{li p div dt dd legend label h1 h2 h3 h4 h5 h6}.join('|')
@avdgaag
avdgaag / gist:190399
Created September 21, 2009 17:43
Cycle function that alternates between arguments on every call.
<?php
/*
* Cycle between a series of arguments.
*
* Usage:
*
* cycle('even', 'odd') # => 'even'
* cycle('even', 'odd') # => 'odd'
* cycle('even', 'odd') # => 'even'
*
@avdgaag
avdgaag / gist:189868
Created September 20, 2009 18:10
When you are desperate and need to replace special characters across an entire wordpress database, here's one way of generating the right SQL statements to do that.
terms = {
'ë' => 'ë'
}
{
'wp_posts' => %w{post_content post_title post_excerpt},
'wp_comments' => %w{comment_author comment_author_url comment_content},
'wp_terms' => %w{name},
'wp_term_taxonomy' => %w{description}
}.each_pair do |table, columns|
columns.each do |column|
@avdgaag
avdgaag / gist:183617
Created September 9, 2009 10:03
Loop through all PHP files and add width and height to images that do not have them
pattern = /<img\s+((alt|border|class|id|src|usemap|hspace|vspace)="[^"]+"\s*)+>/
# Invoke sips to try and find the image's original dimensions
# This returns both the widht and height.
def get_original_size_for(image)
output = %x{sips -g pixelWidth -g pixelHeight "#{image}"}
if output.scan(/pixelWidth:[^\d]*(\d+).*pixelHeight:[^\d](\d+)/im)
return $1, $2
else
exit_show_tool_tip "Could not get image size from #{output.inspect}"
@avdgaag
avdgaag / gist:183612
Created September 9, 2009 09:24
Regular expression for finding HTML4 images witout width or height
<img\s+((alt|border|class|id|src|usemap|hspace|vspace)="[^"]+"\s*)+>