Skip to content

Instantly share code, notes, and snippets.

View elithrar's full-sized avatar
🌐
usually busy

Matt Silverlock elithrar

🌐
usually busy
View GitHub Profile
@elithrar
elithrar / keybase.md
Created June 12, 2014 21:43
keybase.md

Keybase proof

I hereby claim:

  • I am elithrar on github.
  • I am silverlock (https://keybase.io/silverlock) on keybase.
  • I have a public key whose fingerprint is 73E6 AFB3 9131 E24C A140 F660 D6E8 9C78 40EB 8D6B

To claim this, I am signing this object:

require 'bundler/setup'
require 'sinatra/base'
require 'rack/contrib'
# The project root directory
$root = ::File.dirname(__FILE__)
class SinatraStaticServer < Sinatra::Base
get(/.+/) do
@elithrar
elithrar / use.go
Last active December 29, 2015 02:29
use.go — the little HTTP middleware helper that could.
// use provides a cleaner interface for chaining middleware for single routes.
// Middleware functions are simple HTTP handlers (w http.ResponseWriter, r *http.Request)
//
// r.HandleFunc("/login", use(loginHandler, rateLimit, csrf))
// r.HandleFunc("/form", use(formHandler, csrf))
// r.HandleFunc("/about", aboutHandler)
func use(h http.HandlerFunc, middleware ...func(http.HandlerFunc) http.HandlerFunc) http.HandlerFunc {
for _, m := range middleware {
h = m(h)
}
@elithrar
elithrar / history.js
Last active January 10, 2016 14:03
smartScroll for Ember.js - reset the scroll position on forward transitions you haven't previously visited - via @rwjblue on embercommunity.slack.com
// app/locations/history.js
export default Ember.HistoryLocation.extend({
pushState() {
this._super(...arguments);
window.scrollTo(0, 0);
}
});
```​
@elithrar
elithrar / ratelimit.go
Last active February 17, 2016 06:14
Quick and dirty HTTP request rate limiter (will eventually wrap this into a package!)
package main
import (
"errors"
"github.com/garyburd/redigo/redis"
"net/http"
"time"
)
type RateStore struct {
@elithrar
elithrar / config
Created March 28, 2016 20:47
.git/config - Pull PRs into local branches (via @alaska)
Locate the section for your github remote in the `.git/config` file. It looks like this:
```
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
url = git@github.com:joyent/node.git
```
Now add the line `fetch = +refs/pull/*/head:refs/remotes/origin/pr/*` to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:
@elithrar
elithrar / archive_cloudapp.rb
Last active July 4, 2016 19:14
archive_cloudapp.rb - leverages https://github.com/aaronrussell/cloudapp_api to archive your CloudApp uploads to the current directory. Intentionally simple.
# vim: ts=2 et sw=2 sts=2
# #!/usr/bin/ruby
# (c) 2016, Matt Silverlock. BSD 3-Clause licensed.
# Downloads all items in your CloudApp account to the current directory.
require "cloudapp_api"
require "optparse"
require "json"
require "open-uri"
require "shellwords"
@elithrar
elithrar / logger.go
Created July 12, 2016 05:52
An example of turning https://github.com/go-kit/kit/tree/master/log into usable HTTP middleware for Go.
package handler
import (
"bufio"
"io"
"net"
"net/http"
"time"
"github.com/go-kit/kit/log"
@elithrar
elithrar / helpers.go
Created June 5, 2014 11:50
GenerateShortGUID() - generate a 8-byte, URL-safe ID for slightly saner URLs with a very low collision chance (http://goo.gl/VWAFOo) and avoid http://example.com/thing/550e8400-e29b-41d4-a716-446655440000 ugliness. Leverages Go's existing cryptographically secure random number generator: http://elithrar.github.io/article/generating-secure-random…
// GenerateRandomBytes generates a crytographically secure random byte string using crypto/rand.
func GenerateRandomBytes(s int) ([]byte, error) {
b := make([]byte, s)
n, err := rand.Read(b)
if n != len(b) || err != nil {
return nil, fmt.Errorf("Unable to successfully read from the system CSPRNG (%v)", err)
}
return b, nil
}
@elithrar
elithrar / balance.weakauras
Created July 5, 2016 03:02
Balance Druid WeakAuras - Legion (Beta). Screenshot: http://d.pr/i/nqIl
dGe4HaqiQuj1IOsL6ssrQrPQQQtPIknlQujClIuTlHQ4xQOIHrLCmIYYKGNrLY0uv5AejBtO03iQACQOCoQuX7OsLO5jfj19KsyFsj1bjQSqI4HePmrPKCrPO2OqXiLIeNuOQwPuIMPuLUPue7Kk(PkYqLQyPQQYtvMQixvfv9vPijNLkvsMRqvAVWFvHblv1Hf1ILkESqMmv1LjTzj6ZuLrlv60iTAvvvEnvQA2s62Q0UP43uA4QYYr8Ccth11fSDPuFxkmEHkNxvz9QQk7xcn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