More things in life does not always leads to a good quality life. If the things is duplicated, its function is already done by something else, it's existence is a clutter and use up unnecessary energy. The duplication is bad in code too, it is a nightmare to maintain the same logic that scattered on several places. One changes on one place need to be repeated on the other ones that use similar logic, otherwise you'll break the code.
Having enough things is not just about living a minimalistic lifestyle, it also a way to stay sane, to not use things unnecessarily. If we can simplify things internally, we can achieve more complex meaningful things with much ease.
Thursday, September 26, 2013
No Duplication for a Good Code and Good Life
Diposting oleh
Hafiz
di
Thursday, September 26, 2013
0
komentar
Label: coding, miscellaneous
Wednesday, September 25, 2013
Bootstrap : Programmer's Friendly Web Front-end Framework
I had task recently to port some web content into a mobile App. I translated some web-navigation navigation into native mobile one. For example, some section listing is translated into TableView in iOS. However, for the content pages itself I need to basically put the HTML content into an offline-bundled resources within the App.
Below is some problem with the task :
- The Desktop version link to various online Javascript and CSS resources
- The layout is for desktop and need to be made more mobile-friendly
The content of bootstrap pretty much suffice for the current typical need for multi-device HTML rendering. At least with it I can port the existing Desktop-based content pretty quickly for offline mobile consumption. The styling and layout is already fit out-of-the box to my need. I can strip the existing Javascript and CSS references and make the content use things from Bootstrap. There is still some labor work on the porting but doing on top of a good foundation makes it more manageable.
Diposting oleh
Hafiz
di
Wednesday, September 25, 2013
0
komentar
Thursday, September 12, 2013
JEdit : One Text Editor to Rule Them All (Functions and Platforms)
Any programmer would say his favorite text editor is the best one so I won't bother saying which one is best :). However, I do use one text editor, JEdit, for quite a long time already and find it a really useful text editor. Below is some of the reason :
- It does "everything" I can think of and more. It has a rich plugin list and so far I haven't find any of my needs that is has not met. Apart from coding which I do mainly on IDE, I use JEdit for the rest. Editing and Viewing binaries with it's Hex editing plugins, Editing XML even using it as a full-fledged IDE for some language e.g: Ruby, Python.
- It runs on all Platform. One of my main priorities of text editor is it needs to to be able to run on OS that I use. I did works on Windows, Mac and Linux so having text editor that can run on all of them is a big requirement for me. It saves a lot of time to be familiar with one advanced text editor and can run it on all system. The time you spend customizing the configuration, learning the shortcuts will pay off really well.
Diposting oleh
Hafiz
di
Thursday, September 12, 2013
0
komentar
Label: system
Wednesday, September 11, 2013
Code for your future self
It's quite annoying to work on existing code that you find hard to navigate and understand. It makes you spend some significant time first to understand the existing structure before you can finally add the feature or fix bug you intend to do in the first place. It does not have to be the code written by someone else, even your own code can give you some hard time when you revisit it again at the later time.
That is why the importance of writing good code is not just so the features runs well and the code looks good to your peer. It is also for your own benefit to have the code done in a well-designed and intuitive way at the moment you wrote it.
There will be temptation to code something quickly when deadline is approaching or you just feel lazy to extract those abstraction that you find. For your own sake, resist them and write code properly in the most natural and the most obvious way you can think of it. Your future self with start with that kind of intuitive thinking before he jump into specialize cases, workarounds and other tricks.
Here is an example of the things you can do to minimize the pain of your future self coding session :
- Choose good naming. This is simple and highly essential but easy to break at the time when you feel lazy or under pressure
- Have all the dependencies locally and self-contain whenever possible. For all dependencies that you can not put locally, put detailed documentatio on how to get it
- Automate and simplify the build system. Again document unscrypted steps extensively
- Make notes and diagram on general architecture. Give high level diagrams and don't forget to update them when it no longer reflect the actual code. Do not go into too much detail on this. Focus on describing the big picture of architecture on the notes and diagram and let the code speak for itself whenever it can
Diposting oleh
Hafiz
di
Wednesday, September 11, 2013
0
komentar
Label: coding
Tuesday, September 10, 2013
Focus on Personal Workflow and System, Not Gadget and Apps
Gadgets and Apps are abound today and the discussions that runs mostly are about what Gadgets can do this and that. I think many times the focus are misplaced. Gadgets are just tools and what is most important is the personal system workflow that a person has. Without that, gadget has no context and will just be a distraction with each additional feature. However, when you have system, each feature on the gadget can use to improve certain aspect of that system.
When you have a workflow involving calendar and reminder, a good calendar app can make that part of your system more optimal and in turn will make the overall system runs better. However, when you don't have need for calendar in your personal workflow (which is not a sin, BTW :) ) it will be just a toy to try a little bit and never used again or worse you keep keep wasting time using it without adding any benefit to your system.
So, I guess what matters is what system that you have and what combinations of gadgets and apps that can make it runs better. Researching new gadgets and apps can be useful if you use it to see how you can improve your existing system with it.
Diposting oleh
Hafiz
di
Tuesday, September 10, 2013
0
komentar
Label: system
Monday, September 09, 2013
Winforms C# : Prefer initialization in constructor instead of Form_Load event handler
On Windows Forms, I have been doing initialization of values on Form_Load event handler. I use constructor mostly for make instances of member variables and setting basic/default values. I did the rest of the settings e.g: config, last state, on Form_Load. It turns out that it's not actually a best practice to do so.
I've just stumbled upon this discussion on Stack Overflow that explain that it is actually better to minimize the use of Load. In summary, here's the guideline on Constructor vs. Load issues :
- Initialize things on constructor
- Only use Load for code that needs valid windows handle e.g: code that requires the window size and location to be known
- Override OnLoad instead of using Form_Load event handler. This ensure more deterministic order of execution in relation to parents OnLoad call
Diposting oleh
Hafiz
di
Monday, September 09, 2013
0
komentar
Friday, September 06, 2013
When You Know Better, Code Better (In the meantime, code it the best you know how at the moment)
There is a good, albeit very short, article on Lifehacker titled "When You Know Better, Do Better". The important take of the article is actuall the message "Do the best you can with what you know now".
There is always a better way to do anything. If we got preoccupied wondering if this is the best we can do right now we'll get paralyzed and nothing will get done. Even worse, when we finally decide to take action anyway, we might take less optimal approach due to self-doubts.
I think this is even more apparent in programming world. There are literally thousands of choices available for us to solve a programming problem. From libraries, frameworks, patterns, languages, text editor, diagram tools, we will probably won't do our best work if we agonize over what is the best that is available.
Referring to the advice above, we could focus our search for the best on what we know already at that time. We will learn new things along the way and at later moment we can do our best again with our knowledge at that time and repeat. I find this quite liberating and help a lot to minimize the noise on the head while coding. I can focus to produce the best work with what I know at the time. I'll do better when I know better.
Diposting oleh
Hafiz
di
Friday, September 06, 2013
0
komentar
Label: coding
Thursday, September 05, 2013
Diagram Smell and Refactoring
My use of UML for reverse engineering the existing code perhaps the same amount as my use of it for designing codes to be written. They both server the same purpose though, to give me insights on what to do next on the code. On reverse engineering case, it sometimes reveal certain connection that does not look right. There is a term Code Smell, so perhaps this could be named Diagram Smell.
The same as Code Smell where you see/feel something unpleasant on the code e.g: conditionals that looks like stairs, duplications everywhere, diagrams that is not pleasant to see and draw could hint part of the system that is not optimally structured.
Below is an example of diagram that looks suspicious :
Sometime, when I encounter the construct as above, there is a superclass that is waiting to be extracted. The code can then refactored that when reflected to diagram can be seen as below :
Of course, visual can be subjective things. Some people might not like the picture above :). However, I think we can now "understand" the nature of Class A and Class B better. We can also see more naturally their connections with the related helpers. I like things that could add the understandability of the code, it will ease maintenance in the long run.
Bad-looking diagram does not always means bad code though. It just a hint for us to look more at the code in case there is potential problem to be fixed. It could be the code is already in good condition while we draw diagram from the wrong understanding of it.
Diposting oleh
Hafiz
di
Thursday, September 05, 2013
0
komentar
Wednesday, September 04, 2013
Book Notes : Paradox of Choice by Barry Schwartz
I have recently finished reading "Paradox of Choice" by Barry Schwartz. Below is my personal notes of it.
The book is centered around reminding us on how the larger number of choices does not always means more happiness. It is true that low number of choice is limiting and certain number of choices can empower us. However, when the choices has grown large several factors started to come out that could limit our effectiveness to utilize those choices. Factors like regrets, opportunity costs can ruin our lifes as much as, if not worse than, the lack of choices.
Regarding the above issues, the book can be quite repetitive. It discuss the same matters several times although using different studies and perspective. I am already quite convinced that too much choices is problem by half of the book, so the additional facts add little to it although still quite informative. The book finally closes itself by summarizing some things we can do to manage the explosion on the number of choices to our advantage. It discusses the "trick" along the previous chapters but it gave one chapter to lay it out in a summarized format. It is useful for reviews and make some plan of action.
Below is some of what you can do when faced with choices so you can utilize it optmally :
- Choose when to choose. Decide on which area the choice is important and then spend time energy to make a good choice there. Still, limit the number of choice, so you can choose effectively. As for other areas, just stick to safe defaults.
- Be a chooser. Have time to reflect and not being pressured. Can choose to not choose and create new options and opportunity instead. Decide substantial goal and evaluate choice based on it
- Satisfice more and maximize less. Choose things that is "good enough", fulfill your needs and be happy with it, do not worry about loosing the ultimate best, it might not worth your time
- Think about opportunity cost of opportunity cost. Do not worry too much about what you miss
- Make decisions non reversible. You'll regret less
- Practice an “Attitude of Gratitude”
- Regret Less
- Anticipate Adaptation. Be aware that you will finally get used to what you choose. It might not get as exciting as you experience initially. Remind ourselves about the intrinsic quality of the choice that we have made
- Control Expectations
- Curtail Social Comparison
- Learn to Love Constraints. Choices within constraints is better then having none or having infinite one
Diposting oleh
Hafiz
di
Wednesday, September 04, 2013
0
komentar
Label: book
Tuesday, September 03, 2013
Use Fody to Simplify INotifyPropertyChanged Implementation
I was looking for a way to simplify implementing INotifyPropertyChanged. The standard way was too noisy to my taste so it would be really nice if there is a way to simplify it. Early on the search I stumble upon PostSharp . However, it's quite expensive and seems to be a relatively big "framework" for just my simple needs.
I later found the PropertyChanged.Fody and it fits my needs nicely. It is free and works really well. You just need to install with the command below in NuGet's Package Manager Console
PM> Install-Package PropertyChanged.Fody
and you are good to go. NuGet will take care of installing the needed dependencies e.g: Fody. Implementing INotifyPropertyChanged is now just a matter of adding [ImplementPropertyChanged] attribute to a class. Very convenient.
Diposting oleh
Hafiz
di
Tuesday, September 03, 2013
0
komentar
Label: dotnet
Monday, June 10, 2013
Hiding Future Task on Pocket Informant for iOS, A Workaround
Pocket Informant is a great software. I have used it since Windows Mobile days and now its 3.0 version of Pocket Informant iOS. I find many of my needs can be met with it in some way. However, one important thing that missing from is a good way to hide future task from showing.
The above makes my task list looks cluttered with tasks that I don't want to focus on right now. This is most annoying on routine tasks. For example, on a routine task that repeat daily, when I complete today's task the task for tomorrow will auto-generate and show up on the current list. It makes the list not as clear to look at compare if it's gone from my view until tomorrow. This kind of option exist Toodledo's own iOS app but somehow does not get into Pocket Informant so far.
Anyway, not all is lost. I still like to use PI and there is some indirect way to make future task, especially the routine ones, can be better managed in PI in it's current state.
Utilizing Grouping
The grouping feature on Pocket Informant is nice (can be accessed on button on upper right corner). t has great visual and easy to access. I use grouping by Due Date to separate future tasks from the rest. It helps on some circumstances but still can be a problem when I need the grouping for some other field. When that happen, I just group as I needed and try to ignore future tasks from it's label that does not say 'today' or blank.
Filter by Tag
Another feature that can be used for hiding future task is filtering by tag feature. I label the routine task with specific label so when I really need them to go away to focus on non-routine task including those what will happen later, I can just filter the label from showing.So far, with the above workaround, I still find it usable and does not hurt so much on my workflow. It still better if there is true future task filtering though.
Diposting oleh
Hafiz
di
Monday, June 10, 2013
0
komentar
Label: system
Friday, May 24, 2013
Workaround bug in Android's DownloadManager
Bug in Android's DownloadManager service is quite well known. You can check it out here and here for some example. Here is what I found on my use of it :
- Some files are re-downloaded and and saved with '-1' suffix
- Some other files are re-downloaded but failed on the second download. However, it just not fail but together with it, the first succesfully downloaded files are deleted!
- The events on 'onReceive' is pretty whacky too which takes some tries and hack to get it right
In my case, the first case above (successful double download) is not my primary concern. The duplicates are negligible. However, the second one done some catastrophic damage on how my code are run. So, after trying things here and there, here's what I come up with in pseudocode :
- prepare two files : the true destination file and temporary destination file
- download to temporary
- right after download successful, rename temporary to original destination file
- now, in the case Android going into the second case above, it will try to delete temporary file instead and the original destination file is save
1 if(status == DownloadManager.STATUS_SUCCESSFUL)
2 {
3 File fileTmp = new File(fileNameTmp);
4 File file = new File(fileName);
5
6 if(file.exists())file.delete();
7 fileTmp.renameTo(file);
8 }
Diposting oleh
Hafiz
di
Friday, May 24, 2013
4
komentar
Label: android
Tuesday, April 02, 2013
Releasing resource in Java (no destructor)
I needed to release resource in Java class and thinking about C++ style of resource management in class (open in constructor and release it in destructor). It turns out that there is no destructor in Java (finally doesn't cut it). So instead of open the resource in constructor and release it in destructor I should open it locally in the function and use try finally construct. Something like below (quoted from StackOverflow link on references list below) :
Resource r = new Resource();
try {
//work
} finally {
r.dispose();
}
Not as elegant as having the real destuctor (I'll need to use the above locally in every functions that needed it) but it gets the job done.
References :
http://stackoverflow.com/questions/171952/is-there-a-destructor-for-java
http://c2.com/cgi/wiki?FinalizeInsteadOfProperDestructor
Diposting oleh
Hafiz
di
Tuesday, April 02, 2013
0
komentar
Label: java, programming
Wednesday, March 13, 2013
JodaTime, for easier DateTime handling in Java
Having tasted the DateTime classes in .Net made you wish that there is something like it on the Java World. Compared to .Net's DateTime, what's available on Java world regarding the date and time handling feelds a little dated. It turns out that there is even a better stuff on Java, JodaTime. It has more detailed and useful abstraction regarding date time matters. It even has a sister library NodaTime for .Net which seems shows that the abstraction choices adopted to significant number of developers.
You can head out to it's front page and read "Why Joda Time?" section on overview of the relevance of the library. For me personally, it makes the bridging from .Net world of DateTime to Java world easier
Diposting oleh
Hafiz
di
Wednesday, March 13, 2013
0
komentar
Label: library, programming
Friday, February 15, 2013
Tunnel Internet traffic through OpenVPN per client only
We have been using OpenVPN at the office to access development resources only. So, as long as we have LAN connection to the VPN host server all is good. However, there is the need to direct all traffic including internet through it. It can be useful on public network to have it as a secure tunnel for all traffic to have more peace of mind. I don't want it to apply to every connection, I still prefer using internet non-tunneled on secure local network for speed reason.
Some references assume the setting is to be applied to all connected clients so the setup is set on server config. The notes below move the server-side setting to client so it can be set per client/case only.
Setting things up on the server side
The server is Ubuntu using Shorewall as a Firewall. What is needed on the server side is setting NAT from OpenVPN interface to the internet so the internet traffic from vpn can be forwarded to the outside world. Here's what to doAllow IP Forwarding in /etc/shorewall/shorewall.conf :
IP_FORWARDING=Yes
add entry to /etc/shorewall/masq :
eth0 [vpn network IP]
allow traffic from vpn to internet on /etc/shorewall/policy :
vpn net ACCEPT
Client Side
Here's the lines to be added on the client configuration :
redirect-gateway def1
dhcp-option DNS 8.8.8.8
dhcp-option DNS 8.8.4.4
Google DNS used to override whatever exist on client system in case it cannot be accessed through the tunnel.
I make two different .ovpn file with the same keys setting but one has the above setting. This makes it easy to switch between the one for tunneling internet traffic and vpn-lan-only.
That's about it. Below is some source references :
- http://openvpn.net/index.php/open-source/documentation/howto.html#redirect
- http://wiki.debian.org/HowTo/shorewall (part about PAT and NAT)
Diposting oleh
Hafiz
di
Friday, February 15, 2013
1 komentar
Label: system
Tuesday, January 08, 2013
Utilizing Springpad with a little help from Evernote
I stumble upon Springpad sometime ago. It was on some discussion on some forum (probably stackoverflow, it's a bit hazy now) about programmer's notebook. It was hard to really pinpoint the usage of it for me initially since it's feature is all over the place. I can't really describe what it is personally, you just have to try it yourself to really get the feel of it. It's a mix of Evernote, Pinterest and probably several other cloud-services.
I tried to use it for several purpose some which does not seems to fit well. In the end I settle with using it for more collecting-related purposes. It is a great tool to collect things on the fly. On GTD space it is great for Inbox and Someday/Maybe stuff. I migrated my Waiting-For list to it also since it has a good list item support. Here's the highlight of it's features that relevant for my usage :
- Flexible views. You can see the items using several different layout : cards, list, custom. If you are an Evernote's user, you might find some visuals quite interesting compare to it, at least visually
- Notebook and Tagging organization
- Great iOS mobile client feature-wise although still quite buggy in term of stability
- Interesting collecting workflow. Saving books, movies and other stuff is actually fun
Comes Evernote to the rescue. I am not a newcomer with Evernote, it's just that somehow I prefer OneNote style of note-taking (on iMac I settle with Growly that has the closest workflow with OneNote) so I am not actively using it. I have been thinking about porting the note-taking business to the cloud though and it seems a good time to do so. Not much needed to say when related to cloud-based note app since currently Evernote is the de-facto standard. I need to adjust my system though since it only has limited notebook number allowed and the organization seems to center around tagging (I think I am gonna miss OneNote a lot due to this).
So, the serious note matters are on Evernote while Springpad note system currently only useful for basic notes for me. I might switch fully to Springpad if it has a comparable note feature (accross multiple device that is). Until then, having to switch between the two is bearable considering the usefulness.
Diposting oleh
Hafiz
di
Tuesday, January 08, 2013
0
komentar
Label: system
Thursday, December 06, 2012
Setup Cyrus IMAP account on Thunderbird
I connected to Cyrus-IMAP server using Thunderbird. There's some problems on the first try :
- All the folder reside under INBOX folder. Trying to move them up fails
- The sending does not work, always hang with the message box informing that it can not save to Sent folder
Below is how the dialog looks like :
Diposting oleh
Hafiz
di
Thursday, December 06, 2012
0
komentar
Label: system
Wednesday, December 05, 2012
Setup postfixadmin on top of existing postfix installation
My office mailserver was a result of migration sometime ago. It was done in a limited time at that time so I only migrated the needed data and setup to keep it running as soon as possible. So, stuff like postfixadmin was left out (the system is postfix+courier+sasl setup).
Until this recent time that I need to add the account that it started to bite me. Most of the setup guide for postfixadmin assume a pristine install where it generate the database from scratch which could possibly wipe out my existing installation. So, I need to follow them less linearly.
After some searching around, I settled using this article as a starting point. However, it's quite outdated (to the point the writer marked it oudated on a big font at the top of the page) but it prove useful in my case nonetheless. It also assume fresh install but it define the steps more clearly including some behind the scene matters that happen which help me make some workaround for my specific case.
So, here's the summary (some silly-but-useful trial and errors and mistakes omitted) on what I did :
- Backup like crazy. It's a live system after all and one can not be too careful
- Download and install the .deb package from postfixadmin site : dpkg -i postfixadmin*.deb. Saying no when asked for auto setup apache and database.
- Add apache setting : make symbolic link on /etc/apache2/conf.d/postfixadmin to /etc/postfixadmin/apache.conf
- Add setting for the existing postfix database to /etc/postfixadmin/config.inc.php along with other settings there
- I couldn't find the admin account for it and find the solution to reset it here. Here's what I did on my case :
- Installed dovecot-common package since I used courier instead of dovecot. It is needed to get access to dovecotpw utility
- run : dovecotpw -s MD5-CRYPT -p password | sed 's/{MD5-CRYPT}//'
- update the admin account (it's on admin table of postfix db) with the above result
Diposting oleh
Hafiz
di
Wednesday, December 05, 2012
0
komentar
Wednesday, November 14, 2012
Multiple Monitor Setup : 2 +1
It is quite the norm now to use multiple monitor setup for software development. It used to be that dual monitor setup is quite hot but now three monitor is already quite common. However, I find it better to have 2 + 1 setup instead of going to 3 monitor setup (with "+ 1" being a screen of another device ).
I have only certain space at one time (not to mention attention) and with several devices and gadgets I use, they all have to battle for the space in my workspace. So, I set aside one side for secondary device instead of third monitor. I find it more useful this way since I have more flexibility with the third space which I can use for Laptop, Tablet or even Books when needed. Also, if I want to breath a little I can just clear it up (or have there a snack, tea or whatever).
Below is my current workspace following the above setup.
With the above setup, I have quite generous leftover space as below.
As you might see, there is still some space free for support stuff. That is PS3 on the far corner for those stressful times :), connected to the secondary monitor (Dell monitor) that has comfortable source auto-switch.
And here's my Windows workspace which has the blank right space to be used for the +1 as the above setup i.e: for non-desktop devices.
As you might notice, I am generally a desktop guy. I don't like working on laptop so much (at least for major development work) unless I really need to.
I find the +1 screen can function as third monitor quite easily e.g: opening references, utilities and even with more flexibility. The downside is that it has no direct computing connection to the main machine which break a flow a little compare to having the keyboard and mouse interacting with the integrated three screen. This can be helped a little using stuff like cloud, file sharing, bonjour protocol, etc.
Diposting oleh
Hafiz
di
Wednesday, November 14, 2012
0
komentar
Label: system
Tuesday, October 23, 2012
Integrating Personal Information Manager accross Devices
I like to have integrated Personal Information Manager (Calendar, Task, Contacts, Notes, Files) across my devices. It just does not make sense for me to have different set of tasks, calendar, contacts, etc.. on different devices that I used.
On the pre-Cloud days I used BirdieSync at the core of my synching (I am a happy Thunderbird user). It worked well until I updated my mobile ecosystem to Apple (iPhone and iPad). It was the time when I switched my system to Cloud-based since trying to keep device-to-device synching was no longer practical. So, below are my current setup in general.
Backend : Google, Toodledo and Dropbox
After some searching I settle with Google, Toodledo and Dropbox as backend :- Google : Calendar, Contacts, Email
- Toodledo : Task, Support Notes
- Dropbox : Files
Desktop : Thunderbird+Lightning and Addons
On the desktop I manged to have one conveniently integrated setup below- Thunderbird + Lightning Calendar Addon. I only used the calendar on Lightning since the task on Toodledo does not support bidirectional synching to it
- There are Google Providers Addon that helps sync contact and calendar with Thunderbird
- For Toodledo, I mount it to Thunderbird using WepApp Tabs Addon
Mobile : Pocket Informant, Toodledo App
It's quite flexible on the mobile side these days since lot of various options available to connect to the above backends. Here are just the highlights of what I used currently
- Pocket Informant. It synched all calendar, task, contacts and notes to Google and Toodledo, so it's almost a one-stop solution for it
- Dropbox client. The mobile version support file viewing to some extent.
Having a reliably integrated Information Manager is essential to have us really using it. Otherwise, on this time of multiple devices, we'll just play around with the system on the beginning and potentially discard it later on when the data become scattered and unusable.
I find the above setup working for me personally. You might find other setup more align with your usage and the level of integration that you think is acceptable.
Diposting oleh
Hafiz
di
Tuesday, October 23, 2012
0
komentar
Label: system