Skip to content

Instantly share code, notes, and snippets.

View nfisher's full-sized avatar
🏠
Working from home

Nathan Fisher nfisher

🏠
Working from home
View GitHub Profile
@nfisher
nfisher / profile-1514340216912.trace
Created January 2, 2018 21:52
profile-1514340216912.trace
This file has been truncated, but you can view the full file.
[{"name":"`Boolean","ts":1514340216924000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Byte","ts":1514340216924000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Character","ts":1514340216924000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Class","ts":1514340216924000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`ClassLoader","ts":1514340216924000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Compiler","ts":1514340216924000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Double","ts":1514340216926000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Enum","ts":1514340216926000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`Float","ts":1514340216926000,"ph":"X","tid":1,"dur":0,"pid":0}
,{"name":"`InheritableThreadLocal","ts":1514340216926000,"ph":"X","tid":1,"dur":0,"pid":0}
@nfisher
nfisher / index.go
Last active January 13, 2018 01:09
Using James nlp package.
package search
import (
"github.com/james-bowman/nlp"
"github.com/james-bowman/nlp/measures/pairwise"
"gonum.org/v1/gonum/mat"
)
type Index struct {
vectoriser *nlp.CountVectoriser
@nfisher
nfisher / main.rl
Last active January 30, 2018 18:34
bracket matching with ragel
package main
// generate with ragel -G1 -Z main.rl no compile error with -G2 the following;
// main.rl:13[/Users/nathanfisher/workspace/go/src/github.com/nfisher/gir/command/runner/main.go:119:2]: syntax error: unexpected goto at end of statement
// main.go:59[/Users/nathanfisher/workspace/go/src/github.com/nfisher/gir/command/runner/main.go:59:1]: label _again defined and not used
import "fmt"
%%{
machine graphql_collections;
@nfisher
nfisher / default.yaml
Created February 16, 2018 21:44
Sample CSP handlers section for Google App Engine
handlers:
- url: /(.*\.html)
static_files: public/\1
upload: public/(.*\.html)
mime_type: text/html; charset=UTF-8
secure: always
expiration: "0d 3m"
http_headers:
Strict-Transport-Security: max-age=31536000; includeSubDomains; preload
Content-Security-Policy: default-src 'none'; font-src 'self' https://cdnjs.cloudflare.com https://fonts.gstatic.com a.gwponline.com; style-src 'self' https://cdnjs.cloudflare.com https://fonts.googleapis.com a.gwponline.com; img-src 'self' ws1.postescanada-canadapost.ca a.gwponline.com; script-src 'self' a.gwponline.com; connect-src 'self' ws1.postescanada-canadapost.ca; media-src a.gwponline.com
@nfisher
nfisher / compose_run.sh
Created March 23, 2018 23:45
docker bind local folder
docker-compose run dev bash
@nfisher
nfisher / sampler.py
Last active April 18, 2018 20:33
Python: sampling for top referrers to a type
def teardown(self):
# other stuff...
gc.collect()
parents = {}
for o in gc.get_objects():
if not isinstance(o, list):
continue
c = c + 1
if c % 1000 == 0:
@nfisher
nfisher / histo.R
Created April 19, 2018 00:47
R - histogram and scatter plot
library (ggplot2)
library (gridExtra)
# arg1 - online csv
# arg2 - base filename
options <- commandArgs(trailingOnly = TRUE)
basename = options[2]
@nfisher
nfisher / ExtractMessage
Created September 19, 2018 14:29
Dataflow primitive operations
// .apply("Extract Body", ParDo.of(new ExtractMessage()))
class ExtractMessage extends DoFn<PubsubMessage, String> {
@ProcessElement
public void processElement(final ProcessContext c) {
final PubsubMessage msg = c.element();
final String s = new String(msg.getPayload());
c.output(s);
}
}
@nfisher
nfisher / DataToRow.java
Last active September 20, 2018 23:33
POJO to BigQuery TableRow converter
class DataToRow {
public static TableRow asRow(final Object child, final String pkg) {
if (null == child) {
return null;
}
TableRow row = new TableRow();
Field[] publicFields = child.getClass().getFields();
for (Field f : publicFields) {
String name = f.getName();
@nfisher
nfisher / cipher.sh
Created April 23, 2020 14:58
Probe for valid ciphers (modified from an SO response)
#!/usr/bin/env bash
# OpenSSL requires the port number.
SERVER=$1
PORT=$2
DELAY=1
ciphers=$(openssl ciphers 'ALL:eNULL' | sed -e 's/:/ /g')
echo Obtaining cipher list from $(openssl version).