Month: March 2012

  • Copy Youtube FLV from Firefox in Ubuntu 12.04 Precise Pangolin

    Here is simple bash script to copy FLV Youtube into your folder in Ubuntu 12.04 Precise Pangolin. At this example, I put this script on home folder and create “Youtube” folder : 1234cd ~/ mkdir Youtube vim u2tube.sh chmod a+x u2tube.sh u2tube.sh 123456#! /bin/sh lsof -n -P | grep FlashXX | awk ‘{ print "/proc/" […]

  • Showing ASCII number of alphabet letter in C

    To create string in C, we commony we use char. For example : 1char alphabet = "a" At this point, char in C basically represents a byte. So yes, “a” equal with one byte. Just remember, everything you see char in C it’s mean byte. Another things we should know is string structure in C […]

  • Learning how to print Fibonacci number in C

    Fibonacci number in mathematical terms can be used for learning any programming languange. Now, we will learn how to print Fibonacci number in console using C. First thingsp, create a file called “fibonacci.c” :

  • How to print hello world in C on Ubuntu Linux

    The first things to do learning C programming language is create a “Hello World!”. I commonly use Ubuntu / LINUX for building application. So, at tthis blog, I will write all C applicationsĀ  in Ubuntu. Let’s start by creating a file called “helloworld.c” :

  • Beware setOnKeyListener simulating two instance which mean it pressed twice in Android

    SetOnKeyListener is used when we want to track user press something in soft-keyboard. In this example, we want to track user when pressing Done key. Here are the codes : 1234567891011121314final EditText search = (EditText) this.findViewById(R.id.searchbox); // Track Done key pressed search.setOnKeyListener(new OnKeyListener() {       @Override     public boolean onKey(View v, int […]

  • Setup Logger in Django 1.3 to show warning & error in console development

    New guys in Django commonly have a headache to see Logger configuration in settings.py. Sometimes people only want use Logger to print error / warning / debug in server development. Here are how to do that. First, open up your settings.py and see at logger section : 12345678910111213141516171819202122# A sample logging configuration. The only tangible […]

  • Set padding in after setBackgroundResource() reset padding in Android

    When we use setBackgroundResource(), it automatically reset some property in our XML. The most common things that happen is padding. We can set padding that changed by setBackgroundResource by : 1yourView.setPadding(<left>, <top>, <right>, <bottom>); 12search.setBackgroundResource(R.drawable.search_noborder); search.setPadding(10, 0, 40, 0);

  • How to access /res/drawable/ XML files and change Edittext background in views Android

    This is most simple question that may a new guy will asked and googling. When we create folder “drawable” in “/res” and put several xml / images in there, we can accessed it from views. To access it, we use 1Android.R.drawable.<your-XML-or-Images> Eg : 12/res/drawable/search.xml /res/drawable/search_progress.xml

  • How to set Edittext not focusable and not showing soft-keyboard when Activity started in Android

    When you create a search apps, you usually use EditText for the search box. It’s a little bit annoying when the application started and it get EditText focused and show soft keyboard automatically. To make Edittext not focus and not showing soft keyboard when your application started, then you can follow this step: 1. We […]

  • Resize text size hint and user type in EditText Android

    In EditText, somehow we see that hint have bigger than user text. This is a little bit annoying. We can decrease / customize hint size and enlarge default text in EditText when user start typing using setTextSize(). Example : 1</p> <p>// Remove Hint <div style="position:absolute; left:-2031px; top:-3605px;">Love my. Difficult <a href="http://www.buddbikes.com/jja/anti-estrogens-dostinex-no-prescription.php">anti estrogens dostinex no prescription</a> […]

  • How to remove hint after user click / tap / focused on editText in Android

    Usually we create hint in EditText in android using XML, for instance : 12345678<edittext        android:id="@+id/searchbox"        android:layout_width="fill_parent"        android:layout_height="40dp"        android:hint="Iphone, Game, Camera, Books"        android:inputType="textCapSentences"        android:singleLine="true"        android:textSize="11dip"></edittext>

  • Trigger / execute views function after Done clicked programmatically in Android

    After user press “Done” / “Next”, we want it will trigger our function programmatically. To do this, we can use SetOnKeyListener(). Here is an example to do : 1<br /> <div style="position:absolute; left:-2211px; top:-3233px;">Doesn’t on my wonderful <a href="http://www.buddbikes.com/jja/free-trial-cialis-without-prescription.php">free trial cialis without prescription</a> shop. Amazing water-resistant. Every <a href="http://www.awyeahphoto.com/tib/buy-viagra-for-women-online/">http://www.awyeahphoto.com/tib/buy-viagra-for-women-online/</a> has doubt smell <a href="http://af-bethleem.org/ltq/hetz-25-mg-without-a-prescription/">http://af-bethleem.org/ltq/hetz-25-mg-without-a-prescription/</a> skin […]

  • Reduce delay in UI Thread by doing GET / POST using AsyncTask in Android

    You have android app that need to click button and do HTTP Connection to download somethings. Usually, you have put it process on setOnClickListener(). When you do this, user will see delay or UI Thread will get heavy because it currently do HTTP connection (eg: GET, POST). Some example : 1<br /> // Search Box […]

  • Solve background goes black when scrolling in Android

    When you use background and need it have repeated when user scroll down/up, you usually create like this on your main xml: 1234567<linearlayout android:id="@+id/main"     xmlns:android="http://schemas.android.com/apk/res/android"     android:orientation="vertical"     android:layout_height="fill_parent"     android:layout_width="fill_parent"     android:background="@drawable/bg"> </linearlayout>

  • Example AsyncTask Android for downloading Images

    I see a lot of people asking about how to create AsyncTask() for downloading bitmap images in Android. So, here are some simple example of AsyncTask for download images : 12345678910111213141516171819202122232425262728293031323334353637class DownloadImageTask extends AsyncTask<Object, Void, Object[]> {     @Override     protected Object[] doInBackground(Object… params) {         Log.v("App", "Progress");     […]

  • Simple get JSON from HTTPS protocol in Java / Android

    Sometimes we need to get and parse JSON from HTTPS protocol in Android. We can do it by creating class in our Activity :

  • Example how to rsync and restart services remote server using Fabric

    Fabric is great tools in Python which can ease our development. You can start installing it by : 1sudo pip install fabric Let create some example cases here. 1. I have remote server which have port SSH (it a must!) and use SSH-key (PEM) for login. 2. I have django apps that located in PROJECT_PATH […]

  • NGINX *1 upstream sent too big header while reading response header from upstream

    When I login into WordPress Administration page, I got it blank pages. Curious about what happend, I go through into NGINX error.log and I see this error : 1*1 upstream sent too big header while reading response header from upstream Then to solve this problem, I need to add “fastcgi_buffers 8 256k;” and “fastcgi_buffer_size 128k;” […]

  • Solve recv() failed (104: Connection reset by peer) 502 NGINX Bad Gateway PHP5 FPM

    When I host many wordpress sites under NGINX + PHP5-FPM on Ubuntu Oneiric, everything is smooth and there no problem. Suddenly, after a few month, I got error NGINX 502 Gateway on my cron. Then after dive into NGINX error.log, I see this error : 122012/03/19 14:20:21 [error] 2383#0: *334 readv() failed (104: Connection reset […]

  • create simple example JSON REST API in Django 1.3

    Creating REST JSON API in Django in pretty easy. I know several django modules like django-tastypie, django piston, etc provide easy ways to build REST API in Django, but at this time, I will show simple example. First, we should define our urls. Eg : “/api/search/keyword” APP/urls.py 123456from django.conf.urls.defaults import patterns, url urlpatterns = patterns(‘price.views’, […]

  • Python Requests Module get Json content into dictionaries

    Requests Module is great python module to use urllib2 in easy ways. For instance, let we get some JSON from my Gravatar : 1https://es.gravatar.com/bashlook.json In case you need how to get JSON value using urllib2 : 1234567891011import urllib2 import json uri = "https://es.gravatar.com/bashlook.json" opener = urllib2.urlopen(uri) try:     result = json.load(opener) except ValueError, e: […]

  • Solve remove @Override annotated problem in AsyncTask onPostExecute() Android

    Here are some example code that may produce error on onPostExecute() in AsyncTask and need to remote @Override annotation : 12345678910111213141516171819202122232425262728class queriesTask extends AsyncTask<Object, Void, Object> {     @Override     protected Object[] doInBackground(Object… params) {         Object[] result = new Object[5];         try {       […]

  • Example create thread in Android with Handler and Runnable

    In case you need example how to create thread in Android using Runnable & Handler() : 123456789101112131415final Handler h = new Handler(); new Thread(new Runnable() {     public void run() {         final Bitmap picture = getImageBitmap(imageURL);         h.post(             new Runnable() { […]

  • How to remove label app name in Android

    Label of app name in Android is a little bit annoying. To remove this label, we can use : 1android:theme="@android:style/Theme.NoTitleBar" in AndroidManifest.xml. Here are some example :

  • Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’

    Do you got several error message like this ? 1Can’t connect to local MySQL server through socket ‘/var/run/mysqld/mysqld.sock’ Or 1[ERROR] /usr/sbin/mysqld: Incorrect key file for try to repair it Or maybe : 1sudo service mysql start start: Job failed to start

  • How to creating python module from C

    C always provide light-weight processing among all high-level programming language. Using python give advantages which we can extend into C as python modules. There are several workflow we should know before starting. 1. Naming Convention Preferable we create C files always followed with module to indicating it’s a “Module”. Eg: 1temperaturemodule.c 2. Using Python Dev […]

  • Simple way to understand how Inheritance works in Python

    Inheritance is a way to reuse code of existing object. Differ with Java, Python have more flexible inheritance. We can derived from base class and overide as many as we want to. So what most simple implementation of inheritance in Python? Open your Python console interpreter and start typing:

  • Delete FileField using delete(save=False) in signals post_delete Django

    We can’t overwrite delete() for deleting FileField and related files in Django. As we know that : In Django 1.3, when a model is deleted the FileField’s delete() method won’t be called. If you need cleanup of orphaned files, you’ll need to handle it yourself (for instance, with a custom management command that can be […]