Skip to content

Instantly share code, notes, and snippets.

@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 user@remote.server
# port forward 8554 to 192.168.1.100:80
ssh -g -L 8554:localhost:80 -f -N root@192.168.1.100
# 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) {
@wwwins
wwwins / app.py
Created November 7, 2017 06:50
simple flask server for api.ai
import json
from random import randint
from flask import Flask
from flask import request
from flask import make_response
app = Flask(__name__)
@wwwins
wwwins / s3upload.py
Created May 24, 2017 09:10
python boto3 upload files to aws s3
# -*- coding: utf-8 -*-
"""
Usage:
python s3upload.py -b bucket -i image.jpg
python s3upload.py -b bucket -f images -i image.jpg
python s3upload.py -b bucket -f images -i image.jpg -t img.jpg
python s3upload.py -p tokyo -b bucket -i image.jpg
"""
from argparse import ArgumentParser