Skip to content

Instantly share code, notes, and snippets.

@drakeguan
drakeguan / rename_to_fit_flickr_upload_datetime.py
Created February 8, 2019 15:34
Extract upload datetime from flickr and rename it according to the datetime
import os
import re
from time import gmtime
# ref: https://stuvel.eu/flickrapi-doc/
import flickrapi
api_key = 'OOOOOOOOOOOOOOOOO'
api_secret = 'XXXXXXXXXXXXX'
@drakeguan
drakeguan / convert_mp4_to_caf_opus.sh
Last active October 14, 2020 22:18
Extract audio track, convert to CAF/Opus, and generate a RSS2 feed for personal hosting podcast!
#!/bin/bash
ffmpeg -y -i "$f" -vn -c:a libfdk_aac -b:a 128k "audio/$(basename $f .mp4).m4a"
afconvert -f caff -d opus -b 8000 "audio/$(basename $f .mp4).m4a" "opus/$(basename $f .mp4).caf"
@drakeguan
drakeguan / simple-cors-http-server.py
Created April 13, 2017 08:59
Simple HTTP server with CORS.
#!/usr/bin/env python
# vim: set sw=4 sts=4 ts=4 et si:
from SimpleHTTPServer import SimpleHTTPRequestHandler
import BaseHTTPServer
class CORSRequestHandler (SimpleHTTPRequestHandler):
def end_headers (self):
self.send_header('Access-Control-Allow-Origin', '*')
SimpleHTTPRequestHandler.end_headers(self)
@drakeguan
drakeguan / my_sentiment_analysis_in_google_cloud_next_17.json
Created April 13, 2017 08:43
Sentiment Analysis by Cloud Vision API in Google Cloud Next '17
{
"faceAnnotations": [
{
"rollAngle": 3.2389677,
"panAngle": -9.39832,
"tiltAngle": 1.9103807,
"detectionConfidence": 0.94434965,
"landmarkingConfidence": 0.7591174,
"joyLikelihood": "UNLIKELY",
"sorrowLikelihood": "VERY_UNLIKELY",
@drakeguan
drakeguan / convert_node_to_alias.py
Last active February 4, 2017 05:44
Warp up of gradually conversion of old blogs to Hugo preferred ones.
import os
def get_url_from_node(filename):
with open(filename) as fin:
for line in fin:
if 'refresh' in line:
return line[42:-5]
#iname = 'www/node/1/index.html'
#print get_url_from_node(iname)
@drakeguan
drakeguan / Latex.sublime-build
Created January 30, 2016 06:27 — forked from lusentis/Latex.sublime-build
Latex (xetex) build system for Sublime Text 2
// Compilation settings
// ====================
//
// The actual magic happens in the make_pdf command
// I stick to the format of standard ST2 sublime-build files
// with minor variations.
// NOTE: the viewer is NOT configured from here!
// As of 5/24/11, it cannot be changed, but I will introduce a setting later
{
@drakeguan
drakeguan / get_html_pages.sh
Created January 3, 2016 15:15
Happy New Year 2016 - The force is always with you.
#!/bin/bash
mkdir -p html_pages
if [ ! -f html_pages/$1.html ]; then
echo 'get html page' $1
curl -s http://www.movieposterdb.com/posters/?page=$1 > html_pages/$1.html
fi
#!/bin/bash
_invoke()
{
local cur prev opts
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opts=$(invoke -l | tail -n+3 | awk '{ print $1 }' | tr '\n' ' ')
@drakeguan
drakeguan / bootstrap_for_encoding_server.sh
Last active January 12, 2017 03:13 — forked from xdamman/install_ffmpeg_ubuntu.sh
Bash script to install latest version of ffmpeg, x264 and libvpx on Ubuntu 14.04 server
#!/bin/bash
# Bash script to install latest version of ffmpeg and its dependencies on Ubuntu 14.04
# Copyright @ 2014 Shuen-Huei (Drake) Guan <drake.guan@gmail.com>
# References:
# * https://gist.github.com/xdamman/e4f713c8cd1a389a5917
# * https://blog.dlasley.net/2013/05/install-ffmpeg-from-source/
# * http://fermat-little-theorem-blog.logdown.com/posts/203069-solved-when-building-gpac-suffer-usr-local-lib-libswscalea-error-adding-symbols-bad-value
@drakeguan
drakeguan / mpd_validator.py
Last active December 12, 2019 03:25
poor man's MPD validator
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: set hls is ai et sw=4 sts=4 ts=8 nu ft=python:
#
# Copyright © 2014 drake <drake.guan@gmail.com>
#
# Distributed under terms of the MIT license.
# Built-in modules