Skip to content

Instantly share code, notes, and snippets.

@wwwins
wwwins / LunarSolarConverter.js
Last active January 4, 2019 09:23
lunar converter
/**
* Modified by isobar on 04/01/19.
*
* Created by isee15 on 15/1/14.
*/
/*
Usage:
var converter = new LunarSolarConverter();
var solar = new Solar();
solar.solarYear = 1985;
@wwwins
wwwins / mk-py-pkg.sh
Last active December 20, 2018 03:53
Init python package
#!/bin/sh
#
# Copyright 2018 isobar. All Rights Reserved.
#
# Usage:
# ./mk-py-pkg.sh MyImgPy wwwins [email protected]
#
echo '>>>>> python package init <<<<<'
if [ -z "$1" ]
@wwwins
wwwins / ipython.py
Created December 14, 2018 10:08
ipython tips
# load a python file
%load teeth-whitening.py
# setup sys args for argparse
sys.argv = ["teeth-whitening.py", "data/shape_predictor_68_face_landmarks.dat", "faces/Cara_Delevingne.png"]
# debug
%debug main()
ipdb> s
ipdb> n
@wwwins
wwwins / crontab
Created October 19, 2018 09:07
intel-8th crontab
*/5 * * * * /usr/local/bin/autossh.sh
#20 0 * * * find /home/isobar/upload -type f -mtime +0 -exec mv '{}' /mnt/data/backup/ftp/ \;
#22 0 * * * mkdir /mnt/data/backup/public/$(date +\%Y\%m\%d);find /home/xxx/intel-8th/public -mindepth 1 -type d -mtime +0 -exec mv '{}' /mnt/data/backup/public/$(date +\%Y\%m\%d)/ \;
31 0 * * * mkdir /mnt/data/backup/ftp/$(date +\%Y\%m\%d);mv /home/isobar/upload/*.mp4 /mnt/data/backup/ftp/$(date +\%Y\%m\%d)/;
41 0 * * * mkdir /mnt/data/backup/public/$(date +\%Y\%m\%d);mv /home/xxx/intel-8th/public/* /mnt/data/backup/public/$(date +\%Y\%m\%d)/;
@reboot /usr/bin/forever --workingDir /home/xxx/intel-8th start /home/xxx/intel-8th/src/app.js
@wwwins
wwwins / tips.sh
Last active October 6, 2020 16:16
Bash shell script tips
# copy a-*.ejs to d-*.ejs
$ for f in a-*.ejs; do cp $f d${f: 1}; done;
cp a-1.ejs d-1.ejs
cp a-2.ejs d-2.ejs
cp a-3.ejs d-3.ejs
cp a-4.ejs d-4.ejs
# copy loop_*.mp3 to loop_*.wav
$ for f in loop_*.mp3; do echo $f ${f:0:-4}.wav; done;
loop_1.mp3 loop_1.wav
@wwwins
wwwins / autossh.sh
Last active April 19, 2019 07:31
setup reverse ssh tunnel with cron
#!/bin/bash
#
# add the following job into crontab
# */5 * * * * /usr/local/bin/autossh.sh
IP="1.1.1.1"
/bin/ping -c 3 $IP > /dev/null
if [ $? != 0 ]
then
@wwwins
wwwins / ssh.sh
Last active September 26, 2018 02:18
ssh tips
# gen id_rsa/id_rsa.pub in .ssh/
ssh-keygen -t rsa
# on remote server
cat id_rsa.pub >> .ssh/authorized_keys
chmod 600 authorized_keys
# ssh login remote server
ssh -i .ssh/id_rsa [email protected]
# port forward 8554 to 192.168.1.100:80
ssh -g -L 8554:localhost:80 -f -N [email protected]
# reverse ssh tunnel
@wwwins
wwwins / curl.sh
Last active January 15, 2021 08:20
curl tips
# POST multipart/form-data with a file upload
curl --request POST --url https://postman-echo.com/post -F "foo1=bar1" -F "foo2=bar2" -F "image=@/Users/isobar/Downloads/radar.jpg"
## POST multipart/form-data with json string
curl --request POST --url https://postman-echo.com/post -F "json=$jsonString"
# POST on windows
curl --request POST --url https://xxxxxx.ngrok.io/upload/ -F "filename=@d:\Data\My documents\Processing\mySample_http_post\test.tif"
# POST binary data with a file upload
@wwwins
wwwins / ffmpeg.sh
Last active August 16, 2018 10:34
ffmpeg tips
# video to image by fps
ffmpeg -i in.mp4 -vf fps=1/5 pic%03d.png
# video to image by input seeking
ffmpeg -ss 5 -i in.mp4 -frames:v 1 pic.png
# https://trac.ffmpeg.org/wiki/Seeking
# cut from 00:05 to 00:10
ffmpeg -ss 00:05 -i in.mp4 -t 00:05 -c copy -copyts out.mp4
@wwwins
wwwins / await_test.js
Last active January 9, 2020 04:20
Promise and aysnc/await demo
/*
* Promise and async/await function
*/
'use strict';
// type-1
// function(resolve) {}
function action1(msg) {
return new Promise(
function(resolve) {