Skip to content

Instantly share code, notes, and snippets.

View 13k's full-sized avatar

K 13k

View GitHub Profile
#!/bin/sh
#
# Identifies the predominant color in an image.
# You can specify certain colors to discard from the result.
#
# Usage: $0 <image> [colors to discard]
[ -z "$1" ] && exit 1
file="$1"
@13k
13k / irbrc.rb
Created September 24, 2009 19:58
def Object.method_added(method)
return super(method) unless method == :helper
helper.instance_variable_set("@controller", app)
def helper.method_missing(method, *args, &block)
helper.send(method, *args, &block) if helper.instance_variable_get('@controller') && method.to_s =~ /_path$|_url$/
end
end if ENV['RAILS_ENV']
@13k
13k / ackrc
Created October 5, 2009 02:26
--type-set
haml=.haml
require 'rexml/parsers/pullparser'
require 'htmlentities'
class String
# Truncate strings containing HTML code
# Usage example: "string".truncate_html(50, :word_cut => false, :tail => '[+]')
def truncate_html(len = 30, opts = {})
opts = {:word_cut => true, :tail => ' ...'}.merge(opts)
p = REXML::Parsers::PullParser.new(self)
tags = []
"
" CSS 1-line comment helpers
"
" Comments the current line
fun CssComment()
:s@^\(\s*\)\(.*\)$@\1/*\2*/@
endfun
" Un-comment from current line
<?php
require_once 'util.php';
class Application_Model_Abstract
{
public function __construct(array $options = null)
{
if (is_array($options)) {
$this->setFromArray($options);
<?php
/***
* Helper functions to convert strings:
* - from CamelCase to camel_case and;
* - from under_score to UnderScore
*
* These are very probably not fast (or the fastest version).
***/
#!/usr/bin/env python
# If Win32, MSYS/cygwin with sed is required
import sys
if __name__ != '__main__':
print "This script must be run, not imported"
sys.exit(1)
try:
= Christian Neukirchen's Ruby Style Guide
[ http://github.com/chneukirchen/styleguide/blob/master/RUBY-STYLE ]
You may not like all rules presented here, but they work very well for
me and have helped producing high quality code. Everyone is free to
code however they want, write and follow their own style guides, but
when you contribute to my code, please follow these rules:
== Formatting: