Skip to content

Instantly share code, notes, and snippets.

View clsung's full-sized avatar

Cheng-Lung Sung clsung

View GitHub Profile
// Values is a helper that converts an array command reply to a []interface{}.
// If err is not equal to nil, then Values returns nil, err. Otherwise, Values
// converts the reply as follows:
//
// Reply type Result
// array reply, nil
// nil nil, ErrNil
// other nil, error
func Values(reply interface{}, err error) ([]interface{}, error) {
if err != nil {
// Strings is a helper that converts an array command reply to a []string. If
// err is not equal to nil, then Strings returns nil, err. Nil array items are
// converted to "" in the output slice. Strings returns an error if an array
// item is not a bulk string or nil.
func Strings(reply interface{}, err error) ([]string, error) {
if err != nil {
return nil, err
}
switch reply := reply.(type) {
case []interface{}:
@clsung
clsung / bench_gingo.go
Created September 27, 2016 08:24
using github.com/clsung/gingo
package main
import (
"flag"
"log"
"github.com/clsung/gingo"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
)
@clsung
clsung / redigin.go
Created September 27, 2016 04:40
gin with redigo
package main
import (
"flag"
"github.com/garyburd/redigo/redis"
"github.com/gin-gonic/gin"
)
var (

Last updated: 2015-08-11

Searching for Files

Find images in a directory that don't have a DateTimeOriginal

exiftool -filename -filemodifydate -createdate -r -if '(not $datetimeoriginal) and $filetype eq "JPEG"' .

###Output photos that don't have datetimeoriginal to a CSV### Note this can take a long time if you have a lot of jpgs

@clsung
clsung / install_opencv_2.4.9.sh
Last active August 29, 2015 14:03
shell to install opencv 2.4.9 on my Centos
wget http://downloads.sourceforge.net/project/opencvlibrary/opencv-unix/2.4.9/opencv-2.4.9.zip
unzip opencv-2.4.9
cd opencv-2.4.9
mkdir build
cd build
export PYTHON_EXECUTABLE=$(readlink -e $(which python))
export PYTHON_INCLUDE_DIR=${PYTHON_EXECUTABLE%/*/*}/include
export PYTHON_LIBRARY=${PYTHON_EXECUTABLE%/*/*}/lib/libpython2.7.a
export PYTHON_NUMPY_INCLUDE_DIR=${PYTHON_EXECUTABLE%/*/*}/lib/python2.7/site-packages/numpy/core/include/numpy
export PYTHON_PACKAGES_PATH=${PYTHON_EXECUTABLE%/*/*}/lib/python2.7/site-packages
!/usr/bin/env bash
# Pre-requisites
sudo apt-get -y update
sudo apt-get --no-install-recommends -y install build-essential openssl libreadline6 libreadline6-dev curl git-core zlib1g zlib1g-dev libssl-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt-dev autoconf libc6-dev libgdbm-dev ncurses-dev automake libtool bison pkg-config libffi-dev vim python2.7 python-dev
# Add SaltStack repository
# sudo add-apt-repository ppa:saltstack/salt
echo deb http://ppa.launchpad.net/saltstack/salt/ubuntu `lsb_release -sc` main | sudo tee /etc/apt/sources.list.d/saltstack.list
wget -q -O- "http://keyserver.ubuntu.com:11371/pks/lookup?op=get&search=0x4759FA960E27C0A6" | sudo apt-key add -
@clsung
clsung / gist:6822574
Created October 4, 2013 08:10
A simple crop image to 80x80 jpeg file script
package main
import (
"fmt"
"os"
"log"
"flag"
"image"
_ "image/gif"
"image/jpeg"
@clsung
clsung / crop
Created September 29, 2013 10:29
try:
import Image
size = 96, 96
thumb_96x96 = StringIO()
im = Image.open(src_file)
if im.mode != "RGB":
im = im.convert("RGB")
width, height = im.size
if width > height:
delta = width - height
@clsung
clsung / gist:5361118
Created April 11, 2013 06:11
kerberos
#!/usr/bin/env python
import requests
import kerberos
class KerberosTicket:
def __init__(self, service):
__, krb_context = kerberos.authGSSClientInit(service)
kerberos.authGSSClientStep(krb_context, "")
self._krb_context = krb_context
self.auth_header = ("Negotiate " +