Skip to content

Instantly share code, notes, and snippets.

@daz
daz / gist:10010044378bf49224d5
Created May 23, 2014
grep and awk to get the local network IP from ifconfig
View gist:10010044378bf49224d5
ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}'
@daz
daz / check-url-for-changes.sh
Created Sep 12, 2014
Check URL for changes in a loop
View check-url-for-changes.sh
#!/bin/bash
URL="http://store.apple.com/au/buy-iphone/iphone6/5.5-inch-display-64gb-space-grey-unlocked?proceed=proceed&step=select&product=MGAH2X%2FA&cppart=UNLOCKED%2FWW&step=select"
while true
do sleep 20
HASH=$(curl -s "$URL" | shasum)
echo -n "."
if [ "$HASH" != "$OLD_HASH" ] && [ "$OLD_HASH" != "" ]; then
echo "UPDATED - $(date)"
View dokku_setup.md

Deploy your own PaaS!

Setting up Dokku with DigitalOcean and Namecheap

..or how I made my own heroku in a few hours for $3.98.

This write-up owes a great deal to dscape's Node.js Deployments with Docker, Dokku, & Digital Ocean, the dokku project itself, and the fine folks working on dokku's issues. I took dscape's article as a starting point when trying this out but found some details lacking so I documented my own process for getting dokku up and running.

1. Get a domain

View geo_world_map_migration.rb
class CreatePlaces < ActiveRecord::Migration
# Rails migration for GeoWorldMap db into postgresql db
# (inspired by http://blog.inspired.no/populate-your-database-with-free-world-cities-countries-regions-in-2-minutes-using-a-rails-migration-273/ post)
# extract files from GeoWorldMap.zip archive from here
# http://www.geobytes.com/GeoWorldMap.zip
#
# and place them into #{Rails.root}/db/migrate/
# the archive has 'cities.txt' file, rename it 'Cities.txt'
#
@daz
daz / gist:a30780946cbaf32ea59a
Created Apr 4, 2015
Capistrano task to export and import Wordpress database
View gist:a30780946cbaf32ea59a
# Requires WP-CLI on the client and server
namespace :db do
desc 'Backup Wordpress database to shared/backup/timestamp.sql.gz and create a latest.sql.gz symlink'
task :backup do
stamp = Time.now.utc.strftime('%Y%m%d%H%M%S')
filename = "#{fetch(:application)}_#{stamp}.sql.gz"
backup_path = "#{shared_path}/backup/#{filename}"
on roles(:app) do
execute "mkdir -p #{shared_path}/backup"
@daz
daz / Mellow Black.terminal
Created May 6, 2010
Mellow Black OS X Terminal theme. Save this file as "Mellow Black.terminal" and open it, then set it to default if you like it. Screenshot http://imgur.com/alhUa.png
View Mellow Black.terminal
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BackgroundColor</key>
<data>
YnBsaXN0MDDUAQIDBAUGFRZYJHZlcnNpb25YJG9iamVjdHNZJGFyY2hpdmVyVCR0b3AS
AAGGoKMHCA9VJG51bGzTCQoLDA0OViRjbGFzc1xOU0NvbG9yU3BhY2VVTlNSR0KAAhAB
TxARMCAwIDAgMC44OTk5OTk5OADSEBESE1okY2xhc3NuYW1lWCRjbGFzc2VzV05TQ29s
b3KiEhRYTlNPYmplY3RfEA9OU0tleWVkQXJjaGl2ZXLRFxhUcm9vdIABCBEaIy0yNztB
View Rakefile
ssh_user = "user@domain.com" # for rsync deployment
remote_root = "~/path/to/remote/" # for rsync deployment
namespace :styles do
desc "Clear styles"
task :clear do
puts "*** Clearing styles ***"
system "rm -Rfv css/*"
end
desc "Generate styles"
@daz
daz / f1-results.rb
Created May 30, 2010
Formula 1 results scraper using Mechanize
View f1-results.rb
# Gets race and quali info from f1.com and returns an array table with Position, Driver, Team, Time/Retired, Laps
#
# Eg
# [
# ["1", "Jenson Button", "McLaren-Mercedes", "1:34:09.565", "58"],
# ["2", "Sebastian Vettel", "Red Bull Racing-Renault", "+2.1 secs", "58"],
# ["3", "Lewis Hamilton", "McLaren-Mercedes", "+4.0 secs", "58"],
# ...
require 'rubygems'
@daz
daz / skype_status.rb
Created Dec 16, 2010
Skype status checker for Ruby
View skype_status.rb
# Check Skype status. You need to enable 'Show my status on the web' in Skype prefs
#
# skype = SkypeStatus.new('some.username')
# skype.online?
# => true
require 'net/http'
require 'uri'
class SkypeStatus
@daz
daz / gist:818065
Last active Sep 24, 2015
Google Analytics Rails helper
View gist:818065
# <%= google_analytics 'UA-XXXXXX-XX' %>
# </body>
# application_helper.rb
module ApplicationHelper
def google_analytics(id)
content_tag :script, :type => 'text/javascript' do
"var _gaq = _gaq || [];
_gaq.push(['_setAccount', '#{id}']);