Skip to content

Instantly share code, notes, and snippets.

View hans's full-sized avatar

Jon Gauthier hans

View GitHub Profile
# l33t regular expression for matching URLs
# thanks @ Alex Payne of Twitter for providing this
# http://groups.google.com/group/twitter-development-talk/browse_thread/thread/369d81c2010f16a8#msg_eb0409891c5e18e3
%r{(<\w+.*?>|[^=!:'"/]|^)((?:https?://)|(?:www\.))([-\w]+(?:\.[-\w]+)*(?::\d+)?(?:/(?:(?:[~\w\+%-]|(?:[,.;@:][^\s$]))+)?)*(?:\?[\w\+%&=.;:-]+)?(?:\#[\w\-\.]*)?)([[:punct:]]|\s|<|$)}x
@hans
hans / gist:7393
Created August 27, 2008 01:39 — forked from defunkt/gist:7391
task :spec do
require 'rubygems'
Gem::manage_gems
require 'rake/gempackagetask'
gemspec = ENV['gemspec'] || ''
@spec = eval(File.read(gemspec + '.gemspec'))
Rake::GemPackageTask.new(@spec) do |pkg|
pkg.need_tar = true
#!/usr/bin/php -q
<?php
// modified from http://3v1n0.tuxfamily.org/scripts/detextile/HTML-to-Textile.php
class html2textile {
function detextile($text) {
$text = preg_replace("/(<\/?)(\w+)([^>]*>)/e", "'\\1'.strtolower('\\2').'\\3'", $text);
$text = preg_replace("/<br[ \/]*>\s*/","\n",$text);
$text = preg_replace("/(^[\r\n]*|[\r\n]+)[\s\t]*[\r\n]+/", "\n", $text);
$text = stripslashes($text);
$oktags = array('p','ol','ul','li','i','b','em','strong','span','a','h[1-6]',
@hans
hans / Rakefile
Created March 13, 2011 20:44
A Rake task for compiling CoffeeScripts stored inside the /public/javascripts directory into a single `application.js` JavaScript file. Requires the 'coffee-script' binary (`npm install coffee-script`).
require 'find'
desc 'Compile CoffeeScript files to JavaScript'
task :coffee do
files_to_compile = []
# Find the
Dir.chdir File.join(Rails.root.to_s, 'public', 'javascripts') do
Find.find(Dir.pwd) do |path|
if FileTest.directory? path
$(document).ready(function() {
$('ul.icons li').hover(
function() {
$('.icon-name', this)
.css({opacity: 0})
.animate({opacity: 100}, 1000)
},
function() {
$('.icon-name', this)
.animate({opacity: 0}, 500)
jido = Jido.load 'fr'
jido.conjugate 'être'
var fs = require('fs');
var http = require('http');
--Got code from: http://www.haskell.org/haskellwiki/Why_Haskell_matters
qsort [] = []
qsort (x:xs) = qsort less ++ [x] ++ qsort more
where less = filter (<x) xs
more = filter (>=x) xs
@hans
hans / zip.coffee
Created April 12, 2011 04:42
Haskell-esque `zip` and `zipWith`, ported to node.js / CoffeeScript
zip = (arr1, arr2) ->
basic_zip = (el1, el2) -> [el1, el2]
zip_with basic_zip, arr1, arr2
# I wrote two implementations of `zipWith`: one is iterative, and one is recursive. Feel free to do some benchmarks if you feel like it :)
# zip_with, iterative style
zip_with = (func, arr1, arr2) ->
min = Math.min arr1.length, arr2.length
ret = []
@hans
hans / gist:950757
Created May 1, 2011 19:12
a higher-order function which flips the order of the arguments of an input function
(fn [thefn]
(fn [& args]
(apply thefn (reverse args))))