Skip to content

Instantly share code, notes, and snippets.

@daz
daz / f1calendar.rb
Last active December 14, 2015 14:59
Formula1 calendar script. P1-3, qualifying. and race start times for the year
# Dependencies
#
# $ gem install icalendar
#
# Usage
#
# $ git clone https://gist.github.com/5104840.git f1calendar
# $ ruby f1calendar/f1calendar.rb
#
# FORMULA 1 GRANDE PRÊMIO DO BRASIL 2015 - Sao Paulo - 2015-11-13 12:00:00 UTC - Practice 1
@daz
daz / live-f1-libevent-install.sh
Last active December 15, 2015 05:49
Install live-f1-libevent on OS X
# Install bzr
brew install bzr
# Pull down bzr repo
bzr branch lp:~ymishkov/live-f1/live-f1-libevent
cd live-f1-libevent
# Install dependancies
brew install autoconf automake pkg-config gettext libevent
@daz
daz / gist:5392816
Last active December 16, 2015 06:39
Getting distinct years in Rails and Postgresql
# start_time is a #datetime column, Postgres stores as a timestamp, we need to use date_part to extract 'year'
Event.select("date_part('year', start_time)").uniq
# Spits out
# SELECT DISTINCT date_part('year', start_time) FROM "events"
@daz
daz / live-f1.rb
Last active March 20, 2016 01:53
live-f1 libevent for Homebrew
# git clone https://gist.github.com/daz/5411271 live-f1-recipe
# brew install live-f1-recipe/live-f1.rb
require 'formula'
class LiveF1 < Formula
homepage 'https://launchpad.net/live-f1'
version '0.2.11-libevent'
url 'https://github.com/daz/live-f1/archive/libevent.zip'
sha1 '1fa0dbfadf2d144a1f9af8a075822de7fd324bde'
@daz
daz / go.xero.js
Last active December 17, 2015 22:38 — forked from ash37/go.xero
// keymaster.js
// (c) 2011-2012 Thomas Fuchs
// keymaster.js may be freely distributed under the MIT license.
(function(e){function f(e,t){var n=e.length;while(n--)if(e[n]===t)return n;return-1}function l(e,t){if(e.length!=t.length)return!1;for(var n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function h(e){for(t in r)r[t]=e[c[t]]}function p(e,t){var i,o,u,l,c;i=e.keyCode,f(a,i)==-1&&a.push(i);if(i==93||i==224)i=91;if(i in r){r[i]=!0;for(u in s)s[u]==i&&(m[u]=!0);return}h(e);if(!m.filter.call(this,e))return;if(!(i in n))return;for(l=0;l<n[i].length;l++){o=n[i][l];if(o.scope==t||o.scope=="all"){c=o.mods.length>0;for(u in r)if(!r[u]&&f(o.mods,+u)>-1||r[u]&&f(o.mods,+u)==-1)c=!1;(o.mods.length==0&&!r[16]&&!r[18]&&!r[17]&&!r[91]||c)&&o.method(e,o)===!1&&(e.preventDefault?e.preventDefault():e.returnValue=!1,e.stopPropagation&&e.stopPropagation(),e.cancelBubble&&(e.cancelBubble=!0))}}}function d(e){var t=e.keyCode,n,i=f(a,t);i>=0&&a.splice(i,1);if(t==93||t==224)t=91;if(t in r){r[t]=!1;for(n in s)
@daz
daz / user.rb
Last active December 18, 2015 01:29 — forked from matthewlehner/user.rb
# Because we have some old legacy users in the database, we need to
# override #has_secure_passwords' method for checking if a password is valid.
# We first ask if the password is valid, and if it throws an InvalidHash
# exception, we know that we're dealing with a legacy user, so we check the
# password against the SHA1 algorithm that was used to hash the password in
# the old database.
#SOURCES OF SOLUTION:
# http://stackoverflow.com/questions/6113375/converting-existing-password-hash-to-devise
# https://github.com/binarylogic/authlogic/blob/master/lib/authlogic/crypto_providers/sha512.rb
# http://www.xbsd.nl/pub/osx-pl2303.kext.tgz
sudo cp -R osx-pl2303.kext /System/Library/Extensions/
cd /System/Library/Extensions
sudo chmod -R 755 osx-pl2303.kext
sudo chown -R root:wheel osx-pl2303.kext
cd /System/Library/Extensions
sudo kextload ./osx-pl2303.kext
sudo kextcache -system-cache
; CNAME
calendar 1 IN CNAME ghs.googlehosted.com
drive 1 IN CNAME ghs.googlehosted.com
mail 1 IN CNAME ghs.googlehosted.com
sites 1 IN CNAME ghs.googlehosted.com
video 1 IN CNAME ghs.googlehosted.com
; MX
@ 1 IN MX 10 aspmx3.googlemail.com
@ 1 IN MX 1 aspmx.l.google.com
@daz
daz / f1teams.rb
Last active January 3, 2016 18:19
Formula1 teams script. List all teams and drivers for the current year.
# Dependencies
#
# $ gem install mechanize
#
# Usage
#
# $ git clone https://gist.github.com/8501219.git f1teams
# $ ruby f1teams/f1teams.rb
#
# Red Bull Racing
@daz
daz / gist:10010044378bf49224d5
Created May 23, 2014 06:35
grep and awk to get the local network IP from ifconfig
ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}'