Tuan Anh

container nerd. k8s || GTFO

Theming Apache's mod_autoindex directory listing

By default, your shared folder with mod_autoindex enabled looks like this.

apache fancy index

The icons looks like they were from Windows 3.1 era. I am by no mean a designer but looking at this seriously make me want to vomit.

I decided to take a quick look at mod_autoindex’s documentation and grab some free icons from Dribbble to make it better.

Turns out, it’s easier than I thought. Theming is supported out-of-the-box with mod_autoindex. I just have to copy some icons (frequently used file types) and add a few lines in my Apache’s vhost config. I can even inject CSS too. Every element already has proper id and class so I can just inspect the page and customize to my liking.

IndexIgnore /_theme # hide _theme folder
AddIcon /_theme/icons/blank.png ^^BLANKICON^^
AddIcon /_theme/icons/folder.png ^^DIRECTORY^^
AddIcon /_theme/icons/upper_level_directory_icon.png ..

AddIcon /_theme/icons/image.png .png .jpeg .gif .jpg
DefaultIcon /_theme/icons/fallback_icon.png

IndexStyleSheet "/_theme/style.css" # injecting CSS
HeaderName /_theme/header.html # customize header
ReadmeName /_theme/footer.html # footer

Here’s how mine looks like after.

apache mod autoindex

If you’re too lazy for this stuff and just want a decent looking theme, take a look at Apaxy. Follow the installation instruction there.

Some of the most useful tips I learn when working with NodeJS

modules management with npm

Nodejs comes with an amazing package manager called npm. Start a project with npm init which will then create a configuration file named package.json, keeping track of all the modules your project is using. You don’t have to manually manage this file yourself. If you want to add a package to package.json you can add --save parameter when installing it.

npm install koa-static --save

Also, you should ignore npm_modules folder when git push because whoever clone the repo can do npm install by themselves. npm_modules folder can grow pretty big so no one would want to git clone the whole thing.

pm2 instead of forever

When you start learning about NodeJS, you may notice that node process may exit unexpectedly when errors are not handling properly. forever is a node package that ensure node process will run continuously in the background. But forever is very limited. It doesn’t have support for clustering, very limited logging and monitoring.

I later found out a much leaner solution called pm2. Compare to forever, pm2 looks like a full solution for deployment with builtin clustering support, terminal configuration and better logging support. In fact, ever since, I only use pm2 for my production server.

Enabling clustering with pm2 is as easy as

pm2 start app.js -i 0

Using 0 means that pm2 will utilize number of threads equals to number of your CPU’s cores. You can specify the no. of child process as you want, ideally one per processor core.

As for local development, I prefer nodemon to keep track of changes in my application and automatically restart the server.

Fuck callbacks

For starters, callbacks are nightmare. Many popular frameworks still make use of callback heavily which creating the sense for newbies that it is the correct way of doing things in nodejs. It’s not. Over the last 2 months, I’ve started using Q, async, bluebird and then generators. Of those, generator seems to be the most elegant solution, producing much more readable code than callbacks.

Debugging with node-inspector

I’m pretty sure most nodejs starters will use console.log() everywhere to debug the application. I did that. It was ok for quick debugging but sometimes, you need a little more than just console.log. node-inspector is a node package based on Blink Developer Tools that let you debug right in your favorite browser.

Install node-inspector and use node-debug app.js for debugging.

npm install node-inspector -g
node-debug app.js

The end

These are some of the things that I’ve learnt in the last 2 months working with nodejs. Nodejs is an amazing platform but it can be a pain sometimes. These tips save me a lot of times and make developing in nodejs so much more bearable.

Install io.js on Mac OS X

I believe iojs is not going to be a flop. Look at the current development rate, I would say iojs would replace nodejs eventually if Joyent not doing anything to turn it around.

I prefer to install iojs with nvm instead of the default installer package on iojs’s homepage since it allows me to switch between node version with a single command.

As of current, iojs is basically a dropin replacement for nodejs so you don’t have to worry much.

Install iojs

Install nvm - a node version manager with homebrew

curl https://raw.githubusercontent.com/creationix/nvm/v0.23.2/install.sh | bash

Install iojs with nvm

nvm install iojs

Add these lines to your .zshrc or .bashrc

export NVM_DIR=~/.nvm
source $(brew --prefix nvm)/nvm.sh%

Set iosjs as the default node version

nvm alias default iojs

You can check again with which node to see which version of node is using.

Things software developers wish they had known in their 20s

  1. The era in which a common career trajectory is to become a lifer at some software company and work one’s way up to higher and higher internal positions has been over for a long time (This era had already been over in the 1990s when I was a young programmer).

  2. You don’t owe the company you work for anything beyond what you put your name on when you signed the employee agreement.

  3. Don’t stick around too long if the place you are working for isn’t doing much for your bottom line, is not your dream job, and isn’t adding anything new to your resume; that is, the easiest way to get a promotion and a substantial raise is to switch jobs. Don’t switch jobs if you like what you are doing but also don’t stay somewhere only out of loyalty to a company.

  4. If you think 2. and 3. are cynical and if looking at things this way makes you feel like an asshole, console yourself with the knowledge that the company you work for views you in exactly the same way and will act on such a view in a second if it is in its interest to do so.

  5. You can usually skip all hands meetings even if they are supposedly mandatory.

  6. Keep an eye on corporate politics. Being a successful computer programmer is about social engineering as much as it is about software engineering.

  7. Make sure you are at the meetings at which the scope and/or requirements are defined for any piece of software for which you are going to be responsible.

  8. Don’t go dark. Check in code often – with stubs or whatever if necessary. It is better to check in code sooner rather than later despite the fact that doing so might entail dealing with transitory problems. A few hiccups now are better than a gigantic merge conflict down the line.

  9. Be careful about your estimates on dates and on how long things are going to take. Understand that the whole game is about dates. When in doubt just triple what you actually think even if it secretly sounds absurd to you.

  10. Don’t be religious about languages, libraries, or platforms.

  11. Except for Perl. Perl sucks.

  12. At a certain point it is you the programmer who will decide when things are done, even if it isn’t officially supposed to be your decision. Ultimately there is a point before releases when you have to push back at PM or whoever and say, “What you are asking for is not a bug fix – it is a feature request. We are way beyond the point at which we can even be considering introducing new features” It will always be you the programmer who does this because no one else will.

  13. Don’t check in a lot of code right before a vacation or long weekend.

  14. It is easier to not get assigned to something that you don’t want to work on than it is to get out of it after it has been assigned to you. Trust your instincts regarding death marches. If some project doesn’t feel right, don’t get assigned to it.

  15. If you find yourself working for a place at which there is a manager who is printing out burn-down charts and hanging them on the wall, start looking for another job.

  16. Working for big companies/name software companies can suck more than you can possibly imagine. Just because your friend who works for Company X is always bragging about the rock climbing wall doesn’t mean that Company X is a great place to work.

  17. For all but the simplest cases, prefer recursive descent parsers over regular expressions.

  18. Get good at debugging and learn to use a profiler.

  19. Focus on making your way into a position in which you are doing what you like software-wise while you are young and can more easily take risks.

  20. Don’t break the build. If you do break the build, don’t make a lot of excuses – no one cares – just fix it quickly.

Source: Quora.

In order to get link without Quora censoring stuff, just add any ?abc= in the url. My personal favorite is ?fuck=you, in the hope that it will be popular enough to show in their log someday :D

How the Other Half Works: an Adventure in the Low Status of Software Engineers

Bill had been a Wall Street quant and had “Vice President” in his title, noting that VP is a mid-level and often not managerial position in an investment bank. His current title was Staff Software Engineer, which was roughly Director-equivalent. He’d taught a couple of courses and mentored a few interns, but he’d never been an official manager. So he came to me for advice on how to appear more “managerial” for the VP-level application.

A fascinating read by Michael O. Church. Lots of advices on software development careers.

Great blog. Subscribed!

link bài gốc

How movies could change your perception

It’s interesting how much movies can change our perception: survey asking people in France who contributed the most to the defeat of Nazi Germany.

sondage nation contribue defaite nazis

link bài gốc

Fix WELD-001408 unsatisfied dependencies for type error when deploying to GlassFish

Took me half an hour today to figure this out when deploying to production servers. Apparently, the CDI extension loaded from a JAR in a WAR, thus different classloader, makes it uninjectable.

The problem can be fixed by simply disable implicit CDI on GlassFish

${GLASSFISH_HOME}/bin/asadmin set configs.config.server-config.cdi-service.enable-implicit-cdi=false

REST APIs made easy with StrongLoop

StrongLoop allows you to quickly create REST APIs using their graphic interface and CLI. SLC also supports debugging, profiling, tracing, deploying as well as monitoring features.

Creating REST APIs with slc is as easy as creating datasource and model. StrongLoop will do the rest for you.

I was very tempted to use StrongLoop for a recent project but I had to deal with a legacy database that use a very old odbc driver which force me to use node.js and express.

link bài gốc

Microsoft HoloLens

microsoft hololens

Microsoft is really on a roll lately. They are on the right track to regain their cool factor among devs. The device looks truly impressive and based on what we know so far, it looks a lot better than Google Glass and Oculus Rift.

When you change the way you see the world, you can change the world you see.

It’s interesting that Microsoft calls this holographic technology instead of augumented reality. Though it’s not technically correct, they’ve got themselves a better brand to distinguish their product.

There are zillions use case for this kind of technology: healthcare, entertainment, education; you name it. Just to name a few that pop up in my head real quick.

  • expert coaching

  • training

  • modelling

  • gaming

  • millitary applications

  • etc …

Not to mention, whenever a technology like this is introduce, people will find a way to use this in adult entertainment.

Let’s just hope that Microsoft will not overpromise like Google did and let it ended up where Google Glass is now.

link bài gốc

Create a contact form with jekyll

Since jekyll blog is static, we have to rely some some kind of service endpoint to send email to our mailbox. Good thing is that there are plenty of services for this purpose: heroku for free hosting and mailgun, mandrill or mailjet for sending email. Pick one of your choice.

I did a quick search before firing up Sublime Text to create a simple app for sending email and luckily, someone already wrote one. One less thing to do :)

Create Heroku and a Mandrill account

Sign up an account at Heroku. Download and install heroku toolbelt while you’re at it.

For sending email, you can go with Mandrill, Mailgun or Mailjet. They all come with free plan which is more than enough for personal use. If you pick something other than Mandrill, you will have to edit the app a bit use their own libraries. If you’re lazy, just go with Mandrill.

Install the app on heroku

heroku auth:login # enter your account credentials when asked

git clone https://github.com/ousenko/simple-contact-form.git
heroku create <YOUR_HEROKU_APP>
heroku config:set MANDRILL_API_KEY=<KEY>
heroku config:set USER_EMAIL=<YOUR EMAIL>
heroku config:set USER_SITE=<YOUR SITE>

git push heroku master # deploy

Create contact form on your website

Create a page with simple form like below. I’m using Bootstrap for my blog so styling is just a matter of adding a couple of CSS classes.

<form action="https://<YOUR_HEROKU_APP>.herokuapp.com/send">
  Email: <input type="text" name="name"><br>
  Name: <input type="text" name="email"><br>
  Subject: <input type="text" name="subject"><br>
  Message: <textarea name="message" cols="40" rows="5"></textarea>
  <input type="submit" value="Send Message">

Adding reCAPTCHA (optional)

Sign up for an API key pair and add it to your page. I don’t have a need for this, personally.

Here what’s mine like

contact form with jekyll