Skip to content

Instantly share code, notes, and snippets.

View lucidfrontier45's full-sized avatar

杜世橋 Du Shiqiao lucidfrontier45

  • GROUND Inc.
  • Tochigi, Japan
View GitHub Profile
@lucidfrontier45
lucidfrontier45 / sor_iteration.c
Created July 7, 2014 09:28
SOR iteration test
/*
* sor_iteration.c
*
* Created on: Jul 7, 2014
* Author: du
*/
#include <stdio.h>
#include <string.h>
#include <math.h>
@lucidfrontier45
lucidfrontier45 / mapred.py
Last active August 29, 2015 14:06
Simple one-file MapReduce template in Python
#!/usr/bin/env pypy
# -*- coding: utf-8 -*-
'''
Created on 2013/09/03
@author: Shiqiao Du
run
cat <input> | ./mapred.py -m mapper | sort | ./mapred.py -m reducer
'''
@lucidfrontier45
lucidfrontier45 / gist:68ff24d37cad46ab9fb7
Created September 8, 2014 14:44
fix extra space when using anaconda's ipython in Linux
$ conda remove readline
$ pip install readline
# postgresユーザーのパスワードを変更
sudo passwd postgres
# 新しいユーザーを作成
sudo -u postgres createuser du -P --interactive
# DBの作成
create databese test_db owner du
import pandas as pd
import sqlalchemy
from sklearn import datasets
# create iris dataframe
iris = datasets.load_iris()
iris_data = pd.DataFrame(iris.data)
iris_data.columns = ["sep_length", "sepal_width","petal_length","petal_width" ]
iris_data["species"] = map(lambda i:iris.target_names[i], iris.target)
@lucidfrontier45
lucidfrontier45 / gdata_text_db_query.py
Last active August 29, 2015 14:07
gdata text_db example
from gdata.spreadsheet import service, text_db
client = text_db.DatabaseClient(username=user, password=password)
db = client.GetDatabases(name=spreadsheet_name)[0]
table = db.GetTables(name=worksheet_name)[0]
# notice that even if it is shown as some thing like "DD/MM/YY" in the table, timestamp or date should be YYYY-MM-DD
for row in table.FindRecords("timestamp > 2014-10-01"):
print row.content
# -*- coding: utf-8 -*-
import datetime
from numpy import asarray, ceil
import pandas
import rpy2.robjects as robjects
def stl(data, ns, np=None, nt=None, nl=None, isdeg=0, itdeg=1, ildeg=1,
nsjump=None, ntjump=None, nljump=None, ni=2, no=0, fulloutput=False):
@lucidfrontier45
lucidfrontier45 / ipython_notebook_fist_cell.py
Last active August 29, 2015 14:17
ipython notebook first cell
%matplotlib inline
import numpy as np
import pandas as pd
from matplotlib import pyplot as plt
plt.style.use("ggplot")
plt.rcParams["font.size"] = 14
plt.rcParams["figure.figsize"] = 10, 6
@lucidfrontier45
lucidfrontier45 / asset_allocation_highcharts.js
Created March 26, 2015 09:52
asset_allocation_highcharts
$(function () {
$(document).ready(function () {
// Build the chart
Highcharts.setOptions({
colors: ['#4572A7', '#AA4643', '#89A54E', '#80699B', '#3D96AE', '#DB843D', '#92A8CD', '#A47D7C', '#B5CA92', '#0000cd', '#dda0dd']
});
$('#container').highcharts({
@lucidfrontier45
lucidfrontier45 / calcHist.py
Created July 6, 2015 16:41
calculate image histogram
def colorHist(img):
size = img.size / 3.0
ret = {}
color = ('b','g','r')
for i,col in enumerate(color):
histr = cv2.calcHist([img],[i],None,[100],[0,256])
ret[col] = histr.flatten() / size
return ret