Dec 14, 2010

Why some filters are disabled in Photoshop


Well, admittedly, filter is one of the best features available in Photoshop is filters, which enable us to create pretty cool effect like turning a photograph into a water color painting, a mosaic picture (not really "mosaic" in a sense, but more like pixelating it)...

However, you might be surprised when got into such situation, when many of the filter is not available anymore.
By default, this shouldn't happen, which mean some settings in Photoshop. But what is it ?

I also went through the same problem, and luckily, I found out why. So I will be sharing it with you today.

Well, the problem is actually the color mode. Normally, you would be in will have 8 bits per channel color, hich mean for each of the RGB (red, green, blue) color, you will get 2^8=256 degree, and combining them together in RGB will give you 2^24, approximately 16 million colors.

Meanwhile, there are 16 bits/channel and 32 bits/channel also, which makes your picture more "real", in a sense that it can represent more color.
However, this makes some of the filter unusable, as they are not designed to work with such number of color.

So, to get all your filter backs, just return to 8 bits mode. But beware that if you have constrains about coloring, then it might make your photo much more uglier than you expect

To change, simply go to menu Image -> Mode -> 8 bit / Channel , and you are done.

Hope it helps


Dec 9, 2010

Source Code versioning with Google Code

Hello there,

Today, I am going to share my experiences about source code versioning, a very useful technique used in coding project to keep track of what you have done in your code.


First, what is source code versioning? Well, it's simply a method to store your code files and the changes you have made on them at specific points in time. It sounds simple and it is indeed simple. Basically, you just need to copy your code in to a folder and take note of what your changes in the files. Not only can you avoid situations where you unconsciously screw up something and create an uncountable number of errors in your projects, but you can also take advantage of the most powerful features version control: reverting to previous version of the project, team collaboration, to name a few. While this is not much of concern for small projects, where files are manageable, it is a huge help for big projects of thousands of files. In fact, big projects like Mozilla, NetBeans, OpenOffice benefits from this a lot.

If you are interested in existing programs for version control, please read the next section, otherwise, jump to "Project hosting with Google Code".

A little about Version Control Systems program (VCS)

There are two methods for version control: centralized and distributed. Basically, in the centralized method, all the code is hosted on a single sever and all the collaborators need to access the server to download the code, update changes… The benefit is a easy to manage and uniform project. However, every time changes are made, collaborators will need to upload it to the server, and this is inconvenient, especially when the server is down.

The counterpart of centralized technology is distributed, where code is divided onto local machines of developers. Here, they will update small changes on their own storage, called a "repository". After all changes and verified to work, developers will push all those changes onto the server. This help to keep the server updated with important changes, instead of being overloaded with small fries. Also, developer don't need internet access all the time to work.

To visualize it, you can think of the centralized technology as a single warehouse, where all developers are salesmen that only come in to take / deposit goods as they required. And these salesmen don't actually possess any goods.

Distributed system, on the other hand is a franchise. The central warehouse will distribute / receive goods from stores, which also have their own storages. The central will not care whatever the stores do, as long as the goods are sold.

In reality, software like SVN falls under the category of centralized version control, while Git and Mercurial falls under the distributed category.

Now, let's move on to hosting your project with Google.

Project hosting with Google Code

Google provide an open source environment to host your project. You will need a Google Account to create a 2GB hosting repository for you project. Also, you can join other existing projects as well.

While you can search for existing open source projects to join here, I will focus on creating a new project and usage of Mercurial Hg (for Windows).

The reason this guide is made is while learning to use Mercurial, I found out that the guide book "Mercurial: The Definitive Guide" is a bit overwhelmed for first time user, in my opinion, that is, those who have never heard of the term version control before, it's very demotivating. Also, after a few hours searching, I only found guides with for the command shell Mercurial, not the GUI version of Mercurial Hg, which is much more intuitive to use.

Not to delay you anymore, we will now create a project on Google Code by visiting this link:

http://code.google.com/hosting/createProject

(note, please click on the images for a larger preview)

You will need to fill in the project name, summary and description. Your version control system should be Mercurial. About the license, you may choose depend on your purpose (you can refer here). In case you don't know what to choose, then go for "GNU General Public License v2". Also, add in some labels to indentify your project. Click "Create project".

After finished, you will see your homepage like this. Congrats, now you have a repository for your own ^^.










Next step is created a clone of your repository. Basically, one or many clones will be allocated to a developers and he will be coding on that clones. After some iterations and verification, the (supposedly) satisfied developer will push his changes on to the main repository.

To create a clone, from the homepage, go the the "Source" tabs, then "Clones" and "Create a clone".

You will be prompted for information about this clone. By default, your Google account's name is associated with the clones.

Enter the details and click "Create repository clone". Again, you will see a familiar interface.





There is a couple of things to explore here:

  • "Source – Checkout" will give information to setup the local repository on your computer.

 

  • "Source – Browse" provides you with a list of files and directories currently inside your clone.

  • "Source – Changes" gives a visual overview of the changes you made. If you are the only developer, all the version goes in a straight line. However, if there are multiples developers involved, most of the times the code will be going in different branches.
  • "Source – Clones" list all the clones you have. I hope it should be simple enough to understand :P
Now, with the server setup, you will need to download Mercurial Hg for Windows at http://mercurial.selenic.com/downloads/

Follow the instruction to install it and restart your machine. Now you are ready.
Go to where you want to create your repository clones. After that, right-click and select "TortoiseHg -> Clone…"

Go back to Google code. Under the link Checkout of the clone you have just created, you will see a command, something like "hg clone [project url] [clone name]". Copy the project url and clone name to the source properties of the clone dialog

Finally, click Clone and you have now have a the codes on your hard drive. Of couse, at the moment, it is empty since we haven't added anything to it. But we will.

Add caption
On your hard drive, you should see another folder appearing. Go inside it and add all the code files you want. For me, to test out, I just add some random .txt and .c files.



Go back out to the folder, right-click on your clone and choose "Hg Commit". This will create a revision of your code on the hard drive for you to roll back and revise later. However, keep in mind that by committing, you only make LOCAL changes. The server clone is not updated.


After debugging (what we always do :P) and improve your code's readability, to ensure the quality, you can upload it to the server via an action called "push".

To do so, right-click on your local clone and choose "TortoiseHg -> Repository Explorer". Inside, find the Push icon and click it. You will then be prompted for username and password. The username is you Google Account username, while password is a generated string that you can find in your clones' Checkout tab. (There is a link of "googlecode.com password" inside).


That's it. Now, if you check your clone, you will see that the files are updated.


There are a few things you can also do: if you want to revert to the previous version of the code, in the Repository Explorer, choose that revision and right-click, choose "Revert". Confirm with Mercurial again and you are back to where you start. The beautiful thing is that after you have committed, you can always go back to that revision again.

In addition, say another user updated the directory clone, you will need to update his code. You will need to perform a Pull operation (the opposite of Push, as expected) in the Repository Explorer. The command is in the same toolbar as push, so I will not be including it here.








And now you can do version control :P It is really useful, since even for my 2nd year project in a semester, our group updated like 700+ revision of code. Imagine how hard it would be to manage those.



More reading will be available at inside the "Mercurial: The Definite Guide". I hope that the intro here is good enough for you to go on, read and understand the book. It lacks the GUI help, but the explanations are good, so, you just need to figure out where to execute that command in GUI J

Thank you for reading and see you next time J
Sincerely yours!

Nov 20, 2010

Publish post form Word to Blogger

Hi,

This tutorial will help you manage your Blog easier by editing in Word and automatically publish to Blogger.

No plug-ins for Word is required.



Okay, here goes:


 
First, you will need to change your Word Interface to blog posting mode. Click on the main menu, then choose "Publish" and "Blog" option.
















After that, you will need to connect to your blog account. Select "Manage account" from the ribbon to open a dialog box. Choose "New" there.













Select your blogging platform. Here, I will use Blogger.







Log in using your username and password.






Select your option about image. By default, Word is limited to posting text, because most blog can understand text under XML format, not image. One more point, if you want to insert images, you will need to do it on your blogging platform (Picasa Web Album with Blogger, for my case). If you have knowledge about server and FTP and wish to upload images to your own host, I think you can manage from here :P Otherwise, just leave the option as default: "None – Don't upload pictures".




If you own more than one blog, select it from the drop down list







Finally, it's writing type. J Write as you wish J










Lastly, after you have finished editing, click Publish. Here, you can choose to publish directly or as draft.

And you are done.












Hope this tutorial will give you more convenience with your blog posts J

Dedicate for Molly :) Hope to read her post more often :)

Oct 18, 2010

National Instrument - MultiSim - Component details

Hi,

Suggested by Rajesh today, I tried to opt out of using Xilinx, which is too much troublesome (for me at least) and use MultiSim (from National Instrument) instead. By far, it has been much more reliable than Xilinx, with just a little problem when started learning (due to the vast component library).


The software can be downloaded at
https://lumen.ni.com/nicif/us/academicevalmultisim/content.xhtml

Here, I will try to document the components and their usage, hope it serves as a good start.
Also, you may want to refer to this getting started tutorial:
http://www.mediafire.com/?2956aws7pekd20p



Here is the list of components (plz note that the name in bold is the comprehensive one that I give it)
The format will be:



<Component name>
Component Image


Purpose: <Usage of this component>
Group: <Group>
Family: <Family>
Component: <Component Name>
Component value list
  • <Value 1>: <Usage 1>
  • <Value 2>: <Usage 2>
  • ...
  • <Value n>: <Usage n>

List


Selection Switch
Purpose: To Select between two different value, interactively. This correspond to a physical switch.
Group: Basic
Family: Switch
Component: SPDT
Component value list
  • Key for toogle: During simulation, you can toggle between the two values by pressing the key specified here. In this example, pressing "Space" will toggle the switch


VCC


Purpose: 5 Volt Vcc Logic
Group: Sources
Family: Power_Sources
Component: VCC
Component value list: None



Dip Switch Pack


Purpose: Used to toggle voltage input
Group: Basic
Family: Switch
Component: DSWPK_X where X is the number of switches
Component value list
  • Switch 1 key: Toggle switch no.1
  • Switch 2 key: Toggle switch no.2
  • ...
  • Switch X key: Toggle switch no.X
 There is a need for explanation here, as it took me half an hour figuring out the operation of the switches here.
Basically, to perform our desired function, you can't simply connect Vcc and the switch. Since when you turn it OFF (disconnecting the input from the output), you make the ouput become FLOATING (not connected to any electrical sources, and this is not a good thing to do in circuit design).

by connecting the switch with a resistor, you created this schematic:
When the switch is turn ON, pin 1 is connected to Ground, hence, it output 0V
When the switch is turn OFF, pin 1 is connected toVcc via the resistor. Normall, there will be a voltage drop and V1 will be less than Vcc. However, if we choose the resistor to be that of high-impedance (high resistance), the current - as derived form Ohm's law - will be very small. Hence, voltage drop is negligible and V1 is approximately equal to Vcc.

    Oct 14, 2010

    Facade pattern in GUI design

    Today's post will be about Facade pattern and its application in GUI programming.


    I would assume that you guys have already know about GUI basic, like event handling (basically, it's a method that is invoked when something happen to the GUI, either by you or by God, haha). Also, if you have tried to integrate several UI (not just GUI, but include TextUI, mobile apps UI...) for your logic classes, you might see that's it is quite trouble some to keep calling methods in Logic from your GUI.
    If you happen to do so, you might end up with something like this:

    <Sr for the hand writing :P> Basically, each of  TextUI and GUI's event handler A and B is calling method A and B in Logic. It's a bit wrong, technically, since TextUI don't normally have handler.
    This is only for 2 UI classes. imagine i you have more: mobile Apps, Web interface, embedded system interface... if you implement it this way, you will have to write the calling code again and again. Plus, if you change your Logic, then the whole code in UI classes have to change. Plus, your UI have to "know" the structure of Logic class, which is considered a bad design in software.

    Instead, people have proposed a design pattern, called Facade pattern.

    A "facade" class will be made and you will be calling methods in that facade class. then, the facade class will call Logic, get result and return it ot UI.
    It won't shorten much of your work, though. You still have to make a call from UI to facade class and back, but it is helpful since your UI only know about the facade, which acts more or less like an API (correct me if I am wrong here :D). Then UI doesn't of whatever happen in Logic, or even if there is a Logic class at all. This will reduce your load when modifying code inside.


    Basicall, it the new structure will be

    <again, hand writing :P> now, event handler in TextUI and GUI will call methods from facade class, then facade class will call logic. So, if by any chance you need to modify your internal logic w/o changing API, you can do it freely. UI classes now only know up to facade class and no more.
    It will be a good design :D

    If you only have 2 class, then you can also consider splitting the facade in half:
    GUI will have a method that receive info from Logic, then checking that info and distribute to respective UI methods
    Logic will also have a method receiving info from UI, checking it and call appropriate logic methods
    Logic and UI will also have a method that sends info to the other class. This method will be invoked each time info need to be passed.
    Logic and UI will only be communicating through these broadcaster and listener methods

    This is, in my opinion, not a recommended approach though :P but it's fast.

    That's all for today :)

    Sep 7, 2010

    Put your C++ code into directory in Visual Studio

    Wow, finally, I found the way to put C++ codes into different folder, as well creating and managing those folders in Visual Studio.

    Before, all I have been doing is creating .cpp and .h files in the same root folder (where all your codes goes) and assign them to created filters. This, however, become an disadvantage when I switch from writing small program on my own to teamwork for my projects.

    A filter in Visual C++ is, basically, a filter. It is not a directory that you put your code files into but rather some kind of "tag" that help you identify your code file. This makes your project cumbersome when you want to put the files into folders, each with a purpose (like Project\Logic, Project\GUI, etc)


    Okay, that's enough of the chit chat, now let's do it



    Show All Files
    First, from the Solution Explorer (left side of the window by default / View-Solution Explorer / Ctrl + Alt + L ), click the "Show all files" button.
    Solution explorer with directory
    After that, you should see something like this panel. All the folders in your project will be displayed here. By default, there will be one folder called Debug (for temporary compiled files during debugging process) and another folder with the name of your project (SRS_HK for my case).
    All you files should also be listed according to the directory they belong.
    You can press the "+" / "-" button to expand, collapse your directories.

    Finally, you can add in folder and files by right-click, Add -> New Folder / New Item




    Of course, putting your files to folders requires some modification to the #include command. For example, you have to use
    #include "SRS_HK\SimpleException_HK.h" 
    to include the header file now.

    Hope it helps :)

    Aug 31, 2010

    OMG - VIM

    Yup, today is the day I started liking VIM
    =)

    This is kinda funny though, as my previous experience with Visual Studio is much much better than using VIM, but somehow, it just feel right.

    Actually, I think that there is something in VIM that all programmer like: the ability to NOT follow convention. Surely, navigating with H, J, K, L is difficult, but why follow everyone else and use arrow key =)). After all, they are just conventions, not compulsory!

    Nevertheless, I should start posting something about coding here:

    This is an old habit of mine ever since I use Windows: CTRL - S to save.
    In VIM, this actually makes the program hangs. However, according to the developers, this only "stop the data from arriving so that you can stop a fast scrolling display to look at it" (Refer Here)

    To compensate for that, just do a CTRL - Q.

    This actually helps a lot since I don't have to disconnect from my Unix server in school again :)

    Aug 25, 2010

    Change the Project's Directory & couldn't find "stdafx.h"

    Last time I built a working program with a GUI.
    After that, I saved it, changed the DIRECTORY NAME that it was in ( so, originally, it was in [Original name]/[Original name], but i changed the directory to [New name]/[Original name] ).
    Then, when I go back and run the program again, I got error: 
    fatal error C1093: API call 'ImportFile' failed '0x80070003' : ErrorMessage: The system cannot find the path specified.
    it seems quite impossible, since "stdafx.h" is already there in my project.
    Confused!!!!

    However, after a while, I found some article online and tried to imitate it, and the issue is solved :)
    Here is what I do:
    • Goto Build - Clean Solution
    • Build & Run again
    Hope this help anyone catching it later

    The new C++

    Phew, I finished getting a Win Form App, included with a user-built class, running. It was quite a pain, especially if you have already got used to the comfort of Command Line Interface (CLI) used for studying C++ or GUI development with C#. C++ is somewhere in between, and well, a  bit hard to catch up

    After spending around 5 hours on this, I found some of the following interesting features:
    • In C++, whenever you create a Win Form project (all I know beside Win32 Console right now), you will automatically have a stdafx.h & stdafx.cpp to do the standard #include operation for all the code file. Any special #include can be implemented in stdafx.h
      Sample:


      // stdafx.h : include file for standard system include files,
      // or project specific include files that are used frequently, but
      // are changed infrequently

      #pragma once

      // TODO: reference additional headers your program requires here
      //#include <string>
      #include "SimpleException.h"
    • Class ends with ";" (semi-colon). I forgot about that and wasted a few hours.
    • C++ can also have garbage collection like C#. Fot that, you must follow a special syntax called "managed C++":


      ref class SimpleException
          {
          public:
          //constructor
              //default
              SimpleException(String^);
          //accessor
              //get error message
              String ^GetError();
          private:
              String ^_errMsg;
          }
    • In managed C++, instead of using value typed variables, the code uses handler (which is still different from unmanaged C++), something like pointer. However, instead of using the asterisk character (*), we use  the caret character '^' to denote these managed objects. Plus when declaring structures & classes, we also use the "ref" keyword (since all the structure / classes are "handler" by definition)
    Okay, this is the code for referencing:
    Download