Skip to content

Instantly share code, notes, and snippets.

View clsung's full-sized avatar

Cheng-Lung Sung clsung

View GitHub Profile
!/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 / 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
@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 " +