Skip to content

Instantly share code, notes, and snippets.

@xmichaelx
xmichaelx / detrac_convert.sh
Created October 28, 2018 13:43
converts detrac individual image frames into video
for D in `find . -mindepth 1 -type d`
do
ffmpeg -i ${D}/img%05d.jpg -c:v libx264 -vf fps=25 ${D}.mp4
done
@xmichaelx
xmichaelx / wallet_worth_estimator.html
Last active August 31, 2017 14:26
Computes estimated wallet value using CoinMarketCap API and some JS
<!DOCTYPE html>
<html>
<head>
<title>Wallet worth estimator</title>
<meta name="description" content="Small snippet of code for estimating worth of your crypto wallet">
<meta name="author" content="Michał Drzał - michal.drzal@gmail.com">
<meta name="version" content="0.1.1">
<script>
var portfolio = (function() {
function add(currency, amount, usdValue) {
@xmichaelx
xmichaelx / get_name.py
Created May 20, 2017 16:29
gets name of the raspberry pi device it operates on
def get_revision():
try:
with open('/proc/cpuinfo','r') as f:
for line in f:
if line.startswith('Revision'):
return line.split(":")[1].strip()
except:
return None
# sourced from: http://www.raspberrypi-spy.co.uk/2012/09/checking-your-raspberry-pi-board-version/
@xmichaelx
xmichaelx / PasswordGenerator.html
Last active January 18, 2019 08:29
password generation based on https://www.eff.org/dice
<html>
<head>
<script>
function getDictionary() {
var wordDictionary = {};
document.getElementById("wordlist").value.trim().split("\n").forEach(line => {
var tokens = line.split("\t");
wordDictionary[tokens[0]] = tokens[1];
});
return wordDictionary;
@xmichaelx
xmichaelx / PasswordGenerator.cs
Last active March 31, 2017 23:11
password generation based on https://www.eff.org/dice
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Security.Cryptography;
namespace PasswordGenerator
{
class Program
{
@xmichaelx
xmichaelx / simpleLineFitting.cs
Created February 24, 2016 14:49
Fitting line while minimizing least squares error
Tuple<double, double> LinearLeastSquaresFit(List<Point> points)
{
double length = points.Count;
double Sx = points.Sum(p=> p.X);
double Sy = points.Sum(p => p.Y);
double Sxx = points.Sum(p => Math.Pow(p.X,2));
double Sxy = points.Sum(p => p.X * p.Y);
var a = (Sxy * length - Sx * Sy) / (Sxx * length - Sx * Sx);
var b = (Sxy * Sx - Sy * Sxx) / (Sx * Sx - length * Sxx);
@xmichaelx
xmichaelx / cellular.js
Last active November 21, 2015 21:08
1D cellular automata
function shuffle(o){
for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
return o;
}
function cellular1d(width, height, density, rule) {
var blackPixelsCount = Math.floor(width*density), whitePixelsCount = width - blackPixelsCount;
var initial = [];
while(blackPixelsCount--) {
@xmichaelx
xmichaelx / DBFImporter.cs
Created November 10, 2015 01:01
dbf importing
using System.Data;
using System.Data.OleDb;
using System.IO;
namespace Importers
{
public class DBFImporter
{
public static DataTable ExtractDataTable(string filePath)
{
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Diffusion-Limited aggregation</title>
<meta name="description" content="Diffusion-Limited aggregation">
<meta name="author" content="Michal Drzal">
<link href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">
<script src="dla.js"></script>
</head>
import sys
from skimage import io, color
from scipy.ndimage.measurements import label, sum
from skimage.morphology import convex_hull_image
def main():
if len(sys.argv) < 4:
print("Input format: <filename> <minimum size of detected shape in pixels> <threshold between 0 and 1>")
return