Saturday, July 01, 2017

when I looking for a more lightweight search engine, mongodb came cross my mind. it does supports text search.

I know mongodb has lots of bad comments, but as I said it's getting better, its wiredtiger storage engine supports compression

I decided give a try. use it to replace MySQL and elasticsearch


last week I was writing crappy node.js codes (callback hell style) under terminal using vim

however, just code and think less seem work pretty well on me. (partly because I'm still fluent in vim)

code was crappy but I could get the result faster. once I got the result I want, I could kept fine tuning and refactoring with less worry. because job was done and it's always possible to make it better.

worse is better, make it work then make it better. it was a good experiment and reminds me my junior years.


some recent tweets:

5 Programming Languages You Should Really Try

tl;dr version: nim, go, f#, rust and clojure

I told my colleagues the choice of mine are: elixir/erlang (prolog family), rust (c family), f# (ML family), clojure (lisp family) and haskell (king of all)


Why the JVM is a Good Choice for Serverless Computing: John Chapin Discusses AWS Lambda at QCon NY

I like JVM but I'm not quite sure about this one, the development process so painful because it's too damn slow to upload.


Inventory management in MongoDB: A design philosophy I find baffling

I read this after I finished my reading on MongoDB in Action 2nd Edition, of course I didn't notice the problem, but I'm more interested in how not to do it from discussion on hackernews and Model Data for Atomic Operations

Sunday, July 02, 2017

reading an old book: Effective MySQL Replication Techniques in Depth

because I'm going to setup a myrocks slave, wants to make sure I understand how replication works first.

the book is quite good by the way.

Saturday, July 08, 2017

finger hurts again, leave emacs and return to vim temporarily.

probably because of the alt key, which I used heavily under tmux and emacs


also discovered more vim usage:

for emacs ctrl-l vim equivalent:

  • zz: center
  • zt: top
  • zb: bottom
  • z.: like center, but put cursor at the first non-blank character

to lower/upper case, after selected block of text, u to lowercase and U to uppercase.

open file under cursor:

  • gf to open it
  • ctrl-w f to open it with split window
  • ctrl-w gf to open it in new tab

for tabs:

  • :tabe to open file in new tab
  • :tabf to find file in new tab
  • :tabc to close tab, or use ctrl-w c
  • gt/gT moves between tabs
  • :tabs lists all tabs

when under split window, ctrl-w T moves current window to new tab

Thursday, July 20, 2017

trying Wily editor, maybe I should try plan9port for acme or sam editors, but wily is just an apt-get install command.

I played acme on inferno before, I already forgot how to use it.


some history, about Lars Bak (Dart) and Robert Griesemer (Go), they are both worked at Strongtalk and HotSpot, then V8

they are the creators of Dart (Lars) and Go (Robert, with Rob Pike and Ken Thompson)

two members from StrongTalk team are super famous too:

Gilad Bracha, co-author of Java Language Specification and Java Virtual Machine Specification, Dart team.

Urs Hölzle, hotspot, Google's eighth employee and built Google's infrastructure.

all these people were in a team ... crazy.


I need to leave clojure for a while, I feel inefficient when working with it lately.

I'm doing go now.


I was searching for a jq wrapper for go, didn't find anything great.

maybe this one will work: threatgrid/jqpipe-go: A Go Wrapper for JQ

Saturday, July 22, 2017

I read Go in Action last year, but I'm reading it again now. actually I already forgot what I've read last time.

one thing I still not figured out yet is when designing a function, how to determine accept values or pointers.

there're two parts, receivers and arguments

for receivers:

  • if not an interface type, either values or pointers can be used. compiler will reference/dereference automatically.
  • if receiver is an interface type, pointers receiver can only be called by the type contains pointers. values receiver can be call by the type contains both values and pointers.

the best practice to declare methods is using pointer receivers.

for arguments, I'm not sure yet. I think as the book said:

if you need to access and change the state of a variabel, pass pointer. if you don't need to manipulate the state, pass value.


when starting a new go project, I noticed since v1.6 lookup paths include ./vendor/ folder.

but how about go get? will it download packages to ./vendor?

looks like I'll need to copy dependencies from $GOPATH/src/foo to ./vendor/foo

should I check in the ./vendor folder?

I think I will, but need to remove .git folders inside dependencies.

I don't want to use godep or govendor or glide yet.


one important thing is the ./vendor folder must inside GOPATH:

.
└── src
    ├── foo
    │   └── foo.go
    └── user
        ├── main.go
        └── vendor
            └── bar
                └── bar.go

this will work:

$ GOPATH=$PWD go run src/user/main.go
$ GOPATH=$PWD go build user

if you put main.go and verdor outside of user folder, it's not going to work.

it's weird and seems they're still working on a solution. so we have to stick with GOPATH.


recently I switched to use GNU Unifont

under ubuntu, simply apt-get install ttf-unifont

Sunday, July 23, 2017

JSON-to-Go helps you convert json to go structs, very useful.

json in go standard library is under encoding namespace, you can decode but also have to be able to encode as well. that's why they don't deal with dynamic fields.


some discussion on clojure start-up time again: How ’bout that start-up time?

slow start-up time is very painful, especially on my old laptops.


vim tips time:

to zoom/expand a split window, use

  • c-w | (horizontally)
  • c-w _ (vertically), c-w = to un-zoom.
  • c-w r and c-w R to swap windows.

:ls to list buffers, :bn and :bp to navigate.

you can set make command like this:

autocmd BufNewFile,BufRead *.js set makeprg=node\ %

then when editing .js files, :make to run the file.

however, now I will create a Makefile for the project and :make will automatically calls it.

I have to turn off set autochdir because of this, and use:

  • :pwd to check current directory
  • :lcd %:p:h to change directory

the benifits of using Makefile is vim now able to open corresponding file and line when error occurs.

surround plugin

change surroundings, use cs remove surroundings, use ds insert surroundings, use ysiw or yss


my colleagues mentioned Linux Torvalds uses uemacs

I checked out the repo and compiled it. I'm afraid it is not an emacs

but it should be a good reference for writing an editor.


after uemacs and wily experience, I decide to try turning off colors on my editor and shell.

I like it so far.

Tuesday, July 25, 2017

gocon 2017 videos are here

I watched a very good one: Liz Rice - A Go Programmer's Guide to Syscalls

she implemented a strace in go, really cool. I also learned seccomp which can limit what syscalls you allow the application to run and docker support seccomp

Also watch a little bit of:


watched dotGo 2015 - Rob Pike - Simplicity is Complicated

now I agree that maybe they are right. when coding in clojure I need to think a lot. while using go, I just code, because there's no alternative, you just have one way to do things. I don't have to think about is this the best way to do it? is there any better way?

but on the other hand, it's less fun.

same as now I switched back to vim, I think less (I have very little plugins and custom keys), emacs I just have too many short keys.


Elixir v1.5 released

after clojure I was picking a language between go and elixir, I choosed go because it's more simple.

I will continue my study on elixir sometimes next year maybe?

Wednesday, July 26, 2017

Watching Renzo Borgatti - Clojure Transducers In The Wild

Renzo Borgatti has some pretty cool stuffs:


more low level go stuff from gophercon 2017: Areg Melik Adamyan - Let NFV Go: Experimental Framework for Network Functions

I don't think I'll touch these, but good to know:


go 1.9rc1 is released:

$ go get golang.org/x/build/version/go1.9.rc1
$ go1.9rc1 download
$ go1.9rc1 version

for what's new can check this slide: The State of Go (May 2017)


watching Rich Hickey - Inside Transducers

it's a difficult talk and I'll need some time to finish it. but it goes over many implementation of clojure functions, worth the time.


defn Episode #24 – Enter the Dragan

the guest uses xmonad:

I took a look, seems depends on ghc, which is pretty large. I think I'll better stick with awesome wm


I learned today systemd supports Timers, as alternative to cron

basically setup a systemd service and a .timer file.

more details on systemd/Timers - ArchWiki

I'm not sure if it's better than cron? I'll just let puppet handles it.


Why I don't use cider

cider-jack-in is painfully slow, I may try some of suggestion mentioned in this article.

but I'm not doing any clojure right now ...


reading Go Web Programming, it is good.

now I understand more about the net/http package, and the difference between HandleFunc and HandlerFunc:

  • HandlerFunc convert a function to handler and register it to DefaultServeMux
  • HandlerFunc is a function type

if you have a function foo that takes http.ResponseWriter and *http.Request as arguments, you can use HandlerFunc(foo) to convert foo to HandlerFunc type (just like string(1) to convert 1 to "1")

HandlerFunc has one method: ServeHTTP.

another type that has ServeHTTP method is ServeMux, the DefaultServeMux is an instance of ServeMux.

the type has ServeHTTP method fulfill the requirement of handler interface:

type Handler interface {
        ServeHTTP(ResponseWriter, *Request)
}

so HandlerFunc and ServeHTTP are both Handler.

Wednesday, July 31, 2017

watched GopherCon 2017: Kris Nova - Valuable Lessons in Over-Engineering the Core of Kubernetes kops

they changed from YAML config to use FuncMap Type, had great performance improvement.

I found some Example Of Using Templates In Golang:

fmap := template.FuncMap{
    "formatAsDollars": formatAsDollars,
    "formatAsDate": formatAsDate,
    "urgentNote": urgentNote,
}

t := template.Must(template.New("email.tmpl").Funcs(fmap).ParseFiles("email.tmpl"))

using a template like this:

{{.FromDate | formatAsDate}} to {{.ToDate | formatAsDate}}.

Blog Archives

Search Blog: