Skip to content

Instantly share code, notes, and snippets.

View edingroot's full-sized avatar

Chi Chang edingroot

  • Yelp
  • London, United Kingdom
View GitHub Profile
# Convert Lat/Lon to TWD97
# Ref: http://fyyang.blogspot.tw/2012/09/python-twd97.html
from math import tan, sin, cos, radians # Using math.tan, math.sin, math.cos, math.radians
class LatLngToTWD97(object): # class for convert
"""This object provide method for converting lat/lng coordinate to TWD97
coordinate
The reference to:
http://blog.ez2learn.com/2009/08/15/lat-lon-to-twd97/
// Ref: https://kuro.tw/posts/2015/06/11/js-note-twd97-convert-to-longitude-and-latitude/
function twd97_to_latlng($x, $y) {
var pow = Math.pow, M_PI = Math.PI;
var sin = Math.sin, cos = Math.cos, tan = Math.tan;
var $a = 6378137.0, $b = 6356752.314245;
var $lng0 = 121 * M_PI / 180, $k0 = 0.9999, $dx = 250000, $dy = 0;
var $e = pow((1 - pow($b, 2) / pow($a, 2)), 0.5);
$x -= $dx;
$y -= $dy;
public class Main {
public static void main(String[] args) {
int num = -32700;
// Signed int to 2 bytes (32767 ~ -32768)
byte b0, b1;
b1 = (byte) ((num & 0xff00) >> 8);
b0 = (byte) (num & 0xff);
@edingroot
edingroot / DijkstraRouting.cpp
Last active January 4, 2018 17:04
Dijkstra’s Routing Algorithm (Homework of "Introduction to Computer Network")
/**
* NOTE: node id should start from 1
* topo.txt format (see the end of this file for example):
* #row id1 id2 cost
* 0 1 2 2.0
*/
#include <stdio.h>
#include <stdlib.h>
#include <vector>
function fract(x) {
return x - Math.floor(x);
}
function packFloat(x) {
let s = x > 0 ? 1 : -1;
let e = Math.floor(Math.log2(s * x));
let m = s * x / Math.pow(2, e);
return [
Math.floor(fract((m - 1) * 256 * 256) * 256),
/**
* Numerical Computation HW1.2 / by Chi Chang
* Ref:
* http://en.cppreference.com/w/cpp/numeric/math/fpclassify
* http://en.cppreference.com/w/cpp/types/numeric_limits/signaling_NaN
* https://en.wikipedia.org/wiki/NaN
*/
#include <iostream>
#include <cmath>
@edingroot
edingroot / ParallelFlowableLimit.java
Last active July 29, 2018 08:09
RxJava ParallelFlowable with throughput limitation
// PS. Another approach with Observable: https://stackoverflow.com/a/36383691
import io.reactivex.BackpressureStrategy;
import io.reactivex.Flowable;
import io.reactivex.schedulers.Schedulers;
public class ParallelFlowableLimit {
public static void main(String[] args) {
// Flowable.range(0, 10)
Flowable.create(emitter -> {
CC := g++
INCLUDE_PATH = -Isrc/http_server/core
CPPFLAGS := -std=c++14 $(INCLUDE_PATH)
HTTP_SERVER_SOURCES = $(shell find ./src/http_server -type f -name '*.cpp')
HTTP_SERVER_OBJS = $(HTTP_SERVER_SOURCES:%.cpp=%.o)
CONSOLE_CGI_SOURCES = $(shell find ./src/console_cgi -type f -name '*.cpp')
CONSOLE_CGI_OBJS = $(CONSOLE_CGI_SOURCES:%.cpp=%.o)
@edingroot
edingroot / clean_code.md
Created March 17, 2022 05:50 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

#!/bin/sh
tstart=$(date +%s%N)
cstart=$(cat /sys/fs/cgroup/cpu/cpuacct.usage)
sleep 5
tstop=$(date +%s%N)
cstop=$(cat /sys/fs/cgroup/cpu/cpuacct.usage)
bc -l <<EOF