This file contains 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
#settings | |
set :user, 'deployer' | |
set :domain, ENV['on'] == 'prod' ? '<prod ip>' : '<qa ip>' | |
set :deploy_to, '/var/www/example.com' | |
set :repository, '[email protected]:your_company/sample.git' | |
set :branch, 'master' | |
task :provision do | |
# add nginx repo |
This file contains 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
#!/usr/bin/env ruby | |
require "fileutils" | |
def build_file_content prj_name | |
<<-EOS | |
name := \"#{prj_name}\" | |
version := \"0.1\" | |
scalaVersion := \"2.10.1\" |
This file contains 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
def solveRPN(expression: String):String = { | |
expression.split(" ").foldLeft(List[String]()) { | |
(stack:List[String], e:String) => | |
e match { | |
case "*" => | |
stack match { | |
case List(z) => List(z) | |
case x :: y :: ys => (y.toInt * x.toInt).toString :: ys | |
} | |
case "+" => |
This file contains 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
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]()) |
This file contains 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 as parameter java implementation // | |
//-------------------------------------------// | |
class UerFetcher implement Callable<User> { | |
private String userId; | |
@Autowired | |
private UserService userService; | |
This file contains 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
//-------------------------------------// | |
// 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) |
This file contains 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
val userFetcher: String => User = { | |
//... | |
} | |
val commentFetcher: User => List[Comment] = { | |
//... | |
} | |
val userCommentFetcher : String => List[Comment] = userFetcher andThen commentFetcher |
This file contains 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
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 | |
} |
This file contains 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
//in post controller | |
User user = null; | |
try { | |
user = userService.findById(userId) | |
} catch (UserNotFoundException e) { | |
throw //handling exception | |
} |
This file contains 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
trait Quack { | |
this: { def quack(): Unit } => | |
} | |
class Duck extends Quack { | |
def quack() = { | |
println("Quack, Quack...") | |
} | |
} |
OlderNewer