Month: March 2012

Copy Youtube FLV from Firefox in Ubuntu 12.04 Precise Pangolin

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/" …

+ Read More

Showing ASCII number of alphabet letter in C

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 …

+ Read More

Learning how to print Fibonacci number 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

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

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 …

+ Read More

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

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 …

+ Read More

Set padding in after setBackgroundResource() reset padding in Android

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

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 12Android.R.drawable.<your -XML-or-Images> </your> 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

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 …

+ Read More

Resize text size hint and user type in EditText Android

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> …

+ Read More

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

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 : 1234567<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

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 …

+ Read More

Solve background goes black when scrolling in Android

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: 12345678<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

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");     …

+ Read More

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

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;” …

+ Read More

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

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 …

+ Read More

create simple example JSON REST API in Django 1.3

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’, …

+ Read More

Python Requests Module get Json content into dictionaries

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: …

+ Read More

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

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 {     …

+ Read More

Example create thread in Android with Handler and Runnable

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() { …

+ Read More

How to creating python module from C

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 …

+ Read More

Simple way to understand how Inheritance works in Python

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

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 …

+ Read More