Note To Self

nginx is super useful and easy to set up, but I forget how to set up a proxy to pass to a an internal service. This helps a lot.

Read more at Note To Self

IceDozer Review

Ice dozer! It's the bomb. I've broken two and bought replacements.

Read more at IceDozer Review

Hosting Multiple Go Websites Using Nginx

So I've obviously been playing around with Go for a little while. I'd say now I've put in like 20-30 hours of good productive learning and coding in Go. I basically rewrote the blog display of this website in Go, connecting to MongoDB and stuff, using Go html/template, downloaded Gorilla Web Toolkit (AWESOME BTW), and tried to write very modular code that can be reused for other websites.  However, there was that question of "other websites"?  Each Go program compiles into its own program, calling the http.ListenAndServe() on the port specified, which when hosted on, would have to be 80.

I was playing with ideas in my head, like having a server.exe (obviously not .exe when I run it on Linux), which runs on port 80, and listens on another port for websites to register with it.

Server.exe starts up, jtccom.exe starts up, sends a message through RPC or some other network protocol that says "Yo, sup. If you would be so kind to send requests for to me, that'd be mighty generous of you." Server.exe would make note of the domain name and port that it's running on, and forward requests to it. This could also be done through a config file as well. But that would mean writing another full featured webserver in Go. I've already done one in Node.js, in Go it would be a bit easier since it's more fully featured as a webserver (including a template engine), and seems a bit faster. It wouldn't be as much work as doing it in Node because of the fact that templates are included (if you want to see some interesting code, ask me for my Node.js template engine code). But as John Carmack once said, "I don't think I have another engine in me".

Wanting to avoid writing another web server, I googled "host multiple Golang websites" (you have to add golang instead of go since go is such a generic term).  I found this article, which is hosting Go websites with Nginx, and also covered a lot of other things I won't be doing. Using that article, I was able to download Nginx, set it up with some minimal configuration, and had two Go websites up and running successfully.  I would have commented on that article to thank the author, but it required a login.

Here is the configuration in my nginx.conf file. This is within the main server node within the config (I also like how the config file is structured)

server {
    listen 80;
    server_name jtccom;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://jtccom:8080;

    server {
    listen 80;
    server_name stringed;
    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $remote_addr;
        proxy_set_header Host $host;
        proxy_pass http://stringed:8081;

Then I was able to hit http://jtccom and http://stringed with both of those programs running.

This has a lot of implications. With Node, I was running everything as root. Since I can put these on ports 44444 if I wanted to, I can run these as a non-root user, increasing the security in the process. My other server where this site was hosted was hit with a virus or something that crashed the site for a few days.  My dev machine is on Windows, so it's not immediate and I wasn't getting the teen response time when just hitting the Go process directly, but that should speed up on Linux when the sites are ready to launch. Another implication is that I can continue down my path of fully committing to Go for future development, since the hosting issue is solved. I could still go down the path of writing my barebones server with proxying capabilities in Go if the Nginx server doesn't work out completely, speed-wise.

I'm intrigued by the possibilities in Go. Writing small code that is mind blowing, compiled, fast, runs on multiple different systems, has a huge corporate backing, and is just fun to write. My first foray into it a couple of months ago was just "Hmm... I have no idea what I'm looking at", which is my brain's way of saying "you should learn that". Fun stuff.

Chrome 37 Keeps Scroll Position On Page Reload

It's pretty neat, but I mostly refresh a page in order to quickly scroll back to the top without having to use the mouse. My workflow is severely detrimented. Page Up will do I suppose.

Web Fonts

At work we have what's called "Brown Bag Lunch", where a co-worker will give a talk about some emerging tech or strategy, or an age old thing, like someone once did Brainstorming. On Friday, our designer gave a talk about Web Fonts, and I decided to try to find one on Google Fonts that made my headers look good. I went with Mate SC. It's pretty nice.

The Power of Runtime File Combining

This can apply to any language and architecture, but I've been applying it in my Node.js programming. The idea of combining is to have all of your resources separated for development, but combined at runtime since the browser doesn't care about your structure, and fewer files is fewer requests, so the page loads faster. I did this with javascript at first, but was later faced with a huge css file, and decided to take the same approach.

So you have a tag or control or whatever your dev environment provides, where you pass it all of the files you would like to combine. On the server, if the combine file doesn't exist, you create it, writing the contents of all of the files to that single file, then you write out the html tag that points to the combined file on the server, with the correct MIME type tag (script tag for js, style or link tag for css, etc).

The "do it at runtime" version of this method takes the same list of files, but checks the modified date of each file, and compares it to the modified date of the resulting, combined file. If there's a newer version of any of the files, you overwrite the combined file. Then you write out the tag with the millisecond representation of the date modified of the combined file appended to the querystring of the file! It might look like this:

<style src="/css/combine/style.css?t=347483929" />

I'm typing on my iPad, otherwise I'd have code samples and maybe correct html syntax, if that's not correct... I don't even know :)

One from the archives

Ever notice this phenomenon:
Friday mornings usually, there will be a clear passing lane on the left side, and yet there will be a line of around 10 cars driving 50 mph in the right lane??

I call this phenomenon : Hung Over

Originally Added 7/11/2003 9:22:54 AM (I still have that database and website code... I can import the database soon for browsing)

Another gem, posted July 7th, 2004. It was about the dude at the bank being way too friendly and always wanting to talk to me. This was Bank of America (or Fleet, at the time) in Wayne, PA.

"He then has to shake your hand on the way out, saying "Thanks for stopping in!" Like, I'm gonna keep the check in my pocket and never deposit it."

God this is brilliant:
I recurse like a sailor
Added 12/29/2004 5:18:32 PM