Skip to content

Instantly share code, notes, and snippets.

View sheronw's full-sized avatar

Sheron W sheronw

  • New York, US
View GitHub Profile
@sheronw
sheronw / forInForOf.js
Created March 21, 2020 18:04
different between for...in and for...of #js
let list = [6,8,10];
list.tag = "hello";
// values of the numeric properties of the object being iterated
for(i of list) { // 6 8 10
console.log(i)
}
// keys on the object being iterated
for(i in list) { // 0 1 2 tag
@sheronw
sheronw / unrelated_history.sh
Last active March 22, 2020 01:43
merge unrelated branch back to master #git
git checkout master
# put everything remote to this branch
git rebase origin master
# merge another branch to the updated master
git merge your-branch --allow-unrelated-histories
@sheronw
sheronw / var_let.js
Created March 23, 2020 15:44
difference between var and let in #js
// var is kind of global variable
console.log(a); // undefined
var a = "wow";
console.log(a); // wow
var a = "wowow";
console.log(a); // wowow
// visible globally
// visible only within a block
while (true) {
@sheronw
sheronw / functions.js
Created March 23, 2020 16:08
different types of function declaration in #js
// 1. as an object
// it works as "let" i.e. visible in block
func1("wow"); // Error
let func1 = function(var1) {
console.log(var1);
}
func1("wow"); // wow
// 2. as a function
func2("wow"); // wow
@sheronw
sheronw / toggle_telegram_ifttt.js
Created April 14, 2020 00:22
Use #IFTTT to send #Toggl Reports to #Telegram
const https = require("https");
const api_token = "你的 API Token";
const workplace_id = "你的 Workplace ID";
const user_agent = "你的邮箱或应用名";
const webhook = `https://maker.ifttt.com/trigger/你的Event名/with/key/你url的key`;
const url = new URL(
"https://toggl.com/reports/api/v2/details?user_agent=" +
@sheronw
sheronw / crawler_text-to-speech.js
Last active April 17, 2020 22:43
Some snippets for **my** raspberry Pi speaker
const Crawler = require("crawler");
const textToSpeech = require('@google-cloud/text-to-speech');
const fs = require('fs');
const util = require('util');
const MPlayer = require('mplayer');
const player = new MPlayer();
async function getSpeech(ssml) {
// Construct the request
@sheronw
sheronw / prop.js
Last active June 12, 2020 01:26
set up #react
import PropTypes from 'prop-types';
class App extends Component {...
getSth(){ return this.xxx; } // getSth = () => this.xxx;
render() {
return (<p>{this.getSth().bind(this)}</p>)
}
}
@sheronw
sheronw / sh
Last active June 18, 2020 22:28
build pyrealsense2 from source
# valid for pyrealsense2 2.35.2
# make sure to upgrade python and other packages (cmake, for example)
# https://github.com/IntelRealSense/librealsense/tree/master/wrappers/python for details
# 1. download source code from
# https://github.com/IntelRealSense/librealsense/releases
# 2. in the top level of the package
mkdir build
cd build
@sheronw
sheronw / git_diff.sh
Created September 25, 2020 01:39
compare between different state #git
# 1. committed
# 2. staged but not comitted
# 3. not added to stage
# compare between 2 & 3
git diff [file]
# compare between 1 & 2
git diff [file] --cached
@sheronw
sheronw / build_osmesa.sh
Created April 18, 2021 01:56
build OSMesa with GLU
# Based on Ubuntu 20.04
apt get install python3 python3-distutils ninja-build libpciaccess-dev
# add Mako and meson dependency from python
wget https://bootstrap.pypa.io/get-pip.py
python3 get-pip.py
pip install Mako
pip install meson
# download and install newest libdrm