Skip to content

Instantly share code, notes, and snippets.

View cheald's full-sized avatar

Chris Heald cheald

View GitHub Profile
@cheald
cheald / config.ru
Last active December 15, 2015 09:59
require 'rack'
require 'erb'
def normalize(token)
token.strip.upcase.gsub(/[^\w]/, '')
end
def nurble_token(token)
NOUNS[normalize token] && token || NURBLE
end
$pattern =
'/'
. '<p>' // Opening paragraph
. '\\s*+' // Optional leading whitespace
. '(' // 1: The shortcode
. '\\[' // Opening bracket
. "($tagregexp)" // 2: Shortcode name
. '\\b' // Word boundary
// Unroll the loop: Inside the opening shortcode tag
. '[^\\]\\/]*' // Not a closing bracket or forward slash
@cheald
cheald / relay.rb
Last active December 14, 2015 15:49
# Used to talk to your "relay server" or smart host.
# It supports a few simple operations for sending mail, replying, and can
# log the protocol it uses to stderr if you set debug=1 on __init__.
class Relay
# Public: Set up a new relay
# host - the host to connect to. May accept an IP address or hostname
# port - the port to connect to
# username - optional username to authorize with
# password - optional password to authorize with
@cheald
cheald / proposal.md
Last active January 3, 2016 18:21
rubygems-trust proposal

Root Key & Signing System

A single X509 key is generated per distribution platform (Rubygems.org, Gemfury, etc). This key is used to sign gem author requests.

A gem author may generate a certificate and request that the platform sign it. Alice generates her x509 keypair with her email address encoded as the x509 name field, stashes the private key somewhere safe, and submits the pubkey to the signing system.

The signing system consists of two parts:

  1. [Machine A] A web UI (or email inbox) responsible for accepting public keys and sending emails
  2. [Machine B] A signing machine with a shared data store (shared NFS mount, redis store, whatever - it must simply be a data store to act as a dead drop)
local Prototype = {}
local Prototype_mt = {__index = Prototype}
function Prototype.do_stuff(times)
-- Do stuff
end
function Prototype:new()
local new_inst = {} -- the new instance
setmetatable( new_inst, Prototype_mt ) -- all instances share the same metatable
@cheald
cheald / cryptor.rb
Last active December 10, 2015 21:38
require 'openssl'
require 'base64'
class Cryptor
def initialize
@secret = "fd5d148867091d7595c388ac0dc50bb465052b764c4db8b4b4c3448b52ee0b33df16975830acca82"
@cipher = OpenSSL::Cipher.new("AES-256-CFB")
end
def encrypt(*numbers)
> db.test.insert({'foo': 'bar'})
> db.test.find()
{ "_id" : ObjectId("50e756d52756f7c12acbfb30"), "foo" : "bar" }
> db.test.update({ "_id" : ObjectId("50e756d52756f7c12acbfb30")}, {})
> db.test.find()
{ "_id" : ObjectId("50e756d52756f7c12acbfb30") }
>
function wp_clear_auth_cookie() {
do_action('clear_auth_cookie');
setcookie(AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, ADMIN_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(SECURE_AUTH_COOKIE, ' ', time() - 31536000, PLUGINS_COOKIE_PATH, COOKIE_DOMAIN);
setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, COOKIEPATH, COOKIE_DOMAIN);
setcookie(LOGGED_IN_COOKIE, ' ', time() - 31536000, SITECOOKIEPATH, COOKIE_DOMAIN);
def purge(ip, port, domain, uri)
begin
socket = TCPSocket.new(ip, port)
socket.write "PURGE #{uri} HTTP/1.1\r\nX-Purge: #{uri}\r\nUser-Agent: ruby/socket\r\nAccept: */*\r\nHost: #{domain}\r\n\r\n"
rescue Errno::ECONNREFUSED, Errno::ETIMEDOUT, Errno::EHOSTUNREACH
# Nothing to do
ensure
socket.close if socket and !socket.closed?
end
end
desert:
lat: [1, 50]
long [20, 60]
file: "netcdf/GCS/biomes/Desert.nc"
var: dsrt
marsh:
lat: [51, 150]
long [120, 160]
file: "netcdf/GCS/biomes/Marsh.nc"
var: mrsh