Skip to content

Instantly share code, notes, and snippets.

@OutOfBrain
OutOfBrain / FindStreaks.java
Created January 16, 2016 00:41
Find all streaks in a sequence of numbers
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
public class FindStreaks {
public static void main(String[] args) {
int[] array = new int[Integer.MAX_VALUE/32];
Random rand = new Random();
int maxInt = 10000;
@OutOfBrain
OutOfBrain / mutex_bench.go
Created February 7, 2016 21:19
Testing speed of channel lock and sync lock. Turns out channel lock is actually faster than sync lock (mutex).
package main
import (
"fmt"
"sync"
"testing"
)
var lockChannel chan bool = make(chan bool, 1)
var lockSync sync.Mutex
<?php
const MALE = 1;
const FEMALE = 0;
$leftFemale = 0;
$rightFemale = 0;
$i = 0;
while (true) {
$frogLeft1 = rand(0,1);
@OutOfBrain
OutOfBrain / generator.go
Last active March 4, 2016 23:32
Create a generator in go - similar to yield in python
package main
import "fmt"
func countGenerator() func() int{
// state
c := make(chan int)
var i int
// generator
go func(){
@OutOfBrain
OutOfBrain / Intersect.php
Created April 26, 2016 07:54
Intersect arrays recursively in php.
<?php
class Interect
{
/**
* Return intersecting array of varargs arrays.
* Compares keys and values. Checks recursively.
* Returns empty array if no intersection.
*
@OutOfBrain
OutOfBrain / concatvideos.sh
Created May 1, 2016 09:54
Concatenate videos. Usage: ./concatvideos.sh outputname.mp4 inputname1.mp4 inputname2.mp4 inputnameN.mp4
#!/bin/bash
OUTPUT=$1
shift
ffmpeg -f concat -i <(
while [[ $# > 0 ]]; do
printf "file '$PWD/$1'\n"
shift
done
FILE=~/speedtestdata
date "+%Y-%m-%d %H:%M" | tee -a $FILE
echo "-----------------------" | tee -a $FILE
~/dev/speedtest-cli --list | tail -n +3 | head -n8 | while read line; do
echo $line | tee -a $FILE
(~/dev/speedtest-cli --simple --server $(echo $line | sed -e "s/).*/ /g") \
&& echo) \
| tee -a $FILE
done
@OutOfBrain
OutOfBrain / gist:23d8be9dbe4403f6f9fa17a572109d37
Created June 23, 2016 22:25
Slither.io MODS with Zoom and Less Latency for Tampermonkey
// ==UserScript==
// @name Slither.io Mods
// @namespace DerpCookiePrograms
// @version 0.1
// @description Sliter.io Mods
// @author DerpCookiePrograms
// @match http://slither.io/*
// @grant none
// ==/UserScript==
@OutOfBrain
OutOfBrain / startopenssh.sh
Last active November 24, 2016 18:28
Start an openssh server on the fly somewhere- still missing installing docker in the first place
# curl https://gist.githubusercontent.com/.../startopenssh.sh | bash
wget https://get.docker.com/builds/Linux/x86_64/docker-latest.tgz
tar -xvzf docker-latest.tgz
mv docker/* /usr/bin/
nohup dockerd &
OVPN_DATA="ovpn-data"
docker run -v $OVPN_DATA:/etc/openvpn --rm kylemanna/openvpn ovpn_genconfig -u udp://$(ifconfig | grep -A 5 eth0 | awk -F':' '/inet addr/&&!/127.0.0.1/{split($2,_," ");print _[1]}')
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn sh -c 'echo -e "yes\nblep\n" | ovpn_initpki nopass'
docker run -v $OVPN_DATA:/etc/openvpn -d -p 1194:1194/udp --cap-add=NET_ADMIN kylemanna/openvpn
docker run -v $OVPN_DATA:/etc/openvpn --rm -it kylemanna/openvpn easyrsa build-client-full thecert nopass
@OutOfBrain
OutOfBrain / MontyHallSimulation.java
Created January 29, 2017 01:16
Monty Hall Problem Simulation
import java.util.Random;
public class MontyHallSimulation {
public static void main(String[] args) {
new MontyHallSimulation().start();
}
private Random rand = new Random(4);