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 / 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 " +
import mmap
from time import sleep
with open('cmd.txt', 'r+b') as f:
m = mmap.mmap(f.fileno(), 0)
while True:
data = m.readline()
print data
sleep(0.5)
m.seek(0)
@clsung
clsung / supervisord.sh
Created September 20, 2012 02:15
auto start script supervisord centos
#!/bin/sh
#
# /etc/rc.d/init.d/supervisord
#
# Supervisor is a client/server system that
# allows its users to monitor and control a
# number of processes on UNIX-like operating
# systems.
#
# chkconfig: - 64 36