Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / 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 / 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": [
struct AMG_ANGLES {
float yaw;
float pitch;
float roll;
};
int main() {
AMG_ANGLES struct_data;
struct_data.yaw = 87.96;
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
}
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)
wget https://static.coupangcdn.com/image/retail/images/3820450603696599-6f882635-b5ef-427f-88b7-e02f95f817fe.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/image/vendor_inventory/fbc8/7255ef95f641dae104e82b52ea36af9bfcd0bcc1722db53479e0c14d5a92.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/image/product/image/vendoritem/2019/04/03/3000100186/91f4c21b-112d-4280-aba3-9986508373a5.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/image/retail/images/9106832342621663-eec2ebc5-0959-4fb8-9421-fc4b69ebb5c9.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/image/vendor_inventory/01c4/2b3aaa3f6de5d3eee5163fb0aa85c605221fd8a9beea33328fbd73a17665.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/image/product/image/vendoritem/2019/02/26/3001018078/920ed84a-83b0-4491-80ad-eec1e326854a.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/image/retail/images/4954777811148116-eef2bce1-8c2a-4254-bb53-f02452191fa4.jpg -P ~/Downloads/tmp
wget https://static.coupangcdn.com/ima