Skip to content

Instantly share code, notes, and snippets.

@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)
<%--
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 / 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.

@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
SUBMITTING job 2014y-3m-8d-9h-40m-44s-236r from 1.72.4.228 (1.72.4.228)
SARTING job 2014y-3m-8d-9h-40m-44s-236r at Sat Mar 08 09:40:44 EST 2014
Primer3 returned no oligos for sequence ACCAATGGTGGCGCGATGTAACACGAGAAAGCACATACCAAGGCCACCACACACCACCTGTCCAAAAAGGCCTTCGATACGGGATAATCCTATTTATTACCTCAGAAGTTTTTTTCTTCGCAGGATTTTTCTGAGCCTTTTACCACTCCA
Primer3 returned no oligos for sequence GCACATACCAAGGCCACCACACACCACCTGTCCAAAAAGGCCTTCGATACGGGATAATCCTATTTATTACCTCAGAAGTTTTTTTCTTCGCAGGATTTTTCTGAGCCTTTTACCACTCCAGCCTAGCCCCTACCCCCCAACTAGGAGGGC
Primer3 returned no oligos for sequence TCCAAAAAGGCCTTCGATACGGGATAATCCTATTTATTACCTCAGAAGTTTTTTTCTTCGCAGGATTTTTCTGAGCCTTTTACCACTCCAGCCTAGCCCCTACCCCCCAACTAGGAGGGCACTGGCCCCCAACAGGCATCAACCAATGGT
Primer3 returned no oligos for sequence TATTTATTACCTCAGAAGTTTTTTTCTTCGCAGGATTTTTCTGAGCCTTTTACCACTCCAGCCTAGCCCCTACCCCCCAACTAGGAGGGCACTGGCCCCCAACAGGCATCAACCAATGGTGGCGCGATGTAACACGAGAAAGCACATACC
Primer3 returned no oligos for sequence CAGGATTTTTCTGAGCCTTTTACCACTCCAGCCTAGCCCCTACCCCCCAACTAGGAGGGCACTGGCCCCCAACAGG
@ngocdaothanh
ngocdaothanh / rtsp_to_file.sh
Created December 8, 2013 02:46
Use ffmpeg to save NVC1000 & IPE300M video streams to files
ffmpeg -i rtsp://211.241.204.87/ch0_unicast_firststream -vcodec msmpeg4v2 -an output.avi
ffmpeg -i rtsp://211.241.204.87/ch0_unicast_secondstream -vcodec msmpeg4v2 -an output.avi
/**
* 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 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._
#!/bin/bash
###########################################################################
# Choose your ffmpeg version and your currently-installed iOS SDK version:
#
VERSION="2.1.1"
SDKVERSION="7.0"
#
#
###########################################################################
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