Skip to content

Instantly share code, notes, and snippets.

View onpaws's full-sized avatar
🚴‍♂️
building things

Pat onpaws

🚴‍♂️
building things
View GitHub Profile
@onpaws
onpaws / database2seeds.rb
Created February 13, 2014 01:39
Rake task to dump current Rails database into seeds.rb format
namespace :export do
desc "Prints Country.all in a seeds.rb way."
task :seeds_format => :environment do
Country.order(:id).all.each do |country|
puts "Country.create(#{country.serializable_hash.delete_if {|key, value| ['created_at','updated_at','id'].include?(key)}.to_s.gsub(/[{}]/,'')})"
end
end
end
#via http://xyzpub.com/en/ruby-on-rails/3.2/seed_rb.html
@onpaws
onpaws / bash-template.sh
Created April 16, 2014 20:04
bash: start here
#!/bin/bash
set -o nounset
set -o errexit
<<COMMENT
via http://robertmuth.blogspot.com/2012/08/better-bash-scripting-in-15-minutes.html
To perform a syntax check/dry run of your bash script run:
bash -n myscript.sh
@onpaws
onpaws / gist:2b40f25e67fb98d60bec
Created June 2, 2014 21:53
find in page with regex (JS)
var p=/.*(regu).+?\ /gi; console.log( document.body.innerText.match(p) );
@onpaws
onpaws / loadCSVfromSQL
Created October 2, 2014 16:37
Load CSV from SQL
LOAD DATA INFILE '/tmp/stats-2014.csv'
INTO TABLE orig_stats
FIELDS TERMINATED BY ','
LINES TERMINATED BY '\r\n'
IGNORE 1 LINES ;
@onpaws
onpaws / bootstrap3-CurrentPageNavHighlight
Last active August 29, 2015 14:08
animate navbar clicks
$('#nav .navbar-nav li>a').click(function(){
var link = $(this).attr('href');
var posi = $(link).offset().top;
$('body,html').animate({scrollTop:posi},700);
});
@onpaws
onpaws / bootstrap3-CurrentPageNavHighlight
Created October 28, 2014 21:50
highlight current page on navbar
def is_active(action)
params[:action] == action ? "active" : nil
end
def nav_entry(body, path)
content_tag(:li, link_to(body, path), class: ('active' if current_page?(path)))
end
def nav_entry_indent(body, path)
entry_class = 'nav-indent'
entry_class += ' active' if current_page?(path)
@onpaws
onpaws / run-tests-over-git
Created March 11, 2015 17:37
run a test suite over git revisions
(set -e && git rev-list --reverse master~3..master | while read rev; do git checkout $rev; python runtests.py; done)
# set -e causes shell to stop while loop on test error
# via Gary Bernhardt
@onpaws
onpaws / batch-like-all
Created March 16, 2015 20:53
batch like all facebook
/*via http://n8henrie.com/2015/03/how-to-batch-like-all-facebook-posts-on-a-page-with-jquery-2/
open javascript console & copy paste jquery latest from
http://code.jquery.com/jquery-latest.min.js
*/
$('a.UFILikeLink[title="Like this"]').each(
function(i, e){
this.click()
}
@onpaws
onpaws / ruby_fiddle.rb
Created June 14, 2012 16:04 — forked from anonymous/ruby_fiddle.rb
testing activegist
# Your Assignment:
# (easy) First, print the numbers 1 to 10 in the console
puts "1. ---------------"
(1..10).each do |i|
puts i
end
# (medium) Second, Write a method that takes an array [-4,-76, 64, 200, -2, 644] and only prints positive integers
@onpaws
onpaws / removeQuarantine.sh
Created October 14, 2015 08:52
fix for so-called 'corrupt' apps
xattr -d com.apple.quarantine /path/to/file