Skip to content

Instantly share code, notes, and snippets.

View wjlroe's full-sized avatar
📷

William Roe wjlroe

📷
View GitHub Profile
@wjlroe
wjlroe / test-em-http.rb
Created August 23, 2013 11:00
How to stream a file download with em-http
require 'em-http'
require 'eventmachine'
url = ARGV[0]
puts "going to try to download #{url}"
EventMachine.run do
req = EventMachine::HttpRequest.new(url).get
File.unlink("really_big_file") if File.exist?("really_big_file")
@wjlroe
wjlroe / core.cljs
Last active December 21, 2015 08:48
After some core.async fun - this is a simple bit of event listening code for mouse and keyboard events. game.js is compiled from core.cljs
(ns chaotic-god.core
(:require [goog.dom :as dom]
[goog.Timer :as timer]
[goog.events :as events]
[goog.events.EventType :as event-type]
[goog.events.KeyCodes :as key-codes]
[chaotic-god.utils :as utils]
[cljs.core.async :refer [>! <! chan put! close! timeout]])
(:require-macros [cljs.core.async.macros :refer [go alt!]]))
class NullObject
def method_missing(*args, &block)
self
end
def nil?; true; end
end
def Maybe(value)
value.nil? ? NullObject.new : value
# HODOR
module.exports = (robot) ->
robot.hear /hodor/i, (msg) ->
msg.send "HODOR"
@wjlroe
wjlroe / some.clj
Last active December 17, 2015 00:29
Messing about with some-> in Clojure
user=> (def some-hash {:hello {:name "john" :aliases [{:text "woot"} {:name "lala"}]}})
#'user/some-hash
user=> (some-> some-hash :hello :name)
"john"
user=> (some-> some-hash :hello :age)
nil
user=> (some-> some-hash :byebye :name)
nil
user=> (some-> some-hash :hello :aliases first)
{:text "woot"}
@wjlroe
wjlroe / minimalism.html
Last active December 16, 2015 19:10
LimeJS rendering problem. No errors on the browser console. This is with LimeJS from master, revision e295e8898d382a4d9c60c558d8b0d14beffadd8e
<!DOCTYPE HTML>
<html>
<head>
<title>minimalism</title>
<script type="text/javascript" src="../closure/closure/goog/base.js"></script>
<script type="text/javascript" src="minimalism.js"></script>
</head>
<body onload="minimalism.start()"></body>
@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)
@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'
(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))]