Skip to content

Instantly share code, notes, and snippets.

View Narnach's full-sized avatar

Wes Oldenbeuving Narnach

View GitHub Profile
@Narnach
Narnach / text_shadow.sass
Created October 21, 2009 23:09
sass: text-shadow
// Apply a CSS text-shadow cross-browser.
// There is one todo/gotcha: the direction is hardcoded to towards the bottom-right for IE, but that's good enough for my use case.
// Usage example: +text-shadow(#333, 1px, 1px, 1)
=text-shadow(!color, !x, !y, !blur)
:text-shadow= !color !x !y "#{!blur}px"
:-ms-filter "progid:DXImageTransform.Microsoft.Shadow(Color=#{!color},Direction=135,Strength=#{!blur})"
@Narnach
Narnach / opacity.sass
Created October 20, 2009 14:16
sass: opacity
/ This SASS function makes it easy to get cross-browser opacity.
/
/ Firefox and Safari use CSS opacity.
/ Internet Explorer 7 and 8 each require their own flavor of the opacity alpha filter.
/
/ See http://www.quirksmode.org/css/opacity.html for more info on opacity.
/
/ Pass an opacity value between 0.0 and 1.0
=opacity(!value)
:opacity= !value
@Narnach
Narnach / nginx.conf
Created October 14, 2009 20:26
nginx config file
# This config works great to run my Sinatra app over Phusion Passenger,
# but it does not use my custom static error pages for 404 and 50x errors.
# Any help in getting it to work is much appreciated!
worker_processes 1;
error_log /var/log/nginx/error.log info;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
#!/usr/bin/env ruby
def assert_equal(reference, value)
raise "Expected #{value.inspect} to equal #{reference.inspect}" unless reference == value
end
class Array
def remove(other)
copy = self.dup
other.each do |e|
# Simple message filtering logic for a Ruby-based Twitter client.
#
# This demonstrates two simple string-based filtering approaches:
# * blacklist words
# * blacklist phrases
#
# It uses a slightly optimized matching and shows a sub-optimal one as comment.
#
# This can ofcourse also be used for highlights, dynamic grouping and whatnot.
messages = [
#!/usr/bin/env ruby
# Usage: githubify <gemspec_file> [username]
# Requires: github.name to be set for the current git project or [username] to be specified
# Result: creates/overwrites a file named <username>-<gemspec_file> and updates the s.name in there have the same project name format.
#
# Author: Wes Oldenbeuving
# E-mail: [email protected]
# License: MIT-LICENSE
class String
@Narnach
Narnach / gist:148408
Created July 16, 2009 13:36
A fast version of Enumerable#group_by.
# Basis for fast_group_by gem: http://github.com/Narnach/fast_group_by
module Enumerable
# An unordered group_by implementation that is a gazillion times faster than
# ActiveSupport's ordered version, when used with large data sets.
# ActiveSupport uses OrderedHash, which are nested Arrays. Array#assoc is
# way slower than Hash#[] because it does a linear search vs a tree search.
# For small data sets, the difference is not that obvious, but in the range
# of 50k+ items, the difference can be 60 seconds vs less than 1 second.
def fast_group_by(&block)
res = Hash.new { |hash, key| hash[key] = [] }
# Rake tasks to install OpenTTD from their Subversion source.
# Note: this is used on a Macbook, so the configuration and installation are based on this.
def cmd(str)
puts str
system str
end
desc 'Configure sources for compilation'
task :configure do
cmd './configure --with-ccache --enable-strip --disable-universal --with-cocoa MAKEOPTS="-j5" CFLAGS="-pipe" CXXFLAGS="-pipe"'
@Narnach
Narnach / gist:125358
Created June 7, 2009 14:44
Benchmark to show explicit returns are slower than implicit returns.
#!/usr/bin/env ruby
# Benchmark explicit vs implicit returns.
#
# In a loop doing 5,000,000 implicit and the same explicit returns,
# The following stats came back:
#
# user system total real
# explicit return 2.040000 0.010000 2.050000 ( 2.074879)
# implicit return 1.310000 0.010000 1.320000 ( 1.333344)
#
@Narnach
Narnach / excuse.rb
Created March 12, 2009 08:45 — forked from FiXato/excuse.rb
#!/usr/bin/env ruby
# Your random BOFH excuse calendar.
# Based upon the The Bastard Operator From Hell Stories written by Simon Paul Travaglia.
# And the list compiled by Jeff Ballard, http://jeffballard.us/
#
# Automatically downloads the excuses from http://pages.cs.wisc.edu/~ballard/bofh/excuses
# and stores them as ~/.excuses.txt for reuse.
require 'open-uri'
class Array