Skip to content

Instantly share code, notes, and snippets.

View adamrunner's full-sized avatar

Adam Runner adamrunner

View GitHub Profile
# 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 / 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
# 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
@adamrunner
adamrunner / esp8266-ds18s20.ino
Created February 28, 2016 08:25
Read a DS18x20 temperature sensor and upload the data to data.sparkfun.com
#include <OneWire.h>
#include "ESP8266WiFi.h"
#include <Phant.h>
//NOTE: Do your configuration here:
const char* ssid = "Your-wifi-ssid";
const char* password = "your-wifi-password";
//NOTE: interval is in milliseconds
const long sendInterval = 600000;
const char PhantHost[] = "data.sparkfun.com";
const char PublicKey[] = "public-key-from-sparkfun";
@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
@adamrunner
adamrunner / esp8266-temperature-server.ino
Last active March 27, 2016 21:45
A simple ESP8266 web server that acts as a microservice, reports the temperature at http://ip-address/ or http://ip-address/temp
#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <OneWire.h>
const char* ssid = "wifi";
const char* password = "password";
const long pollTempInterval = 10000;
String displayedTempF = "n/a";
unsigned long previousMillisTemp;