Skip to content

Instantly share code, notes, and snippets.

View johnptoohey's full-sized avatar
🎯
Focusing

John Toohey johnptoohey

🎯
Focusing
View GitHub Profile
# Rust type conversions String, &str, Vec<u8> and &[u8]
```rust
let s:String = ...
let st:&str = ...
let u:&[u8] = ...
let v:Vec<u8> = ...
&str -> String String::from(st)
&str -> &[u8] st.as_bytes()
@johnptoohey
johnptoohey / playground.rs
Created May 1, 2019 19:25 — forked from rust-play/playground.rs
Code shared from the Rust Playground
extern crate rustc_serialize as serialize;
use self::serialize::hex::{FromHex, ToHex};
use std::str;
fn parse_hex(hex_asm: &str) -> Vec<u8> {
let mut hex_bytes = hex_asm
.as_bytes()
.iter()
.filter_map(|b| match b {
@johnptoohey
johnptoohey / graceful.go
Created August 13, 2017 16:42 — forked from peterhellberg/graceful.go
*http.Server in Go 1.8 supports graceful shutdown. This is a small example.
package main
import (
"context"
"log"
"net/http"
"os"
"os/signal"
"time"
)

Keybase proof

I hereby claim:

  • I am johnptoohey on github.
  • I am johnptoohey (https://keybase.io/johnptoohey) on keybase.
  • I have a public key ASBKv9Gn4o7QFYq9CM_2QiYvaZULIr2h8RGlr5DW4ONNHQo

To claim this, I am signing this object:

@johnptoohey
johnptoohey / context.json
Created July 10, 2017 14:17 — forked from edsu/context.json
A strawman example of encoding a Dublin Core Application Profile as JSON-LD context object.
{
"@id": "http://example.com/app-profile.json",
"@context": {
"title": "http://purl.org/dc/terms/title",
"description": "http://purl.org/dc/terms/description",
"creator": "http://purl.org/dc/terms/creator"
},
"title": "JSON-LD Dublin Core Application Profile",
"description": "This is an example of a Dublin Core Application Profile as a JSON-LD. The point is to demonstrate that a JSON-LD context document could contain metadata. If it is desirable to annotate the use of particular properties they could theoretically fit into @graph using existing or a new DCAP vocabulary, etc.",
"creator": "http://twitter.com/edsu",
@johnptoohey
johnptoohey / service-checklist.md
Created September 24, 2016 14:46 — forked from acolyer/service-checklist.md
Internet Scale Services Checklist

Internet Scale Services Checklist

A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."

Basic tenets

  • Does the design expect failures to happen regularly and handle them gracefully?
  • Have we kept things as simple as possible?
@johnptoohey
johnptoohey / starred items.md
Created September 24, 2016 14:46 — forked from otw1248/starred items.md
star,good,recommendations

Internet Scale Services Checklist: A checklist for designing and developing internet scale services, inspired by James Hamilton's 2007 paper "On Desgining and Deploying Internet-Scale Services."
System Design Cheatsheet :Picking the right architecture = Picking the right battles + Managing trade-offs

(defn model-from-sequence
"Returns a transition matrix of 'depth' from 'sequence'"
[depth sequence]
(loop [accum {} chunks (partition (inc depth) 1 (seq sequence))]
(if (seq? chunks)
(let [chunk (first chunks)
prefix (drop-last chunk)
suffix (last chunk)]
(recur (assoc accum prefix (conj (get accum prefix []) suffix)) (next chunks)))
accum)))
; Depends on [com.notnoop.apns/apns "0.1.6"].
(:import ('com.notnoop.apns APNS))
(defn send-push-notification [device-token message]
(let [service (.build (.withSandboxDestination
(.withCert (APNS/newService) "resources/apns-dev-cert.p12" "password")))
payload (.build (.alertBody (APNS/newPayload) message))]
(.push service device-token payload)))