Wednesday, June 10, 2015 - Sanitize file name to remove illegal characters such * : \ / < > | " ? [ ] ; = + & £ $

When you develop a system that allow user to upload file, you need to take care the file types, permission and it name. To avoid naming convention that are illegal, you need to sanitize file name and remove any illegal character and replace the character with something else such underscore ("_") which is acceptable. Below are the code you neeed.
private static string MakeValidFileName(string name)
  string invalidChars = Regex.Escape( new string( Path.GetInvalidFileNameChars() ) );
  string invalidReStr = string.Format( @"[{0}]+", invalidChars );
  return Regex.Replace( name, invalidReStr, "_" );
This function are very helpful for filtering file name using regular expression (regex) and GetInvalidFileNameChars() function. For file path, you can change it with GetInvalidPathChars() function to sanitize file path from your input.

JQuery - Disable keyboard input when using datepicker() function

  <meta charset="utf-8">
  <title>jQuery UI Datepicker - No keyboard input</title>
  <script src=""></script>
  <script src=""></script>
  <script type="text/javascript">
    $(function () {
        $("#datepicker").datepicker({ maxDate: "-1D" }).attr('readonly', 'readonly');
Date: <input type="text" id="datepicker"></p>

Reference : Restrict user to enter date manually in text field

Executing Java code in comments

Well, today.. I spend my time at StackOverFlow and found a interesting question about executing Java code in comment. That freak me up, how a comment can be executed, right? By using non-ASCII characters, such example below this comment will be execute (line 3) :
public static void main(String... args) {
   // The comment below is no typo. 
   // \u000d System.out.println("Hello World!");
The reason for this is that the Java compiler parses the unicode character \u000d as a new line (line 4) and gets transformed into:
public static void main(String... args) {
   // The comment below is no typo. 
   System.out.println("Hello World!");

Whoah, programmer can insert malicious code or bring defect / bugs to the compiled software. So, I prefer and believe that an equivalent file containing only ASCII characters. Btw, some IDE block / disable this unicode character such Netbeans IDE.

Check the discussion HERE if you need more information.

Sunday, June 7, 2015

C++ : Constructor & Distructor

  • Is a member function that is automatically called when an object that class is declare
  • Has same name with class & constructor definition cannot return value
  • If programmer does not provide any constructor, the compiler does default constructor which is very primitive and does nothing.
  • If programmer provide any type of constructor, then programmer must also define a default constructor if it is needed.
  • Used to allocated memory when class object and it’s class member is destroyed.
  • Is a member function with the same name as it’s class prefixed by ~ (tilde)

Object Oriented Programing (OOP) : Object Concept

  • An object is a person, place, event, or thing about which we want to capture information.
  • Each object has properties (or attributes).
  • The state of an object is defined by the value of its properties and relations with other objects at a point in time.
  • Objects have behaviors — things that they can do — which are described by methods (or operations)
  • Objects do not use primary or foreign keys, instead each instance is assigned a unique identifier (UID) when it is created.

Everyone can write code..but no one can write good code

Any fool can write code that a computer can understand. Good programmers write code that humans can understand.

Object Oriented Programing (OOP) : Visibility

Type Description
Private Access only by the declared class
Protected Access only by the declared class and their subclass
Public Access only by the declared class, subclass and others classes

VB6 : Already running?

Private Sub Form_Load()
    If App.PrevInstance Then
        MsgBox "Program telah dijalankan", vbExclamation, "Amaran"
    End If
End Sub

Saturday, June 6, 2015

More than a Degree - Turisaina Tukiman

Today I saw my friend share a articles written by Turisaina Tukiman on Pulse. I think you should read this too.

My course-mates used to think that studying, going to classes and getting a CGPA of more than 3.5 is all that matters when you're in university. My family said that too. But boy, they couldn't be more wrong.

I am currently a trainer, teaching problem solving tools to youths in my country. My team and I travel far from north to south, central to even crossing the ocean. We went to almost every state in the country. 

Although it is an exciting job to inspire and motivate youths on problem solving, it could also be frustrating sometimes. Just imagine I travel 5-6 hours by car just to give a free training to youths but end up with a shitty crowd who couldn't care less. I remember their types. They were same as my course-mates during my Degree. 

1. Trying to change their mindset is my toughest challenge yet. Whenever we go down to solving problems, at solutioning stage, more often than not, they would often say, "The government should do this... The government should do that..." It truly was a face-palm moment for me. And I would always tell them, that my friends who are entrepreneurs or change makers agree to this sentiment, "Changes never start with the government. It starts with one person who is frustrated, angry and upset with how things are the way they are and then they decide to do something about it." Sometimes we succeed, sometimes we fail. But, all I can say is that I tried my best to eradicate that mindset. All I can do now is hope. 

2. Sometimes a vacant position opens up and we promote the news to our previous participants (from the training). The candidates are almost hopeless. The portfolios they brought for us to see (if they brought it), has little or none experience from outside of their university. They'd just show us their assignments. And when I ask them, what other experiences they have besides inside the classroom, I think you can predict what their answer is. And it is just frustrating.

Based on a study conducted, students think it is the educator's responsibility to train them on the skills employers are looking for when hiring. Educators are torn between putting the responsibility on themselves and employers or on the students. For employers, most of them believe it should be the responsibility of the educators.

What conclusion can we draw from this? That none of them; neither students, educators nor employers, see it as their responsibility to teach them on these necessary skills:

  • Communication skills
  • Basic ICT skills
  • Problem solving skills

In my opinion, it is the responsibility of the students themselves to acquire those skills. I still remember during my university years, I spent almost all of my free time doing extracurricular activities. I did event management to project management to training. Not saying that I'm spectacular because I'm not. But, all of these helped me to market myself out there. 

Late last year, I went to Singapore for an ASEAN Forum. There, while I was pitching my program enthusiastically to a stranger I just met 5 minutes ago, I saw a familiar face. A judge from my pitching session from about 3 years ago. And she remembered me. She remembered my name. The guy I was pitching to, he told her that I got him excited with my team's program and she nodded, saying that she remembered my passion. This word of mouth is really helpful in building my reputation. It could help me get my next job in the industry.

Just these past few weeks, I got 2 job offers from startups. The offer came from people I've worked with. They know how I work. That's why they believe in me. Their recommendations will do me good. They will serve me well. 

Point us. I didn't start this journey just after I've graduated. I started this journey a long time ago because I knew I needed to have something unique to compete against my ex course-mates and other candidates. My commitment and passion towards my extra curricular activities just simply gave me a good start in the job hunt. A little bit of something is definitely better than nothing. 

And even now, I find learning to be vital as a trainer. I need to know more than the participants. Because I hate to be put in the hot seat where I know less than them. It is my job to teach them so that means I have to be 3-4 steps ahead. Reading helps. Watching Ted Talk helps. Doing research helps. Creating helps. Anything helps. Just as long as I keep growing, then I know I'll be fine. 

So those of you who are still studying in your college or university, market yourself out there. Have the thirst for experience. Have the hunger of making mistakes. It's important to break that shell, network with strangers and do things. Dare to be different. Dare to explore. Dare to adventure. 

Education isn't your Degree. It is lessons of which cannot be learned within the four walls. 

Source :

Dropbox cannot start - IOError: [Errno 13] Permission denied

Problem : I can't start the dropbox application from linux menu laucher
[email protected]:~$ dropbox start -i
Starting Dropbox...Traceback (most recent call last):
  File "dropbox/client/", line 37, in <module>
  File "dropbox/client/", line 17, in <module>
  File "dropbox/", line 21, in <module>
  File "dropbox/", line 1, in <module>
  File "arch/", line 28, in <module>
  File "arch/linux/", line 52, in <module>
  File "dropbox/", line 19, in <module>
  File "dropbox/", line 31, in <module>
  File "babel/", line 33, in <module>
  File "pkg_resources/", line 3032, in <module>
  File "pkg_resources/", line 933, in subscribe
  File "pkg_resources/", line 3032, in <lambda>
  File "pkg_resources/", line 2573, in activate
  File "pkg_resources/", line 2667, in insert_on
  File "pkg_resources/", line 2697, in check_version_conflict
  File "pkg_resources/", line 2566, in _get_metadata
  File "pkg_resources/", line 1589, in get_metadata_lines
  File "pkg_resources/", line 1581, in get_metadata
  File "pkg_resources/", line 1692, in _get
IOError: [Errno 13] Permission denied: '/var/lib/dropbox/.dropbox-dist/dropbox-lnx.x86_64-3.6.5/futures-2.1.3-py2.7.egg/EGG-INFO/top_level.txt'
Error executing command as another user: Request dismissed
The installation of Dropbox failed.

My solution: Give permission for thus files
[email protected]:~$ sudo chmod 644 /var/lib/dropbox/.dropbox-dist/dropbox-lnx.x86_64-3.6.5/futures-2.1.3-py2.7.egg/EGG-INFO/top_level.txt
[email protected]:~$ dropbox start -i
Starting Dropbox...Dropbox isn't running!
[email protected]:~$ dropbox start -i
Dropbox is already running!

Thursday, June 4, 2015

Myql - create new user and grant remote access to whole subnet

Today, someone ask a question at JomWeb facebook group about getting remote access with specific ip and whole subnet. Here, have a look at the question :

hello. sorry if i am asking too much question. but earlier i have a problem regarding connection between phpmyadmin and mysql server and it have been solved by grating the permission to the server. This time i got this kind of error when i am trying to use other server. can anyone help me this time around? i already granted the permission needed.

So, here my solution..and I wrote it back on my blog for my future reference and maybe I can help someone that face the same problem. As PoC,I create new user "dummy" and grant the access. Btw, in my opinion user "root" should not be remote and just use in local machine, because of security reason.

1 - Let's create new mysql user called as "dummy". You can skip this part if you already have target mysql user :
mysql> CREATE USER 'dummy'@'localhost' IDENTIFIED BY 'password';
Query OK, 0 rows affected (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

2 - Now let's grant the user with all database access and connection from 192.168.1.* (modified this based on you own need) :
mysql> GRANT ALL PRIVILEGES ON *.* TO 'dummy'@'' 

Query OK, 0 rows affected (0.00 sec)
P/s : You can set different password for each IP address.

3 - Try give a look our mysql user and mysql host access :
mysql> SELECT user,host FROM mysql.user;
| user             | host                      |
| root             |                 |
| dummy            | |
| root             | ::1                       |
| debian-sys-maint | localhost                 |
| dummy            | localhost                 |
| phpmyadmin       | localhost                 |
| root             | localhost                 |
7 rows in set (0.00 sec)

Succes! That all for now.. :)