Tag Archive: programming

Publish WordPress Updates to Social Networks with IFTTT

Integrate IFTTT with WordPress

This post originally published on 02/23/2012. I don’t have the original version of the article anymore. The following content is recovered from web.archive.org. Since Wayback Machine only store HTML and links and doesn’t store any media files, the original images and videos has been removed and the corresponding content has been modified. Please read the original version over at Wayback Machine with image and video placeholders.

IFTTT is a web service that “put the Internet to work for you”. It stands for If This Then That.

If you have some programming knowledge, you know what it means. For instance, if you posted a tweet then post this tweet to Facebook, if you uploaded a video to YouTube then write a post on Tumblr, if today is raining then email you a warning, and so on. Basically, it means that if something happens then do the specified action. In “If this then that”, the “this” is a trigger and the “that” is an action.

This service is currently in beta, therefore it lacks many features. For example, it cannot allow users to create one trigger with multiple actions and vise versa. Because of this limitation, I created several same triggers with each different action:

IFTTT currently supports (exclude social network aggregators such as Boxcar and Buffer, as well as paid services such as Pinboard): Delicious, Diigo,Facebook, Flickr, Linkedin, Posterous, Storify, Tumblr, Twitter, and Zootool.

You can also create your own tasks by signing up for the service. As I stated in the beginning of this post, it’s like if … then statements in the programming world (maybe in real life as well), you can create some tasks just like scripting. For instance, you can write a tweet every 30 minutes using this service without knowing the Twitter API or writing any code.

Two Quick Sublime Text Tips

Sublime Text tips

After a long time, I decided to switch back from Coda to using Sublime Text as my main IDE because it has more customize options. Here are two of the quick tips I found during the setup of Sublime Text:

User Settings

By reading through the default settings in Preferences -> Settings – Default, you can see many useful settings which can be modified. Copy the lines on which the settings you wish to be modified, paste into Preferences -> Settings – User, and modify them from there.

Here are my user settings for Sublime Text:

Note that normally when you modified a file in Sublime Text, there will be a filled circle replacing the close button on the tab of modified file. With “highlight_modified_tabs” on, not only does it have the filled circle, the tab also changes color.

highlight_modified_tabs in Sublime Text

Once the user settings are saved, the change is immediate. No restart of Sublime Text is needed.

Move User packages folder

One of the benefits of using Sublime Text is that just like Linux, everything is a file, including its settings. On top of that, most changes modified by you is stored in the User folder inside the Packages folder in Sublime Text root folder (/Users/username/Library/Application Support/Sublime Text 2/Packages/User), such as installing a package and adding a snippet. By using this advantage, you can move the User folder to another location (such as an external hard drive or Dropbox folder) and link to it.

Type the following command into the terminal:

Replace “~/Development/Sublime/Packages/User” to the location you saved the folder to, as well as “username” with your username. Note that you must move the User folder to your desired location first.

As of this writing, I haven’t found a way to link the file using a File Manager.

Make alias in Finder

The Make Alias command in Finder for Mac does not work for this operation.

Please leave a comment below if you have a GUI way of link the User folder successfully.

Do you have any other tips on Sublime Text? Please share them in the comment below.

Some Useful gEdit Plugins for Developers: Part Two – Third-Party Plugins (1)


In part 1, I listed some useful development plugins in the default gEdit installation and the gedit-plugins. In this post, I will list the first batch of useful third-party plugins for developers from the third party gEdit plugins list (http://live.gnome.org/Gedit/Plugins).

The List

  • Advanced Find/Replace (http://code.google.com/p/advanced-find/)
    This plugin can search or replace specified characters whether in the current document, opened documents, or selected directory. The search results will be outputted to the Bottom Pane after a search is performed. It also highlights the search results in the document. It is useful to find a specified function or class within a project/directory.
  • AutoComplete (https://github.com/nagaozen/gedit-plugin-autocomplete/)
    This plugin suggests words that exists in the opened documents as you type. According to its website, I think it also suggests custom libraries although I was not tested it yet. It would save me lots of time to retype the function name.
  • Session Autosave (http://sourceforge.net/projects/geditautosaves/)
    Once this plugin is enabled, it will save the current opened tabs/documents on exit and reopen them when gEdit started next time. The feature is the exactly the same with NetBeans default feature for opening up last opened documents to continue editing them. However, I noticed that it only saves opened documents. This means that it will open the previously closed documents when gEdit started. The solution is to select Tools -> Session Save to refresh the session.

To Be Continued …

These are just a couple of plugins I tested. In the next post, I will list some more plugins useful for programming development. All the plugins mentioned in this post and the upcoming posts are available on the gEdit plugin page (http://live.gnome.org/Gedit/Plugins).

Do you have any gEdit plugins that does not list on the gEdit plugin page? Please share them in the comments below.

The C Functions

C ++ & --

Functions are the most important and powerful part of the C programming language. They are series of code that have been given a name. The benefits of using functions are to break a program up into smaller pieces in order to be more organized and to reducing the repeatable source code so that it’s reusable across the multiple projects.

In order to create a function, a section of statements need to be enclosed with curly brackets and give it an unique name. Note that the function cannot have more than one same name. Also, the function source code must be placed outside the main function.

Here is a sample function as well as a sample code for calling the sample function inside the main function:

Note that the code called greet() function multiple times. This reduced the repetitiveness of the code.

Here is the sample code for the functions:

There are several different variables declared in each of the above functions. They are called local variables, means that they can only be accessed in the function where it was declared, otherwise the compiler will generate an error. The only way to use a variable inside multiple functions is to declare a global variable. A global variable is a variable that can be accessed by all functions. An uninitialized global variable is automatically initialized to 0.

Here is the sample code for the global variable:

Note that the global variables must declared at the beginning of the source code and outside any of the functions.

Since the global variables are not a good way to use because of the need to use the same variable in each function for different purposes, an alternative way to use is the function parameters. A function parameter is a local variable that is inside the parentheses right after the function to modify the function behavior.

Below is an example:

And the str_length function looks like this:

Here are two sample codes that contain the above statements:

While using function parameters, the passed variables only work within the function. The function cannot process the result back to the main function. The variable outputted in main function will still be the value before calling the function.

For example,

If the input value for the above program was 4, then the output value still is 4 because the calculation part of the code is in a separate function. The solution x = 8 did not transfer back to the main function since the function resets once the function ended.

The function need to return a value at the end of the function in order to output the result back to the main function. This type of functions with a return value needs to specify a type before the function name. For example,

And here is how it looks like to call function:

In the above example, the variable “result” passed the value back to the variable “z”.

The returned variable type must be the same type as the function. For instance, the return type is an integer if the function is an integer function. As stated above, the returned function must specify a variable type before the function name. However, if there is no type specified like the example above, the default variable type for the returned function is int (integer).

Here are the sample codes for the average, strlen, and double functions:

As you can see in the output() function, it’s possible to call function inside another function expression.

Before declaring a function, a function prototype can be declared. Function prototypes have no affect on the functions, it just provides the template of a function which is used to decrease the errors during development cycle of the project. It also provides the compiler correct format of the function to check the correctness of use of the functions. The function prototypes are usually placed inside a header (.h) file. For example,

Note that the first prototype is the same as the prototype in C++ which I learned long time ago. The function prototypes have a semicolon at the end to distinguish between the regular function and the function prototype.

Here is the sample code to explain what’s the difference between regular function and prototyped function:

Note the average3() function prototype at the beginning of code. Without this prototype, average3() must be defined before the function is called. As you can see above, the function is called before average3() is defined. Therefore the function prototype must be declared, otherwise the compiler will generate a warning and the compiled program will not execute the way as expected. The compiler also will generate an error if the parameters requirements don’t match the requirements specified in the function prototype.

Linux Shell Programming Basics


I have been reading Wrox Beginning Linux Programming. The book mainly teaches how to programming in Linux using C. Since I’m learning the basics of C, I thought I could understand some of the materials in this book. In Chapter 2, it talks about shell programming and how does it relate to C programming in Linux. I wrote the following code which is based on the example code in Chapter 2:

And the screenshot below is the output:

Click the image to enlarge

Note that the read command is similar to the scanf function in C. They are used to let user input value. Also note that this script would take a moment to complete depending on the size of each file where the script file is in.

If you have this book, the above script is similar to the example provided in the Chapter 2 of the book, except I removed static input value (POSIX) and added an user input field using read command and several blank lines to make the output more cleaner.