Cara Upload File Dan Form di Android Menggunakan OkHttp

Beberapa tahun yang lalu saya sudah pernah menuliskan tutorial yang sama. Saat itu, belum banyak library HTTP yang sangat memudahkan developer. Sekian tahun kemudian, saat ini, banyak sekali library, wrapper, framework yang sangat memudahkan developer android dalam membuat aplikasi. Tulisan kali ini saya ingin membagikan bagaimana cara kita melakukan upload file dan data dengan menggunakan OkHttp.

Continue reading “Cara Upload File Dan Form di Android Menggunakan OkHttp”

Share

Quick Add NodeJS App Dependency Without Opening Package.json

On most Node.JS tutorials, you might see that to add dependency, you will be asked to open up your project’s package.json and manually edit the dependencies section. After editing, you will save it and go to console to type

$npm install

Continue reading “Quick Add NodeJS App Dependency Without Opening Package.json”

Share

Menampilkan Daftar Referral Dari Google Analytics

Siapa yang setiap membuka panel wordpress, selalu melihat daftar Incoming Link? atau, bagi yang menggunakan google analytics, melihat daftar referral? Saya termasuk diantara kedua tipe ini. Hal yang menyenangkan, melihat website / tulisan kita dimention di tempat lagi.

Free Image Hosting at www.ImageShack.us

Continue reading “Menampilkan Daftar Referral Dari Google Analytics”

Share

Menampilkan Daftar Folder Yang Tersedia di GMail Melalui IMAP

Pada tulisan terdahulu, kita sudah lihat bagaimana cara melakukan koneksi IMAP ke gmail menggunakan PHP. Kali ini kita akan melihat bagaimana cara menampilkan daftar folder / label yang ada di GMail.

Continue reading “Menampilkan Daftar Folder Yang Tersedia di GMail Melalui IMAP”

Share

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 small amout of posts per month that will only take 2 pages and you don’t one your visitor to click next just to see it all?

Continue reading “HOW TO: Display All Your Monthly Archive In One Page”

Share

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 want

UPDATE:

  1. 2010-02-05 15:03:25 – Fixing $howmany usage. Sorry, for the inconvenience:D
Share

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 file and directory

How to create directory:

import os
dir = os.path.dirname('/tmp/current_object/')
  if not os.path.exists(d):
    os.makedirs(d)

Using code above will ensure you did not create directory that already exists

How to delete file or directory:

import os
os.remove('/tmp/')

or if you want to delete non empty directory:

import shutil
shutil.rmtree('/tmp/somefolder')

How to create temporary directory:

import os
import tempfile
import shutil
#let OS decide where they want to create the temp directory
tmpdir = tempfile.mkdtemp('somesuffix', 'someprefix')
#You want to take control where you want the temp directory be created
tmpdir = tempfile.mkdtemp('somesuffix', 'someprefix', '/tmp/path/of/your/choice/')
#be sure to remove the temp directory once work is done
shutil.rmtree('/tmp/somefolder')

How to create temporary file:

import os
import tempfile
#let OS decide where they want to create the temp directory
tmpfile = tempfile.mkstemp('somesuffix', 'someprefix', None, 'some initial contents')
#You want to take control where you want the temp directory be created
tmpfile = tempfile.mkstemp('somesuffix', 'someprefix', '/tmp/path/of/your/choice/', 'some initial contents')
#be sure to remove the temp directory once work is done
os.remove(tmpfile)

How to check file permission:

import os
import stat
file = '/tmp/'
stt = os.stat(file)
mode = stt[stat.ST_MODE]
print "%s mode is: %s" % (file, mode)

Share