Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie Lawrence ideasasylum

View GitHub Profile
@ideasasylum
ideasasylum / 0_reuse_code.js
Last active Aug 29, 2015
Here are some things you can do with Gists in GistBox.
View 0_reuse_code.js
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
View DaftHousePrices.js
// ==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==
View motion-mmalcam.conf
############################################################
# 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 / gist:3e85fb520f03d5b672d7
Created May 7, 2014
Check for unsafe query risk in active_record in Postgres
View gist:3e85fb520f03d5b672d7
-- 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);
@ideasasylum
ideasasylum / Description.md
Last active Dec 21, 2015
A Pry session when debugging a Figaro problem.
View Description.md
  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 / pre-commit
Created Mar 7, 2013
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
View pre-commit
#!/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 / Piddle.rb
Created Sep 5, 2012
Trying to dynamically create around_ callbacks in ActiveRecord
View Piddle.rb
# 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 / gist:452055
Created Jun 24, 2010
This is how I use should_change macros
View gist:452055
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
View Sony lens info
exiftool -r "-lensId>lens" <folder name> -overwrite_original