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
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)
<!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--) {
@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);
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
@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
{