Skip to content

Instantly share code, notes, and snippets.

Go vs. Scala (Akka) Concurrency

A comparison from 2 weeks using Go.

Actors vs. Functions

Akka's central principle is that there you have an ActorSystem which runs Actors. An Actor is defined as a class and it has a method to receive messages.

/*
* Main.java
*
* Created on 27 August 2007, 11:11
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package hotthread;
@kevinclcn
kevinclcn / check_async_mysql.sh
Created March 9, 2018 05:29 — forked from lefred/check_async_mysql.sh
Consul Asynchronous Slave Check
# script used in consul to check if mysql is primary master and asynchronous slave
# v.0.1 - lefred 2018-02-16
SLAVEOFDC="dc2"
SLAVEUSER="async_repl"
SLAVEPWD="asyncpwd"
# check if we are the primary one
ROLE=$(mysql -h 127.0.0.1 -BNe "select MEMBER_ROLE from performance_schema.replication_group_members where MEMBER_HOST=@@hostname")
@kevinclcn
kevinclcn / check_mysql.sh
Created March 9, 2018 05:29 — forked from lefred/check_mysql.sh
MySQL InnoDB Cluster Consul check
# script used in consul
# the following addition to sys is required:
# https://gist.github.com/lefred/153448f7ea0341d6d0daa2738db6fcd8
# v.0.1 - lefred 2018-02-14
read -r mysql_primary mysql_readonly mysql_tx mysql_cert <<<$(mysql -h 127.0.0.1 -P 6446 -BNe "select * from sys.gr_member_routing_candidate_status")
if [[ "${mysql_primary}" == "YES" ]] && [[ "${mysql_readonly}" == "NO" ]]
then
@kevinclcn
kevinclcn / webcrawler.go
Last active March 18, 2018 01:06
golang tutorial web crawler
package main
import (
"fmt"
"sync"
)
type Fetcher interface {
// Fetch returns the body of URL and
// a slice of URLs found on that page.
@kevinclcn
kevinclcn / manual.md
Last active September 21, 2024 05:50
pandoc导出中文pdf的模板

http://code.haleby.se/2017/01/27/markdown-to-pdf-in-macosx/

  • 安装pandoc,mactex和xelatex
  • 命令行程序都在/Libarary/Tex/Root/bin/x86_64-darwin/下面,需要将pdflatex, xelatex, tlmgr链接到/user/local/bin下面
  • 需要使用tlmgr安装titling, lastpage
  • 需要提供一个导出pdf的latex模板,默认的模板不支持中文
  • 调用命令生成pdf

pandoc --pdf-engine=xelatex --template=template accesstoken.md create.md customer.md customerevent.md list.md tag.md -o customer.pdf

@kevinclcn
kevinclcn / gist:1df8bf7116acc9fda96576c79531527f
Last active August 15, 2018 07:39 — forked from Capncavedan/gist:2844679
Analyze MySQL binary log file
# from http://dzone.com/snippets/analyse-binary-log
# cat /bin/mylog
#!/bin/sh
# usage:
#$ mylog /mysql-bin-log/db-bin.000223
# 2132 insert into customers
# 1887 update userlog_access
# 788 insert into gn_commission
# 718 insert into con_tab
@kevinclcn
kevinclcn / bench.txt
Created August 21, 2018 02:49 — forked from rodaine/bench.txt
Code snippets for my blog post "The X-Files: Avoiding Concurrency Boilerplate with golang.org/x/sync"
BenchmarkMutexCache/10-8 10000000 180 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/100-8 10000000 187 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/1000-8 10000000 214 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/10000-8 10000000 231 ns/op 0 B/op 0 allocs/op
BenchmarkMutexCache/100000-8 5000000 254 ns/op 2 B/op 0 allocs/op
BenchmarkMutexCache/1000000-8 1000000 1159 ns/op 102 B/op 1 allocs/op
BenchmarkMutexCache/10000000-8 1000000 1481 ns/op 184 B/op 2 allocs/op
BenchmarkMutexCache/100000000-8 1000000 1655 ns/op 187 B/op 3 allocs/op
BenchmarkSyncMapCache/10-8 5000000 221 ns/op 0 B/op 0 allocs/op
@kevinclcn
kevinclcn / docker-cleanup-resources.md
Created September 16, 2018 12:46 — forked from bastman/docker-cleanup-resources.md
docker cleanup guide: containers, images, volumes, networks

Docker - How to cleanup (unused) resources

Once in a while, you may need to cleanup resources (containers, volumes, images, networks) ...

delete volumes

// see: https://github.com/chadoe/docker-cleanup-volumes

$ docker volume rm $(docker volume ls -qf dangling=true)

$ docker volume ls -qf dangling=true | xargs -r docker volume rm

package main
import (
"fmt"
"log"
"net"
"time"
)
// Dialer .