Skip to content

Instantly share code, notes, and snippets.

@flying3615
flying3615 / HanoiTower.java
Last active July 26, 2016 04:50
recursive solution for HanoiTower
package recursion;
import java.util.Scanner;
/**
*
The base case for the problem is n = 1. If n == 1, you could simply move the disk from A
to B. When n > 1, you could split the original problem into the following three subproblems
and solve them sequentially.
1. Move the first n - 1 disks from A to C recursively with the assistance of tower B,
@flying3615
flying3615 / Timing.java
Created October 19, 2016 08:21
Data in, Data out functional programming to check code timing!!!
package Java_FP.Timing;
import java.util.Date;
import java.util.function.Consumer;
import java.util.function.Supplier;
/**
* Created by liuyufei on 19/10/16.
*/
public class Timing {
@flying3615
flying3615 / TimingTest.java
Created October 19, 2016 08:31
create junit test for Timing code
package Java_FP.Timing;
import java.util.concurrent.atomic.AtomicReference;
/**
* Created by liuyufei on 19/10/16.
*/
public class TimingTest {
@org.junit.Test
@flying3615
flying3615 / Example.java
Created October 19, 2016 08:36
Main for Timing
package Java_FP.Timing;
import java.util.logging.LogManager;
import java.util.logging.Logger;
import static Java_FP.Timing.Timing.timed;
/**
* Created by liuyufei on 19/10/16.
*/
public class Example {
@flying3615
flying3615 / FunctionOverTime.java
Created October 19, 2016 08:38
Sale calculator functional interface
package Java_FP.FP;
/**
* Created by liuyufei on 18/10/16.
*/
@FunctionalInterface
public interface FunctionOverTime {
double valueAt(int time);
@flying3615
flying3615 / Example.java
Created October 19, 2016 08:38
Main for Sale calculator
package Java_FP.FP;
/**
* Created by liuyufei on 18/10/16.
*/
public class Example {
final static double[] EXPECTED_SALES_JAN_TO_DEC =
new double[]{42.0, 45.6, 43.6, 50.2, 55.6, 54.7,
58.0, 57.3, 62.0, 60.3, 71.2, 88.8
@flying3615
flying3615 / CollectionExample_8.java
Created October 19, 2016 09:49
interesting example using java 8 to string processing
package Java_FP.collection;
import java.util.Arrays;
import java.util.Optional;
import java.util.function.BinaryOperator;
import java.util.function.Function;
import java.util.function.Predicate;
import java.util.stream.Stream;
/**
@flying3615
flying3615 / TodaySales.java
Created October 23, 2016 00:31
Over all Java Stream methods
package Java_FP.salesFP;
import java.util.*;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;
/**
* Created by liuyufei on 19/10/16.
*/
@flying3615
flying3615 / elasticsearch.md
Created November 14, 2016 09:16 — forked from nicolashery/elasticsearch.md
Elasticsearch: updating the mappings and settings of an existing index

Elasticsearch: updating the mappings and settings of an existing index

Note: This was written using elasticsearch 0.9.

Elasticsearch will automatically create an index (with basic settings and mappings) for you if you post a first document:

$ curl -X POST 'http://localhost:9200/thegame/weapons/1' -d \
'{
  "_id": 1,
@flying3615
flying3615 / AkkaCalcu1000in4.scala
Last active January 6, 2017 08:33
Akka calculate 10000 in 4 concurrent actors
package chapter4
import akka.actor.{Actor, ActorSystem, Props}
import akka.routing.RoundRobinPool
/**
* Created by Administrator on 2017/1/6.
*/