Skip to content

Instantly share code, notes, and snippets.

View nanne007's full-sized avatar
🏠
Working from home

caojiafeng nanne007

🏠
Working from home
View GitHub Profile
@nanne007
nanne007 / bits.move
Created August 11, 2022 11:03
bits operations in movelang
/// Big Endian bits representation.
module omo::bits {
/// 0x0000_0000_0000_0000
struct Bits has copy, drop, store, key {
data: u64,
len: u8,
}
public fun zero(): Bits {

Keybase proof

I hereby claim:

  • I am nonsense2020 on github.
  • I am fengcj1984 (https://keybase.io/fengcj1984) on keybase.
  • I have a public key ASCYAcKH1hfFNkyBIfve8BNGebeZdhiYetRi-aFhH3KMtgo

To claim this, I am signing this object:

@nanne007
nanne007 / Count Code lines
Created January 22, 2019 02:32 — forked from amitchhajer/Count Code lines
Count number of code lines in git repository per user
git ls-files -z | xargs -0n1 git blame -w | perl -n -e '/^.*\((.*?)\s*[\d]{4}/; print $1,"\n"' | sort -f | uniq -c | sort -n
version: "3.2"
services:
zero:
image: dgraph/dgraph:latest
volumes:
- type: volume
source: dgraph
target: /dgraph
volume:
nocopy: true

Rust/Haskell: Higher-Kinded Types (HKT)

A higher kinded type is a concept that reifies a type constructor as an actual type.

A type constructor can be thought of in these analogies:

  • like a function in the type universe
  • as a type with a "hole" in it
@nanne007
nanne007 / concurrent.js
Created July 19, 2017 15:02 — forked from matianfu/concurrent.js
A base class for writing concurrent processes, with abort, until, race and settle.
// licensed under public domain
// author: matianfu@gmail.com
const EventEmitter = require('events')
// K combinator, not necessary, just for fun
const K = x => y => x
// this class is mainly for settle logic.
// the concrete class should emit a 'finish' event with err/data at the end of the process
@nanne007
nanne007 / benchmark-commands.txt
Created December 17, 2016 02:09 — forked from jkreps/benchmark-commands.txt
Kafka Benchmark Commands
Producer
Setup
bin/kafka-topics.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --create --topic test-rep-one --partitions 6 --replication-factor 1
bin/kafka-topics.sh --zookeeper esv4-hcl197.grid.linkedin.com:2181 --create --topic test --partitions 6 --replication-factor 3
Single thread, no replication
bin/kafka-run-class.sh org.apache.kafka.clients.tools.ProducerPerformance test7 50000000 100 -1 acks=1 bootstrap.servers=esv4-hcl198.grid.linkedin.com:9092 buffer.memory=67108864 batch.size=8196
@nanne007
nanne007 / macro_def.ex
Last active July 27, 2016 12:03
strange behavior of elixir macro
defmodule FuncMacro do
defmacro func(name) do
quote do
def unquote(name)(args) do
Enum.join(args, "-")
end
end
end
defmacro func_with_body(name, do: body) do
@nanne007
nanne007 / loop.ex
Created July 22, 2016 15:34
loop, while,break construct in elixir
defmodule Loop do
defmacro while(predicate, do: block) do
quote do
try do
for _ <- Stream.cycle([:ok]) do
if unquote(predicate) do
unquote(block)
else
throw :break
end
@nanne007
nanne007 / .rubocop.yml
Created July 14, 2016 07:48 — forked from jhass/.rubocop.yml
My preferred Rubocop config
AllCops:
RunRailsCops: true
# Commonly used screens these days easily fit more than 80 characters.
Metrics/LineLength:
Max: 120
# Too short methods lead to extraction of single-use methods, which can make
# the code easier to read (by naming things), but can also clutter the class
Metrics/MethodLength: