Skip to content

Instantly share code, notes, and snippets.

View leozc's full-sized avatar

Leo Liang leozc

View GitHub Profile
@leozc
leozc / HttpSleeper.js
Last active July 23, 2018 20:15
Node.js HTTP sleep server Simulate HTTP Timeout error
var http = require('http');
var sleep = require('sleep');
var timeout = 100000; //sleep 100 seconds
http.createServer(function (req, res) {
setTimeout((function() {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.end("Hello I am awake");
}), timeout);
}).listen(8080);
@leozc
leozc / Slower.js
Created April 16, 2013 22:23
This implementation simulates very very slow HTTP server
/**
This implementation simulates very very slow HTTP server
**/
var http = require('http');
var sleep = require('sleep');
var fs = require('fs');
var timeout = 1000; //sleep 1 seconds
var iteration = 100; //sleep 100 iteration
@leozc
leozc / gist:6126556
Last active December 20, 2015 11:49
Host this php on php-fpm + nginx, each page hit creates TWO Pairs of connections to replicaset, FOUR Authentication done (primary + secondary) * 2
<?
// simple mongoclient dumpper
$a=getMongo();
$b=getMongo();
var_dump($a->getConnectionss());
print("===================================SECOND MONGO CONN REQUEST ===================================\n");
var_dump($b->getConnectionss());
function getMongo(){//{{{
@leozc
leozc / gist:6171821
Last active December 20, 2015 17:49
Cool bash Prompt e.g. ''' (leozc@mactal)-(jobs:0)-(~)-(LE:0)-(23:59:48) -> '''
#you need git bash completion package for using __git_ps1
export PS1='\n\[\e[32;1m\](\[\e[37;1m\]\u@\h\[\e[32;1m\])-(\[\e[37;1m\]jobs:\j\[\e[32;1m\])-(\[\e[0;32m\]\w)\[\e[34;1m\]-(LE:$?)-\[\e[37;1m\](\t)-$(__git_ps1 " \[\033[1;32m\](%s)\[\033[0m\]")\n->\[\e[0m\] '
<html>
<head>
<meta name="twitter:card" content="product">
<meta name="twitter:site" content="@leozc">
<meta name="twitter:creator" content="@leozc">
<meta name="twitter:title" content="Cool Car">
<meta name="twitter:description" content="Cool Car and Green!">
<meta name="twitter:image:src" content="http://www.teslamotors.com/tesla_theme/images/modelx/falcon_frames/full40.jpg">
<meta name="twitter:data1" content="$180000">
<meta name="twitter:label1" content="Price">
Verifying that +leozc is my Bitcoin username. You can send me #bitcoin here: https://onename.io/leozc
@leozc
leozc / Run ScalaTest From CLI
Last active August 29, 2015 14:06
Run ScalaTest From CLI, great for play ground activities
#Example
scala -cp ~/.ivy2//cache/org.scalatest/scalatest_2.10/jars/scalatest_2.10-2.1.5.jar
scala> import org.scalatest._
scala> Seq(1,2,3) must contain (1)
scala> Seq(1,2,3) must contain (5)
org.scalatest.exceptions.TestFailedException: List(1, 2, 3) did not contain element 5
at org.scalatest.MatchersHelper$.newTestFailedException(MatchersHelper.scala:160)
at org.scalatest.MustMatchers$MustMethodHelper$.mustMatcher(MustMatchers.scala:6141)
at org.scalatest.MustMatchers$AnyMustWrapper.must(MustMatchers.scala:6187)
@leozc
leozc / gist:6451baec171c3aad64e4
Last active August 29, 2015 14:24
R: Cheetgraph on common complexity function
fun1<- function(x) x*log(x,2)
fun2<- function(x) log(x,2)
fun3<- function(x) x
fun4<- function(x) x^2
fun5<- function(x) x
x<-seq(0,50)
matplot(x,cbind(fun1(x),fun2(x),fun3(x),fun4(x),fun5(x)),type="l",col=c("blue","red","pink","green","black"))
@leozc
leozc / minimum triangle path.py
Last active August 29, 2015 14:24
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. https://leetcode.com/problems/triangle/
from collections import defaultdict
class Solution:
#top down
def minimumTotal(self, triangle):
if not triangle:
return None
minCost = [] # [ [(int,[elems)]]], [[cost1,[path2cost1]],[(cost2,[path2cost2])...
minCost.append([(triangle[0][0], [triangle[0][0]])]) # add first level
for rowId in range(1, len(triangle)):
@leozc
leozc / fpmsample.py
Last active September 11, 2015 08:48
Sample PHP-FPM workers
from subprocess import call
import subprocess
import json
import time
repeat = 30
print '{\"result\":['# header
for x in range(repeat):
p = subprocess.Popen(["curl", 'http://localhost/php_fpm_status?json&full'], stdout=subprocess.PIPE, stderr=subprocess.PIPE)