Skip to content

Instantly share code, notes, and snippets.

View wjlroe's full-sized avatar
📷

William Roe wjlroe

📷
View GitHub Profile
@wjlroe
wjlroe / v1.clj
Last active December 16, 2015 08:09
Map destructuring. In v1 - I manually merge a map with default options In v2 - I use Clojure's built-in map destructuring defaults
(def status-params
{:count 200})
(defn tweets
"Get the user's tweets
params contains params to override the defaults, such as :since_id"
[params]
(:body (statuses-home-timeline :oauth-creds my-creds
:params (merge status-params
@wjlroe
wjlroe / ios-icons.rb
Last active December 16, 2015 05:19
Rough set of scripts for: * rounding corners on large icons (for Apple things) - rounded corners of 179px is for 1024x1024 images * saving each logo size for ipad,ipad-retina,iphone,iphone-retina
#!/usr/bin/env ruby
require 'RMagick'
def generate_image(name, size)
puts "#{name}: generate #{size}x#{size} image"
Magick::Image::read('logo.png').first.resize(size, size).write(name)
end
[144, 120, 114, 100, 72, 60, 58, 57, 50, 29].each do |size|
generate_image("icon-#{size}x#{size}.png", size)
(streams
(where (and metric (service "app1")(tagged "sign_in")
; We want to get alerted about failed sign ins. However we expect that there will be failures
; due to incorect passwords etc. So we only want to get alerted if more than 50% of the signins
; in a 60 second period are failures. The app tags failed signins with a warning state.
(fixed-time-window 60
(smap (fn [events]
; count all warnings and count all received events and work out the percentage
(let [percent (/ (count (filter #(= (:state %) "warning") events))
(count events))]
@wjlroe
wjlroe / Gemfile
Last active December 16, 2015 04:38
A really bad service that nags Riemann about how bad it is
gem 'pickup'
gem 'riemann-client'
module Util
module StatsHelper
def gauge(key, value)
key = full_key(key)
puts "key: #{key}, value: #{value}"
$statsd.gauge(key, value)
$riemann_client << {service: key, metric: value}
end
// Last commit: 8801f2e (2013-02-15 13:53:27 -0800)
(function() {
window.DS = Ember.Namespace.create({
// this one goes to 11
CURRENT_API_REVISION: 11
});
})();
## Rails Upgrade check
#
# Check your github repos for out of date rails apps
#
# usage: $ USERNAME=yourusername PASSWORD=yourpassword ruby railscheck.rb
# or
# usage: $ USERNAME=yourusername PASSWORD=yourpassword ORG=yourorgname ruby railscheck.rb
#
# n.b requires the octokit gem
@wjlroe
wjlroe / woot_by_emacs.rb
Last active December 12, 2015 06:49
Trying to indent some code
do_something([
{
"metadata"=> {
"url"=>"http://www.nature.com/nature/journal/v489/n7415/full/nature11421.html",
"metadata_attributes"=> [{
"attr"=>"doi",
"value"=>"10.1038/nature11421"
}]
}
},
2013-01-29 14:20:47 supervisor [ERROR] Error on initialization of server mk-supervisor
java.lang.RuntimeException: java.io.EOFException
at backtype.storm.utils.Utils.deserialize(Utils.java:59)
at backtype.storm.utils.LocalState.snapshot(LocalState.java:24)
at backtype.storm.utils.LocalState.get(LocalState.java:28)
at backtype.storm.daemon.supervisor$standalone_supervisor$reify__4786.prepare(supervisor.clj:476)
at backtype.storm.daemon.supervisor$fn__4733$exec_fn__1207__auto____4734.invoke(supervisor.clj:322)
at clojure.lang.AFn.applyToHelper(AFn.java:167)
at clojure.lang.AFn.applyTo(AFn.java:151)
at clojure.core$apply.invoke(core.clj:601)
@wjlroe
wjlroe / try.clj
Created November 16, 2015 10:03
Ruby's (2.3.0) dig and Clojure's get-in
(def people [{:name "Will"
:health 1}
{:name "Not Will"
:health -10}])
(get-in people [0 :name]) #=> "Will"