Skip to content

Instantly share code, notes, and snippets.

Xiaojun Ren nicholasren

Block or report user

Report or block nicholasren

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View push_daemon_v1.java
package com.thoughtworks;
import org.apache.http.HttpEntity;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.HttpClients;
import java.io.IOException;
import java.lang.String;
@nicholasren
nicholasren / realtime-searching.scala
Created Oct 13, 2014
a small example of real time indexing and searching engine
View realtime-searching.scala
package actors
import akka.actor._
import scala.concurrent.{Future, ExecutionContext}
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
import java.io.{PrintWriter, FileOutputStream}
import rx.lang.scala.Observable
import rx.lang.scala.Observable._
@nicholasren
nicholasren / Duplication.java
Last active Sep 6, 2018
java clean code examples
View Duplication.java
import java.util.Arrays;
import java.util.List;
import java.util.function.BinaryOperator;
public class Duplication {
public static void main(String[] args) {
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5);
Integer product = Math2.sum(numbers);
System.out.println(product);
}
@nicholasren
nicholasren / duck-typeing.scala
Created May 20, 2014
scala training example - structural types
View duck-typeing.scala
trait Quack {
this: { def quack(): Unit } =>
}
class Duck extends Quack {
def quack() = {
println("Quack, Quack...")
}
}
@nicholasren
nicholasren / biz-logic-in.java
Last active Aug 29, 2015
scala training example - monad
View biz-logic-in.java
//in post controller
User user = null;
try {
user = userService.findById(userId)
} catch (UserNotFoundException e) {
throw //handling exception
}
@nicholasren
nicholasren / pattern-matching.scala
Created May 19, 2014
scala training example - pattern matching
View pattern-matching.scala
case class Option[T]
case class Some(t: T) extends Option[T]
case class None extends Option[T]
val possibleNumber = Some(1)
val numbers = possibleNumber match {
case Some(x) => x
case None => 0
}
@nicholasren
nicholasren / function-composition.scala
Last active Aug 29, 2015
scala training example- function composition
View function-composition.scala
val userFetcher: String => User = {
//...
}
val commentFetcher: User => List[Comment] = {
//...
}
val userCommentFetcher : String => List[Comment] = userFetcher andThen commentFetcher
@nicholasren
nicholasren / high-order-function.scala
Last active Aug 29, 2015
scala the language matters training
View high-order-function.scala
//-------------------------------------//
// readFile is a high order function //
// which can take another function //
// as parameter //
//-------------------------------------//
def using[T](f: File)(handler: FileInputStream => T): T = {
val resource = new java.io.FileInputStream(f)
try {
handler(resource)
@nicholasren
nicholasren / function-as-first-class-citizen.java
Created May 19, 2014
scala the language matters training
View function-as-first-class-citizen.java
//-------------------------------------------//
// function as parameter java implementation //
//-------------------------------------------//
class UerFetcher implement Callable<User> {
private String userId;
@Autowired
private UserService userService;
@nicholasren
nicholasren / blocking-with-future.scala
Created May 11, 2014
solving nested future problem
View blocking-with-future.scala
val fa = callToRemoteServiceA();
val fb = callToRemoteServiceB();
val fc = callToRemoteServiceC(fa.get());
val fd = callToRemoteServiceD(fb.get());
val fe = callToRemoteServiceE(fb.get());
val executor = new ThreadPoolExecutor(4, 4, 1, TimeUnit.MINUTES, new LinkedBlockingQueue[Runnable]())
You can’t perform that action at this time.