Skip to content

Instantly share code, notes, and snippets.

View bdcravens's full-sized avatar

Billy Cravens bdcravens

View GitHub Profile
@bdcravens
bdcravens / .gitignore
Created June 22, 2015 02:28
.gitignore for typical Packer project
variables.json
vendor/cookbooks
Berksfile.lock
Gemfile.lock
.vagrant
@bdcravens
bdcravens / delete_sidekiq_retries_by_queue.rb
Created January 22, 2015 23:42
delete Sidekiq retries for only a certain queue
query = Sidekiq::RetrySet.new
query.select do |job|
job.queue=='ups_tracking'
end.map(&:delete)
gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
@bdcravens
bdcravens / gist:ceaebed8bbb12964649b
Last active August 29, 2015 14:09
Gumroad "Add to Library" bug

"Add to Library" not working. Button flashes "Adding ..." and then returns, no notice, no error. Request goes to add_purchase_to_library.json, returns a 200 status code, and the JSON returned is success: false.

Source on a purchased product page reveals this for button:

<... name="user[purachse_id" ....>

An obvious typo in form. Inpect Element and changing to:

&lt;... name="user[purchase_id]" ....&gt;

@bdcravens
bdcravens / gist:84e4248e12db29eee998
Last active August 29, 2015 14:08
adding second database and migrations to rails file
# lib/pg_database.rb
# models extend this class
class PgDatabase < ActiveRecord::Base
self.abstract_class = true
establish_connection "rr_#{Rails.env}"
end
# lib/pg_migrations.rb
# migrations extend this class
@bdcravens
bdcravens / open_csv.rb
Created October 7, 2014 20:30
csv contents to array of hashes
# contents of csv:
# a,b,c
# 456,"foo",0
# 123,"bar",1
# 789,"bam",2
require 'csv'
# iterating through array
result = []
@bdcravens
bdcravens / grab-tapas.rb
Created September 3, 2013 06:54
Ruby Tapas scraper
require "mechanize"
agent = Mechanize.new
agent.user_agent = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_8_4) " + \
"AppleWebKit/536.30.1 (KHTML, like Gecko) Version/6.0.5" + \
" Safari/536.30.1"
page = agent.get "https://rubytapas.dpdcart.com/subscriber/content"
login_form = page.form_with id:"login-form"
login_form.field_with(id:"username").value = tapas_username
login_form.field_with(id:"password").value = tapas_password
@bdcravens
bdcravens / gist:5843297
Created June 23, 2013 00:59
Nokogiri global search
doc.search("[text()*='b']").size
@bdcravens
bdcravens / invoice-filename-change.sh
Created February 16, 2013 16:41
was: Invoice_000000ABCDEF012_010113.csv changeto: ABCDEF012.csv (leading zeros may change)
#!/bin/bash
FILES=Invoice_*_*.csv
for f in $FILES
do
newname=`echo $f| cut -d'_' -f 2`
newnamelen=${#newname}
leading=$[newnamelen-9]
invnum=${newname:leading}
mv $f $invnum.csv
done
@bdcravens
bdcravens / search-text-columns-mssql2000.sql
Last active December 12, 2015 04:28
Generates SQL (SQL Server 2000) for searching all text columns for a given string. (Need to remove last UNION) Good for catching SQL injection results.
SELECT
'select ' + column_name + ' as txt,
''' + column_name + ''' as [column_name],
id from applications where ' + column_name + ' like ''%payday%'' union '
FROM INFORMATION_SCHEMA.COLUMNS
where table_name = 'applications'
and data_type in ('nvarchar','varchar','char','nchar')