Thursday, April 24, 2014

Solving "perl: warning: Setting locale failed" in Ubuntu

It is happen because locale setting needs to be reconfigured. To do that, just type this in terminal
sudo dpkg-reconfigure locales
If it doesn't successfull, try to set locale first
sudo locale-gen en_US en_US.UTF-8
and then type dpkg again.

source

Sunday, April 20, 2014

Install Squid Proxy Ubuntu Server

  • Install Squid
sudo apt-get install squid
  • Set squid to run after startup
update-rc.d squid3 defaults
  • Open squid configuration file
sudo nano /etc/squid/squid.config
  • Add this to the first line of squid.conf to use ipv4 only
dns_v4_first on
  • Press Ctrl+w to search "http_access deny all"
  • clear "#"
  • Search "acl localnet" with Ctrl+w
  • add line "acl localnet src your-ip-public"
  • Press Ctrl+w to search "http_access allow"
  • add line "http_access allow localnet"
  • Press Ctrl+o and then press enter to save edited file
  • restart squid service
sudo service squid3 restart
NB:
  • You can change localnet to whatever you want
  • To change proxy port, search "http_port 3128" and change 3128 with port you want
Source

Friday, April 11, 2014

How Priority Queue in Java is Working

Source Code

  1. import java.util.*;  
  2. class PQ{  
  3.     static class PQsort implements Comparator<Integer>{   // inverse sort  
  4.         public int compare(Integer one, Integer two){  
  5.             return two - one;           // unboxing  
  6.         }  
  7.     }  
  8.     public static void main(String[] args){  
  9.         int[] ia = {1,5,3,7,6,9,8};         // unordered data  
  10.         PriorityQueue<Integer> pq1 =   
  11.             new PriorityQueue<Integer>();     // use natural order  
  12.           
  13.         for (int x : ia)                // load queue  
  14.             pq1.offer(x);  
  15.               
  16.         for (int x : ia)                // review queue  
  17.             System.out.print(pq1.poll() + " ");  
  18.         System.out.println("");  
  19.               
  20.         PQsort pqs = new PQsort();          // get a Comparator  
  21.         PriorityQueue<Integer> pq2 =   
  22.             new PriorityQueue<Integer>(10,pqs);   // use Comparator  
  23.               
  24.         for (int x : ia)                // load queue  
  25.             pq2.offer(x);  
  26.           
  27.           
  28.         for (int x : ia)                // review queue  
  29.             System.out.print(pq2.poll() + " ");  
  30.           
  31.         System.out.println(" ");  
  32.     }  
  33. } 

Saturday, April 5, 2014

Backup and Restore Database MySQL

For backup all databases
  mysqldump -u username -ppassword --all-databases > /tmp/alldatabases.sql
For backup spesific database
 mysqldump -u username -ppassword --databases databasename > /tmp/filename.sql
For restore
mysql -u username -ppassword databasename < /tmp/filename.sql

Friday, April 4, 2014

Instaling Kubuntu Desktop without KDE Application

Just type this in terminal
sudo apt-get install --no-install-recommends kubuntu-desktop

Setting Proxy for apt-get in Ubuntu

  1. Open terminal
  2. Type this
    sudo nano /etc/apt/apt.conf
  3. Add this line if there in no authentication in your proxy
    Acquire::http::proxy "http://proxyserver:port/";
  4. Add this if there is authentication in your proxy
    Acquire::http::proxy "http://username:password@proxyserver:port/";
  5. Press Ctrl+x and then press y

Wednesday, March 12, 2014

Check Status and Wear Level Battery in Ubuntu

Just try this in terminal

upower -i /org/freedesktop/UPower/devices/battery_BAT0

And you will get this


In there you can get your battery status. You can also look how many real capacity your battery have. My battery have 38.006 Wh for its designed capacity but just 34.942 Wh left because battery will lose its capacity over time. Thats all :D