Skip to content

Instantly share code, notes, and snippets.

View mbjd's full-sized avatar

Balduin mbjd

  • ETH Zürich
  • Zürich, CH
View GitHub Profile
@mbjd
mbjd / plotcdf.py
Created May 2, 2024 10:08
pipe a stream of numbers into this script, get a nice plot of the cdf :)
#!/usr/bin/env python3
# plot the cumulative distribution function of bunch of numbers
import numpy as np
import matplotlib.pyplot as pl
A = np.loadtxt('/dev/stdin', delimiter=',')
assert len(A.shape) == 1, f'Data must be one-dimensional but has shape {A.shape}'
#include <math.h>
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
/*
* Test different methods of uniformly sampling a point on the unit circle.
* Inspired by https://www.youtube.com/watch?v=4y_nmpv-9lI
* Sample outputs:
*
@mbjd
mbjd / tri_squares.hs
Last active July 13, 2016 17:10
Find numbers that are both square and triangle numbers. To use, start ghci and execute `:l tri_squares.hs`, followed by `tri_squares`
-- find numbers that are both a square and a triangle number.
-- https://www.youtube.com/watch?v=Gh8h8MJFFdI
squares = map (\x -> x * x) [0..]
triangle_number x = div (x * (x + 1)) 2
triangle_numbers = map triangle_number [0..]
-- Check if you can arrange x points in a triangle with an integer side length
is_triangle x =
@mbjd
mbjd / cliptracker.sh
Created April 2, 2016 19:17
Print clipboard changes to stdout with timestamp and new content. Works only on OS X (or wherever you have something equivalent to `pbpaste` installed).
#!/usr/bin/env bash
# Tracks contents of the clipboard by printing changes to
# stdout with a timestamp
last=$(pbpaste)
# Check if the clipboard content has changed, and if it has
# output the new contents with a timestamp
sample() {
@mbjd
mbjd / kmtogo.py
Last active April 2, 2016 19:38
Display some numbers about how much cycling you've done this year and how you need to adjust to reach a certain goal. Pulls data from a strava profile.
#!/usr/bin/env python
#
# This script parses a strava athlete page to get the amount of bicycling kilometers this year
# to date from strava, and calculates some statistics from that (km/day and km/week to date and
# necessary to hit a target, and km to go / km already done).
#
# usage: $ ./kmtogo.py [target]
# If no target is specified, it'll take the default value (2000).
#
// Solution to advent of code, day 6
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
// Part 1
bool lights[1000][1000] = {false};
@mbjd
mbjd / Hexacopter.bsg
Created May 14, 2015 11:44
Two besiege files, a hexacopter and its armed version with 44 bombs. Steering is as follows: up/down to pitch forward/backwards, left/right to roll left/right, G/J to yaw left/right and Z/H to increase/decrease the collective pitch. The bombs can be released using the 0-9 keys (4 or 6 are dropped each time).
PREFAB IDS
0|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|7|7|7|7|7|7|15|15|15|15|15|15|2|2|2|2|2|2|2|2|2|2|22|22|22|22|22|22|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|13|13|13|13|26|26|26|26|13|13|13|13|13|13|13|13|26|26|26|26|26|26|26|26|13|13|13|13|13|13|13|13|13|13|13|13|26|26|26|26|26|26|26|26|26|26|26|26|1|1|7|7|7|7|7|7|7|7|7|7|15|15|15|15|15|15|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|15|16|16|16|16|16|16|16|14|14|14|14|14|14|14|14|14|14|14|14
POSITIONS
0,0,0|-0.5,0,0|-2.5,0,-4.145808E-07|-4.5,0,-1.713005E-06|-6.500001,0,-3.716458E-06|0.5,0,0|2.5,0,-4.145808E-07|4.5,0,-1.713005E-06|6.500001,0,-3.716458E-06|8.500001,0,-6.509234E-06|-8.500001,0,-6.42494E-06|-10.5,0,-9.922745E-06|10.5,0,-1.010156E-05|6,0,-0.5000032|6,0,-2.500003|6,0,-4.500003|6,0,-6.500003|6.000001,0,0.4999969|6.000001,0,2.499997|6.000001,0,4.499997|6.000001,0,6.499997|-6.000001,0,0.4999969|-6.000001,0,2.499997|-6.000001,0,4.499997|-6.000001,0,6.499997|-6,0,-0.5000032|-6,0,-2.500003|-6,0,-4.5000
PREFAB IDS
0|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|2|2|2|2|22|22|22|22|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|35|13|13|13|13|13|13|13|13|13|13|13|13|13|13|13|13|7|7|7|7|7|7|7|7|1|1|1|1|16|16|16|16|23|23|23|23|23|23|23|23|23|27|27|27|27|27|27|27|27|27|14|14|14|14|14|14|14|14|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|7|1|7|7|7|7|1|11|11|11|11|26|26|26|26|26|26|26|26|26|26|26|26|26|26|26|26
POSITIONS
0,0,0|0.4999998,0,2.340613E-09|2.5,0,-4.170207E-07|4.499999,0,-1.706465E-06|6.499999,0,-3.72107E-06|1.170307E-09,0,-0.4999999|7.802043E-10,0,-2.5|7.021839E-09,0,-4.499999|1.484407E-09,0,-6.499998|3.098017E-08,0,-8.499993|8.499994,0,-6.448053E-06|-7.802043E-10,0,2.5|-7.021839E-09,0,4.499999|5.965535E-09,0,6.499998|1.371948E-08,0,8.499993|-0.5,0,3.724971E-09|-2.5,0,-4.099228E-07|-4.499999,0,-1.716784E-06|-6.499999,0,-3.699072E-06|-8.499994,0,-6.485046E-06|3.332078E-08,0.5,-9.999993|9.999994,0.5,-9.202191E-06|1.137887E-08,0.5,9.999993|-9.999994,0.5,-9.154466E-06|9.999994,1,-9.053192E-06|1.137887E-08,1,9.999993|3.332078