Skip to content

Instantly share code, notes, and snippets.

View schmohlio's full-sized avatar

Matthew Schmohl schmohlio

View GitHub Profile
@schmohlio
schmohlio / TextEditorBuffer.java
Created January 14, 2019 00:44
Text Editor Buffer with 2 Stacks (Sedgewick Algorithms) Example
public class GapBuffer {
private final Stack<Char> left, right;
private final int n;
public GapBuffer() {
left = new Stack<>();
right = new Stack<>();
n = 0;
package latch.common.utils;
import com.google.common.collect.Lists;
import java.util.List;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
@schmohlio
schmohlio / prepend.py
Last active August 10, 2017 23:42
Prepend text to files matching pattern in current directory
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys
import os
from os.path import join
TEXT = """syntax = "proto2"\n"""
def main():
@schmohlio
schmohlio / NestedMap.java
Created April 21, 2017 22:23
Variable Depth Java HashMap
class NestedMap<K, V> {
private final HashMap<K, NestedMap> child;
private V value;
public NestedMap() {
child = new HashMap<>();
value = null;
}
@schmohlio
schmohlio / gist:4157d2fa82f3680fd08f1b111ed61515
Created April 10, 2017 03:16 — forked from mikepfeiffer/gist:4d9386afdcceaf29493a
EC2 UserData script to install CodeDeploy agent
#!/bin/bash
yum install -y aws-cli
cd /home/ec2-user/
aws s3 cp 's3://aws-codedeploy-us-east-1/latest/codedeploy-agent.noarch.rpm' . --region us-east-1
yum -y install codedeploy-agent.noarch.rpm
@schmohlio
schmohlio / BlockingQueue.java
Created February 16, 2017 05:04 — forked from dougnukem/BlockingQueue.java
Example Threadsafe BlockingQueue implementation in Java
public class BlockingQueue implements Queue {
private java.util.Queue queue = new java.util.LinkedList();
/**
* Make a blocking Dequeue call so that we'll only return when the queue has
* something on it, otherwise we'll wait until something is put on it.
*
* @returns This will return null if the thread wait() call is interrupted.
*/
@schmohlio
schmohlio / StringChains.java
Created January 18, 2017 22:11
"String Chains" brain teaser
package io.schmohl;
import java.util.*;
public class StringChain {
// we can use depth first search for each word to calculate the length of the chain.
static int longestChain(String[] words) {
@schmohlio
schmohlio / FriendCircles.java
Created January 18, 2017 22:10
"friend circles" brain teaser
package io.schmohl;
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class FriendCircles {
/*
@schmohlio
schmohlio / sse.go
Last active August 21, 2024 05:00 — forked from ismasan/sse.go
Example SSE server in Golang
// v2 of the great example of SSE in go by @ismasan.
// includes fixes:
// * infinite loop ending in panic
// * closing a client twice
// * potentially blocked listen() from closing a connection during multiplex step.
package main
import (
"fmt"
"log"
@schmohlio
schmohlio / sortByteSlice.go
Created September 7, 2016 21:37
sort byte slices in Golang without needing to fmt as string. useful for Set hashes
package main
import (
"bytes"
"log"
"sort"
)
// implement `Interface` in sort package.
type sortByteArrays [][]byte