Skip to content

Instantly share code, notes, and snippets.

@linnil1
linnil1 / upload_drive.py
Created July 29, 2017 04:01
upload image in image/ to gdrive
import subprocess
from os.path import expanduser, join
from concurrent.futures import ThreadPoolExecutor
import os
import time
def upload(path, name):
rep = subprocess.run(["gdrive", "upload", path, "--delete", "-p", "0B2RYolW0g60rQmh2ZjNFWUZxZmM", "--name", name], stdout=subprocess.PIPE)
rep = str(rep.stdout, "utf-8")
# print(rep)
@linnil1
linnil1 / webcam_save.py
Created July 29, 2017 04:07
save webcam capture image
import cv2
import numpy as np
import time
cap = cv2.VideoCapture(0)
while not cap.isOpened():
print("Reset")
time.sleep(0.1)
cap = cv2.VideoCapture(0)
var click = function(ch){
e = new KeyboardEvent('keydown',{'keyCode':ch.charCodeAt()});
document.getElementById("canvas").dispatchEvent(e);
}
var keypress = function(ch){
var eventObj = document.createEvent("Events");
eventObj.initEvent("keydown", true, true);
eventObj.which = ch.toUpperCase().charCodeAt();
document.getElementById("canvas").dispatchEvent(eventObj);
@linnil1
linnil1 / ADC_1.py
Last active September 26, 2017 13:48
import numpy as np
import matplotlib.pyplot as plt
f = 5 # frequence
A = 10 # amplitude
sf = 50 // f # sampling frequence
t = np.linspace(0, 1/f, 10 * sf)
fun = A * np.sin(f * 2 * np.pi * t)
import numpy as np
import matplotlib.pyplot as plt
f = 150 # frequency
period_point = 10 # how many point each sampling interval
period = 50
sf = 200 * period // f # sampling times
t = np.linspace(0, period * 1 / f, period_point * sf)
fun = 4 * np.sin(100 * np.pi * t) + 4 * np.sin(300 * np.pi * t)
@linnil1
linnil1 / PhaseDistortion.py
Last active October 18, 2017 16:04
An example of phase distortion
import matplotlib.pyplot as plt
import numpy as np
# use latex
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
x = np.linspace(0, 2 * np.pi, 100)
plt.subplot(411)
@linnil1
linnil1 / sin_adc_bin.py
Last active October 19, 2017 06:55
Use ADC to convert sin wave to bin historgram and also output formula
import matplotlib.pyplot as plt
import numpy as np
sample_num = 100
lim = [0, 0.05]
x = np.linspace(-0.999999, 0.999999, sample_num)
plt.subplot(311)
num = np.arcsin(x[1:]) - np.arcsin(x[:-1])
plt.plot(x[:-1], num/2)
plt.title("derived formula")
#include <DHT.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
const int lightPin = 13,
motorPin = 9,
dhtPin = 8,
temperture = 27; // strictly larger
int lightFeq = 0,
motorFeq = 0,
@linnil1
linnil1 / LAB03_confidence.py
Created October 22, 2017 14:09
get 68% and 99% confidence of the data
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import scipy.stats as st
us = [4.8949, 4.8957, 4.8939, 4.8932, 4.8954]
ts = [0.0004995, 0.0004992, 0.001768, 0.001757, 0.0006654]
n = 5000
tns = np.array(ts) / np.sqrt(n - 1)
print(us)
@linnil1
linnil1 / postLab03.py
Created October 22, 2017 16:07
same thing as lab03
import matplotlib.patches as mpatches
import matplotlib.pyplot as plt
import matplotlib
import numpy as np
import scipy.stats as st
data = np.array("1.0006 1.0072 0.9941 0.9918 0.9986 0.9991 1.0107 0.9981 1.0011 1.0218".split(), dtype=np.float)
data1 = np.array("0.9854 1.0056 1.0041 1.0132 0.9902 0.9876 1.0094 0.9815 0.9999 1.0027".split(), dtype=np.float)