Skip to content

Instantly share code, notes, and snippets.

@ngocdaothanh
ngocdaothanh / gist:3764694
Created September 22, 2012 00:43
Scala Assignment: Recursion
package recfun
import scala.collection.mutable.ListBuffer
import common._
/** https://class.coursera.org/progfun-2012-001/assignment/view?assignment_id=4 */
object Main {
def main(args: Array[String]) {
println("Pascal's Triangle")
for (row <- 0 to 10) {
@ngocdaothanh
ngocdaothanh / autoretry-one-liner.sh
Last active June 28, 2022 03:56
Retry failed command with random delay
# Autoretry failed command 10 times, with 1-60s random delay:
# https://unix.stackexchange.com/questions/82598
for i in $(seq 1 10); do [ $i -gt 1 ] && delay=$[$RANDOM % 60 + 1] && echo "Retry after ${delay}s" && sleep $delay; command "$1" && failed=0 && break || failed=$?; done; (exit $failed)
@ngocdaothanh
ngocdaothanh / many_users.js
Created January 15, 2015 04:31
MongoDB's DB creation benchmark
// MongoDB's DB creation benchmark:
// * データベースを作る前にデータベース用のユーザを作成。
// * そのユーザ権限でデータベースを作成。
// * コレクションを10個、ドキュメントを10個、フィールドを10個ずつ作成。
// * 作成データベース数は10000
//
// 1.
//
// Start MongoDB server without "--auth" option, and create a bootstrap admin user:
// use admin
/**
* Copyright (C) 2009-2013 Typesafe Inc. <http://www.typesafe.com>
*/
package actorbintree
import akka.actor._
import scala.collection.immutable.Queue
object BinaryTreeSet {
trait Operation {
package simulations
import math.random
class EpidemySimulator extends Simulator {
def randomBelow(i: Int) = (random * i).toInt
protected[simulations] object SimConfig {
val population = 300
val roomRows = 8
package nodescala
import scala.language.postfixOps
import com.sun.net.httpserver._
import scala.concurrent._
import scala.concurrent.duration._
import ExecutionContext.Implicits.global
import scala.async.Async.{async, await}
import scala.collection._
@ngocdaothanh
ngocdaothanh / Benchmark.scala
Created December 17, 2011 14:00
ByteBuffer.allocateDirect vs Unsafe
object Benchmark {
private val LOOP_COUNT = 1000000
private val ARRAY_SIZE = 1024
def main(args: Array[String]) {
val t1 = System.currentTimeMillis
var i = 0
while (i < LOOP_COUNT) {
testDirectByteBuffer
@ngocdaothanh
ngocdaothanh / introrx.md
Last active December 28, 2017 20:16 — forked from staltz/introrx.md

The introduction to Reactive Programming you've been missing

(by @andrestaltz)

So you're curious in learning this new thing called Reactive Programming, particularly its variant comprising of Rx, Bacon.js, RAC, and others.

Learning it is hard, even harder by the lack of good material. When I started, I tried looking for tutorials. I found only a handful of practical guides, but they just scratched the surface and never tackled the challenge of building the whole architecture around it. Library documentations often don't help when you're trying to understand some function. I mean, honestly, look at this:

Rx.Observable.prototype.flatMapLatest(selector, [thisArg])

Projects each element of an observable sequence into a new sequence of observable sequences by incorporating the element's index and then transforms an observable sequence of observable sequences into an observable sequence producing values only from the most recent observable sequence.

<%--
Document : one
Created on : 24/03/2017, 3:37:22 PM
Author : Tyler
--%>
<html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
@ngocdaothanh
ngocdaothanh / Build.scala
Created June 15, 2011 01:37
dependsOn packageBin
import sbt._
import Keys._
object MyBuild extends Build {
val mySettings = Defaults.defaultSettings ++ Seq(
organization := "tv.cntt",
name := "comy",
version := "1.3-SNAPSHOT",
scalaVersion := "2.9.0-1"
)