Skip to content

Instantly share code, notes, and snippets.

View clsung's full-sized avatar

Cheng-Lung Sung clsung

View GitHub Profile
@clsung
clsung / gist:912103
Created April 10, 2011 06:33
Ruby (Rack) application could not be started
These are the possible causes:
There may be a syntax error in the application's code. Please check for such errors and fix them.
A required library may not installed. Please install all libraries that this application requires.
The application may not be properly configured. Please check whether all configuration files are written correctly, fix any incorrect configurations, and restart this application.
A service that the application relies on (such as the database server or the Ferret search engine server) may not have been started. Please start that service.
Further information about the error may have been written to the application's log file. Please check it in order to analyse the problem.
Error message:
@clsung
clsung / flaskplotlib.py
Created July 6, 2012 12:27 — forked from wilsaj/flaskplotlib.py
Example of rendering a matplotlib image directly to Flask view
from flask import Flask, make_response
app = Flask(__name__)
@app.route("/simple.png")
def simple():
import datetime
import StringIO
import random
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
@clsung
clsung / mili
Created July 20, 2012 09:39
Get epoch time in milisecond
from datetime import datetime
import time
from struct import unpack, pack
datetime.fromtimestamp(float(unpack("Q",pack("Q",float(datetime.now().strftime('%s.%f')) * 1000))[0]) / 1000), datetime.now()
@clsung
clsung / iam_ec2_example.py
Created September 11, 2012 06:19 — forked from garnaat/iam_ec2_example.py
Use IAM/boto to provide access to EC2 and S3
"""
IAM boto examples:
In this example we create a group that provides access
to all EC2 and S3 resources and actions and then add a
user to that group.
"""
import boto
#
# First create a connection to the IAM service
@clsung
clsung / supervisord.sh
Created September 20, 2012 02:11 — forked from danmackinlay/supervisord.sh
an init.d script for supervisord
#! /bin/sh
### BEGIN INIT INFO
# Provides: supervisord
# Required-Start: $remote_fs
# Required-Stop: $remote_fs
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Example initscript
# Description: This file should be used to construct scripts to be
# placed in /etc/init.d.
@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
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 / 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 " +
@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: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"