Skip to content

Instantly share code, notes, and snippets.

View eoinkelly's full-sized avatar

Eoin Kelly eoinkelly

View GitHub Profile
@eoinkelly
eoinkelly / Problem.rb
Last active December 18, 2015 16:29 — forked from ootoovak/Problem.rb
# Want to pass in a hash or instance of object. Was hoping to avoid is_a? or creating a new object but
# think that can only be done with is_a? or overriding new. Also, I might be missing the point as
# avoiding is_a? should mean I am using Duck Typing but if I'm using Duck Typing then I shouldn't be
# checking object equality anyway. See RSpec test for details.
class MyClass
attr_accessor :name
attr_accessor :description
def initialize(args = {})
@eoinkelly
eoinkelly / getting_started.md
Last active February 1, 2016 21:50
Getting started with requirejs-rails

Usage

  1. Add this to your Rails app's Gemfile:

    gem 'requirejs-rails'
    

    and then run bundle install on the command line.

@eoinkelly
eoinkelly / post-push.rb
Created April 8, 2016 13:21
post push git hook that will automatically generate a codeship CI build badge that you can paste into your PR description
#!/usr/bin/env ruby
require "net/http"
require "json"
CODESHIP_API_KEY = "PUT_YOUR_CODESHIP_API_KEY_HERE".freeze
origin_remote_url = `git config --get remote.$(git config --get branch.master.remote).url`.chomp
current_project_name = %r{(?:\:|\/)(.+)\.git$}.match(origin_remote_url)[1]
current_branch_name = `git rev-parse --abbrev-ref HEAD`.chomp
@eoinkelly
eoinkelly / bus.rb
Created September 19, 2016 07:05
Command line tool to get upcoming bus departures for a particular stop in Wellington NZ
#!/usr/bin/env ruby
require "nokogiri"
require "net/http"
courtenay_place = 5002 # Get your stop number from the metlink.co.nz website
buses_i_care_about = %w(52 56 57 58)
# .../departures returns 20 results
module Part2
# 1
# 2 3 4
# 5 6 7 8 9
# A B C
# D
class State
def go_u; self; end
def go_d; self; end
def go_l; self; end
@eoinkelly
eoinkelly / postgres-upgrade-recipe.sh
Last active November 9, 2017 16:59
Upgrade Postgres to 9.4 using Homebrew on Mac OSX
#!/bin/bash
# This script can be used in "run & hope" mode or you can use it as a recipe to
# do things manually - you probably want the latter if you really care about
# the data in your databases.
# Happy hacking
# /Eoin/
# Tell bash to stop if something goes wrong
set -e
@eoinkelly
eoinkelly / allib-menu-sorted-query.php
Created April 16, 2012 11:49
Get all posts included in a WordPress Menu, sorted in the order they appear in the menu
<?php
/*
* This is a convenient wrapper that allows you to retrieve the list of posts
* mentioned in a Menu. The posts are returned in the order they are in the menu.
* Args: An array containing these keys:
* theme_location: (required) the name of the theme location you have defined
* for the menu with register_nav_menu()

GET /numbers at log level 'debug' is 462 lines

[c23afe93-b615-4c4d-bf0a-539ea1d6928f] Started GET "/numbers/" for 127.0.0.1 at 2019-01-19 17:25:17 +1300
[c23afe93-b615-4c4d-bf0a-539ea1d6928f] Processing by PagesController#show as HTML
[c23afe93-b615-4c4d-bf0a-539ea1d6928f]   Parameters: {"slug"=>"numbers"}
[c23afe93-b615-4c4d-bf0a-539ea1d6928f]   Setting Load (1.4ms)  SELECT  "settings".* FROM "settings" WHERE "settings"."key" = $1 LIMIT $2  [["key", "footer"], ["LIMIT", 1]]
[c23afe93-b615-4c4d-bf0a-539ea1d6928f]   Page Load (11.2ms)  SELECT  "pages".* FROM "pages" WHERE "pages"."id" = $1 ORDER BY "pages"."order" ASC LIMIT $2  [["id", 11], ["LIMIT", 1]]
[c23afe93-b615-4c4d-bf0a-539ea1d6928f]   Page Load (3.2ms)  SELECT  "pages".* FROM "pages" WHERE "pages"."slug" = $1 ORDER BY "pages"."order" ASC LIMIT $2  [["slug", "numbers"], ["LIMIT", 1]]
[c23afe93-b615-4c4d-bf0a-539ea1d6928f]   Rendering pages/numbers.html.haml within layouts/application
# Add this to your ~/.zshrc (it only works in zsh not bash AFAIK)
# #####################################
# A fast way of chdir to a code project
function work {
cd ~/Code/repos/$1
}
function _work() {
local state