Skip to content

Instantly share code, notes, and snippets.

View ckhung's full-sized avatar

Chao-Kuei Hung ckhung

View GitHub Profile
@ckhung
ckhung / gh2umap.sh
Last active August 29, 2015 14:25
convert GraphHopper exported gpx to geojson suitable for importing into umap
#!/bin/bash
# usage: gh2umap.sh directions.gpx > directions.geojson
# see http://newtoypia.blogspot.tw/2015/07/fs-biking.html
TMPDIR=/tmp/gh2umap-$$
mkdir $TMPDIR
ogr2ogr -f geojson $TMPDIR/tr.geojson $1 tracks
jq '.features' $TMPDIR/tr.geojson > $TMPDIR/tracks.geojson
ogr2ogr -f geojson $TMPDIR/rp.geojson $1 route_points
opencc < $TMPDIR/rp.geojson | jq '.features | map(.properties+={_storage_options: {"iconClass": "Ball"}} | .properties.name=.properties.desc )' > $TMPDIR/route_points.geojson
@ckhung
ckhung / csv2geojson.perl
Last active August 19, 2016 01:58
convert csv containing lon,lat,name files into geojson
#!/usr/bin/perl -w
# see http://newtoypia.blogspot.tw/2015/07/csv-geojson.html
$prev = 0; # was there any previous output?
print "[\n";
while (<>) {
chomp;
next if (/^#/ or /^\s*$/);
@f = split /\s*,\s*/;
if (defined($F{lon}) and defined($F{lat})) {
@ckhung
ckhung / android.txt
Last active July 6, 2019 10:00
在 kivy 程式裡面顯示中文
title=zh_TW_test
author=ckhung
orientation=landscape
@ckhung
ckhung / multi2maxpolygon.py
Last active September 19, 2015 01:55
本程式把鄉鎮縣市的 geojson 檔裡面的 MultiPolygon 當中面積最大的一塊抓出來, 變成一個單獨的 Polygon, 就可以上傳至 umap 了。
#!/usr/bin/python
# -*- coding: utf-8 -*-
# http://newtoypia.blogspot.tw/2015/08/admin-boundary.html
# 「臺灣各級行政區域(縣市/鄉鎮/村里)邊界座標檔, 自選解析度、 存成 csv、 畫成 svg 」
import json, argparse, sys, math, warnings
def area(coords):
n = len(coords)
if n < 3:
@ckhung
ckhung / geojson2csv.py
Last active September 19, 2015 02:09
find all "coordinates" field in a geojson file, and output x,y coordinates as csv
#!/usr/bin/python
# -*- coding: utf-8 -*-
# http://newtoypia.blogspot.tw/2015/08/admin-boundary.html
# 「臺灣各級行政區域(縣市/鄉鎮/村里)邊界座標檔, 自選解析度、 存成 csv、 畫成 svg 」
import json, argparse, sys, math, warnings
def ispoint(coords):
return isinstance(coords, list) and isinstance(coords[0], (int, long, float)) and len(coords)==2
@ckhung
ckhung / falc.perl
Last active January 2, 2016 09:17
filter adb logcat
#!/usr/bin/perl -w
# http://newtoypia.blogspot.tw/2015/08/cordova-debug.html
# 徒手除錯 Cordova
$kw = ($ARGV[0] or "console");
while (<STDIN>) {
if (m#console#i) {
print "\x1b[30;46m$_\x1b[m";
} elsif (m#$kw#i) {
print "\x1b[31m$_\x1b[m";
} elsif (not m#^[VDIW]/#) {
#!/usr/bin/python
# http://newtoypia.blogspot.com/2015/09/vector-tiles.html
# 用向量圖磚 (vector tiles) 自製陽春離線地圖
import math, sys, argparse, os, re
def deg2tile_id(zoom,lon,lat):
lat_rad = math.radians(lat)
n = 2.0 ** zoom
xtile = int((lon + 180.0) / 360.0 * n)
#!/usr/bin/perl -w
# http://newtoypia.blogspot.com/2015/09/gmail-mbox.html
# 備份/清空 gmail, 以及命令列查詢/切割 mbox 格式檔案
use MIME::Base64;
while (<STDIN>) {
foreach $kw (@ARGV) {
next unless (($line) = /^$kw:\s*(.*)/);
$line = decode_base64($1)
if $line =~ /=\?utf-8\?\w+\?(.*)/i;
@ckhung
ckhung / toCammel.perl
Created October 25, 2015 10:41
convert all underscore variable names to cammel case
#!/usr/bin/perl -wp
my @saved = ();
while (s#((['"]).*?\2)#<<toCammelSkip>>#) {
push @saved, $1;
}
while (/([a-z0-9]+)(_[a-z0-9]+)+/i) {
$cammelled = $orig = $&;
$cammelled =~ s/(_[a-z0-9]+)/$x=substr($1,1); "\u$x"/ieg;
@ckhung
ckhung / dynamic-legend.html
Last active December 28, 2015 06:12
a legend (using d3-legend.js) that dynamically changes labels
<html>
<head>
</head>
<body>
<div id="main-content">
</div>
<script type="text/javascript" src="d3.js"></script>
<script type="text/javascript" src="d3-legend.js"></script>
<script>
var canvas = d3.select('#main-content')