Skip to content

Instantly share code, notes, and snippets.

View JoshuaGross's full-sized avatar

Joshua Gross JoshuaGross

View GitHub Profile
@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 / README.md
Last active April 9, 2022 04:10
Freeing up extra disk space inside a Docker container

Freeing up extra disk space inside a Docker container

Sometimes while running a command inside of a docker container, the container itself will run out of disk space and things can fail (sometimes in strange ways). This is not a guide on how to allocate resources, but a quick cookbook on how to free up disk space inside a container. See below for links to more resources and reading.

If at all possible, just run Docker with increased disk space

See Limit disk size and bandwidth of a Docker container.

Resize an aufs volume

@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 / 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 / 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 / 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:

@JoshuaGross
JoshuaGross / pg-datediff.sql
Created September 30, 2016 22:11
PostGres custom DATEDIFF function (from http://www.sqlines.com/postgresql/how-to/datediff)
CREATE OR REPLACE FUNCTION DateDiff (units VARCHAR(30), start_t TIMESTAMP, end_t TIMESTAMP)
RETURNS INT AS $$
DECLARE
diff_interval INTERVAL;
diff INT = 0;
years_diff INT = 0;
BEGIN
IF units IN ('yy', 'yyyy', 'year', 'mm', 'm', 'month') THEN
years_diff = DATE_PART('year', end_t) - DATE_PART('year', start_t);
@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 / pg-running-queries.sql
Created September 30, 2016 22:04
List running queries in PostGres
select * from pg_stat_activity;