Skip to content

Instantly share code, notes, and snippets.

@smilingleo
smilingleo / HashingTest.java
Created January 14, 2020 01:08
Consistent hash by using Google Guava
import com.google.common.hash.Hashing;
import org.junit.Test;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
public class HashingTest {
@Test
@smilingleo
smilingleo / main.rs
Created February 26, 2019 06:52
Learning Rust
extern crate term;
use std::ops::Add;
fn main() {
test_unsafe();
}
// -------------
fn crate_test() {
@smilingleo
smilingleo / starWarSchema.js
Created December 13, 2018 08:19
Delegation GraphQL resolver
/**
*
* @flow strict
*/
import {
GraphQLEnumType,
GraphQLInterfaceType,
GraphQLObjectType,
GraphQLList,
@smilingleo
smilingleo / props.js
Last active June 20, 2018 01:27
A drawIO plugin which parses the `tooltip` attribute in markdown format.
;/*! showdown v 2.0.0-alpha1 - 19-04-2018 */
var showdownFn = function(){
/**
* Created by Tivie on 13-07-2015.
*/
function getDefaultOpts (simple) {
'use strict';
var defaultOptions = {
@smilingleo
smilingleo / HttpProtocolComparison.java
Created March 27, 2018 15:36
Performance comparison between HTTP/1.1 and HTTP/2 using OkHttpClient
package leo.me;
import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Protocol;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.TimeZone;
/**
* This is a test indicating the timezone issue for a datebase which is in a timezone which observes
* DST,
* for example, America/Los_Angeles.
@smilingleo
smilingleo / postgres-cheatsheet.md
Created June 5, 2017 15:25 — forked from Kartones/postgres-cheatsheet.md
PostgreSQL command line cheatsheet

PSQL

Magic words:

psql -U postgres

If run with -E flag, it will describe the underlaying queries of the \ commands (cool for learning!).

Most \d commands support additional param of __schema__.name__ and accept wildcards like *.*

@smilingleo
smilingleo / GraphQLBatchFetcher.java
Last active June 12, 2017 02:27
GraphQL java client example, use batch data fetcher for performance optimization.
package leo.me.graphql;
/**
* Created by leo on 4/26/17.
*/
import static graphql.Scalars.GraphQLString;
import static graphql.schema.GraphQLFieldDefinition.newFieldDefinition;
import static graphql.schema.GraphQLList.list;
import static graphql.schema.GraphQLObjectType.newObject;
@smilingleo
smilingleo / JavaTest.java
Created June 28, 2016 00:35
a way to get actual parameter type
@Test
public void testJavaGeneric() {
// have to use a empty `{ }`, so that the `getClass().getGenericSuperclass()` will return a `ParameterizedType` instance.
List<Integer> list = new LinkedList<Integer>() {
};
// superclass contains the unerased info.
Type supers = list.getClass().getGenericSuperclass();
assertTrue(supers instanceof ParameterizedType);
ParameterizedType paramType = (ParameterizedType) supers;
@smilingleo
smilingleo / WordCounterTest.java
Created October 19, 2015 07:13
word counter implementation by different approaches.
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.Arrays;
import java.util.List;
import java.util.Spliterator;
import java.util.function.Consumer;
import java.util.stream.IntStream;
import java.util.stream.Stream;