Profile

Cover photo
Yan-Fa Li
Lives in Northern California
307 followers|386,749 views
AboutPostsReviews

Stream

Yan-Fa Li

Shared publicly  - 
 
Musings on Go Context

As of golang v1.7 google has integrated Context deeply into it's standard library APIs. Context is a deceptively simple but sophisticated idea. For any type of long running action, you can attach a timeout/deadline and/or values that are to be transmitted across logical boundaries in a portable manner.

For example, every HTTP Request or Response now has a default Context. This can be used to configure a timeout and automatically cancel the request or response if they take too long freeing up resources.

This is so useful, it's been wired into all of go's built in network APIs and their command execution library, making it the default way to write code which can be cancelled. This is normally a genuinely hard problem in many languages/runtimes.

That's not all, you can also stash values in one method and retrieve them later in an arbitrary later method that is invoked subsequently. For example, in HTTP servers, it's common to structure the code as a series of middleware components that decorate the HTTP request and add cross cutting concerns like user identities after authentication. This is now very easy to do with a Context. In your authentication middleware, you can validate the credential and then add a user object to the request which can then be read by later middleware or the destination handler in a loosely coupled way.

At work, I maintain a loose collection of libraries and glue code which in composite represent our REST APIs. Previously we'd been using gorilla/context; a solid pre-1.7 way to pass values between different middleware handlers in a HTTP server. As an intellectual exercise I thought I'd try and see how hard it would be to remove gorilla/context and replace it with google Context.

As it turned out it was beautifully easy. Google Context is very pleasant to use and while it wasn't quite a drop-in replacement, it was quite close. I'm also pleased how much cleaner the new solution feels. The go team always strikes me as thoughtful and pragmatic, one of the reasons I really love go, and this is just more evidence of that careful and well considered approach to software engineering.
2
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
How to DDOS yourself. At work we have people looking at large PCAP files all the time, and the other day people started complaining that the network was unresponsive and services were randomly failing.

Turns out one of our research staff was inspecting PCAPs in wireshark. Wireshark for reasons unknown defaults to looking up every IP address in the file on DNS, and does not rate limit the lookups. This DDOS'd the DNS infrastructure bring the network to it's knees as random stuff started failing.

Today I installed an unbound DNS cache, had the researcher re-test and problem solved. unbound DNS is awesome!
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
I have a keyboard fetish. Recently an opportunity to pick up a 60% gateron brown keyboard came up and a discounted price, so I pulled the trigger. I've been using it now for about 2 weeks.

This keyboard is awesome. The only change I've made to stock is I inserted rubber rings to soften the keypresses somewhat. Interestingly the key I seem to use the most is S.

It supports OSX, so I swapped the alt/windows keys via dip. I also disabled the CAPS lock key and made it into a FN key so I can get to the 2nd layer of key presses. I also reconfigured the tilda to be ESC since I'm a heavy vim user.

Pros:
* great key feel
* mechanical keyboard awesomeness
* quiet enough to use in an office environment
* small - so portable
* configurable dip switches - OSX mode, and swapping keys

Cons:
* no cursor keys without holding FN
* tilda requires 3 keys - sad for vim because I use that to change case and also a lot in git for rebasing.

I really love this keyboard. Previously I was using a KUL87, another keyboard I really love but I've switched over to this full time. I may switch back as I'm getting PBT key caps for the 87 but right now this is my favorite keyboard. Gateron Brown switches are lovely.
KBParadise V60 Mini Mechanical Keyboard (Gateron Brown). Great for gaming and typing, this KBParadise V60 features tactile switches for tactile feedback without the noise of a clicky style switch.
1
Yan-Fa Li's profile photoTravis Hayes's profile photo
3 comments
 
Some of those letters aren't even used that much. Ditch 'em!
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
Kind of pissed at apple track pads today. I had one in my office, but hadn't used it in about a year. I tried remove the battery but found that the Aluminum cover jammed closed. I even used a drill to try and remove it.

Basically another piece of land fill. Really disappointing, I even had some rechargeable batteries in there, which I can probably never get back :( I've never seen anything like it.
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
About a month ago I started using golang's vendor directory support to help resolve build problems I was having in various projects I have at work.

I'd tried using tools like `godep` before, but they always felt confusing and a bit unsatisfying. I looked at the `gb` project by the prolific and awesome Dave Cheney, but it didn't feel like a solution that worked for the general case.

More recently, I've been using `govendor`. Govendor now uses the standard vendor directory and has the features that make it just helpful and useful enough to make me use it instead of the standard `go` command.

My favorite features so far are how it helps me understand the project layout. For example, I was diagnosing a project for another co-worker, and I quickly discovered it was a bad idea to nest binary builds underneath library paths.

Govendor helped me understand that with it's helpful flags. Switching the cmd/ pattern solved the issue and allowed me to proceed with the build. It does feel somewhat heavyweight to include all the 3rd party libraries in the same repository, but the speed up and consistency in build times is appreciated.

Govendor also supports some useful features, like pinning branches, and including sub-directories containing non-go code like sqlite's C bindings. Overall this is the tool I'll be using for now, as it makes me life as a developer somewhat easier; all this of course coursed by Golang's reluctance to have a versioning system built in; hopefully this will be addressed by Go v2 in the distant future.
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
Performing my first major hardware replacement on a ZFS on Linux RAIDZ2 array. So far 1 drive down 5 drives to go. I'm replacing Western Digital Reds which have survived 3.5 years of service with only 1 outright failure. This time I've decided to go with Hitachi Megascale 5900RPM drives.

I spent 4 days burning the megascales in using 4 passes of badblocks, so I think they are beyond infant mortality issues. The first drive I replaced took 5 hours to resliver 1.2TB of data.

At this rate I should be done this weekend, which would be a nice bonus. The documentation on replacing individual drives is a little bit confusing. This is the process I used.

1. `zpool offline zfstank <disk-path-name>`
2. Physically eject the drive from bay
3. Insert new drive into bay
4. `parted <full disk dev path> mklabel gpt`
5. `zpool replace zfstank <disk-path-name>`

Wish me luck.

1
Yan-Fa Li's profile photo
 
OK, all done. It's reslivering the last drive. I also discovered I'd never removed a failed drive and was still using a 4TB replacement. The 4TB has not become a hot spare, since I now have 3 and 4TB drives in the same zfs tank. I believe this isn't recommended, but for my uses it's probably ok.

ZFS is much slicker than I remember the process being under LVM and/or RAID. Of course these days I'm running much better HBA hardware too so that's probably a factor.

Also zero'ing out the old drives before recycling. Don't want to end up as part of a study in bad recycling hygiene.
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
Neat little hack that can save you quite a bit of money if you are into building storage arrays on the cheap. The important cliff notes.

1. use the utilities in the article, don't use the ones from LSI they are designed to not let you do this hack
2. use the firmware binaries in the zip file, they include both the files from Dell to revert your RAID controller to a stock HBA and the latest working firmware from Avago/LSI, version 19.

I payed over 250USD for one of these controllers about 4 years ago. They can now be had for about 50USD used. Flashing them with the IT firmware turns them back into plain Host Bus Adapters (HBA). If you have interest in ZFS this is what you want, not a RAID adapter; as it gives you full access to the SMART data on the drive.

The SAS to SATA cables cost about 15USD on monoprice and come in lengths from 0.5 to 1 meter. So basically for 80USD you can get a very high performance 8 port SATA card.

Only major downside to these devices is power consumption and heat. They use about 10w of power and generate a lot of heat. I usually put some active cooling on them in the form of a fan above the PCI slots.

They do require a 8x PCI slot, so you may not be able to use them in all consumer motherboards unless you are willing to sacrifice a 16x slot. However, if you are running a ZFS file server, you already know you should probably be using something with ECC RAM if you expect to have good data integrity.


Please visit the updated guide here: UPDATE: I’ve updated this post as of 2013-09-21. I’ve removed parts about the IBM M1015 and focused more on the Dell H310 and H200. I’ve also …
1
Add a comment...
In his circles
170 people
Have him in circles
307 people
constant flow currency's profile photo
Kamil Travnik's profile photo
khadija anjos's profile photo
Pak' Patsaporn's profile photo
Walter AltamiranoHz's profile photo
Renu Dixit's profile photo
Tiffany Mitchell's profile photo
Jordan King's profile photo
lauriane reis alves's profile photo

Yan-Fa Li

Shared publicly  - 
 
Switching to golang 1.7 was a bit awkward for me for two reasons. 1 I was using context which has now been promoted to stdlib. 2. I was using vendoring via govendor and at first it didn't seem like it would work.

To prevent other issues, I had disabled go1.7 support in govendor, so to make it work I had to:

1. remove the go1.7 flag from ignore
2. remove and re-add the context and net/http2 libraries

Then I was back in business. Much easier than I had expected. Good job, though I wish there had been better instructions on how to do this transition, so I'm sharing what I learned here.
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
For sale on Swappa: a gently-used BYM002 Moto X 2014 Pure Edition (Unlocked) for $210. Buy safely on Swappa and save time and money.
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
+Chris Wadge​ happy birthday old man
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
Golang mystery finally understood. So something I've always struggled with in go is how to deal with non canonical source code repositories. E.g. private github repos or github enterprise.

Go actually has quite an elegant way to deal with source code repos served over http if using meta tags in the content. This doesn't work though if you use SSH to access your repos.

Turns out there is a solution since go1.4 that I completely missed. Firstly you need to add a rewrite rule to your gitconfig which takes an https address and converts it to SSH style requests. And then you have to rewrite all your import statements to end with .git

Then magically, go get works. This means tools like govendor work properly and your entire workflow becomes go like rather than an exercise in frustration. I'm kind of chuffed I've finally figured this out. It's not immediately obvious while reading the docs. They really need more examples.
1
Add a comment...

Yan-Fa Li

Shared publicly  - 
 
Finally upgraded my ancient Core 2 based hackintosh to El Capitan. Color me surprised, it actually works. I really like the new approach to booting the OS via an EFI layer. It actually goes to sleep and wakes up and seems to be working well for a processor created in 2007.

This is a good use for obsolete hardware and gives our kid a family computer for doing his various school assignments. Looks like I'll be able to squeeze another year out of this hardware, which is even better.

The toughest part of loading OSX (MacOS) onto the system has remembering to turn off nvidia support during install and remembering to set the system as MacPro3,1. Without those 2 changes the kernel would panic.

I'm really impressed by the folks at tonymac86 and have sent them a donation.

#hackintosh #recycleoldhardware  
1
Add a comment...
People
In his circles
170 people
Have him in circles
307 people
constant flow currency's profile photo
Kamil Travnik's profile photo
khadija anjos's profile photo
Pak' Patsaporn's profile photo
Walter AltamiranoHz's profile photo
Renu Dixit's profile photo
Tiffany Mitchell's profile photo
Jordan King's profile photo
lauriane reis alves's profile photo
Places
Map of the places this user has livedMap of the places this user has livedMap of the places this user has lived
Currently
Northern California
Previously
U.K. - Deutschland
Links
YouTube
Contributor to
Story
Tagline
Pragmatic Programmer
Work
Occupation
Front-End Developer
Skills
Swiss Army Knife
Basic Information
Gender
Male
Public - a year ago
reviewed a year ago
Very fast, in and out in half an hour, including a quick oil change, recommended because I'd already hit the maintenance indicator. 30 for the oil change, 40 for the smog. I would use him again.
Public - 3 years ago
reviewed 3 years ago
Food: Very GoodDecor: GoodService: Good
Public - 3 years ago
reviewed 3 years ago
Delicious Taiyaki
Appeal: ExcellentFacilities: ExcellentService: Excellent
Public - 3 years ago
reviewed 3 years ago
24 reviews
Map
Map
Map
Really great place. They are nice, friendly and obviously take a lot of pride in their work. Rosanna is an excellent stylist.
Public - 3 years ago
reviewed 3 years ago
Disappointing nabeyaki udon. All veggies, no egg, layered flavor or tempura. One note dish.
Food: Poor - FairDecor: Very GoodService: Good
Public - 3 years ago
reviewed 3 years ago
Delicious. I ordered the Falafel plate, Greek Salad and Hummus plate for 2 adults and a child. The food was fresh and very tasty. The Falafel are not a style I've every tried before, and are really tasty and different from other Mediterranean places. The hummus was creamy and really excellent. I will definitely eat here again.
Public - 3 years ago
reviewed 3 years ago