Skip to content

Instantly share code, notes, and snippets.

View darrenterhune's full-sized avatar

Darren Terhune darrenterhune

  • Canada
View GitHub Profile
@darrenterhune
darrenterhune / nokogiri.sh
Last active August 29, 2015 13:55
Nokogiri Mac OS X Mavericks
gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.1/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1.28
@darrenterhune
darrenterhune / finder.rb
Last active August 29, 2015 13:57
Find all users unless has_many matches a specific date
User
has_many :bookings
| id | name |
---------------
| 1 | amy |
| 2 | jack |
@darrenterhune
darrenterhune / heartbleed.sh
Created April 9, 2014 19:24
openssl heartbleed update
# Update the system and packages
sudo apt-get update
sudo apt-get dist-upgrade
# Restart server
sudo shutdown -r now
# Check openssl is upgraded against versions below
dpkg -l | grep "openssl"
@darrenterhune
darrenterhune / search-widget.html
Last active August 29, 2015 14:05
ASAP Search Widget (NEW)
<!-- START aircraftsalesandparts.com widget -->
<style type="text/css" media="screen">
#asap.asap-widget{margin:20px 0;}#asap.asap-widget .title{background:#ddd;color:#666;text-shadow:1px 1px 0 #eee;top:-1px;border:1px solid #C2C2C2;padding:10px;margin:0;}#asap.asap-widget .link{padding:5px;background:#333;color:#eee;}#asap.asap-widget table{display:block;border:1px solid #D8D8D8;border-bottom:none;}#asap.asap-widget table tr{padding:5px;}#asap.asap-widget table th{text-align:left;padding:5px;color:#333;}#asap.asap-widget table td{padding:10px;}#asap.asap-widget table td.title{width:200px;font-weight:bold;color:#777;}#asap.asap-widget table form input.submit{margin-left:4px;}</style>
<div id="asap" class="asap-widget"><div class="recent-widget"><h3 class="title"><span>Find Aircraft Parts</span></h3><div class="items"><table><tr><td><form action="https://aircraftsalesandparts.com/parts/search" method="get" target="_blank"><input id="search" name="search" type="text" /><input type="hidden" name="submit" value="
@darrenterhune
darrenterhune / redis.sh
Last active August 29, 2015 14:16
Redis install
# redis install
sudo apt-get install tcl8.5
wget http://download.redis.io/redis-stable.tar.gz
tar xvzf redis-stable.tar.gz
cd redis-stable/
make
make test
sudo make install
sudo mkdir /etc/redis
@darrenterhune
darrenterhune / kernel-commands.sh
Last active September 4, 2015 02:45
helpful unix kernel commands
# 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 February 24, 2010 09:23
csv import example in 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 October 29, 2010 08:12
Example bitfield calculations in ruby with thinking-sphinx
# 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
#
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']
@darrenterhune
darrenterhune / order_ranking_algorithm.rb
Created October 3, 2011 22:57
ranking algorithm in mysql
# 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