Skip to content

Instantly share code, notes, and snippets.

Avatar

Karim Naufal mysticaltech

View GitHub Profile
@mysticaltech
mysticaltech / mirror_mirror.sh
Created Dec 3, 2021 — forked from marshki/mirror_mirror.sh
One-way Rsync mirror of data from source to destination. Run as a crontab.
View mirror_mirror.sh
#!/usr/bin/env bash
#
# mirror_mirror
#
# One-way Rsync mirror of data from source to destination.
#
# Author: M. Krinitz <mjk235 [at] nyu [dot] edu>
# Date: 2020.04.20
# License: MIT
#
View bayesian_ab_test.py
from matplotlib import use
from pylab import *
from scipy.stats import beta, norm, uniform
from random import random
from numpy import *
import numpy as np
import os
# Input data
@mysticaltech
mysticaltech / crc.py
Created Oct 11, 2021 — forked from Lauszus/crc.py
Generic CRC-8, CRC-16 and CRC-32 calculations in Python
View crc.py
#!/usr/bin/env python
# Inspired by: https://www.youtube.com/watch?v=izG7qT0EpBw
# The CRC values are verified using: https://crccalc.com/
def reflect_data(x, width):
# See: https://stackoverflow.com/a/20918545
if width == 8:
x = ((x & 0x55) << 1) | ((x & 0xAA) >> 1)
x = ((x & 0x33) << 2) | ((x & 0xCC) >> 2)
x = ((x & 0x0F) << 4) | ((x & 0xF0) >> 4)
View gist:22f5ed5466c2372d69c82f5c743da3d6
Basically, to make it work and have it resolve DNS queries, you need to disable systemd-resolved as it monopolizes the /etc/resolv.conf file, more about this process here https://fedoraproject.org/wiki/Changes/systemd-resolved.
sudo systemctl disable systemd-resolved
sudo systemctl stop systemd-resolved
sudo bash -c 'mkdir -p /etc/systemd/system-preset && echo "disable systemd-resolved.service" >/etc/systemd/system-preset/20-systemd-resolved-disable.preset'
Then reboot, and don't worry it is normal that you do not have internet at that point. We need to delete an old symlink left over from systemd-resolved operations.
rm /etc/resolv.conf
@mysticaltech
mysticaltech / html_to_text.py
Created Jul 29, 2021 — forked from racitup/html_to_text.py
Extract text from html in python using BeautifulSoup4
View html_to_text.py
from bs4 import BeautifulSoup, NavigableString, Tag
def html_to_text(html):
"Creates a formatted text email message as a string from a rendered html template (page)"
soup = BeautifulSoup(html, 'html.parser')
# Ignore anything in head
body, text = soup.body, []
for element in body.descendants:
# We use type and not isinstance since comments, cdata, etc are subclasses that we don't want
if type(element) == NavigableString:
@mysticaltech
mysticaltech / bitbucket-webhook.php
Created Aug 22, 2020 — forked from jarnix/bitbucket-webhook.php
A simple php script for deploy using bitbucket webhook
View bitbucket-webhook.php
<?php
// edit these lines:
// example: /var/www/repositories/project.git
$repo_dir = '~/repository.git';
// example: /var/www/project
$web_root_dir = '~/project';
// example: /var/www/project/scripts/post_deploy.sh
View simulatePOWERdistributions
library(MBESS)
library(pwr)
nSims <- 100000 #number of simulated experiments
p <-numeric(nSims) #set up empty container for all simulated p-values
obs_pwr <-numeric(nSims) #set up empty container
t <-numeric(nSims) #set up empty container
d_all<-numeric(nSims)
N<-33 #number of participants
@mysticaltech
mysticaltech / dunn.py
Created May 8, 2020 — forked from alimuldal/dunn.py
Implementation of Dunn's multiple comparison test, following a Kruskal-Wallis 1-way ANOVA
View dunn.py
import numpy as np
from scipy import stats
from itertools import combinations
from statsmodels.stats.multitest import multipletests
from statsmodels.stats.libqsturng import psturng
import warnings
def kw_dunn(groups, to_compare=None, alpha=0.05, method='bonf'):
"""
View g_series_9.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@mysticaltech
mysticaltech / sample_size_AB.R
Created Apr 3, 2020 — forked from uttara-cmu/sample_size_AB.R
Evan Miller's Tool - R code
View sample_size_AB.R
# The code given in #2 gist is not in R. There is a change in formula compared to the one in this blog post and the one used by Evan Miller's tool (#3). http://www.alfredo.motta.name/ab-testing-from-scratch/#easy-footnote-bottom-24-982
#1. https://stats.stackexchange.com/questions/357336/create-an-a-b-sample-size-calculator-using-evan-millers-post
#2. https://gist.github.com/mottalrd/7ddfd45d14bc7433dec2#file-gistfile1-txt
#3. https://www.evanmiller.org/ab-testing/sample-size.html
p = 0.03
pct_mde = 0.1
alpha = 0.05
power = 1- 0.2