Skip to content

Instantly share code, notes, and snippets.

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 / 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
@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 / 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(){
<?php
const MALE = 1;
const FEMALE = 0;
$leftFemale = 0;
$rightFemale = 0;
$i = 0;
while (true) {
$frogLeft1 = rand(0,1);
@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
@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;
cat VIDEO_TS/VTS_01_[1234].VOB | nice ffmpeg -i - ~/dvd_rip.mp4
@OutOfBrain
OutOfBrain / BinaryPrint.java
Created October 27, 2015 21:46
Another binary print
class BinaryPrint {
static void print(int number) {
int mask = 1<<31;
while ((number <<= 1) != 0) {
System.out.print(((number & mask) != 0) ? 1 : 0);
}
}
}
@OutOfBrain
OutOfBrain / ConstructorReference.java
Last active October 23, 2015 20:02
Java testing
import java.util.function.IntFunction;
public class ConstructorReference {
public static void main(String...args) {
IntFunction<Integer> intMakerSingle = Integer::new;
int intSingle = intMakerSingle.apply(40); // int value
IntFunction<int[]> intMakerArray = int[]::new;
int[] intArray = intMakerArray.apply(100); // array size
}