Skip to content

Instantly share code, notes, and snippets.

View bentranter's full-sized avatar

Ben Tranter bentranter

View GitHub Profile
@bentranter
bentranter / fillstruct_test.go
Created July 27, 2022 17:17
Fill a struct in Go using reflection
package fillstruct
import (
"reflect"
"testing"
)
// FillStruct fills a struct with a string value as an example of how to use
// reflection to accomplish this.
func FillStruct(v interface{}) {
@bentranter
bentranter / race_test.go
Created December 18, 2019 17:45
An attempt to recreate the race condition in godo.
package race_test
import (
"context"
"fmt"
"log"
"math/rand"
"os"
"sync"
"testing"
@bentranter
bentranter / four_letter_word_list.txt
Created April 11, 2019 20:21
List of all four letter words in the Unix dictionary at /usr/share/dict/words
AANI
AARU
ABAC
ABAS
ABBA
ABBY
ABED
ABEL
ABET
ABEY
@bentranter
bentranter / uuid_v4.js
Last active September 1, 2021 11:09
Spec Compliant UUIDv4 Generator using the Web Crypto API
// uuid returns an RFC 4122 compliant universally unique
// identifier using the crypto API
function uuid() {
// get sixteen unsigned 8 bit random values
var u = window
.crypto
.getRandomValues(new Uint8Array(16));
// set the version bit to v4
@bentranter
bentranter / rest_api_design_notes.md
Created October 20, 2016 18:07
Notes about REST API Design from StormPath's Latest Webinar

Stormpath Presentation

They focus on security and high availability. Free for devs.

  • Latency caching?

What're the things you can use to make your life easier?

HATEOAS - Hypermedia As The Engine Of Application State. The API and all info is self-contained in the data sent to and from the server - no out-of band info. Basically, you shuldn't need to go elseqhere or look up docs.

@bentranter
bentranter / pointers.c
Last active October 4, 2015 20:32
Pointers in Go: Just like C 😊
#include <stdio.h>
int byVal(int i) {
i = 0;
return i;
}
int byRef(int *i) {
*i = 0;
return *i;
@bentranter
bentranter / gotta_go_fast.go
Created September 3, 2015 18:47
Scrape every course at LU in less than 3 seconds
// Gotta go fast
package main
import (
"fmt"
"net/http"
"time"
"github.com/bentranter/chalk"
"github.com/yhat/scrape"
@bentranter
bentranter / sometimes_concurrency_is_good.go
Last active September 3, 2015 16:37
Async vs. Sync HTTP requests
// This tries to show the difference between async and sync
// HTTP GET requests. Big surprise: its way faster do this
// async...
package main
import (
"fmt"
"github.com/bentranter/chalk"
"net/http"
"time"
@bentranter
bentranter / hell.go
Last active August 29, 2015 14:27
What scraping HTML is like
// This could be you if you choose to scrape HTML
for _, article := range articles {
fmt.Printf("\033[33m%s\033[0m - \033[32mTitle: %s\033[0m\nDescription: %s\n\033[36mhttp://kijiji.ca%s\033[0m\n\n", scrape.Text(article.NextSibling.NextSibling), scrape.Text(article.FirstChild.NextSibling), scrape.Text(article), scrape.Attr(article.FirstChild.NextSibling, "href"))
}
@bentranter
bentranter / user-agent-stylesheet.css
Created July 27, 2015 21:55
Chrome 44 User Agent Stylesheet Excerpt - I never knew it did this kind of stuff
/**
* h1 has different defaults depending on what the h1 element
* is in.
*/
h1 {
display: block;
font-size: 2em;
-webkit-margin-before: 0.67em;
-webkit-margin-after: 0.67em;