Skip to content

Instantly share code, notes, and snippets.

View tobz's full-sized avatar
💁‍♂️
it me

Toby Lawrence tobz

💁‍♂️
it me
View GitHub Profile
@tobz
tobz / gist:6045042
Last active December 20, 2015 00:49
// Go through all the configured servers and organize them by category.
groups := make(map[string]map[string]interface{}, 0)
for _, s := range me.Configuration.Servers {
// Create the group entry if we don't already have one.
if _, ok := groups[s.Category]; !ok {
group := make(map[string]interface{}, 0)
servers := make([]map[string]string, 0)
group["servers"] = servers
$job = array("frequency" => "weekly");
$frequency = $job["frequency"];
$interval = (
$frequency === "weekly"
? "INTERVAL 7 DAY"
: ($frequency === "monthly"
? "INTERVAL 1 MONTH"
: "INTERVAL 1 DAY"));
class Arbiter extends Actor {
var occupants:List[String] = List()
def addOccupant(who: String) = {
occupants = occupants ::: List(who)
}
def removeOccupant(who: String) = {
val (b, a) = occupants span (x => x != who)
occupants = (b ::: a.drop(1))
// Make sure the caller actually has the authority to call these methods.
handler.MapBefore([]string{"GET", "DELETE"}, "token", func(c context.Context) (error) {
// TODO: Figure out if this is the right way to preempt processing of a request.
// Check to see if this token is a supertoken.
if token, ok := c.Data()["Token"].(*ManagedToken); !ok {
goweb.API.RespondWithError(c, 500, "Internal authorization failure")
return fmt.Errorf("Failed to extract authorization token from request - this is bad/not right.")
} else {
if !token.Super {
/*
* Copyright 2013-present Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
#include "phenom/defs.h"
#include "phenom/configuration.h"
#include "phenom/job.h"
#include "phenom/log.h"
#include "phenom/sysutil.h"
#include "phenom/printf.h"
#include "phenom/listener.h"
#include "phenom/socket.h"
#include "phenom/stream.h"
#include "phenom/string.h"
@tobz
tobz / gist:56f50ebc0348bd2c0bb9
Created November 6, 2014 13:58
Benchmarking path.Match vs regular expressions for simple wildcard patterns
package matcher
import "path"
import "regexp"
import "testing"
func BenchmarkPathMatcher(b *testing.B) {
for i := 0; i < b.N; i++ {
matches, err := path.Match("web-*-001", "web-us-001")
if err != nil {
### Keybase proof
I hereby claim:
* I am tobz on github.
* I am tobz (https://keybase.io/tobz) on keybase.
* I have a public key whose fingerprint is D042 9CE5 F32A 6825 2F53 2452 C850 4302 CD64 0A65
To claim this, I am signing this object:
Perl> my $env = "indigo"
indigo
Perl> $env
indigo
Perl> my %env_mappings = ( "indigo" => { "bah" => "quux" } )
2
Perl> $env_mappings{"indigo"}
extern crate openssl;
use openssl::ssl::{SslContext, SslMethod};
fn main() {
let ssl_context = try!(SslContext::new(SslMethod::Sslv23));
}