Skip to content

Instantly share code, notes, and snippets.

@mrhampson
mrhampson / HtmlParser.java
Created November 9, 2018 20:12
Programming problem solution. Trying to parse a simple HTML file and then allow the user to query to check if certain nodes exist.
import java.io.File;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
@mrhampson
mrhampson / JavaContainsListvsSet.java
Created August 9, 2018 20:03
Test which contains is faster ArrayList vs HashSet
import com.liveaction.commons.monitor.Timer;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
class Scratch {
public static void main(String[] args) {
@mrhampson
mrhampson / defaultParamsOveruseExample.ts
Last active August 9, 2018 18:33
Typescript overuse of default parameter issue
/**
I created this gist to point out something I consider a bad practice that I've seen in typescript code:
that is overuse of default parameters. The problem with overusing default parameters is that the default behavior
of the function without args is completely implicit and requires the developer to reference the function definition and
memorize whenever they are looking through the code.
In the examples below I took some of our existing code that had such a function retrieveData where its behavior
was hidden behind default parameters. I refactored it by using functions that are named something descriptive that
then call retrieveData with the appropriate parameters. By providing a function with a descriptive name rather than
letting parameter default it is much clearer what the code is doing when you are far away from the retrieveData
@mrhampson
mrhampson / convertMovToMp4.sh
Last active July 11, 2025 18:02
Convert a mac screencapture .mov to a compressed mp4
#!/bin/bash
usage="$(basename "$0") [-h] [-i] -- program that uses ffmpeg to convert mac screencapture .mov to a compressed mp4 for sharing
where:
-h show this help text
-i (required) the mov file to convert to mp4
dependencies:
Requires ffmpeg to be installed and available in the user's PATH.
function handleDragStart(type, id) {
if (id === SiteTopologyController.SITE_BOUNDING_BOX_ID) {
$('#keylines').css('cursor', 'move');
scope.isBoundingBoxDragging = true;
return true;
}
else {
return scope.preventMovement(type, id);
}
}
#!/usr/bin/env python
import sys
import subprocess
def is_valid_ip4(s):
a = s.split('.')
if len(a) != 4:
return False
for x in a:
if not x.isdigit():