Skip to content

Instantly share code, notes, and snippets.

View wiseleyb's full-sized avatar

Ben Wiseley wiseleyb

  • Monterey, CA
View GitHub Profile
def to_h_time(seconds_diff)
hours = seconds_diff / 3600
seconds_diff -= hours * 3600
minutes = seconds_diff / 60
seconds_diff -= minutes * 60
seconds = seconds_diff
"#{hours.to_i.to_s.rjust(2, '0')}:#{minutes.to_i.to_s.rjust(2, '0')}:#{seconds.to_i.to_s.rjust(2, '0')}"
# ----------------------------------------------------------------
# FILE: launch_action_credits.rb
# ----------------------------------------------------------------
# launch action credits
# to launch: prodrunner ~/launch_action_credits.rb
object_count = ActionCredit.
joins('LEFT OUTER JOIN action_credit_source_data ' +
'ON action_credits.id = action_credit_source_data.action_credit_id').
def run_action_credit_updates(batch, idx)
report_size = 10_000
batch.each_with_index do |b, i|
if i > 0 && i % report_size == 0
puts "Batch #{idx} : #{i} (#{ 100 - ((report_size/i.to_f) * 100).to_i }%)"
end
b.set_source_data
end
puts "Batch #{idx} : Done"
end
@wiseleyb
wiseleyb / gist:9752166
Last active August 29, 2015 13:57
Setting up sds's dot files
Rebuilding your dev box with Shane's dot files
vim --version
should be 7.4 - if not
sudo yum install mercurial
cd ~
hg clone https://vim.googlecode.com/hg/ vim
cd ~/vim
@wiseleyb
wiseleyb / gist:3430937
Created August 23, 2012 00:58
token auth
class TokensController < ApplicationController
skip_before_filter :verify_authenticity_token
respond_to :json
def create
email = params[:email]
password = params[:password]
if request.format != :json
render :status=>406, :json=>{:message=>"The request must be json"}
return
# Job
add_column :current_batch_job_id # current batch job running
# This represents batch job runs - and provides history
create_table "batch_jobs", :force => true do |t|
t.integer "job_id" # job this is related to
t.string "state" # state: create, processed, running, failed, stopped, finished
t.integer "instances_to_create" # count of the planned number of instances to create
t.datetime "created_at"
t.datetime "updated_at"
@wiseleyb
wiseleyb / gist:2015092
Created March 11, 2012 04:58
JS Timer troubles
# I have this timer setup. It's the only way I could get it to work but seems very wrong...
# Specifically in processUserCommand if I don't clearTimeout's every time the win and max
# moves scenarios no longer work. Without the timer tear down the app just goes on and on
# after reaching max moves and/or win.
# Full code up on https://github.com/wiseleyb/solitr
# Sample app up on http://solitr.herokuapp.com/klondike-turn-three-hints
window.timer = new App.AutoRun
window.timers = []
rasputin:wordsquared wiseleyb$ git diff Gemfile.lock
diff --git a/Gemfile.lock b/Gemfile.lock
index cc897f5..33d8652 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,76 +1,77 @@
GIT
remote: git://github.com/thedarkone/rails-dev-boost.git
- revision: e2716ad0bceefbd840528cc5de329de075b602e1
+ revision: 6e093e559003d1986ab95b09a9e21197bb5d8edb
@wiseleyb
wiseleyb / Moneybookers Ruby Code
Created February 15, 2011 17:42
Code we use to handle Moneybookers payments
#----------------------------------------------------------------------------------
# CONTROLLER
#----------------------------------------------------------------------------------
class MoneybookersPaymentsController < ApplicationController
layout :false
ssl_required :mbstatus, :mbreturn, :mbcancel if HTTPS
@wiseleyb
wiseleyb / gist:765348
Created January 4, 2011 20:22
activeresource loosing it's prefix_options
class Base < ActiveResource::Base
def reload
po = self.prefix_options.dup
super
self.prefix_options = po
return self
end
def save