Skip to content

Instantly share code, notes, and snippets.

@calvinxiao
calvinxiao / app.js
Created August 29, 2015 16:34
Better error handling example with NodeJs & restify
// Demostrate how to handle error in nodejs server
var restify = require('restify');
function getHello(req, res, next) {
throw new Error('standard error happens here');
}
function postHello(req, res, next) {
throw new MyError('here is my error');
@calvinxiao
calvinxiao / goroutine-sort.go
Last active May 12, 2016 15:54
goroutine sort
/**
* a sort demo while learning go goroutine
* sorting 10 million numbers concurrently
*/
package main
import (
"fmt"
"sort"
@calvinxiao
calvinxiao / puma_cork_tcpdump.md
Created April 12, 2021 05:20
strace difference with puma cork

with cork

[pid  1503] 13:16:32.931451 ppoll([{fd=3, events=POLLIN}, {fd=4, events=POLLIN}], 2, NULL, NULL, 8 <unfinished ...>
[pid  1510] 13:16:32.947050 <... ppoll resumed> ) = 0 (Timeout)
[pid  1510] 13:16:32.947298 read(3, 0x7fdcd905e780, 8) = -1 EAGAIN (Resource temporarily unavailable)
[pid  1510] 13:16:32.947616 sched_yield() = 0
[pid  1510] 13:16:32.947800 ppoll([{fd=3, events=POLLIN}], 1, {tv_sec=1, tv_nsec=0}, NULL, 8) = 0 (Timeout)
[pid  1510] 13:16:33.949327 read(3, 0x7fdcd905e780, 8) = -1 EAGAIN (Resource temporarily unavailable)
[pid  1510] 13:16:33.949578 sched_yield() = 0
[pid  1510] 13:16:33.949748 ppoll([{fd=3, events=POLLIN}], 1, {tv_sec=1, tv_nsec=0}, NULL, 8) = 0 (Timeout)
@calvinxiao
calvinxiao / ruby_windows_so.rb
Created April 21, 2021 07:45
SystemStackOverflow in CRuby
require 'json'
require 'thread'
# Thread.abort_on_exception = true
# Thread.report_on_exception = true
# this will raise SystemStackOverflow
def json_dump
obj = {}
obj['c'] = obj
@calvinxiao
calvinxiao / cacheline_test.go
Created April 26, 2021 16:05
Cacheline And False Sharing
package main
import (
"sync"
"sync/atomic"
"testing"
)
const THREADS int = 8
const LOOP int = 100000
@calvinxiao
calvinxiao / 20210508-kvrocks-threadsanitizer-full.md
Last active May 8, 2021 07:59
20210508-kvrocks-threadsanitizer-full.log
==================
WARNING: ThreadSanitizer: data race (pid=14056)
  Write of size 8 at 0x7b04000000a0 by thread T19:
    #0 free <null> (libtsan.so.0+0x35f45)
    #1 <null> <null> (libc.so.6+0xd51b1)
    #2 operator() /home/eagle/github/my/kvrocks/src/server.cc:78 (kvrocks+0x1e9b79)
    #3 __invoke_impl<void, Server::Start()::<lambda()> > /usr/include/c++/9/bits/invoke.h:60 (kvrocks+0x1e9b79)
    #4 __invoke<Server::Start()::<lambda()> > /usr/include/c++/9/bits/invoke.h:95 (kvrocks+0x1e9b79)
    #5 _M_invoke<0> /usr/include/c++/9/thread:244 (kvrocks+0x1e9b79)
/usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline/unicode.rb:188:in `get_next_mbchar_size': undefined method `grapheme_clusters' for nil:NilClass (NoMethodError)
3.0.0 :0from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline/line_editor.rb:1413:in `ed_next_char'
3.0.0 :0from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline/line_editor.rb:951:in `call'
3.0.0 :0from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline/line_editor.rb:951:in `wrap_method_call'
from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline/line_editor.rb:968:in `process_key'
from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline/line_editor.rb:1076:in `input_key'
from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline.rb:247:in `block (3 levels) in inner_readline'
from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline.rb:246:in `each'
from /usr/share/rvm/rubies/ruby-3.0.0/lib/ruby/3.0.0/reline.rb:246:in `block (2 levels) in inner_readline'
from /usr/share
@calvinxiao
calvinxiao / a.go
Created June 28, 2021 02:03
Go And Weak Memory Ordering
package main
import (
"log"
"math/rand"
)
//import "runtime"
var x, y, r1, r2 int
@calvinxiao
calvinxiao / cpp.go
Created July 26, 2022 06:47
cpp.go
package main
import (
"encoding/json"
"fmt"
"sort"
)
func main() {
input := `{