Skip to content

Instantly share code, notes, and snippets.

View ideasasylum's full-sized avatar

Jamie Lawrence ideasasylum

View GitHub Profile
@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 / 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
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 / 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 / wercker.yml
Created January 15, 2016 23:33
wercker.yml file for a Hugo site with s3 deployment
box: debian
build:
steps:
- arjen/hugo-build:
version: "0.15"
theme: "rw-theme"
deploy:
steps:
@ideasasylum
ideasasylum / navbar.html
Created January 15, 2016 23:41
Navbar in hugo
<div class="top-bar">
<div class="top-bar-left">
<ul class="menu align-right">
<li class='menu-text'><a href="{{ .Site.BaseURL }}">{{ .Site.Title }}</a></li>
</ul>
</div>
<div class="top-bar-right">
<ul class="menu">
{{ $currentNode := . }}