Skip to content

Instantly share code, notes, and snippets.

@OutOfBrain
OutOfBrain / removeifdark.php
Last active October 23, 2015 12:34
Remove images if they contain mostly black
<?php
$filename = $argv[1];
$dark = explode('/', `identify -format "%[EXIF:BrightnessValue]" $filename`)[0];
if ($dark < 100) {
echo 'remove ' . $filename . PHP_EOL;
unlink($filename);
}
echo '.';
# 0 - rename all files into sequence
c=0; for i in *.jpg; do mv "$i" "`printf %05d $c`.jpg"; c=$((c+1));done
# 1
ffmpeg -r 5 -i %05d.jpg output.mp4
# 2
ffmpeg -framerate 12 -i %05d.jpg -c:v libx264 -r 12 output2.mp4
# 3 - works well
<?php
$files = glob('*.jpg');
foreach ($files as $file) {
$brightness = `identify -format "%[EXIF:BrightnessValue]" $file`;
$brightness_value = explode('/', $brightness)[0];
echo($brightness_value.PHP_EOL);
}
@OutOfBrain
OutOfBrain / download_youtube_list_parallel.sh
Created October 3, 2015 14:13
download youtube playlist parallel
youtube-dl --get-id https://www.youtube.com/playlist?list=<id> | youtube-dl-parallel -
@OutOfBrain
OutOfBrain / birthday_calc.php
Created August 3, 2015 19:55
Calculate the birthday problem distribution
<?php
/**
* Calculate chances for the birthday problem.
*/
$number_rolls = 100;
// number of birthdays
for ($i = 2; $i <= 100; ++$i) {
@OutOfBrain
OutOfBrain / Heating.java
Created May 24, 2015 20:33
In case the hotels heating does not work but there is electricity
package org.tcial;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.util.LinkedList;
import java.util.List;
public class Heating extends JFrame implements ChangeListener {
public Heating() {
@OutOfBrain
OutOfBrain / TimeWatcher.java
Last active October 23, 2015 18:42
Simple timeit implementation to benchmark durations between calls
public class TimeWatcher {
private long start;
public static TimeWatcher createStarted() {
TimeWatcher timeWatcher = new TimeWatcher();
timeWatcher.start();
return timeWatcher;
}
public void start() {