Skip to content

Instantly share code, notes, and snippets.

input = """0:07 Komm, ihr Töchter (Chor)
8:02 De Jesu diese Rede (Rezitativ)
8:46 Herzlieber Jesu (Choral)
9:38 Da Versammleten (Rezitativ)
10:02 Ja nicht auf das Fest (Chor)
10:17 Da nun Jesus war zu Bethanien (Rezitativ)
10:49 Wozu dienet dieser Unrat? (Chor)
11:16 Da das Jesus merkete (Rezitativ)
12:50 Du liebert Heiland du (Arioso)
13:46 Buss un Reu (Arie)
nruns = 10000
FPR <- function(population, allowedFailedRatio){
allowFails = population * allowedFailedRatio
count = match = 0
while (count < nruns) {
x <- rnorm(population, 0, 1)
if (sum(x > 2 | x < -2) <= allowFails){
match = match + 1
}
struct AMG_ANGLES {
float yaw;
float pitch;
float roll;
};
int main() {
AMG_ANGLES struct_data;
struct_data.yaw = 87.96;
@sc268
sc268 / setting.json
Created February 11, 2019 21:02
vs code cygwin default terminal setting
{
"window.zoomLevel": 0,
// start bash, not the mintty, or you'll get a new window
"terminal.integrated.shell.windows": "C:\\cygwin64\\bin\\bash.exe",
// Use this to keep bash from doing a 'cd ${HOME}'
"terminal.integrated.env.windows": {
"CHERE_INVOKING": "1"
},
// Make it a login shell
"terminal.integrated.shellArgs.windows": [
@sc268
sc268 / save_objs.py
Last active February 2, 2021 00:03
python save & load objects
def getModelName(model_path):
fn = args.model.split('/')[-1]
return fn.replace('.tar', '')
def createFolderIfnotExist(dir):
if not os.path.exists(dir):
os.mkdir(dir)
def saveList(fn, alist):
with open(fn, 'w') as f:
for c in alist:
f.write("%s\n" % c)
@sc268
sc268 / getSums.py
Last active December 2, 2018 07:31
getSums.py
def initPartialSum(A):
nrow, ncol = len(A), 0 if not matrix else len(A[0])
#S[i][j] = sum(m, n) for 0 <= m <= i, 0 <= n <= j
S = [[0] * ncol for _ in range(nrow)]
for i in range(nrow):
partialSum = 0
for j in range(ncol):
partialSum += A[i][j]
S[i][j] = partialSum
if i > 0: S[i][j] += S[i-1][j]
@sc268
sc268 / tfidf.py
Created September 22, 2018 00:20
##############################################################
# V2 = use bounding box information to weight words in OCR
## add imagehash to dedup
##############################################
## common functions
##############################################
import logging, os, re
import pandas as pd
import collections, struct, pickle, json, re
from ast import literal_eval
@sc268
sc268 / ui.xml
Created June 9, 2018 03:59
pinterest xml
<?xml version='1.0' encoding='UTF-8' standalone='yes' ?>
<hierarchy rotation="0">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.pinterest" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1200,1823]">
<node index="0" text="" resource-id="" class="android.widget.LinearLayout" package="com.pinterest" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="[0,0][1200,1823]">
<node index="0" text="" resource-id="" class="android.widget.FrameLayout" package="com.pinterest" content-desc="" checkable="false" checked="false" clickable="false" enabled="true" focusable="false" focused="false" scrollable="false" long-clickable="false" password="false" selected="false" bounds="
@sc268
sc268 / parallel.py
Last active July 5, 2018 16:27
run foo.py with different date input in parallel
# run foo.py with different date input in parallel
# input: sys.argv[1]: starting date ; sys.argv[2]): num of days
import sys
import os
from multiprocessing import Process
import pandas as pd
children = []
m0 =5
m1 =18
alpha = 0.05
tau = 1.0
m_arr = sort(list(set(map(lambda x: int(round(x)), np.linspace(m0, m1, 10)))))
print m_arr
for m in m_arr:
kmax = int(round(m/3.))
prior_levels = [1./(m+1)]*(m+1)