Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Joshua Gross JoshuaGross

🎯
Focusing
View GitHub Profile
@JoshuaGross
JoshuaGross / bintree.rs
Created Apr 5, 2020
Rust binary tree + printer
View bintree.rs
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 Jun 27, 2019
Enum conversion undefined behavior in C++
View README.md
$ 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 Jul 29, 2018
JS Matrix transpose
View transpose.js
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 Apr 16, 2018
Workdays in range minus vacation days
View workday-counter.js
#!/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 Apr 27, 2017
JavaScript binary search tree + tests
View bst.js
/**
* 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 Apr 19, 2017
Install and configure DogStatsD to run container-local
View docker-line.md

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 Feb 2, 2017
Use Haskell to display a ByteString as hex
View bytestringToHex.hs
-- 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 Nov 28, 2016
OS X El Capitan, "Reason: image not found" - Python library loading error resolution
View FIX.md

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 <module>
@JoshuaGross
JoshuaGross / pygga.py
Last active Mar 24, 2020
Generate a GPGGA NMEA string using python
View pygga.py
# 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 Apr 15, 2019
Cool URLs and learnings inside
View URLs.md

A list of interesting URLs

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

You can’t perform that action at this time.