Akhir-akhir ini sering membuat halaman web statis (html, css, dan javascript) yaitu berupa dokumentasi proyek, slide presentasi, dan mockup ui. Untuk sharing lebih enak kalo setup webserver untuk serving file-file tersebut daripada copy-paste lewat flashdisk.
Makanlah ketika lapar
berhentilah sebelum kenyang
Jumat, 27 April 2012
Menjalankan apache2 web server standalone
Mungkin judulnya kurang tepat, menjalankan apache2 web server standalone untuk direktori tertentu ke nomor port tertentu tanpa menjadi root terlebih dahulu.
Akhir-akhir ini sering membuat halaman web statis (html, css, dan javascript) yaitu berupa dokumentasi proyek, slide presentasi, dan mockup ui. Untuk sharing lebih enak kalo setup webserver untuk serving file-file tersebut daripada copy-paste lewat flashdisk.
Akhir-akhir ini sering membuat halaman web statis (html, css, dan javascript) yaitu berupa dokumentasi proyek, slide presentasi, dan mockup ui. Untuk sharing lebih enak kalo setup webserver untuk serving file-file tersebut daripada copy-paste lewat flashdisk.
Sabtu, 21 April 2012
Statistik ukuran file HTML di Wikipedia Indonesia offline
Let's do an experiment. Ada mirror Wikipedia bahasa indonesia lokal (entah kapan downloadnya).
Wah, ternyata tampilannya kurang informatif, data terlalu mengelompok pada tiga pertama bins. Sekarang coba plot ukuran file dari yang terkecil sampai terbesar.
$ cd wikipedia_id
$ du . -sh
4.1G .
Total ukurannya 4.1 Gigabyte termasuk file gambar, html dan file pendukung lain.
Langkah pertama generate data ukuran file hanya yang bertipe html, gunakan du, grep dan cut.
$ du . -ab | grep \.html$ | cut -f 1 > /tmp/stats.txt
$ head /tmp/stats.txt
7519
8254
8910
8907
8560
8834
10463
8776
9558
10196
$ wc -l /tmp/stats.txt
277899 /tmp/stats.txt
Ada sekitar 277.899 file html dengan informasi ukuran dalam byte tersimpan pada file stats.txt.
Untuk pembuatan graph histogram statistik, saya menggunakan Python modul matplotlib.
#!/usr/bin/env python
# generate_hist.py
import matplotlib.pyplot as plt
data = open('/tmp/stats.txt').readlines()
data = map(int, data)
plt.hist(data, 50)
plt.title('Histogram ukuran file HTML Wikipedia ID offline')
plt.xlabel('Ukuran file (byte)')
plt.ylabel('Jumlah file')
plt.savefig('hist1.png')
![]() |
| hist1.png |
Labels:
python
Kamis, 19 April 2012
Rabu, 11 April 2012
Menghasilkan kombinasi alfabet menggunakan Python
Berikut kode program Python memanfaatkan modul
itertools untuk menghasilkan kombinasi dari list
# two_alfabets_combination.py
import itertools
import string
def create_circular_alfabet(count=26):
multiplier = count / 26 + 1
result = string.lowercase * multiplier
return result[:count]
source = create_circular_alfabet(100)
item_length = 2
output_file = 'result.txt'
combination_result = itertools.combinations(source, item_length)
fh = open(output_file, 'w')
count = 0
for item in combination_result:
fh.write('%s ' % ''.join(map(str,item)))
count += 1
fh.close()
print "Finished %s result items, check %s" % (count, output_file)
Berikut hasil setelah dijalankan
$ python two_alfabets_combination.py
Finished 4950 result items, check result.txt
$ wc result.txt
0 4950 14850 result.txt
$ cat result.txt
ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av aw ax ay az aa ab ac ad ae af ag ah ai aj ak al am an ao ap aq ar as at au av
.
.
.
Improvement: gunakan modul argparse atau optparse untuk membuat tool command line.
Labels:
python
Rabu, 04 April 2012
Update GCC terbaru pada Ubuntu
Ternyata ada PPA(Personal Package Archive) untuk GCC (GNU Compiler Collection).
Tambahkan PPA,
Update & Install
Mau coba pake salah satu sub module Scipy ternyata keluar error
Sumber
Tambahkan PPA,
$ sudo add-apt-repository ppa:ubuntu-toolchain-r/test
Update & Install
$ sudo apt-get update
$ sudo apt-get install gcc-4.6
Mau coba pake salah satu sub module Scipy ternyata keluar error
ImportError: libquadmath.so.0: cannot open shared object file: No such file or directory. Ternyata libquadmath (GCC Quad-Precision Math Library) tersedia mulai GCC versi 4.6.
Sumber
Labels:
C,
programming,
python,
Ubuntu
Senin, 02 April 2012
Mengambil Informasi Daftar Isi File PDF, Python
Install dulu pdfminer
Cara menjalankan
$ sudo pip install pdfminer
#!/usr/bin/env python
# parse_toc.py
from pdfminer.pdfparser import PDFParser, PDFDocument
def parse(filename, maxlevel):
fp = open(filename, 'rb')
parser = PDFParser(fp)
doc = PDFDocument()
parser.set_document(doc)
doc.set_parser(parser)
outlines = doc.get_outlines()
for (level, title, dest, a, se) in outlines:
if level <= maxlevel:
print ' ' * level, title
if __name__ == '__main__':
import sys
if len(sys.argv) != 3:
print 'Usage: %s xxx.pdf level' % sys.argv[0]
sys.exit(2)
parse(sys.argv[1], int(sys.argv[2]))
Cara menjalankan
$ chmod +x parse_toc.py
$ ./parse_toc.py somefile.pdf 1
Labels:
python
Kamis, 23 Februari 2012
Jika bom nuklir diledakkan di Bandung
Apa jadinya kalo bom nuklir di jatuhkan di Kota Bandung, berikut prediksi dari NUKEMAP.
Tsar Bomba (50 Mt) - The largest USSR bomb tested
Tsar Bomba (100 Mt) - The largest USSR bomb designed
Keterangan:
Credit: NUKEMAP
Tsar Bomba (50 Mt) - The largest USSR bomb tested
![]() |
| 50 Megaton TNT |
Tsar Bomba (100 Mt) - The largest USSR bomb designed
![]() |
| 100 Megaton TNT |
Keterangan:
Credit: NUKEMAP
Langganan:
Entri (Atom)



