Skip to content

Instantly share code, notes, and snippets.

Avatar

Calvin Xiao calvinxiao

View GitHub Profile
@calvinxiao
calvinxiao / a.go
Created Jun 28, 2021
Go And Weak Memory Ordering
View a.go
package main
import (
"log"
"math/rand"
)
//import "runtime"
var x, y, r1, r2 int
View rubybug.tex
/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 / 20210508-kvrocks-threadsanitizer-full.md
Last active May 8, 2021
20210508-kvrocks-threadsanitizer-full.log
View 20210508-kvrocks-threadsanitizer-full.md
==================
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&lt;0&gt; /usr/include/c++/9/thread:244 (kvrocks+0x1e9b79)
@calvinxiao
calvinxiao / cacheline_test.go
Created Apr 26, 2021
Cacheline And False Sharing
View cacheline_test.go
package main
import (
"sync"
"sync/atomic"
"testing"
)
const THREADS int = 8
const LOOP int = 100000
@calvinxiao
calvinxiao / ruby_windows_so.rb
Created Apr 21, 2021
SystemStackOverflow in CRuby
View ruby_windows_so.rb
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 / puma_cork_tcpdump.md
Created Apr 12, 2021
strace difference with puma cork
View puma_cork_tcpdump.md

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)
View goroutine-sort.go
/**
* a sort demo while learning go goroutine
* sorting 10 million numbers concurrently
*/
package main
import (
"fmt"
"sort"
@calvinxiao
calvinxiao / app.js
Created Aug 29, 2015
Better error handling example with NodeJs & restify
View app.js
// 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');