Skip to content

Instantly share code, notes, and snippets.

@DomiDre
DomiDre / score1337.py
Last active November 20, 2019 12:47
Determine from Whatsapp Logs, who has posted how many times 1337 at 13:37 throughout the years
from dataclasses import dataclass
import re, datetime
LEETTIME = "1337"
LEET_HOUR = "13"
LEET_MINUTE = "37"
datasrc = "./whatsapplog.txt"
scores = {}
class Score:
@DomiDre
DomiDre / fit_lognormal_magnetization.py
Created August 20, 2019 20:48
Short script to fit a magnetization curve using a Langevin function with log-normal distributed moment
import numpy as np
import lmfit
from numpy.polynomial.hermite import hermgauss
file_path = "./example_data.xye"
savefile_path = './magnetization_fit.dat'
quadrature_degree = 21 # integer number between 2 and 100
# use kB/muB in Langevin function -> mu is in units of Bohr magneton
kB = 1.380649e-23 # J/K
@DomiDre
DomiDre / fitGaussian.js
Created August 6, 2019 12:15
Fit of a Gaussian model to data using the ml-levenberg-marquardt package
var LM = require('ml-levenberg-marquardt');
var fs = require('fs');
function gaussianFunction([A, mu, sigma, c]) {
return (x) => A * Math.exp(-0.5*((x-mu)/sigma)**2) + c;
}
fs.readFile('../gaussianData.xye', 'utf8', async function(err, data) {
@DomiDre
DomiDre / main.rs
Created August 6, 2019 10:51
A short rust script to execute a fit using the rusfun crate
use ndarray::{array, Array1};
use rusfun::{curve_fit, func1d, size_distribution};
use std::fs::File;
use std::io::{BufRead, BufReader, Result};
fn main() {
// read data
let (x, y, sy) = read_column_file("./gaussianData.xye").unwrap_or_else(|err| {
eprintln!("Error reading data file: {}", err);
std::process::exit(1);
@DomiDre
DomiDre / fit_Gaussian.py
Created August 6, 2019 09:59
Short script that loads a three-column data file and fits the data to a Gaussian model. Times the execution & plots the result.
import numpy as np
from scipy.optimize import leastsq
import time
# Load data from file
rawdata = np.genfromtxt('./gaussianData.xye')
x = rawdata[:, 0]
y = rawdata[:, 1]
sy = rawdata[:, 2]
@DomiDre
DomiDre / generate_randomized_Gaussian.py
Last active August 8, 2019 15:21
A quick generation of a Gaussian data with small noise
import numpy as np
x = np.linspace(0, 10, 51)
A = 42
mu = 4.2
sigma = 0.666
c = 10
sig_y = 3*np.ones(len(x)) #np.sqrt(y)
@DomiDre
DomiDre / introrx.md
Created February 17, 2018 19:31 — forked from staltz/introrx.md
The introduction to Reactive Programming you've been missing