Simon Iong

Meteor Day HK

last week, I attended a very impressive Meteor js meetup in Hong Kong.

Present your idea reactively!

One of the amazing presentation held by Chris Hitchcott (@hitchcott) is really fascinating! While at the very begining of the presentation, he ask everyone in the venue to subscribe to his presentation App using any device! ( Yep, It’s a web app, and build in Meteor! ). And once your device is subscribed ( For me, it’s my laptop ), you will have a live presentation in your device’s screen too! When chris move one slide forward, your subscribed device will also move a slide forward! This is really a reactive and creative present way for you! And if the slide in Chirs’s side is asking a question, everyone can answer this questions in their subscribed device, and within limit time set by Chris. If your answer is correct, you will win a socre, And we can have a summary up after presentation! ( Well, I am not going to tell anyone I am one of the winners in Meteor Day HK! ).

For more information about the technical stuff for Chris presentation, please refer to TapEvent

omniauth authentication with facebook tutorial

This is a basic tutorial using Ruby on Rails 4 on how to make facebook login enable in your website by Omniauth, the Multi-Provider Authentication for Web Application, and it’s very easy to extend this feature to support other service, such as using google or twitter account login to your apps.

First of all, in order to support your web application user to login by facebook account, you need to create a facebook app, and get two specific key, FACEBOOK_APP_ID and FACEBOOK_SECRET, This tutorial assume you have already got it, and then let’s build rails app first

block malicious ssh break-in attack for your virtual machine

A few months ago, I setup my personal GitLab in DigitalOcean, It serve as my personal “Github” to store my private gems, and libraries. I use so-called one key installer provided by DigitalOcean to setup this service, and it’s quite nice, since I don’t need to make my hand dirty to setup Gitlab form the very beginning.

It worked fine until a few days ago, It’s found out that my GitLab service get stuck for a little bit, and I need to restart my virtual machine to resume the service. After research for some while, an abnormal malicious ssh break-in attack was found from my /var/log/auth.log

Apr 10 05:34:32 do sshd[4846]: Failed password for root from 203.81.22.35 port 51847 ssh2
Apr 10 05:34:32 do sshd[4846]: Received disconnect from 203.81.22.35: 11: Bye Bye [preauth]
Apr 10 05:34:35 do sshd[4848]: Address 203.81.22.35 maps to mail.ckgsb.edu.cn, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!
Apr 10 05:34:35 do sshd[4848]: pam_unix(sshd:auth): authentication failure; logname= uid=0 euid=0 tty=ssh ruser= rhost=203.81.22.35 user=root
Apr 10 05:34:38 do sshd[4848]: Failed password for root from 203.81.22.35 port 52189 ssh2
Apr 10 05:34:38 do sshd[4848]: Received disconnect from 203.81.22.35: 11: Bye Bye [preauth]
Apr 10 05:34:41 do sshd[4850]: Address 203.81.22.35 maps to mail.ckgsb.edu.cn, but this does not map back to the address - POSSIBLE BREAK-IN ATTEMPT!

Automated your development environment

When MacOS have a major update every time, for example, from 10.7 to 10.8, there’s always a lot of changes with my development environments: default gcc changes, Xcode version change, and lot of others library need to re-compile, some library need to re-install using tools like “brew” or “port”

It’s really headache for me to get back to work before fix those problems. And the time to fix those dependences talk like a few hours, not a few minutes.

Recently, I am thinking to get rid of those mess with Mac OS dependence, and wanna automatic my development env in Mac OS or other OS like Windows. I have a Windows XP desktop and linux base VM, using putty from Windows to do development job at work, and also got a MacBook Pro for daily hacking or development at home. I want the same environment both in Windows & MacOS, same editor setting(vim), same ruby version ( using rvm ) and hope that I can easily reset/clone all my environment in a few minutes so that I can get back to work ASAP.

Make code better in Exception handling

This is the first post for “make code better” series, which will focus on how to write code in a clean way that every human-programmer can easily understand, maintain and extend.

The purpose of writing better code is to reduce WTFs/min during code review session

use tap when you need debug

When you try to debug in a chain methods like following example:

[1,2,3,4,5].collect { |x| x + 1 }.inject { |sum, x| sum + x }

The typical way is to break the chain block, then insert some shitty print code in the middle block, then introduce new temp variales so that it can keep chaining, one typical solution is demonstrated below:

temp = [1,2,3,4,5].collect do |x| 
           p x
           x + 1
         end
temp.inject { |sum, x| sum + x }

This always is not a good solution. When we break the middle block, it have chance to pollute x variable, and introduce new bug if we forget to change back after debug.

Actually, we can use object#tap method to make this debug more elegant. Typically usage is to inject a tap block in the debuging object, and print the object out in the tap block. In the example above, this debuging object is x of block collect.

[1,2,3,4,5].collect { |x| x.tap { |o| p o } + 1 }.inject { |sum, x| sum + x }
1
2
3
4
5
=> 20
#

tap method can inject into any object, so that we can use this method to avoid breaking out the block. and one more thing: tapped variable will not be pollute in block, so that we can avoid accidently pollute variable we are interesting with and prevent to introduce new bug during debuging.

How to stop annoying bell

It’s quite annoying when you are working on your great software and computer speaker keep beeping, which tell you that you are doing something wrong. ( Actually we don’t need the stupid computer to remind us about that, right? )

Here’s a guide for you guys to stop the annoying beeps in different tools I am working with.

© 2015. All right reserved.