Recent Post

Categories

Archives

Cow Computing

10 Mar 12

Jailkit – Limit User Account on Linux

There’s once I was required to setup a limited shell access user account on a commercial hardware product, in which to secure the original system from being modified and at the same time to provide a flexible environment for general work. I was on the way to make use of chroot command. Then i was lucky to came across Jailkit, which saved me a lot of time. So, i would like to use this post to give a little introduction on how to use it.

# First, let's create a directory for the jail account
mkdir /jail
chown root:root /jail

# Then we create a new user account specially for jail account
# *replace <group name>, <username>, <password> with your own value
groupadd <group name>
useradd -d /home/jail -g <group name> -p <password> <username>

# For example, if we only want to allow the jail account to have ssh and basic shell access
jk_init -v -j /jail basicshell ssh

# Then we shall jail the user account we previously created to the jail directory
jk_jailuser -m -j /jail <username>

Read More / Comment »

10 Mar 8

WordPress Error: Cannot Modify Header Information

Have you ever encountered the error: “Cannot modify header information” when you try to access the admin page of wordpress? The debug message might have suggested you to look at “pluggable.php”. When searching thru google, people often advise you to turn off installed-plugin one by one to see if the problem get resolved.

The above might work, but i would suggest you to try the following method before going thru the turn-off plugin cycle. For example, if you have modified “functions.php”, and the above header information header appeared right after, you can easily resolve this by removing all the extra whitespace before the “<?php” and “?>” tag. Viewing thru editor, you might not notice any whitespace, but try this trick:

  1. Remove the “>” from the “?>” tag at the end of file
  2. Then keep holding Delete key (not backspace) for a few seconds. (*note that the cursor should be locate after the “?”)
  3. You will notice some whitespace being deleted. Amazing isn’t it?
  4. Add the “>” after the “?” to properly close the php tag
  5. Save the file, and try accessing it, the header information error should have been resolved

10 Mar 4

Finding Files with particular extension or Pattern in Java

Often, to find a file with a particular extension or naming pattern within a directory, we might implement as below:

// The directory which search would be conducted
File directoryForSearch = new File("C:\folder");

// This may not be the best way to accomplish the task, please bear me with it
File[] allFile = directoryForSearch.listFiles();
File[] resultFile = new File[allFile.length];
int resultCount = 0;

// loop thru the list of files to find the required files
for(int i=0; i<allFile.length; i++)
{
    if(allFile[i].getName().matches(".*\\.java")
    {
        resultFile[resultCount] = allFile[i];
        resultCount++;
    }
}

Read More / Comment »

10 Mar 3

Some Hidden Mac’s Tips (Terminal Cmd)

In this post, i would like to share a couple of hidden terminal command on mac to help unlocking some useful feature. To use these feature, simply type the command as if it’s shown on the terminal, andd there you go.

  1. Using current Screensaver as the Wallpaper. This can be gorgeous, however, depending on which screensaver you pick, it might take up some CPU & memory. (*To stop it, simple press “Ctrl+C”)
    /System/Library/Frameworks/ScreenSaver.framework/Resources/ScreenSaverEngine.app/Contents/MacOS/ScreenSaverEngine -background
    
  2. Enable hidden files/folders be shown on Finder. This is very useful in particular when you want to locate some important hidden files like “.ssh” or “.bash_rc”.
    // Change TRUE to FALSE to disable the effect
    defaults write com.apple.finder AppleShowAllFiles YES
    
    // Restart the finder to take effect
    killall Finder
  3. Enable the highlight effect on Stack (Highlight the icon when mouse hover)
    // Change yes to no to cancel the effect
    defaults write com.apple.dock mouse-over-hilte-stack -boolean yes
    
    // Restart the Dock to take effect
    killall Dock
  4. Read More / Comment »