Category Archives: Uncategorized

Where can A Malaysian get Electronics Components

One of the common question from people interested in Arduino or doing electronics with the Raspberry Pi is where do I get components.

Here is a few places that you can get your components. I will only cover local source, not sites outsite Malaysia, though they can be a good source.

  1. Jalan Pasar at Pudu. Not newbie friendly, but it is a go to place to get components, but no arduino and raspberry pi though. You need to do your research before getting stuff there.
  2. Cytron, their online store have a very good collection of item, from components, to tools to dev board like arduino, pic, and raspberry pi.
  3. MyDuino is a local store specialize with arduino and drone, they also sell 3d printers. These folks are very active in the local arduino community.
  4. Element14 is also a popular place for local enthusiast.
  5. RS Online is also another of the popular one.
  6. Community site such as the Arduino Malaysia Facebook group on facebook occasionally have members letting their stuff go, it worth checking it out.

I only been through cytron and Jalan Pasar personally, the rest just from my friend that also into electronics.

I hope the brief guide can be helpful



Ping Pong with gevent, socket-io and flask

So recently one of my project allow me to have experience on gevent-socketio. While the code is open source, it can be complicated. Thus the example I show here, while not serious hopefully will make things easier to see.

You will need these dependency,

Before we can start to create a view for socket-io you will need to define the namespace to be used

The gevent-socketio library uses Namespace as the view logic, all the logics will be in a namespace, along with namespace, there is also Mixins that is built on top of namespace that provide extra functionality, gevent-socketio provide BroadcastMixin and RoomMixin, which is useful.

line 3: We create our namespace by subclassing Namespace Class

line 4: This is method defined by us. We prefix on_ to an event that we want to process. In this case it is the ping event. The event will be send from socketio client. The parameter attack, that is essentially the payload that we will be receiving, and we don’t need to do any conversion from json to dict, as the library handle it for us.

line 7 and 9: Self.emit will emit an event to the socketio client, again the dict, is the payload that will be sent, no converstion to json necessary.

Now we can finally define a view

This is the view for socketio. app is just your standard flask app.

line 7: is the route necessary for the socketio client to connect

line 9: this is the same across socketio app, the difference here is the namespace ‘/pingpong’ and the namespace PingPong, that you will need to define yourself.

Now to serve this guy

line 6: this will be the line that serve the app. It will serve all the views include the non-socketio one.

I will skip the view to render the main page and the html, I will focus on the javascript alone.

line 2: This is how you define a socket io.connect(‘/namespace’)

line 10: We bind a javascript click an event, to send an event we use socket.emit(event,data). data will be a javascript object, event will be a string, notice the on_ping method on the Namespace we define on top.

line 3: As the socketio server emit a pong event, this will event handler and do something with it in callback. Again don’t worry about conversion, the data is converted into a javascript object.

Hopefully this will make things slightly clearer. Btw the example on github.


List on Tech Initiative for Good in Malaysia

I have been involved in Sinar Project for some time. Along the way we have found similar initiative, different approach but using tech for doing  good thing in general. Some are commercial, some are voluntary citizen initiative.

None of these are with sinar project.

  1. Jom Pantau is ushahidi installation, for reporting election issue in Malaysia
  2. An election websites
  3. Malaysia crime
  4. Do something good for linking volunteers to organization
  5. eparliment

Project sinar project that we are currently working on

  1. Malysian Representation
  2. The api from reps project.
  3. Curruption
  4. Billwatcher.

Got a feeling we going to have more on the list.


Reading Data Analysis With Open Source Tools



Data Analysis with Open Source Tools
Data Analysis with Open Source Tools

Recently I have been reading the book Data Analysis with Open Source Tools, by Philipp K. Janert. This is a book for anyone that is working with Data. Partly because of the big data buzz, partly is the work I do in Sinar Project. But this is not a book on big data, just data analysis in general.

Unlike other book that deals with data, this don’t cover specific tools, rather use tools as a example, and this books covers a few. But this book focuses on experiences and methods of doing data analysis.

The book have 18 chapter, covers a variety of topic, from statistics, to simulation, clustering etc. Each with enough theory to understand, enough insights coming from the authors experience, enough hands on from demo for us to pick up from there.

While this book don’t covers tools comprehensively, but the method, insights in this book make it worth keeping as a reference for doing data analysis.

Adventure in Overriding Python Str

Recently I have given a project where we are overriding the python str object, I rather not say the reason because it is job related. But the process of it is pretty general, and is pretty interesting.

So here is an example.

A few thing to take note here.

  1. Notice that there is a __new__ method? In python object lifecycle, the first thing to be called is actually __new__ not __init__. __new__ will choose whether whether to replace __init__ or use a new one. In this case, I set the current object cls to str, with value bleeped
  2. Now if object is not setup in __new__ yet, how do object access the bleep method? Introducing, classmethod. Classmethod is a method the bind to a class, not an object. This is useful if you want to do call a function before a class is initiated.
  3. Classmethod binds to the child class, not the parent class it inherited from, and you need the first parameter to be a class. It can be set with a @classmethod on a method
  4. Now because we also want the string to be appended to BleepedString object, to also be bleeped, so we need to override __add__, so when string appended via + operator, will also be bleeped. Interestingly __iadd__ is not inherited, so I need to add __iadd__ method too, so that I can do +=
  5. Notice that inside __add__ I use bleep method like a normal method. That is the reason is set a @classmethod decorator in bleep method, I need the method to be available without need to be instantiated, while able to use it like a normal method in a object.
  6. Actually just override __add__ and __iadd__ is not enough to override the str behavior. Because the parent class str uses __repr__ to provide value to be used in a + and += operation, which is why I override __repr__ method, by replacing the return value to bleeped string.
  7. Then we need to override __str__ so that it return a bleeped string.

This is just a modified example what I used in my work, and have a very different and useful function. But it capture the same idea, overriding the default string behavior and return value.


Long time no post

A few thing happens in between,

  1. Construction Industry Development Board dataset have been release, you can find it here.
  2. CPB is not dead, and the survey is over for long time, in which I too participate. Waiting for the parliament to see how.
  3. I have join Julython with a new project.
  4. Python Meetup Malaysia coming next 2 week. And still going on
  5. Join pycon, and realize that I am still interested in big data.
  6. Join Super Happy Dev House, know some very awesome people there.
Btw my project sinarproject begin to be known to more people. I most probably juggling between day job and this. So will be more busy doing than actually blogging. 


Python Malaysia Meetup April 2012: The Report

So I have organized a python Malaysia meetup in hackerspacekl last weekend. It is a good crowd, within we have developers that uses Django, Bottle and Plone to share their experience in using their respective technology stack.

The group is a diverse one, from experienced developer using python for sometime, to new python user. We have the usual introduction, then we have introduction to Python Malaysia.

Then a talk by Yours Truly, on experience of using bottle micro framework and pyes.


Then have a talk on Mezzanine by renyi khor


And Felix shows us how one can use to use tornadio to provide for django apps. Which is awesome, actually. Again no slide, but the repo is below

and Finally a talk by Khairil Yussoff, which is about Plone Dexterity framework, and also plone development in general. He don’t have slides, but he did hands on demo on plone development and how things work.

Then in between we have some networking session. Which is good, because this meetup is not just about Python, it is about the people that uses or want to try/use it. We have everybody not just the presenter that share their experience, which is awesome.

In the end of the day, this is a good event(I hope). But by July, will finally be updated, things will gone more smoothly for us.

Notes: A few times running an event I still can’t get it right. A few thing is missing is, video, proper photo, groups shots, etc. Maybe I should add a list.

p.s The next meetup will be on May 26, in MindValley, just beside Bangsar LRT station. Detail is

[pe2-gallery class=”alignleft” ] IMG_20120421_151710.jpgIMG_20120421_151700.jpgIMG_20120421_151644.jpgIMG_20120421_151634.jpgIMG_20120421_151459.jpgIMG_20120421_151453.jpgIMG_20120421_132859.jpg[/pe2-gallery]


Thus The Bill is dropped..For now

As from the link above, the Computing Professional Bill is dropped for now, asking for the industry to sort it out first. The war on it is not quite ended. One reason(or excuse depends on which side you pick) of the existence of this bill is the dropping of quality of IT professional in Malaysia, and the quality of project I suspect. Registering people will definitely not helping in bringing up quality.

If one of the measurement of quality is how much we knows. Then browsing the Malaysian job sites, I come to the conclusion that we don’t know that much. Almost all job revolve around .net and php, with a few php and c/c++. Yet we knows that the industry is more than that. I mean where is the job on python, ruby and rails or node.js, where the job for CMS’es?

Does it mean that the industry in Malaysia don’t know about it? Gone to local tech meet up, only a few that use stuff that is not PHP and .net. When people develop a buzz in nosql, or node or devops etc. Where is the Malaysian? Are there only that few people will blog about this? Are there only that few people that can go to the meetup, join communities? Are there only that few people in this neighbourhood that cares about this?

Maybe the real problem in IT in Malaysia, it is really just that most of the people involve in IT in Malaysia, don’t care. That even with help of a legislation, it doesn’t help improve it, but only to make things worst.

p.s This is very programmer specific, I apologize. But this is the group of people I have seen the most.

p.p.s Yes I know hack weekend exist, but there is only one hackathon in the whole Malaysia?

Note on using cron

Edited:1)From @sureshdr on twitter, My cronjob generate too many entry to log, so updated both on the server and the post with >/dev/null 2>&1 at the end of the job.

First time have to produce an app, and maintaining the server all by myself. Previously can work with the sysadmin, now the guys in sinar is pretty busy with a day job.

So first thing first, the thing with virtualenv is, running it in a cron job can be a pain(it is not that bad). Well, billwatcher is using buildout, so it uses less command, buildout have pretty much an isolated environment. So it look like this, more on why I don’t direct to /dev/null:

0 0 * * * /path/to/Malaysia-Bill-Watcher/bin/python /path/to/Malaysian-Bill-Watcher/billwatcher/ >/dev/null 2>&1

Second thing is, the last deployment, I didn’t add a full path to the sqlite database. This is important, so that the data is written in the right place.

Third, because this is my first time running cron(don’t ask why). I finally found the log file to cron.

less /var/log/cron

Except, my cronjob is run at midnight, and a few cronjob run already. Then I found zcat, because the older cronjob is /var/log/cron.n.bz2. n is the number.

zcat /var/log/cron.0.bz2|less

I read it, make sure it is running, I’m happy, then I realized that I kinda polluting the email on my system which I don’t read often. So comes the MAILTO directive. Thus my final cron job look this way

MAILTO=”[email protected]
0 0 * * * /path/to/Malaysia-Bill-Watcher/bin/python /path/to/Malaysian-Bill-Watcher/billwatcher/ >/dev/null 2>&1

And the newbie sysadmin live happily ever after… Until something else break, and there is a new project coming soon…

p.s running billwatcher at midnight is a bad idea, might be a better idea doing it in the morning..