Skip to content

Instantly share code, notes, and snippets.

View adamrunner's full-sized avatar

Adam Runner adamrunner

View GitHub Profile
@adamrunner
adamrunner / display_time.rb
Created August 16, 2012 21:20
Calculate Difference in time in Days, Hours, Minutes, Seconds
def display_time(total_seconds)
total_seconds = total_seconds.to_i
days = total_seconds / 86400
hours = (total_seconds / 3600) - (days * 24)
minutes = (total_seconds / 60) - (hours * 60) - (days * 1440)
seconds = total_seconds % 60
display = ''
display_concat = ''
@adamrunner
adamrunner / resque.rake
Created January 15, 2013 22:58
working resque.rake file for newrelic_rpm
# load the Rails app all the time
require "resque/tasks"
require "resque_scheduler/tasks"
require "newrelic_rpm"
ENV["NEWRELIC_ENABLE"] = "true"
task "resque:setup" => :environment do
Resque.before_fork = Proc.new { ActiveRecord::Base.establish_connection; NewRelic::Agent.manual_start :license_key=>"04bba1b0698194f36a96c319818b19818b614af00a955e", :app_name => "Background Workers" }
end
@adamrunner
adamrunner / git_clean_remote
Created January 17, 2013 21:58
clear all old remote branches
git remote prune origin
git branch -r --merged | grep origin | grep -v '>' | grep -v master | grep -v dev | xargs -L1 | awk '{sub(/origin\//,"");print}' | xargs git push origin --delete
# Script used to quickly get a glance of how many queries since a certain time period were longer than X seconds
# Customize these 2 parameters
STARTDATE="140303" # 2 Digit Year, 2 Digit Month, 2 Digit Day
QUERYTIME=3.0
# Runs the commands and prints out Query_time lines
FIRST=`grep -n -m 1 "# Time: $STARTDATE" slow.log | cut -d : -f 1`; TOTAL=`wc -l slow.log | cut -d ' ' -f 1`; tail -n `echo "$TOTAL-$FIRST" | bc` slow.log | grep Query_time | awk -v time="$QUERYTIME" '$3 > time {print; }'
@adamrunner
adamrunner / 04.python
Last active August 29, 2015 13:57
Problems installing libxml2 with homebrew OS X 10.9.2
/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/distutils/dist.py:251: UserWarning: 'licence' distribution option is deprecated; use 'license'
warnings.warn(msg)
libxslt stub generator not found, libxslt not built
running install
running build
running build_py
creating build
creating build/lib.macosx-10.9-intel-2.7
copying libxml2.py -> build/lib.macosx-10.9-intel-2.7
copying drv_libxml2.py -> build/lib.macosx-10.9-intel-2.7
@adamrunner
adamrunner / resque-scheduler
Last active January 3, 2017 03:42
resque-scheduler
#! /bin/sh
### BEGIN INIT INFO
# Provides: resque_scheduler
# Required-Start: $remote_fs $syslog
# Required-Stop: $remote_fs $syslog
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts Scheduler for Resque
# Description: This script will start the resque scheduler task so
# jobs will be automatically scheduled.
@adamrunner
adamrunner / new_mac_setup.md
Last active March 8, 2016 16:30 — forked from saetia/gist:1623487
Some steps to take when setting up a new mac

OS X Preferences


#Disable window animations
defaults write NSGlobalDomain NSAutomaticWindowAnimationsEnabled -bool false

#Enable repeat on keydown
defaults write -g ApplePressAndHoldEnabled -bool false
# could probably restore
26245b4929cb75c830649ba7863ce5697b4d5235 lib/assets/javascripts/admin/models/item.js.coffee
92fcd0628ce52ab5a89f01c1b63e1bb2b844b489 lib/assets/javascripts/admin/models/item/field.js.coffee
92fcd0628ce52ab5a89f01c1b63e1bb2b844b489 lib/assets/javascripts/admin/models/item/stub.js.coffee
# has been restored
lib/assets/javascripts/admin/models/product.js.coffee
lib/assets/javascripts/admin/models/product_collection.js.coffee
# shouldn't need restored - but if we're being paranoid
#NOTE: gem install blinkstick first
require "blinkstick"
def cycle_colors(blinkstick)
percentages = [0,0,0]
cycle = 1
while true do
sleep(0.01)
if percentages.first <= 100 && cycle.odd?
percentages = percentages.map {|a| a+1}
@adamrunner
adamrunner / ds1820.lua
Created February 23, 2016 17:27
Send tempature (in degrees C) from a DS1820 temp chip to thingspeak.com, runs in NodeMCU on a ESP8266
-- Measure temperature and post data to thingspeak.com
-- 2014 OK1CDJ
--- Tem sensor DS18B20 is conntected to GPIO0
--- 2015.01.21 sza2 temperature value concatenation bug correction
http = require('http')
pin = 4
ow.setup(pin)
counter=0
lasttemp=-999