Skip to content

Instantly share code, notes, and snippets.

Avatar

Darren Terhune darrenterhune

View GitHub Profile
@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
#
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
@darrenterhune
darrenterhune / passwordless_ssh.zsh
Last active Jan 17, 2018
Dreamhost passwordless login
View passwordless_ssh.zsh
scp ~/.ssh/id_rsa.pub user@example.com:~/
ssh user@example.com
mkdir .ssh
cat id_rsa.pub >> .ssh/authorized_keys
rm id_rsa.pub
chmod go-w ~
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
@darrenterhune
darrenterhune / digitalocean.md
Last active Apr 14, 2016
Digital Ocean [Virtual Hosts, MySQL] Setup
View digitalocean.md

Setup Virtual Hosts

Execute the following commands after ssh into vps:

sudo mkdir -p /var/www/example.com
sudo chown -R $USER:$USER /var/www/example.com
cd /var/www/
sudo chown www-data:www-data * -R 
sudo usermod -a -G www-data username-logged-in-as
cd
@darrenterhune
darrenterhune / nokogiri.sh
Last active Aug 29, 2015
Nokogiri Mac OS X Mavericks
View nokogiri.sh
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 Aug 29, 2015
Find all users unless has_many matches a specific date
View finder.rb
User
has_many :bookings
| id | name |
---------------
| 1 | amy |
| 2 | jack |
@darrenterhune
darrenterhune / heartbleed.sh
Created Apr 9, 2014
openssl heartbleed update
View heartbleed.sh
# 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"
You can’t perform that action at this time.