Skip to content

Instantly share code, notes, and snippets.

@xmichaelx
xmichaelx / tle.js
Created August 11, 2014 14:33
Small snippet for converting strings in Two-Line Element into JSON format (with additional computed values such ass period, semi-major axis, JD and MJD).
var TLE =
(function () {
function isCorrupted(line) {
var checksum = parseInt(line[line.length-1]);
var computedChecksum = line.slice(0,line.length-1)
.replace(/[\-\-]/g,"1")
.replace(/[a-zA-Z\.+\s]/g,"")
.split("")
.map(function(digit) { return parseInt(digit) })
.reduce(function(prev, current) {return prev + current;}, 0) % 10;
@xmichaelx
xmichaelx / vis.html
Created August 11, 2014 23:35
Simple network visualized using vis.js
<!DOCTYPE html>
<html>
<title>Network | Images</title>
<head>
<link href="http://visjs.org/dist/vis.css" rel="stylesheet" type="text/css" />
<script src="http://visjs.org/dist/vis.js"></script>
<script type="text/javascript">
function draw() {
var nodes = [
{id: 1, label: 'SLR1', group: 'source', value: 10},
@xmichaelx
xmichaelx / cellular.py
Created November 26, 2014 16:01
Simple implementation of binary, 1D cellular automaton with sample 184 rule (http://en.wikipedia.org/wiki/Rule_184)
from random import uniform
import matplotlib.pyplot as plt
import numpy as np
from random import sample
n = 200 # number of cells in row
num_iters = 200 # number of iterations
density = 0.5 # how many positives
# rule 184
@xmichaelx
xmichaelx / dla.js
Created December 6, 2014 16:22
Simple diffusion-limited aggregation simulation in JS
function createField(width, height) {
var field = new Uint8Array(width * height);
var fcenterX = Math.floor(width / 2);
var fcenterY = Math.floor(height / 2);
// center occupied
field[fcenterX + fcenterY * width] = 1;
return { field: field, width:width, height:height};
}
import snap
# requires python 2.7 and 64-bit machine
G1 = snap.TUNGraph.New()
with open("data/edges.csv") as f:
for line in f:
tokens = line.split()
n1, n2, weight = int(tokens[0]), int(tokens[1]), int(tokens[2])
if not G1.IsNode(n1):
G1.AddNode(n1)
@xmichaelx
xmichaelx / nagel-schreckenberg.py
Created December 9, 2014 05:34
Simple python implementation of nagel-schreckenberg model for modelling traffic
from random import uniform, shuffle
import matplotlib.pyplot as plt
import numpy as np
L = 500 # number of cells in row
num_iters = 500 # number of iterations
density = 0.48 # how many positives
vmax = 2
p = 0.2
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
<!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>
@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)
{
@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--) {