Skip to content

Instantly share code, notes, and snippets.

View dkln's full-sized avatar
🤩

Diederick Lawson dkln

🤩
View GitHub Profile
@dkln
dkln / gist:72716
Created March 2, 2009 11:43
Extract text from Microsoft Word file (ment for search engine indexation)
def parse_word(file)
buffer = ""
File.open(file, 'rb').each_line { |x| buffer = buffer + x + " " if x.include?(0.chr) }
return buffer.gsub!(/[^a-zA-Z0-9\s\,\.\-@\/\_]/, '').sub!(/[,\.\-\\\/@\_]/, ' ').split(' ')
end
@dkln
dkln / gist:72786
Created March 2, 2009 15:06 — forked from finalist/gist:72684
Ruby on Rails 2.3 template
require 'open-uri'
require 'erb'
# Build seperate config files for each db type
CONFIG_URLS = [:mysql, :oracle, :sqlite2, :sqlite3, :postgresql, :frontbase, :ibm_db]
BASE_URL = "http://github.com/rails/rails.git/railties/configs/databases/"
app_name = "app"
socket = false
CONFIG_URLS.each do |c|
@dkln
dkln / Filter textinput in textfields in Actionscript 3.0
Created May 10, 2010 13:34
Filter textinput in textfields in Actionscript 3.0
acceptedRegEx = "^[0-9]{0,3}[\.,]?[0-9]{0,2}$";
...
input.addEventListener(TextEvent.TEXT_INPUT, handleTextInput, false, 0, true);
...
private function handleTextInput(event:TextEvent):void {
var newText:String;
@dkln
dkln / Merging two simple objects (like a hash)
Created May 11, 2010 13:13
Merging two simple objects (like a hash
public class ObjectUtils {
public static function mergeObjects(resultObject:Object, toMergeObject:Object):Object {
var setting:String;
for(setting in toMergeObject)
resultObject[setting] = toMergeObject[setting];
return resultObject;
}
}
@dkln
dkln / convert_all_mysql_tables_to_utf8.sh
Created July 7, 2010 15:07
Convert MySQL tables to utf8
mysql --database=db -B -N -e "SHOW TABLES" -u root | awk '{print "ALTER TABLE", $1, "CONVERT TO CHARACTER SET utf8 COLLATE utf8_general_ci;"}' | mysql --database=db -u root
find . -name .svn -print0 | xargs -0 rm -rf
find . -name .svn -exec 'rm -rf {}\;'
git init
class Person
include ActiveModel::Validations
include ActiveModel::Conversion
extend ActiveModel::Naming
attr_accessor :first_name, :last_name
def persisted?
false
end
rvm install 1.9.2-head -C "--with-openssl-dir=$HOME/.rvm/usr --with-libyaml-dir=/opt/local --with-readline-dir=$HOME/.rvm/usr --with-iconv-dir=$HOME/.rvm/usr"
function rvm_version {
local gemset=$(echo $GEM_HOME | awk -F'@' '{print $2}')
[ "$gemset" != "" ] && gemset="@$gemset"
local version=$(echo $MY_RUBY_HOME | awk -F'-' '{print $2}')
[ "$version" != "" ] && version="@$version"
local full="$version$gemset"
[ "$full" != "" ] && echo "$full "
}
export PS1="\$(rvm_version)$PS1"
class HtmlEmailSanitizer < HTML::WhiteListSanitizer
self.allowed_tags = Set.new(%w(strong em b i p code pre tt samp kbd var sub
sup dfn cite big small address hr br div span h1 h2 h3 h4 h5 h6 ul ol li dl dt dd abbr
acronym a img blockquote del ins html head body title))
self.allowed_protocols = Set.new(%w(http https mailto cid))
end