Skip to content

Instantly share code, notes, and snippets.

Avatar

Jamie Lawrence ideasasylum

View GitHub Profile
@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);
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 / 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
@ideasasylum
ideasasylum / count.rb
Last active Aug 29, 2015
Find out the gender balance from a list of names
View count.rb
require 'rest-client'
file = 'names.txt'
key = 'YOUR GENDER API KEY'
raw = []
results = Hash.new 0
errors = 0
num_names = 0
View Sony lens info
exiftool -r "-lensId>lens" <folder name> -overwrite_original
@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
@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 / 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 / wercker.yml
Created Jan 15, 2016
wercker.yml file for a Hugo site with s3 deployment
View wercker.yml
box: debian
build:
steps:
- arjen/hugo-build:
version: "0.15"
theme: "rw-theme"
deploy:
steps:
View navbar.html
<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 := . }}