Skip to content

Instantly share code, notes, and snippets.

@sheronw
sheronw / build_osmesa.sh
Created Apr 18, 2021
build OSMesa with GLU
View build_osmesa.sh
# 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
@sheronw
sheronw / git_diff.sh
Created Sep 25, 2020
compare between different state #git
View git_diff.sh
# 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
View 📊 Weekly development breakdown
Python 9 hrs 29 mins ███████████████████▋░ 94.0%
JSON 29 mins █░░░░░░░░░░░░░░░░░░░░ 4.8%
XML 6 mins ▏░░░░░░░░░░░░░░░░░░░░ 1.1%
HTML 0 secs ░░░░░░░░░░░░░░░░░░░░░ 0.1%
JavaScript 0 secs ░░░░░░░░░░░░░░░░░░░░░ 0.0%
@sheronw
sheronw / sh
Last active Jun 18, 2020
build pyrealsense2 from source
View sh
# 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 / crawler_text-to-speech.js
Last active Apr 17, 2020
Some snippets for **my** raspberry Pi speaker
View crawler_text-to-speech.js
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 / toggle_telegram_ifttt.js
Created Apr 14, 2020
Use #IFTTT to send #Toggl Reports to #Telegram
View toggle_telegram_ifttt.js
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 / prop.js
Last active Jun 12, 2020
set up #react
View prop.js
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 / functions.js
Created Mar 23, 2020
different types of function declaration in #js
View functions.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 / var_let.js
Created Mar 23, 2020
difference between var and let in #js
View var_let.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 / unrelated_history.sh
Last active Mar 22, 2020
merge unrelated branch back to master #git
View unrelated_history.sh
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