Skip to content

Instantly share code, notes, and snippets.

@mnstrspeed
mnstrspeed / gist:6e5e4a1853ce981452ce
Last active August 29, 2015 14:12
LinkedMap.java
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map;
import java.util.Set;
public class LinkedMap<K, V> implements Map<K, V> {
@mnstrspeed
mnstrspeed / gist:f5bb287cf443c2f0c168
Created November 5, 2014 00:40
Comparator<T> example
import java.util.List;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
public class Test
{
public static void main(String[] args)
{
Integer[] numbers = { 1, 5, 2, 7, 2, 42, 1 };
@mnstrspeed
mnstrspeed / Program.java
Last active August 29, 2015 14:00
Java command line options base
package nl.tomsanders.util;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
public abstract class Program
@mnstrspeed
mnstrspeed / WebSocket.java
Created March 1, 2014 18:54
WebSocket Client
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.Socket;
import java.net.URI;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.HashMap;
@mnstrspeed
mnstrspeed / fucked.py
Last active August 29, 2015 13:56
Fucked.py
from datetime import date, timedelta
import itertools
monthly = lambda first: (first + timedelta(days = i * 365 / 12) for i in itertools.count())
weekly = lambda first: (first + timedelta(days = i * 7) for i in itertools.count())
repeating = lambda first, dates: (lambda since: next(d for d in dates(first) if d > since))
transactions = [
("Rent", -300.00, repeating(date(2014, 3, 1), monthly)),
@mnstrspeed
mnstrspeed / Echo
Last active December 31, 2015 19:19
module EchoServer
import StdEnv, StdTCP
port :== 1887
Start world
# (console, world) = stdio world
# (ok, listener, world) = openTCP_Listener port world
| not ok = fclose (console <<< "ehhh") world
@mnstrspeed
mnstrspeed / gist:7177944
Created October 27, 2013 04:21
Haskell solution (hopefully...) to BAPC 2013 Problem F
import Control.Monad
minimalize [] _ = []
minimalize remaining ((a, b) : xs)
| elem a remaining || elem b remaining =
(a, b) : minimalize (filter (\x -> x /= a && x /= b) remaining) xs
| otherwise = minimalize remaining xs
readInts = getLine >>= \line -> return $ map read $ words $ line
readEdge = readInts >>= \[a, b] -> return (a, b)
@mnstrspeed
mnstrspeed / gist:7177442
Created October 27, 2013 02:50
Haskell solution to BAPC 2013 Problem C
import Control.Monad
import Data.List
type Mapping = [(Char, Char)]
derive_mapping :: String -> [String] -> Mapping
derive_mapping plain encrypted =
merge_mappings $
filter is_consistent $
map (extract_mapping plain) $
@mnstrspeed
mnstrspeed / Line.java
Last active December 23, 2015 02:28
Collisions based on lines
package nl.tomsanders.game.egine.util;
public class Line
{
private final double slope;
private final double intercept;
private final Vector pointA;
private final Vector pointB;
@mnstrspeed
mnstrspeed / Program.cs
Created July 31, 2012 14:55
Internet Connection Interruption Logger
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.NetworkInformation;
using System.Text;
using System.Threading;
using System.Threading.Tasks;