Skip to content

Instantly share code, notes, and snippets.

View dews's full-sized avatar

Calvin Zheng dews

  • Taichung, Taiwan
View GitHub Profile
@dews
dews / slim-redux.js
Last active March 7, 2021 14:03 — forked from gaearon/slim-redux.js
Add applyMiddleware and add example
function mapValues(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
result[key] = fn(obj[key], key);
return result;
}, {});
}
function pick(obj, fn) {
return Object.keys(obj).reduce((result, key) => {
if (fn(obj[key])) {
@dews
dews / modbus_rtu.py
Last active July 29, 2019 03:28
modbus_rtu #modbus
#!/usr/bin/env python
"""
Pymodbus Synchronous Client Examples
--------------------------------------------------------------------------
The following is an example of how to use the synchronous modbus client
implementation from pymodbus.
It should be noted that the client can also be used with
the guard construct that is available in python 2.5 and up::
[device]
murano_host = https://jrxncdkk2ls00000.m2.exosite.io/
murano_id = test
debug = INFO
murano_token = 7504c0bff8e9b9fe73214e0a113bc57a49e7bb14
murano_port = 443
watchlist = config_io,data_out
[edged]
config_io_file = config_io.json
@dews
dews / ModbusClient
Created April 9, 2019 06:38
ModbusClient.py
#!/usr/bin/env python
"""
Pymodbus Synchronous Client Examples
--------------------------------------------------------------------------
The following is an example of how to use the synchronous modbus client
implementation from pymodbus.
It should be noted that the client can also be used with
the guard construct that is available in python 2.5 and up::
@dews
dews / netflix.js
Last active February 2, 2019 04:13
speedup netflix play rate
document.querySelector('video').playbackRate = 1.5
import queue
import time
from threading import Event, Thread
class mo(Thread):
def __init__(self, num, q):
Thread.__init__(self, name='mo' + str(num))
self.num = num
self.q = q
@dews
dews / inheritance_demo.py
Last active October 30, 2018 08:17
python inheritance share variable
class Parent():
i = 123
def assign(self, n):
self.i = n
class ChildA(Parent):
def f1(self):
Parent.assign(self, 1)
@dews
dews / openssl.bash
Last active July 16, 2018 10:06
Verify the Signature of a X.509 Certificate
#!/bin/bash
openssl req -newkey rsa:2048 -nodes -keyout server.key \
-subj '/CN=example.com/C=AU/O=Widgits Pty' -outform d -sha256 -out server.crt
openssl req -inform d -in server.crt -text -noout
# Certificate Request:
# Data:
# Version: 0 (0x0)
# Subject: CN=example.com, C=AU, O=Widgits Pty
@dews
dews / fillDB.py
Created February 9, 2018 03:04
Fill the SQLite
import sqlite3
conn = sqlite3.connect('testDB.db')
cursor = conn.cursor()
# cursor.execute('''CREATE TABLE test5
# (ID INT PRIMARY KEY NOT NULL,
# NAME TEXT NOT NULL);''')
with open('1mb.img') as f:
readFile = f.read()
i = 11
@dews
dews / git.md
Last active February 1, 2018 03:47
Git remove merged branch