Skip to main content

Posts

Showing posts from 2015

How To Make Program to Corrupt File (Java)

Sometime we intentionally want our file to be corrupted e.g. to test software reliability. So, I made a program in Java that intentionally corrupt file. Please be careful to use this program as this program will make your file corrupt and cannot be reverted. Please backup your file before making it corrupt. OK, the logic is very simple. For each byte in the file, I simply put any random character (ASCII character is from 0 to 255). Here is the complete Java program: import java.io.RandomAccessFile; import java.util.Random; /**  *  * @author arwankhoiruddin  */ public class CorruptFile {     /**      * @param args the command line arguments      */     public static void main(String[] args) {         // TODO code application logic here         String FILEPATH = args[0];         System.out.println("File to corrupt: " + FILEPATH);     ...

Tips Berwisata di Saat Liburan Panjang bagi Pembenci Macet dan Keramaian

Saya adalah seorang yang tidak suka pada macet dan tempat wisata yang terlalu ramai. Saya tidak suka macet karena macet bikin waktu serasa cuma habis di jalan. Saya tidak suka tempat wisata yang terlalu ramai karena tujuan berwisata adalah menikmati alam dan menikmati quality time bersama keluarga. Di tempat wisata yang terlalu ramai, waktu biasanya akan dihabiskan untuk nyari tempat parkir, nyari tempat kosong untuk berteduh atau bermain, dan susah sekali untuk bisa menikmati tempat wisatanya sendiri karena justru yang terlihat adalah ramainya. Pada liburan panjang seperti ini (natal dan tahun baru di akhir minggu ditambah dengan liburan anak sekolah), kondisi jalan dan tempat wisata mainstream sungguh sangat tidak menarik. Di mana-mana jalanan macet, dan di tempat-tempat wisata, terlalu banyak orang yang berkunjung. Untuk menyiasati, ada beberapa hal yang bisa dilakukan: 1. Jangan lewat jalan yang biasa dilewati orang. Carilah jalan alternatif (lebih baik gunakan aplikasi peta s...

Install Python 3 and use VirtualEnv (OS X)

Install xcode: $  xcode - select   -- install Install homebrew: $  ruby   - e   "$(curl -fsSL  https://raw.githubusercontent.com/Homebrew/install/master/install )" Create .bash_profile: $ touch ~/.bash_profile Put this line inside .bash_profile:  export  PATH = / usr / local / bin : $ PATH Install python3: $ brew install python3 Create virtual environment. To make it easily found, create it under home: $ cd ~ && pyvenv arwan Activate the virtual environment created: $ source arwan/bin/activate Now you can start working in the new virtual environment. Note that it is worth to look at requirements.txt to see required packages on certain projects.

Pull Older Version from Git

Clone the current repository: $ git clone Go to the cloned directory: $ cd Find the sha1 of the commit to pull. For stash, click on the commit and look at the address bar. It will be the last part of the url. For example, the sha1 for http://mystash.arwan.com/repos/arwanproj/commits/0b004fdb420838ca04c15b25ad2e0b66a5693963 will be  0b004fdb420838ca04c15b25ad2e0b66a5693963   Fetch the version based on the sha1 number found: $ git fetch origin Checkout: $ git checkout FETCH_HEAD

Understanding *args and **kwargs in Python

I need some time figuring out what is behind *args and **kwargs. Finally I understand it, so I want to share it with you here. First of all, you need to know that what you need to understand here is the asterix (*), not the "args" and "kwargs". So if you write f(*params, **oparams) and f(*args, **kwargs), they both will behave similarly. * is used to pass varied length of arguments. Here is an example on how to use * def test_args(a, *b): def test_args(a, *b): print "normal variable: ", a print "first argument: ", b[0] print "second argument: ", b[1] print "third argument: ", b[2] test_args('arwan', 1,2,3,4,5) From the example, "a" is single variable while "b" is varied length of argument. Thus, the first argument will be passed to "a" where the next variable will be passed to "b". Thus, all arguments (1,2,3,4,5) will be passed to "b" ...

Stack Implementation in Python

Stack is one of important concepts in data structure. Stack can be defined as abstract data type (ADT) that collects items with LIFO (last in, first out) principle. Two operations are known for stack i.e. push and pop. Push will add an item into stack, while pop will remove the last element that was added into stack.  You may think stack concept as if you arrange your plates. You will put a plate above other plates, but when you want to take one plate, you will take it from the top. To implement it in python, you will have at least three methods i.e. __init__, push, and pop. However, here we will add some more methods i.e. isEmpty (to check if the stack is empty), peek (to get the item at the top) and size(to get the number of item(s) in the stack). Here are the implementation in python: class Stack: def __init__(self): self.items = [] def isEmpty(self): return self.items == [] def push(self, item): self.items.append(item) def pop(s...

Dragon Ball Super Opening Lyrics (Chozetsu - Dynamic)

Itsuka Togireta  yume no tsudzuki Hajimeyou    Hoshi o tsunagete  Sora ni tobira kakebaii    arata na suteeji wa  Kami ni idomu basho    Kyouretsu - mouretsu -dynamic! Let's Go! GO ! daipanikku  Makeru to tsuyoukunaru    Minohodo shirazu ni wa  koukai toka genkai toka nai mon     Souzetsu-chouzetsu-dynamic! Let's Go! Yes ! renda kikku  abisete mushaburui    sugee koto ga matterun da ze

Free overnight stay at KLIA2

I landed at Malaysia yesterday night. My plan was to find a hotel nearby and go to KL in the morning. I saw some quite cheap hotels near KLIA2. Luckily, while in waiting room before flight, I met a new friend that will fly to Laos and have overnight transit at KLIA2. A new conversation will give us a new friend, and a new friend will always benefit us in any way. He told me to just make a free overnight stay at KLIA2. Hmmm... I should try. In KLIA2, most of the chairs are not meant to be used to sleep. They design the chair so that it is almost impossible for a person to lay down on the chair. But, "most" means that we will find some chairs that can be comfortably used for sleeping. The chairs are above the Departure hall in 3rd Floor (just another floor above gate to international departure). Fiuuuuh, my pocket is saved for one night... thanks, pal...

Download YouTube video as MP3

There are some ways to convert youtube video to mp3. I used to use online converter, but it fails when the video is lengthy (say more than 30 minutes). From my experience, the most convenient way for me is using youtube-dl (I love terminal. It is command based, so it might not very convenient for those who love GUI-based app). Here are the most convenient steps that I use: ## INSTALLATION ## The most convenient way to install is using pip . Followings are full steps for installation: 1. Install python 2. Download pip installer here . 3. Go to folder where you put get-pip.py then write this in your terminal $ python get-pip.py 4. Now you have pip installed. Time to download youtube-dl. Type this in your teminal $ pip install youtube-dl ## DOWNLOAD TIME ## 1.  Now you can download youtube video and convert it to mp3. Just type this in your terminal (change the video URL to the one you want to download) $ youtube-dl --extract-audio --audio-format mp3 https://www.youtub...

Tips Murah Parkir Menginap di Stasiun Jogja

Bismillah... Menjadi seorang pelanggan PJKA (Pulang Jumat Kembali Ahad) seperti saya memang perlu trik-trik khusus di perjalanan, baik itu trik untuk menyiasati perjalanan agar terasa nyaman, tidak melelahkan, tapi juga trik bagaimana agar mengeluarkan duit seminimal mungkin. Pada posting kali ini saya ingin berbagi tentang parkir motor menginap yang murah di stasiun Jogja. Di Jogja, ada dua stasiun besar, yaitu Lempuyangan dan Tugu. Selain itu, ada beberapa stasiun kecil (yang saya tahu Stasiun Wates dan Stasiun Maguwo atau bandara). Dari stasiun tersebut, saya hanya akan membandingkan dua stasiun besar di Jogja saja, yaitu Lempuyangan dan Tugu. Stasiun Tugu Di Stasiun Tugu, setau saya hanya ada parkir di area dalam stasiun. Tarif parkir di tempat ini sudah begitu banyak dikeluhkan orang, bahkan beberapa kali malah sempat masuk berita. Bagaimana tidak mengeluh, tarif yang digunakan adalah tarif per jam. Kalau kita menginap sehari semalam, maka tarif sehari semalam kira2 sebesar...

Some important adb commands (android)

In Mac, the adb is located at /Library/Android/sdk/platform-tools/ list connected devices ./adb devices list installed applications ./adb shell pm list packages clean app data ./adb shell pm clear com.scramphoto.scramphoto uninstall app using adb ./adb uninstall com.scramphoto.scramphoto install app using adb ./adb install -r ~/Download/scramphoto.apk log for adb ./adb logcat save logcat to text ./adb logcat -d > ~/Documents/logcat.txt clear logcat ./adb logcat -c   browse directory on device ./adb shell ls /sdcard/Pictures copy files from device to computer ./adb pull /sdcard/Pictures/ ~/Documents/Pictures   remove files on device  ./adb shell rm /sdcard/Pictures/*  

Sikuli Tutorial - Detect any activity in monitor

This script is used if we want to detect if any activity(ies) happen in monitor using Sikuli . The idea is simple: 1. Capture the screen, 2. Take another capture after certain time interval 3. Compare the second capture to the first 4. Delete temporary image Here is the script (I use python script) def activityDetected():     screen = Screen()     while True:         file = screen.capture(screen.getBounds())         sleep(2)         file2 = screen.capture(screen.getBounds())         f = Finder(file)         f.find(Pattern(file2).exact())         matchVal = f.hasNext()           f.destroy()                  os.remove(file)         os.remove(file2)         if matchVal:             return Fal...

Automated Software Testing: Handling Memory Problem in Sikuli

One of the most important step in software engineering is software testing. Proper software testing will dramatically reduce the risk during software implementation. By the end of the day, testing will ensure your stakeholder about the quality of your software. When you find a bug, you will assign a task to developer to fix it. When the developer has fixed the bug, it will be reassigned back to you. When you find another bug, you and the developer will do it again and again. Bad news is, when your program is fixed in one part, sometime it will make trouble in other part. Sometime what you have found as bug and then fixed, it will be bug again when the developer works in another part or your software. Thus, we have to do thorough testing for each release to ensure that no bugs are re-introduce. Isn't it boring? Yes, doing repetitive task (especially if the developer make daily release) will be boring. Thus, we need to automate our testing. You can do automation with any softwa...

Tips memulai riset - mencari topik dan literatur

Ketika kita mau mendorong sebuah mobil, maka tahap yang paling susah adalah ketika mulai mendorong dan belum bergerak. Ketika mobil sudah bergerak, maka tenaga yang diperlukan tidak sebanyak sebelum bergerak. Dalam banyak hal di hidup kita, memulai biasanya juga merupakan tahap yang paling susah, termasuk dalam urusan riset. Banyak hal yang membuat kita bimbang: topik apa? harus mulai belajar darimana? dan sebagainya. Kebimbangan pertama: mencari topik Untuk mencari topik, kita bisa memulai dengan mencari kata kunci yang saat ini sedang trend di dunia. Pencarian ini tentu saja bergantung pada bidang yang anda tekuni. Apabila anda adalah orang social science, maka riset anda bisa dimulai dari permasalahan yang menurut anda penting dan kira-kira bisa anda cari solusinya. Jika anda bingung, bisa mencoba memulai dari google trend (http://www.google.com/trends/?geo=ID) atau mencari trending topik di twitter, atau juga dengan skimming judul-judul berita di situs-situs berita. Atau juga d...