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 / flask-sqlite.py
Created January 27, 2015 09:11
Enforce FK constraint for SQLite with when using flask-sqlalchemy
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
app = Flask(__name__)
try:
app.config.from_object("config")
except:
pass
if app.config["SQLALCHEMY_DATABASE_URI"].startswith("sqlite"):
@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 / build.gradle
Last active December 21, 2015 16:26
gradle with sbt-assembly like function
group 'com.example'
version '1.0'
apply plugin: "java"
apply plugin: "scala"
apply plugin: "application"
sourceCompatibility = 1.8
@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
@lucidfrontier45
lucidfrontier45 / mlp.py
Created July 13, 2015 09:32
Multi-Layer Perceptron using scikit-chainer
__author__ = 'du'
from chainer import FunctionSet, functions as F, optimizers
from skchainer import ChainerClassifier
class MultiLayerPerceptron(ChainerClassifier):
def _setup_network(self, **params):
print(params)
network = FunctionSet(
options(repos=structure(c(CRAN="http://cran.ism.ac.jp/")))
Sys.setenv(MAKEFLAGS = "-j4")
@lucidfrontier45
lucidfrontier45 / batch_iter.py
Last active July 21, 2016 02:26
batch iterator
from itertools import islice, chain
def batches(iterable, batchsize=10):
it = iter(iterable)
while True:
batch = islice(it, batchsize)
yield chain([next(batch)], batch)
@lucidfrontier45
lucidfrontier45 / .hadoop_aliases
Created October 23, 2015 15:13
hadoop command aliases
alias hls='hdfs dfs -ls'
alias hlsr='hdfs dfs -lsr'
alias hdu='hdfs dfs -du'
alias hdus='hdfs dfs -dus'
alias hcount='hdfs dfs -count'
alias hmv='hdfs dfs -mv'
alias hcp='hdfs dfs -cp'
alias hrm='hdfs dfs -rm'
alias hrmr='hdfs dfs -rmr'
alias hexpunge='hdfs dfs -expunge'
@lucidfrontier45
lucidfrontier45 / template.json
Last active November 30, 2015 09:16
Elasticsearch template with kurumoji_neologd and dispose source
{
"template": "*",
"settings":{
"number_of_shards" : 3,
"index":{
"analysis": {
"analyzer": {
"default": {
"type": "kuromoji_neologd"
}