phuonght
phuonght
Phuong Huynh
8 Snippets  (113rd place)
Published
1 Channel
Created
1 Channel
Following
Mar 7, 2016
Last Visit
Feb 21, 2016
Registered
3 points  (21469th place)
Reputation
Serious Code Generator
Junior Popular Coder
Junior Autobiographer
Senior Autobiographer
Serious Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by phuonght

public by phuonght created Jan 23, 2016  212081  0  3  0

A small script to make recording http live streams (HLS, those streams that work on iOS devices) nicer on a Mac. Script records the stream for a defined period of time and sends the user notifications if anything goes wrong and once it's done.

A small script to make recording http live streams (HLS, those streams that work on iOS devices) nicer on a Mac. Script records the stream for a defined period of time and sends the user notifications if anything goes wrong and once it's done.: HLS_dvr.sh
# required: ffmpeg (e.g. from homebrew), terminal-notifier from https://github.com/alloy/terminal-notifier 
# you can schedule this with launchd to run e.g. weekly

# Specify in seconds how long the script should record (default here is 1 hour).
seconds=3600

# Date format for the recording file name
DATE=`date "+%d-%m-%y_%H-%M"`

# start ffmpeg recording
ffmpeg -re -i http://website.com/playlist.m3u8 -c copy -bsf:a aac_adtstoasc recording_$DATE.mp4 &

# notification that recording has started
if [ "$(pgrep -P $$ 'ffmpeg')" ]
then
	/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title 'ffmpeg' -message "is recording now" -sender 'com.apple.Terminal'
else
	/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title 'ffmpeg' -message "is not recording!" -sound Funk -sender 'com.apple.Terminal'
	exit 42
fi

# check every 30 seconds for $seconds to make sure ffmpeg is still running
START=`date +%s`
while [ $(( $(date +%s) - $seconds )) -lt $START ]; do
	if [ -z "$(pgrep -P $$ 'ffmpeg')" ]
    	then
       		/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title 'ffmpeg' -message "is no longer running" -sound Funk -sender 'com.apple.Terminal'
  	fi
	sleep 30
done

# notification when time is up
/Applications/terminal-notifier.app/Contents/MacOS/terminal-notifier -title 'ffmpeg' -message "recording finished" -sound default -sender 'com.apple.Terminal'

# stop ffmpeg (using this because stopping ffmpeg via -t for duration turned out to be extremely unreliable)
kill $(pgrep -P $$ 'ffmpeg')


;

public by Pavel Shorokhov created Nov 10, 2015  23341  1027  4  0

PHPStorm 10 Activation Key

PHPStorm 10 Activation Key: PHPStorm 10 Activation Key
PHPStorm 10
For activation set license server to: http://idea.lanyus.com
and press Ok. No key. Worked.

Found there:
https://бэкдор.рф/phpstorm-7-8-9-10-product-key/

;

public by Kingsley Huynh created Sep 9, 2015  5535  29  5  0

Golang HTTP Handler to Upload Image => Resize => Convert to JPEG => Save to Disk.

Golang HTTP Handler to Upload Image = Resize = Convert to JPEG = Save to Disk. : gistfile1.go
Go
func UploadHandler(w http.ResponseWriter, r *http.Request) {

	file, _, err := r.FormFile("file")
	if err != nil {
		log.Println(err)
		http.Error(w, http.StatusText(http.StatusBadRequest), http.StatusBadRequest)
		return
	}

	img, _, err := image.Decode(file)
	if err != nil {
		log.Println(err)
		http.Error(w, http.StatusText(http.StatusUnsupportedMediaType), http.StatusUnsupportedMediaType)
		return
	}

	m := resize.Resize(1000, 0, img, resize.Lanczos3)

	out, err := os.Create("test_resized.jpg")
	if err != nil {
		log.Println(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
	defer out.Close()

	// Encode into jpeg http://blog.golang.org/go-image-package
	err = jpeg.Encode(out, m, nil)
	if err != nil {
		log.Println(err)
		http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
		return
	}
}

;

public by yixf created Jul 29, 2015  2241  1  3  0

Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!

Tmux Quick Reference & Cheat sheet - 2 column format for less scrolling!: tmux.cheat
==========================================          ==========================================
             TMUX COMMAND                                        WINDOW (TAB)
==========================================          ==========================================

List    tmux ls                                     List         ^b w
New          -s <session>                           Create       ^b c
Attach       att -t <session>                       Rename       ^b , <name>
Rename       rename-session -t <old> <new>          Last         ^b l               (lower-L)
Kill         kill-session -t <session>              Close        ^b &

==========================================          Goto #       ^b <0-9>
             CONTROLS                               Next         ^b n
==========================================          Previous     ^b p
                                                    Choose       ^b w <name>
Detach       ^b d
List         ^b =                                   ==========================================
Buffer       ^b <PgUpDn>                                         PANE (SPLIT WINDOW)
Command      ^b : <command>                         ==========================================

Copy         ^b [ ... <space> ... <enter>           Show #       ^b q
 Moving         vim/emacs key bindings              Split Horiz  ^b "                --------
 Start          <space>                             Split Vert   ^b %                   |
 Copy           <enter>                             Pane->Window ^b !
Paste        ^b ]                                   Kill         ^b x

==========================================          Reorganize   ^b <space>
             SESSION (Set of Windows)               Expand       ^b <alt><arrow>
==========================================          Resize       ^b ^<arrow>
                                                    Resize x n   ^b <n> <arrow>
New          ^b :new     ^b :new -s <name>
Rename       ^b $                                   Select       ^b <arrow>
List         ^b s                                   Previous     ^b {
Next         ^b (                                   Next         ^b }
Previous     ^b )                                   Switch       ^b o                  other
                                                    Swap         ^b ^o
                                                    Last         ^b ;

;

public by Arul created May 3, 2015  2830  26  3  0

TOR ip renew script using pytorctl https://github.com/aaronsw/pytorctl which is a python based module to interact with the Tor Controller.

TOR ip renew script using pytorctl https://github.com/aaronsw/pytorctl which is a python based module to interact with the Tor Controller. : tor_ip_renew.py
from TorCtl import TorCtl
import urllib2
 
user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.0.7) Gecko/2009021910 Firefox/3.0.7'
headers={'User-Agent':user_agent}
 
def request(url):
    def _set_urlproxy():
        proxy_support = urllib2.ProxyHandler({"http" : "127.0.0.1:8118"})
        opener = urllib2.build_opener(proxy_support)
        urllib2.install_opener(opener)
    _set_urlproxy()
    request=urllib2.Request(url, None, headers)
    return urllib2.urlopen(request).read()
 
def renew_connection():
    conn = TorCtl.connect(controlAddr="127.0.0.1", controlPort=9051, passphrase="Password12")
    conn.send_signal("NEWNYM")
    conn.close()
 
for i in range(0, 10):
    renew_connection()
    print request("http://curlmyip.com/")


;