This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.example | |
import com.sksamuel.scrimage.ImmutableImage | |
import com.sksamuel.scrimage.ScaleMethod | |
import com.sksamuel.scrimage.nio.ImageIOReader | |
import com.sksamuel.scrimage.nio.JpegWriter | |
import net.coobird.thumbnailator.Thumbnails | |
import net.coobird.thumbnailator.resizers.configurations.ScalingMode | |
import java.io.ByteArrayOutputStream | |
import java.io.File |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
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.
- Follow standard conventions.
- Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
- Boy scout rule. Leave the campground cleaner than you found it.
- Always find root cause. Always look for the root cause of a problem.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 -> { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); |
NewerOlder