Archive for the 'snippet' Category

HOW TO: Display All Your Monthly Archive In One Page

Hi, today I want to talk about archive page. You know, the one that popped when you click on archive link? On normal wordpress themes, archive page will bound to post per page settings you’ve set on admin. However, what if you want to display it all in one page? Maybe because you just write [...]

Get Only n Words From String

Here’s the code:

function trim_word( $words, $howmany = 1){
$x = explode(" ", $words);
if(count( $x) <=$howmany ){
return $words;
} else {
return implode(" ", array_slice( $x, 0, $howmany));
}
}

Here’s the output:

$words = "this is string that is long enough that I want to trim it.";

echo trim_word($words, 10) . "\n";
//this will echo: this is string that is long enough that I [...]

Python File System Operation Snippets Collection

In this post, I’ll share some simple snippet to do various file system operation. Pretty much as a bookmark for my own usage, in case I needed it someday.
How to get current working directory:

import os
os.getcwd()

How to change working directory:

import os
os.chdir(‘/tmp/’)

How to list directory contents:

import os
os.listdir(‘/tmp/’)

How to check if directory / file exists:

import os
os.path.exists(‘/tmp/’)#work for both [...]

Automate Facebook Status Update Without Facebook API

Sweet little snippet with only 10 lines of code! Using python mechanize library to update your facebook status. Check out the code: