Skip to content

Instantly share code, notes, and snippets.

View ideasasylum's full-sized avatar

Jamie Lawrence ideasasylum

View GitHub Profile
@ideasasylum
ideasasylum / translate_amazon.js
Last active July 30, 2020 23:18
Translate Amazon service names into plain English (see https://www.expeditedssl.com/aws-in-plain-english)
// ==UserScript==
// @name Translate Amazon
// @namespace http://your.homepage/
// @version 0.1
// @description Translate the Amazon service names into plain English. See https://www.expeditedssl.com/aws-in-plain-english
// @author @ideasasylum
// @match https://*.console.aws.amazon.com/console/home?*
// @grant none
// ==/UserScript==
@ideasasylum
ideasasylum / copy_markdown_from_trello.js
Created August 10, 2015 12:16
Copies a Trello board to the Clipboard as Markdown
// originally found in a comment on: http://www.secretgeek.net/trello_ws
var s = [];
s.push("# " + jQuery(".board-header").children()[0].innerText);
jQuery(".list:has(.list-header-name)").each(function() {
s.push("\n## " + jQuery(this).find(".list-header-name")[0].innerText + "\n");
jQuery(this).find(".list-card-title").each(function() {
s.push("* " + this.innerText);
});
});
@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
@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 / 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==
############################################################
# 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 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);
@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 / 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 / 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}"