Skip to content

Instantly share code, notes, and snippets.

View JoshuaGross's full-sized avatar

Joshua Gross JoshuaGross

View GitHub Profile
@JoshuaGross
JoshuaGross / bintree.rs
Created April 5, 2020 20:51
Rust binary tree + printer
use text_io::try_read;
use std::io;
use std::io::prelude::*;
use std::cmp::Ordering;
use std::fmt;
pub enum BST<T: Ord+fmt::Display> {
Leaf {
value: T,
left_child: Box<BST<T>>,
@JoshuaGross
JoshuaGross / README.md
Created June 27, 2019 17:52
Enum conversion undefined behavior in C++
$ clang++ main.cpp -std=c++11 -o main && ./main
Converting red to string: red
Converting 2 to enum to string: yellow
Converting 20 to enum to string: undefined
Converting 20 to enum to int: 20
@JoshuaGross
JoshuaGross / transpose.js
Created July 29, 2018 21:06
JS Matrix transpose
function transposeMatrix (m) {
return m.map((_, c) => m.map(r => r[c]));
}
console.log(transpose([[1,2,3],[4,5,6],[7,8,9]]));
@JoshuaGross
JoshuaGross / workday-counter.js
Created April 16, 2018 05:53
Workdays in range minus vacation days
#!/usr/bin/env node
const mode = process.argv[2];
const startDate = process.argv[3];
const endDate = process.argv[4];
const vacationDays = parseInt(process.argv[5], 10);
const sugar = require('sugar-date');
const moment = require('moment');
const parsedStartDate = moment(sugar.Date.create(startDate));
@JoshuaGross
JoshuaGross / bst.js
Created April 27, 2017 06:36
JavaScript binary search tree + tests
/**
* Copyright 2017, Joshua Gross, All Rights Reserved.
* Released under the MIT license.
*/
/**
* Each BST is represented as its own root.
* BSTs have no rebalancing, so tree shape can get gnarly real quick!
*/
function BST (key, value, left, right) {
@JoshuaGross
JoshuaGross / docker-line.md
Last active April 19, 2017 20:07
Install and configure DogStatsD to run container-local

Installing

Add this line to a Dockerfile to install and configure DogStatsD in the container. Requires that apt-get is available on the system.

This script will install curl in your environment but not remove it; you should uninstall it if you don't want it available in the container.

These script uses md5sum to validate all external scripts that are

@JoshuaGross
JoshuaGross / bytestringToHex.hs
Created February 2, 2017 23:47
Use Haskell to display a ByteString as hex
-- can be used in ghci
import qualified Data.ByteString as B
import Numeric (showHex)
import qualified Data.ByteString.Lazy as LBS
import qualified Data.Binary as B
-- encode some object to a binary ByteString
let s = (B.encode someObjectThatHasBinaryInstance)
let prettyPrint = P.concatMap ((\x -> "0x"++x++" ") . flip showHex "") . B.unpack :: B.ByteString -> String
@JoshuaGross
JoshuaGross / FIX.md
Created November 28, 2016 07:20
OS X El Capitan, "Reason: image not found" - Python library loading error resolution

Python "image not found" error resolution

This is an error that seems to occur on OS X El Capitan. You may see errors like this that did not occur before:

$ ./my_python_script.py
Traceback (most recent call last):
  File "./my_python_script.py", line 17, in <module>
    import psycopg2
 File "/Users/joshuagross/miniconda2/envs/my_env/lib/python2.7/site-packages/psycopg2/__init__.py", line 50, in 
@JoshuaGross
JoshuaGross / pygga.py
Last active May 17, 2022 09:19
Generate a GPGGA NMEA string using python
# Copyright (c) 2016, Swift Navigation, All Rights Reserved.
# Released under MIT License.
#
# Find documentation of parameters here:
# http://aprs.gids.nl/nmea/#gga
#
# time_t is a `time_struct` (https://docs.python.org/2/library/time.html)
# alt_m, geoidal_sep_m are in meters
import time
from math import floor
@JoshuaGross
JoshuaGross / URLs.md
Last active April 15, 2019 04:39
Cool URLs and learnings inside

A list of interesting URLs

... and a short description of interesting things learned within: