Skip to content

Instantly share code, notes, and snippets.

View bartolsthoorn's full-sized avatar

Bart Olsthoorn bartolsthoorn

View GitHub Profile
@bartolsthoorn
bartolsthoorn / hypergeometric_2f1.py
Created April 14, 2020 14:29
Hypergeometric2F1 with complex arguments in Python by evaluating the power series
from numba import njit
import numpy as np
@njit('c8(c8,u8)')
def rising_poch(x, n):
p = 1+0j
for k in range(n):
p *= (x+k)
return p
@bartolsthoorn
bartolsthoorn / seekpath_run.py
Created June 10, 2019 11:19
SeeK-path minimum set-up to just get a working JS widget with pymatgen/cif files.
from pymatgen import Structure
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
import seekpath
import json
structure = Structure.from_file('diamond.cif')
# spglib primitive cell
sga = SpacegroupAnalyzer(structure)
structure = sga.find_primitive()
@bartolsthoorn
bartolsthoorn / solution.py
Created May 10, 2019 15:29
Solution to Google Code Jam World Finals 2017 - Problem A. Dice Straight in Python
import itertools
import numpy as np
from scipy.optimize import linear_sum_assignment
with open('A-small-practice.in', 'rt') as f:
T = int(next(f))
for t in range(T):
dice = []
N = int(next(f))
for n in range(N):
@bartolsthoorn
bartolsthoorn / multilabel_example.py
Created April 29, 2017 12:13
Simple multi-laber classification example with Pytorch and MultiLabelSoftMarginLoss (https://en.wikipedia.org/wiki/Multi-label_classification)
import torch
import torch.nn as nn
import numpy as np
import torch.optim as optim
from torch.autograd import Variable
# (1, 0) => target labels 0+2
# (0, 1) => target labels 1
# (1, 1) => target labels 3
train = []
@bartolsthoorn
bartolsthoorn / scrape.sh
Last active August 29, 2015 14:10
Scraper using Simhash with DOM trees. This is a proof of concept that scrapes Hackernews with just 3 lines (34-36) of configuration.
wget https://news.ycombinator.com
ruby scraper.rb
enum Node {
Text(String),
Element(String, Vec<Node>)
}
impl Node {
fn stringify(&self) -> String {
match *self {
Text(s) => s,
Element(name, nodes) =>
// A web structure adventure
#![license = "MIT"]
// Disable warning about parser imports
#![allow(dead_code)]
#![allow(unused_imports)]
// Enable peg_syntax_ext phase
#![feature(phase)]
@bartolsthoorn
bartolsthoorn / html.rs
Created August 23, 2014 16:47
`simhash::hash` requires a `&str`
extern crate simhash;
use std::sync::Future;
/// DOM Tree
pub struct Tree {
html: String,
pub hash: Future<u64>
}
impl Tree {
@bartolsthoorn
bartolsthoorn / analyse.sh
Created February 28, 2014 22:09
Reverse engineering bash script helper for OSX. First `chmod u+x analyse.sh` to make it executable, and then use `./analyse.sh file1`
OUT=reports
mkdir -p $OUT/$1
nm $1 > $OUT/$1/nm.asm
otool -Vt $1 > $OUT/$1/text.asm
otool -V -s __TEXT __cstring $1 > $OUT/$1/cstring.asm
xxd -a $1 > $OUT/$1/xxd.hex
echo "Analysing of $1 finished"
(ns overtour.core
(:use [overtone.live]
[overtone.inst.piano]))
(defn -main [& args]
(piano (note :g4))
(println "Piano ready!"))
; Random number between l and h (l inclusive, h exclusive)
(defn rand-between [l h]