Skip to content

Instantly share code, notes, and snippets.

View billju's full-sized avatar

ChuBoy billju

  • NCTU
  • Taiwan
View GitHub Profile
@billju
billju / Drumpad.cpp
Last active October 21, 2021 01:58
/*
Super Easy Diy Drumpad Example
GIT: https://gist.github.com/billju/ce1337ea3c1dbb4341ce22dca1b55442
2017 by Billju
Inspired by Evan Kale
*/
#include <Keyboard.h>
#include "MIDIUSB.h"
from selenium import webdriver
driver = webdriver.Chrome('C:/Users/使用者名稱/Downloads/chromedriver.exe')
driver.get('https://shopee.tw/') #會彈出新的頁面
cookies = driver.get_cookies() #格式為list包dict
csrftoken = [item['value'] for item in cookies if item['name'] == 'csrftoken'][0]
import numpy as np
A = np.array([['男', '市場部', '24000', '無'],
['女', '研發部', '45000', '有'],
['男', '會計部', '45000', '無'],
['男', '研發部', '40000', '無'],
['女', '市場部', '24000', '有'],
['女', '研發部', '40000', '無'],
['男', '市場部', '24000', '有']])
def Hamming_distance(A):
# 定義計算方法
log2 = lambda x: np.log2(x,where=x!=0)
I = lambda *args: sum([-arg/sum(args)*log2(arg/sum(args)) for arg in args])
G = lambda *args: sum([1-(arg/sum(args))**2 for arg in args])
Cum = lambda F, P, y: P.mean() * F(*[ (P&(y==v)).sum() for v in y.unique() ])
CumSum = lambda F, S, y: sum([ Cum(F, S==v, y) for v in S.unique() ])
E = lambda S, y: CumSum(I, S, y)
Gain = lambda S, y: I(*y.value_counts()) - E(S, y)
SplitGain = lambda S: I(*S.value_counts())
GainRatio = lambda S, y: Gain(S,y) / SplitGain(S)
import numpy as np
# activation function
sigmoid = lambda x: 1/(1+np.exp(-x))
# set input, output and hyperparameter
X = np.array([
[1,0,1]
])
y = np.array([
[1]
])
import io
import pandas as pd
from itertools import permutations, combinations
CSV = """
交易紀錄 牛奶(A) 麵包(B) 餅乾(C) 柳橙汁(D) 汽水(E) 泡麵(F) 水果(G)
101 1 1 1 1 0 0 0
102 0 1 1 0 1 1 0
103 1 0 1 0 0 0 1
104 1 1 0 1 0 1 1
105 0 0 1 0 1 0 1
import numpy as np
import pandas as pd
k = 2 # K個群集
max_iter = 10 # 最大迭代
data = np.array([1, 2, 3, 4, 11, 12])
last = np.random.choice(data, k, replace=False) # 初始化K個中心點
func = lambda x,y: np.abs(x-y) # 計算距離方法
steps = []
for _ in range(max_iter):
# 對每筆資料求出最近的中心點
# 下載 https://tesseract-ocr.github.io/tessdoc/Downloads.html
# 權重 https://github.com/tesseract-ocr/tessdata_best
# .box檔案格式:字 6 394 45 410 0
import os
import shutil
from PIL import Image
from glob import glob
lang = 'chi_tra'
font = 'ocrb'
dist = 'tessdata'
const puppeteer = require('puppeteer-core');
const fs = require('fs');
const path = require('path');
const glob = require('glob').sync;
const { execSync } = require('child_process');
const edgeExe = 'C:/Program Files (x86)/Microsoft/Edge/Application/msedge.exe';
/**
* 全國電子公佈欄爬蟲
* https://www.odbbs.gov.tw/odbbs/html/announce.jsp
*/
const fs = require('fs');
const { execSync } = require('child_process');
// 讀取版號
const package = JSON.parse(fs.readFileSync('package.json'));
let version = process.argv[2]; // 指令引數
if (!version) {
// 自動增加版號
version = parseInt(package.version.replace(/\./g, ''));
version = (version + 1).toString();
version = '0'.repeat(Math.max(3 - version.length)) + version;