Skip to content

Instantly share code, notes, and snippets.

View leoluyi's full-sized avatar
🎯
Focusing

Leo Lu leoluyi

🎯
Focusing
View GitHub Profile
@leoluyi
leoluyi / devtols_install_github_behind_proxy.R
Created July 12, 2017 10:45 — forked from datalove/devtols_install_github_behind_proxy.R
How get devtools::install_github() working behind a proxy that messes with the SSL certs
library(httr)
library(devtools)
# make httr set CURL to ignore SSL verification problems
# (needed if the SSL proxy replaces certs with its own)
set_config(config(ssl.verifypeer = 0L))
# set proxy details
set_config(use_proxy("10.10.10.10",8080))
@leoluyi
leoluyi / README.md
Created March 14, 2017 05:48 — forked from jcheng5/README.md
Using arbitrary Leaflet plugins with Leaflet for R

Using arbitrary Leaflet JS plugins with Leaflet for R

The Leaflet JS mapping library has lots of plugins available. The Leaflet package for R provides direct support for some, but far from all, of these plugins, by providing R functions for invoking the plugins.

If you as an R user find yourself wanting to use a Leaflet plugin that isn't directly supported in the R package, you can use the technique shown here to load the plugin yourself and invoke it using JS code.

@leoluyi
leoluyi / shp2gj.py
Created January 18, 2017 05:37 — forked from frankrowe/shp2gj.py
PyShp, shp to geojson in python
import shapefile
# read the shapefile
reader = shapefile.Reader("my.shp")
fields = reader.fields[1:]
field_names = [field[0] for field in fields]
buffer = []
for sr in reader.shapeRecords():
atr = dict(zip(field_names, sr.record))
geom = sr.shape.__geo_interface__
buffer.append(dict(type="Feature", \
@leoluyi
leoluyi / convert.py
Created January 16, 2017 05:38 — forked from jwass/convert.py
Simple Shapefile to GeoJSON converter. Using the shapefile from here: http://www.mass.gov/anf/research-and-tech/it-serv-and-support/application-serv/office-of-geographic-information-massgis/datalayers/senate2012.html it will result in an error "ValueError: Record's geometry type does not match collection schema's geometry type: 'Polygon' != 'Unk…
import fiona
import fiona.crs
def convert(f_in, f_out):
with fiona.open(f_in) as source:
with fiona.open(
f_out,
'w',
driver='GeoJSON',
crs = fiona.crs.from_epsg(4326),
@leoluyi
leoluyi / README.md
Created January 3, 2017 15:15 — forked from dannguyen/README.md
Using Python 3.x and Google Cloud Vision API to OCR scanned documents to extract structured data

Using Python 3 + Google Cloud Vision API's OCR to extract text from photos and scanned documents

Just a quickie test in Python 3 (using Requests) to see if Google Cloud Vision can be used to effectively OCR a scanned data table and preserve its structure, in the way that products such as ABBYY FineReader can OCR an image and provide Excel-ready output.

The short answer: No. While Cloud Vision provides bounding polygon coordinates in its output, it doesn't provide it at the word or region level, which would be needed to then calculate the data delimiters.

On the other hand, the OCR quality is pretty good, if you just need to identify text anywhere in an image, without regards to its physical coordinates. I've included two examples:

####### 1. A low-resolution photo of road signs

@leoluyi
leoluyi / tor.R
Created December 12, 2016 05:55 — forked from jeroen/tor.R
Using TOR in R
# Installing TOR on mac: brew install tor
# Run TOR on custom port: tor --SOCKSPort 9050
# Check the 'origin' field in the response to verify TOR is working.
library(httr)
GET("https://httpbin.org/get", use_proxy("socks5://localhost:9050"))
# Set proxy in curl
library(curl)
h <- new_handle(proxy = "socks5://localhost:9050")
@leoluyi
leoluyi / index.js
Created November 10, 2016 11:52 — forked from edokeh/index.js
佛祖保佑,永无 BUG
//
// _oo0oo_
// o8888888o
// 88" . "88
// (| -_- |)
// 0\ = /0
// ___/`---'\___
// .' \\| |// '.
// / \\||| : |||// \
// / _||||| -:- |||||- \
@leoluyi
leoluyi / server.R
Created October 13, 2016 02:25 — forked from withr/server.R
Encrypt password with md5 for Shiny-app.
library(shiny)
library(datasets)
Logged = FALSE;
PASSWORD <- data.frame(Brukernavn = "withr", Passord = "25d55ad283aa400af464c76d713c07ad")
# Define server logic required to summarize and view the selected dataset
shinyServer(function(input, output) {
source("www/Login.R", local = TRUE)
observe({
if (USER$Logged == TRUE) {
@leoluyi
leoluyi / Taiwan_geodetic_coor_conv.md
Created September 30, 2016 14:50 — forked from mutolisp/Taiwan_geodetic_coor_conv.md
台灣大地座標系統的轉換
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"></script>
2016-09-16 更新
最近內政部釋出 20 m DTM,志展(aka. Rex)收集了資料並做了許多處理應用(參見應用內政部20公尺網格數值地形模型資料),綬草北三也提到幾個參數轉換的更正,一併整理如下:

MillerLiu's comments:

「關於坐標轉換參數請務必更正, 引述參數文章關於轉換部分恰好是我多年前蒐集及撰寫的, OSG1是TWD67轉TWD97、OSG2則是Hu-Tzu-Shan轉TWD97、OSG3則是Bessel轉TWD97,
@leoluyi
leoluyi / script-bash-redmine-backups
Created September 29, 2016 06:30 — forked from ronanguilloux/script-bash-redmine-backups
Backup script (daily & monthly) for Redmine (full instance + db sql snapshot)
#! /bin/bash
#
# backup_redmine.sh
# modified by [email protected]
# Inspiration: https://gist.github.com/gabrielkfr/6432185
#
# Distributed under terms of the MIT license.
# -- VARS
DAY=`date +"%Y%m%d"`