Skip to content

Instantly share code, notes, and snippets.

Darren Terhune darrenterhune

Block or report user

Report or block darrenterhune

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View textmate mate shell open snippet
# add this to your .bash_* to open projects in one fell swoop
function m {
if [ "$1" ]; then
cd ~/Sites; # (update directory root location to suit your needs)
mate $1
fi
}
@darrenterhune
darrenterhune / open app in textmate and start server
Created Oct 13, 2009
unix function to open app/boot rails
View open app in textmate and start server
function ss {
if [ "$1" ]; then
# cd to the rails app directory.
cd ~/Sites; # (update the repository root location to suit your needs)
if [ "$1" ]; then
mate $1
cd `ls|grep $1|sort|tail -1`
fi
echo $(pwd)
fi
View IE Fixes and Hacks
/*best clearfix around*/
.clearfix:after {content: ".";display: block;clear: both;visibility: hidden;line-height: 0;height: 0;}
.clearfix {display: inline-block;}
html[xmlns] .clearfix {display: block;}
* html .clearfix {height: 1%;}
/*transparent pngs... you will need a 1px X 1px transparent.gif on your web server, and may need to modify the url below*/
* html img,* html .png{position:relative;behavior:expression((this.runtimeStyle.behavior="none")&&(this.pngSet?this.pngSet=true:(this.nodeName == "IMG" && this.src.toLowerCase().indexOf('.png')>-1?(this.runtimeStyle.backgroundImage = "none",
this.runtimeStyle.filter = "progid:DXImageTransform.Microsoft.AlphaImageLoader(src='" + this.src + "',sizingMethod='image')",
this.src = "transparent.gif"):(this.origBg = this.origBg? this.origBg :this.currentStyle.backgroundImage.toString().replace('url("','').replace('")',''),
@darrenterhune
darrenterhune / kernel-commands.sh
Last active Sep 4, 2015
helpful unix kernel commands
View kernel-commands.sh
# convert lines in text file
tr '[:lower:]' '[:upper:]' <oldfile> newfile
# download a gzip file from remote server
ssh server "gzip -c remote_file" > local_file.gz
# secure copy local file to remote server
scp localfile user@remote_server.com:remote_directory
# find all files that have been modified in the last 3 days
@darrenterhune
darrenterhune / move logic to model
Created Feb 24, 2010
csv import example in model
View move logic to model
# controller
def proc_csv
import = Import.find(params[:id])
if import.load_csv
flash[:notice] = "woo"
redirect_to some_url
else
flash[:error] = "ohoh"
end
end
@darrenterhune
darrenterhune / Bitfields
Created Oct 29, 2010
Example bitfield calculations in ruby with thinking-sphinx
View Bitfields
# For bitfield calculations...
#------------------------------------------------------------------------
# flag | sale | lease | charter | hide | vertical
#------------------------------------------------------------------------
# booleans | 1 | 1 | 1 | 1 | 1
#------------------------------------------------------------------------
# position | 1 | 2 | 3 | 4 | 5
#------------------------------------------------------------------------
# value | 1 | 2 | 4 | 8 | 16
#
@darrenterhune
darrenterhune / error_messages_for
Created Jan 7, 2011
weird error I'm seeing in staging
View error_messages_for
# controller (dumbed down version)
def email_aircraft
return unless request.post?
@request = Request.new(params[:request])
respond_to do |format|
if @request.valid?
flash[:success] = "Your message was successfully sent."
format.html { redirect_to aircraft_url(@aircraft) }
format.js
@darrenterhune
darrenterhune / memcached-client development hack
Created Feb 4, 2011
ArgumentError (undefined class/module) memcached-client dependency loading hack
View memcached-client development hack
class << Marshal
def load_with_rails_classloader(*args)
begin
load_without_rails_classloader(*args)
rescue ArgumentError, NameError => e
if e.message =~ %r(undefined class/module)
const = e.message.split(' ').last
const.constantize
retry
else
View aws_cf_invalidate.rake
require 'hmac-sha1'
require 'net/https'
require 'base64'
desc "Invalidate files from cloudfront distribution"
task :files, :filenames do |task, args|
CONFIG = YAML.load_file(File.join(RAILS_ROOT, 'config', 'amazon_s3.yml'))[RAILS_ENV]
s3_access = CONFIG['access_key_id']
View order_ranking_algorithm.rb
# I hate this... it's fugly:
order("CEIL((artworks.votes + POW(subscriptions.amount, 2)) / POW(((DATEDIFF(CURDATE(), artworks.created_at)) + 1), 1.5))")
# Would love to be able to do something similar to this (although I like typing *POW!*):
order(((artworks.votes + subscriptions.amount)**2) / (((Time.parse(DateTime.now.to_s) - Time.parse(created_at.to_s) + 1) / 86400).round + 1)^1.5)
# Code could have some boo boos init... this is just as an example fyi
You can’t perform that action at this time.