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 / resolve_hostname.c
Created April 25, 2012 14:12
sample program for getaddrinfo and inet_atop
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
typedef struct sockaddr_in SA4;
typedef struct sockaddr_in6 SA6;
int main(int argc, char **argv){
@lucidfrontier45
lucidfrontier45 / crop.py
Created May 9, 2012 01:11
Crop 4:3 picture to 16:9 without losing EXIF metadata
#!/usr/bin/python
from PIL import Image
from pyexiv2 import ImageMetadata
def is16to9(img):
img.size
return img.size[0] * 9 == img.size[1] * 16
def cropTo16to9(img):
@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
@lucidfrontier45
lucidfrontier45 / json2Table.js
Last active December 12, 2018 00:19
Convert JSON to a Table
/**
* Convert JSON to a Table
* require jsontotable [https://github.com/jongha/jquery-jsontotable]
* @param {String} id: div id to which the table will be inserted
* @param {Array} header_array: array of table headers
* @param {Object} data: json object
* @return {none}
*/
function json2Table(id, header_array, data) {
//clear previous one
# -*- 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):