Skip to content

Instantly share code, notes, and snippets.

RATE_LIMIT_SCRIPT = r'''
local now = tonumber(ARGV[1])
local required = tonumber(ARGV[2])
local rate = tonumber(ARGV[3])
local per_secs = tonumber(ARGV[4])
local do_subtract = tonumber(ARGV[5]) == 1
local full_at = tonumber(redis.call('GET', KEYS[1])) or 0
local score, result
if full_at < now then
score = rate
@begriffs
begriffs / opaleye.lhs
Created June 10, 2014 04:02
Opaleye Preview
This is a preview of Tom Ellis' database query library for Haskell.
> {-# LANGUAGE Arrows, FlexibleContexts #-}
> -- TODO: Get rid of FlexibleContexts if we ever move the definition of s
> -- elsewhere.
> {-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
> {-# LANGUAGE TemplateHaskell #-}
>
> module Karamaan.Opaleye.Examples where
>
@david-christiansen
david-christiansen / FizzBuzz.idr
Last active August 29, 2015 14:04
Dependently typed FizzBuzz, about 5 years late to the party
module FizzBuzz
-- Dependently-typed FizzBuzz, about 5 years late to the party.
-- A specification of the problem. Each constructor tells the conditions
-- under which it can be applied, and the "auto" keyword means that proof
-- search will be used in the context where they are applied to fill them
-- out. For instance, applying `N` to some Nat fails unless there's a proof in
-- scope that the argument meets the criteria.
data FB : Nat -> Type where
@mbj
mbj / example.sh
Last active August 29, 2015 14:06
MRI 2.1.3 parser regression?
# chruby-exec 2.1.2 -- ruby y.rb
{:a=>:foo}
# chruby-exec 2.1.3 -- ruby y.rb
y.rb:2: syntax error, unexpected modifier_if
a: if true; :foo; end
^
y.rb:2: syntax error, unexpected keyword_end, expecting end-of-input
@txus
txus / brokers.rb
Created October 27, 2014 15:50
sigh
require 'json'
require 'verkehr/zookeeper'
module Verkehr
class Brokers
Broker = Struct.new(:id, :host, :port) do
def to_s
"#{host}:#{port}"
end
@progrium
progrium / bash.sh
Created February 17, 2015 14:19
Comparing natural brevity and concise expressiveness between Go and shell/Bash for certain tasks using each tool's "standard" library.
curl -s "$url" | tar -zxC "$dest"
@mbbx6spp
mbbx6spp / gist:1083536
Created July 14, 2011 21:45 — forked from onethirtyfive/gist:1083182
Class-Table Inheritance Meta-model for DataMapper
# Module with mixins for common queries across descendants:
module Descendant
# I guess I could use ActiveSupport::Concern here...
def self.included(receiver)
receiver.extend ClassMethods
receiver.send :include, InstanceMethods
end
module ClassMethods
def self.included(receiver)
@asianmack
asianmack / gist:1482804
Created December 15, 2011 20:49
Emoji Cheat Sheet
:+1:
:-1:
:0:
:1:
:109:
:2:
:3:
:4:
:5:
:6:
source :rubygems
gem "jdbc-openedge", "11.1"
gem "dm-openedge-adapter", :git => "git://github.com/abevoelker/dm-openedge-adapter.git"
gem "data_mapper", "~> 1.2.0"
@ms-ati
ms-ati / 3nightclubs.rb
Created April 29, 2012 22:07
A Tale of 3 Nightclubs (ruby port)
####
## Ruby port of "A Tale of 3 Nightclubs"
##
## Based on Scala version here: https://gist.github.com/970717
##
## Demonstrates applicative validation in Ruby, inspired by the blog post:
## "An example of applicative validation in FSharpx"
## (http://bugsquash.blogspot.com/2012/03/example-of-applicative-validation-in.html)
####