Skip to content

Instantly share code, notes, and snippets.

View ideasasylum's full-sized avatar

Jamie Lawrence ideasasylum

View GitHub Profile
exiftool -r "-lensId>lens" <folder name> -overwrite_original
@ideasasylum
ideasasylum / gist:452055
Created June 24, 2010 22:01
This is how I use should_change macros
context "Parsing example file" do
setup {
@xml = File.open(File.expand_path(File.dirname(__FILE__) + '/../EICK.xml'), 'r'){|f| f.read }
parse_hamweather_data(@xml)
}
should_change("the number of forecasts", :by => 8) {Forecast.count}
should_change("the number of current forecasts", :by => 1) {Forecast.count :conditions => 'current = true'}
should_change("the number of 3hour forecasts", :by => 7) {Forecast.count :conditions => 'priority = 2'}
end
@ideasasylum
ideasasylum / Piddle.rb
Created September 5, 2012 18:00
Trying to dynamically create around_ callbacks in ActiveRecord
# A module for creating around callbacks in a model
module Piddle
module TimelineFor
def self.included(klass)
klass.send(:extend, ClassMethods)
end
module ClassMethods
def timeline_for(event, opts={})
method_name = :"timeline_for_#{event.to_s}"
@ideasasylum
ideasasylum / pre-commit
Created March 7, 2013 21:49
A pre-commit Git hook for preventing commits containing focus: true, debugger, binding.pry etc Based on a blog post I wrote http://jamie.ideasasylum.com/2013/02/preventing-the-stupid-mistakes-like-committing-focustrue/ (which in turn was based on someone else's script). This version allows you to easily setup new rules at the head of the script
#!/usr/bin/env ruby
spec_hits = []
checks = {
'_spec\.rb$' => ['focus:[:space:]*true'],
'\.rb$' => ['binding\.pry', 'debugger']
}
# Find the names of all the filenames that have been (A)dded (C)opied or (M)odified
filenames = `git diff --cached --name-only --diff-filter=ACM`.split("\n")
@ideasasylum
ideasasylum / Description.md
Last active December 21, 2015 15:39
A Pry session when debugging a Figaro problem.
  1. First, you'll need the pry-stack_explorer gem.
  2. Then put <% binding.pry %> into your database.yml file.
  3. Start a rails c
  4. Pry will open when it starts loading the database.yml file
  5. Navigate up the stack until you reach the initializer loading
  6. Run initializers.tsort.collect &:name to see the order that the initialiser are being loaded.
  7. You should (hopefully) see figaro_load before activerecord.initialize_database
@ideasasylum
ideasasylum / gist:3e85fb520f03d5b672d7
Created May 7, 2014 09:42
Check for unsafe query risk in active_record in Postgres
-- Check for vulnerability to the unsafe query risk in Rails mentioned here: https://groups.google.com/forum/#!topic/rubyonrails-security/8CVoclw-Xkk
-- Are any columns named the same as their table? (high risk)
select * from information_schema.columns where table_name = column_name;
-- Are any columns named the same as any other table (might pose a risk during join)
select * from information_schema.columns where column_name in (select distinct table_name from information_schema.columns);
############################################################
# Daemon
############################################################
# Start in daemon (background) mode and release terminal (default: off)
daemon off
# File to store the process ID, also called pid file. (default: not defined)
process_id_file /var/run/motion/motion.pid
@ideasasylum
ideasasylum / DaftHousePrices.js
Last active July 1, 2019 11:08
Daft House Prices
// ==UserScript==
// @name Daft House Prices
// @namespace http://ideasasylum.com
// @version 0.2
// @description Replace Daft house prices with CB deposit and income limits
// @author Jamie Lawrence @ideasasylum
// @match https://www.daft.ie/*
// @grant none
// ==/UserScript==
@ideasasylum
ideasasylum / 0_reuse_code.js
Last active August 29, 2015 14:15
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@ideasasylum
ideasasylum / count.rb
Last active August 29, 2015 14:21
Find out the gender balance from a list of names
require 'rest-client'
file = 'names.txt'
key = 'YOUR GENDER API KEY'
raw = []
results = Hash.new 0
errors = 0
num_names = 0