Skip to content

Instantly share code, notes, and snippets.

View webstory's full-sized avatar

Hoya Kim webstory

View GitHub Profile
@webstory
webstory / AndroidSound.java
Last active June 27, 2016 07:39
Fusetools Android MediaPlayer
package com.example;
import android.media.MediaPlayer;
import android.media.AudioManager;
import java.io.IOException;
public class AndroidSound {
private static AndroidSound instance = null;
private static MediaPlayer mediaPlayer = null;
@webstory
webstory / ps1.py
Created June 16, 2017 03:54
Python and Nodejs with subprocess
#-*- coding: utf-8 -*-
import subprocess
if __name__ == '__main__':
ps = subprocess.Popen(['nodejs','ps2.js'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
out = ps.communicate(input='http://www.daum.net'.encode())[0]
print(out.decode('utf-8'))
@webstory
webstory / binsearch.py
Last active October 13, 2017 01:22
이진 범위 탐색 알고리즘
def withinRangeSearch(aList, key, kpick=lambda x:x[0], vpick=lambda x:x[1]):
left = 0
right = len(aList) - 1
if key < kpick(aList[left]):
return vpick(aList[left]) or left
if key >= kpick(aList[right]):
return vpick(aList[right]) or right
@webstory
webstory / transform.go
Created January 4, 2018 21:48
Transform WGS84 to GOOGLE
package main
/*
#cgo LDFLAGS: -lproj
#include <string.h>
#include <proj_api.h>
*/
import "C"
import (
"fmt"
@webstory
webstory / backpressure.js
Last active February 25, 2018 14:13
Backpressure - Controllable RxJS Producer
const rx = require('rx')
let s = new rx.Observable.from([1,2,3,4,5,6,7,8,9])
let ss = s.controlled()
ss.subscribe((x) => {
console.log("Pull "+x)
setTimeout(() => process(1, x), 100)
})
@webstory
webstory / affine.py
Last active May 24, 2018 01:55
Affine transform with python opencv
import pyproj
import cv2
import numpy as np
import csv
EPSG5174 = pyproj.Proj("+proj=tmerc +lat_0=38 +lon_0=127.0028902777778 +k=1 +x_0=200000 +y_0=500000 +ellps=bessel +towgs84=-115.80,474.99,674.11,1.16,-2.31,-1.63,6.43 +units=m +no_defs")
EPSG5179 = pyproj.Proj("+proj=tmerc +lat_0=38 +lon_0=127.5 +k=0.9996 +x_0=1000000 +y_0=2000000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs") # UTMK
EPSG5186 = pyproj.Proj("+proj=tmerc +lat_0=38 +lon_0=127 +k=1 +x_0=200000 +y_0=600000 +ellps=GRS80 +towgs84=0,0,0,0,0,0,0 +units=m +no_defs")
fromarray = []
@webstory
webstory / cython_np.pyx
Created March 14, 2018 08:49
Cython with OpenMP
from cython.parallel import prange
import numpy as np
cimport numpy as np
def calculate_z(int maxiter, double complex[:] zs, double complex[:] cs):
""" Calculate output list using jullia update rules."""
cdef unsigned int i, length
cdef double complex z, c
cdef int[:] output = np.empty(len(zs), dtype=np.int32)
@webstory
webstory / diffusion.c
Last active March 14, 2018 09:31
Python ffi
/* filename: diffusion.c
* compile:
* gcc -O3 -std=gnu99 -c diffusion.c
* gcc -shared -o diffusion.so diffusion.o
*
* .so file place /usr/lib or /usr/local/lib or set LD_LIBRARY_PATH for custom location
*/
void evolve(int w, int h, double **in, double **out, double D, double dt) {
int i, j;
@webstory
webstory / Main.java
Created March 23, 2018 08:14
Java regex example
import java.util.regex.Pattern;
import java.util.regex.Matcher;
class Main {
public static void main(String[] args) {
String s = "여기는.어디.입니까-12";
Pattern p = Pattern.compile("^([^.]+\\.[^.]+\\.[^-.]+)(?:-([0-9]{2}))?$");
Matcher m = p.matcher(s);
if(m.find()) {
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*