Skip to content

Instantly share code, notes, and snippets.

View dklassen's full-sized avatar

Dana Klassen dklassen

View GitHub Profile
@dklassen
dklassen / phantom_type_state_encoding.rs
Last active January 19, 2025 15:15
Had a problem defining constraints to represent Sqlite Column constraints. Started to fool around with PhantomData and was curious to see if I could achieve what I wanted roughly with typing. This is what the end result was: using Phantom Data to encode stateful logic around adding and transitioning constraints.
use std::collections::HashSet as Set;
use std::marker::PhantomData;
// Marker traits for states
pub trait KeyState {}
pub struct InvalidState;
impl KeyState for InvalidState {}
pub trait UsableState {}
@dklassen
dklassen / groupBy.ts
Last active November 27, 2018 18:41
Vanillia GroupBy in Typescript
const groupBy = (data, key) => {
return data.reduce(
(acc, cur) => {
const value = acc[cur[key]] ? acc[cur[key]] : []
value.push(cur);
acc[cur[key]] = value;
return acc;
}, {});
};
@dklassen
dklassen / mockDate.ts
Last active November 21, 2018 19:11
Mocking global date
// source: https://github.com/facebook/jest/issues/2234
let timeNow;
const realDate = Date;
describe("Stubbed Date", () => {
beforeAll(() => {
timeNow = Date.now();
const _GLOBAL: any = global;
_GLOBAL.Date = class {
http_client.HTTPConnection.debuglevel = 1
logging.basicConfig()
logging.getLogger().setLevel(logging.DEBUG)
requests_log = logging.getLogger("requests.packages.urllib3")
requests_log.setLevel(logging.DEBUG)
requests_log.propagate = True
@dklassen
dklassen / post_request_lever.md
Created July 22, 2016 14:46
Golang Lever API

When making a POST request to lever API via golang you need to be able to send an array in somecases. For example, when updating tags ["test1", "test2"]. In python using the requests lib didn't have this issue but perhaps can save some time because it wasn't obvious right away:

data := url.Values{"tags[]": []string{"test", "test1"}}

req, err := http.NewRequest("POST", "https://api.lever.co/v1/candidates/132412-12312-1241/addTags?perform_as=1341-1243124", strings.NewReader(data.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded") // <- Don't forget the header!
openssl genrsa 1024 > ~/pk.pem
yes "" | openssl req \
-new \
-x509 \
-nodes \
-sha1 \
-days 3650 \
-key ~/pk.pem \
-outform PEM > ~/cert.pem
@dklassen
dklassen / gist:385585425a45e5d41ba7ba918aa9f533
Created June 25, 2016 23:38 — forked from shacker/gist:87908e13c9ee6655ce90
Using the Workday API with Python and the suds client library
import sys
from suds import client
from suds.wsse import Security, UsernameToken
from suds.sax.text import Raw
from suds.sudsobject import asdict
from suds import WebFault
'''
Given a Workday Employee_ID, returns the last name of that employee.
#!/bin/bash
usage()
{
cat << EO
Usage: format_data_disks [options]
Find and format data disks on nodes
EO
import android.content.Context;
import android.os.Debug;
import java.io.File;
public class OomExceptionHandler implements Thread.UncaughtExceptionHandler {
private static final String FILENAME = "out-of-memory.hprof";
public static void install(Context context) {
Thread.UncaughtExceptionHandler defaultHandler = Thread.getDefaultUncaughtExceptionHandler();