Skip to content

Instantly share code, notes, and snippets.

View bdcravens's full-sized avatar

Billy Cravens bdcravens

View GitHub Profile
@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 / 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 / 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 / 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;

gem install pg -- --with-pg-config=/Applications/Postgres.app/Contents/Versions/9.3/bin/pg_config
@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)
@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 / sabre_mashery.html
Created July 28, 2015 21:40
seen on Mashery site
<!-- This no script tag lets people rocking with their JS turned off see content. Buttheads. -->
<noscript>
<style>
#page, #footer {display:block}
</style>
</noscript>
@bdcravens
bdcravens / app_controllers_slack_controller.rb
Created November 27, 2015 19:55 — forked from patio11/app_controllers_slack_controller.rb
Implementing a /healthcheck endpoint in Slack to read out consul status in a human-readable fashion
class SlackController < ApplicationController
skip_before_action :verify_authenticity_token
@@slack_security_tokens =
["copy-paste-the-token-you-get-from-Slack-when-configuring-the-integration-here"]
before_filter :bounce_access_not_from_slack
def healthcheck
services = SystemStatus.list_services
@bdcravens
bdcravens / rebuild_index.sql
Created April 23, 2016 20:04
View table index fragmentation and rebuild index
SELECT a.index_id, name, avg_fragmentation_in_percent
FROM sys.dm_db_index_physical_stats (DB_ID(N'my_db'), OBJECT_ID(N'dbo.my_table'), NULL, NULL, NULL) AS a
JOIN sys.indexes AS b ON a.object_id = b.object_id AND a.index_id = b.index_id;
ALTER INDEX idx_myIndex ON my_table
REBUILD WITH (FILLFACTOR = 80);