Skip to content

Instantly share code, notes, and snippets.

View wmorgan's full-sized avatar

William Morgan wmorgan

View GitHub Profile
@wmorgan
wmorgan / app.rb
Last active October 11, 2016 17:19
#!/usr/bin/env ruby
require 'sinatra'
require 'open-uri'
get '/' do
result = open("http://webapp/hello").read
"#{result}\nDisclaimer: above statement may not actually be true.\n"
end
class Address
def initialize address, display_name, domain
@address = address
@display_name = display_name
@domain = domain
end
attr_reader :address, :display_name, :domain
def self.from_header h # returns an Array of Addresses
@wmorgan
wmorgan / gist:3054620
Created July 5, 2012 16:18
Mustache templating for Clojure
(ns potato.core
(:use [slingshot.slingshot :only [throw+ try+]])
(:use [clojure.string :only [trim split]]))
;; use this provide template values at write time (i.e. not compile time).
;; "name" will be the name of the template variable. "context", when not nil,
;; will be the value previously returned by *template-value* for the enclosing
;; section.
(defn ^:dynamic *template-value* [name context])
@wmorgan
wmorgan / reduler.rb
Created April 17, 2012 06:26
safe scheduler in redis
## THIS VERSION HAS SOME BUGS
## SEE http://masanjin.net/blog/using-redis-for-scheduling for the fixes
##
## call schedule! to schedule an item at a specific time.
## call blocking_each to have each item yielded to you, on or after its scheduled time.
## items will be placed in ERROR_QUEUE during the course of processing. clean these up at will.
class Scheduler
QUEUE = "q"
ERROR_QUEUE = "eq"
#!/usr/bin/env ruby
require 'sinatra'
$conts = []
def link_to title, &b
id = $conts.size
$conts[id] = b
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <time.h>
#include <string.h>
#define SIZE (1024 * 1024 * 500)
#define TIMES 10000000
#define START_TIMER() { \