Jim Cheung

Tuesday, August 08, 2017

watched some video talks today:

the pattern matching talk is good, you can see how hard to put a new feature into java, but Brian Goetz explains very well and I always think they made the right tradeoffs. (I still want to know the reason why Rich Hickey doesn't like the matching part, must be something)

also put these to watch list:


vim tricks

my colleague shows me a trick: man ls | less +/pattern, it will search pattern on start

I used to jump to specific line with vim by using vim +4 file, so I think maybe vim supports it as well.

it does.

I want to jump to end of file on opening, tried vim +G file, doesn't work.

found out vim + file can jump to end of file, but to put cursor to end of line, need this: vim "+normal G$" (or GA)


rohitpaulk/simple-editor: A bare-bones text editor, written in Clojure.

pretty cool, I'd like to develop something for terminal using clojure.

someone in the discussion mentioned ed, I realized I didn't know how to use it, I'll start my study on it: Actually using ed


emacs, the editor I didn't use for quite a while:

to disable buffer coloring: m-x font-lock-mode

or put (global-font-lock-mode 0) to init, however, doesn't work for me.

Wednesday, August 09, 2017

to enable netbeans terminal key repeat under os x:

$ defaults write -g ApplePressAndHoldEnabled -bool false


tried fireplace.vim today, simple and good enough for me to write clojure, similar to emacs' inf-clojure

to start:

  1. start a nrepl by lein repl or boot repl
  2. open the clj file ane run :Connect, then enter the host and port

keys:

the flow is fater than cider and I can close the editor anytime.

Thursday, August 10, 2017

go talks has their own slide tool:

$ go get golang.org/x/tools/cmd/present

then write a .slide, in the format specified by here

run present your-file.slide, it serves your slide with http

can check Go talks repo for reference.

one nice thing of it is you can run code snippets in your slides, present also opens a websocket to receive snippet and send result back to the channel. (for php, ruby etc, remember add shebang #! on top)

Saturday, August 12, 2017

moving my hosting from digital ocean to vultr, for the same price vultr provides double memory.

I forgot how to setup servers alreay...

for 2FA setup:

$ apt-get install libpam-google-authenticator
$ google-authenticator

follow instructions to setup google authenticator for current user.

then update sshd to support it:

fist edit /etc/pam.d/sshd:

# add this line at the top
auth required pam_google_authenticator.so nullok

edit /etc/ssh/sshd:

ChallengeResponseAuthentication yes
PasswordAuthentication yes

LoginGraceTime 30
PermitRootLogin yes
StrictModes yes
MaxAuthTries 3

remember keep an active session before restart

restart sshd


I don't know how to deal with ipv6, so I just disabled it:

echo "net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1" | sudo tee /etc/sysctl.d/99-my-disable-ipv6.conf

sudo service procps reload

I always like the simplicity of ufw:

ufw default deny incoming
ufw default allow outgoing
ufw allow 80/tcp
ufw allow 22/tcp
ufw status verbose

Sunday, August 13, 2017

boot repl to start a nrepl server, then use m-x cider-connect or m-x inf-clojure-connectconnect my script to it

they both works and I don't have preference now.

there's an important function though, put it in build.boot where boot repl runs:

(defn deps [new-deps]
  (merge-env! :dependencies new-deps))

it allows me to include new dependencies without restart the repl.

Monday, August 14, 2017

watched two talks from infoq, both good:

Tuesday, August 15, 2017

to put a java program runs as service under ubuntu, save following to /etc/systemd/user/myservice.service:

[Unit]
Description=myservice
After=network.target

[Service]
WorkingDirectory=/home/user/jars
EnvironmentFile=/home/user/jars/jar_env
Restart=always
RestartSec=5
ExecStart=/usr/bin/java -jar /home/user/jars/myservice.jar

[Install]
WantedBy=default.target

then load the service file: systemctl --user daemon-reload

and start service: systemctl --user start myservice


watched two talks about microservices:

Four Distributed Systems Architectural Patterns by Tim Berglund

the first two 3-tier and sharding are really good

followed lambda and streaming are more like advertisement for kafka, ruined the whole talk.

Using sagas to maintain data consistency in a microservice architecture by Chris Richardson

this talk is a little bit more detailed than GOTO 2016 • The Verification of a Distributed System • Caitie McCaffrey


I hate writing tests, but I agree generated tests are useful and make much more sense to me.

John Hughes - Don't Write Tests is a talk about generated tests using quickcheck

from the talk I watched: Clojure Spec: Expressing Data Constraints without Types

clojure spec makes generating tests much easier

test.check is a quickcheck for clojure


I had some intensive reading on laravel, I really don't like it.

just take a look at the Authentication part.

so driver and provider, should be some classes right? where are they? I have no idea.

then you'll find internally they're passing around using interfaces (Contract in their term), where is the implementation? no idea.

finally somewhere in the config, there're relationships of interfaces and the actual implementation class, it's one to one relationship, why use interface then?

methods often come from nowhere because there're traits everywhere.

and the best practice part: don't put logics in controllers because it's hard to test, put logics in services, and no logics in models as well, repositories are the right place. views are not flexible, need transformers. seriously?

I miss codeigniter a lot, it maybe not as modern as laravel, but I don't see so many wrong abstraction in it. most importantly, it's simple.


I heard good comments about gin-gonic/gin, I'm going to give it a try.

Thursday, August 17, 2017

I'm watching clojure talks again:

clojure startup time is still a topic, Eric Normand also shares his workflow

Saturday, August 19, 2017

when I want to send a file to colleague, I usually starts a nc

$ nc -l [port] < file-to-send

then ask them to get it using nc:

$ nc [my-ip] [port] > save-to-file

however, the connect is very insecure.

I found an utility from nmap does support ssl: ncat

first, generate a new cert:

$ openssl req -new -x509 -keyout test-key.pem -out test-cert.pem

to serve a file:

$ ncat -l --send-only --ssl --ssl-cert test-cert.pem --ssl-key test-key.pem < file-to-send

default port is 31337, you can add verbose flag -v to inspect.

to receive file from another machine:

$ ncat --recv-only --ssl host-name > save-to-file

with --send-only and --recv-only, ncat should be closed the connection once done. without them, you'll need to use ctrl-c or set timeout to close it.

it's very easy. actually I was thinking to write a go program to generate the cert and serve with https. I might still do that but the priority is low now.


I really want to make my emacs works under terminal, however, it's very difficult. I have many keys rely on combination what won't support by the terminal.

Sunday, August 20, 2017

YAGNI, Cargo Cult and Overengineering - the Planes Won't Land Just Because You Built a Runway in Your Backyard

this, can apply to microservices in my opnion. the old 3-tier architecture scales pretty well, and it's simple.

it reminds me I need to dig deep into SQL.

another article is not as popular as the one above, but I like it: Small Functions considered Harmful

I prefer long and duplicate codes, before patterns are seen. wrong abstraction is bad, Spaghetti is better than Ravioli.

Monday, August 21, 2017

reading Working with Linux – Quick Hacks for the Command Line, not deep, learned couple tips from it:

encrypt file in vim

first, put set cryptmethod=blowfish (default is just zip, newer vim version supports blowfish2)

then open a file, enter :X, it asks you for a key to encrypt the file.

once you saved the file, content is encrypted. next time you open the file, enter the same key to decrypt it.

not super secure, as the blowfish method provides strong confidentiality, but no message integrity guarantees.

for emacs, by default it uses EasyPG

even better, you can highlight a region and just encrypt it by m-x epa-encrypt-region with a key.

select the encrypted region and use m-x epa-decrypt-region and enter same key to decrypt it.

once again, emacs is better :p

set default value for bash var

usually I'll just use $1 to accept conditional input for my bash scripts

I learned from the book I can set a default value by using

FOLDER=${1:-default_folder}

append the default value after :-

I won't try to remember all bash patterns, they are so weird, like

extension="${filename##*.}"
filename="${filename%.*}"

the default value one is simple and easy to remember.

Friday, August 25, 2017

I mentioned share file via ncat with ssl above, however, I still wanted to write the program.

so spent a night to develop a simple program with go: goserve

more on TLS in go: Hitless TLS Certificate Rotation in Go

by the way, Go 1.9 is released today

and Makefiles for Golang


saw this article from 2014 on hackernews today: How ACH works: A developer perspective - Part 1

The Automatic Clearing House (ACH) network is the primary way money moves electronically through the banking system today.

I'm working on a virtual currency system now, so I need to finish this series.


reading Linux Phrasebook (2nd Edition)

it is very very good, it explains linux system concisely, my understanding with linux becomes more solid after I read it.

highly recommended.

I remember I read another phasebook before, The Go Programming Language Phrasebook, also a very good one.


lisp

I don't know, I can't use car/cdr

I still want to try common lisp again, since I'm more comfortable with parentheses now.


about clojure:

and cs papers:

Ask HN: What is your favorite CS paper? | Hacker News


youtube, I watched some these days:

GOTO 2016 • Stability Patterns & Antipatterns • Michael T. Nygard

I listened to Michael Nygard on cognicast, then I went to watch his talks.

he has very deep and solid knowledge, I'm looking forward to his Release It! Second Edition

the talk is good, but if you already read release it, you'll know he will deliver high quality content.

Raymond Hettinger - Beyond PEP 8 – Best practices for beautiful intelligible code - PyCon 2015

pep 8 is style guide for python code, I don't code python, but I still found this talk useful.

your code follows style guide, covered with tests, doesn't mean it's good. good code is difficult, I'm still learning.

Blog Archive