Sunday, September 30, 2012

Iterators class example in java

Today I had to use Iterators over a Java List, Java's documentation on Iterator lacks  a good example,here is a  good example about Iterator class.
diagram for iterator class in java

The List and Set collections provide iterators, which are objects that allow going over all the elements of a collection in sequence. The java.util.Iterator interface provides for one-way traversal and java.util.ListIterator provides two-way traversal. Iterator is a replacement for the older Enumeration class which was used before collections were added to Java.

Let say we have an object of ArrayList class name "myList"  . to implement an iterator on a list we should it intialize it on "myList"
Iterator it = myList.iterator();

Iterator methods are :

myList.hasNext()
Returns boolean true or false.
myList.next()
Returns the next object.(with the list's type).
myLlist.revmoe()
Removes the most recent element that was returned by next.


An iterator might be used as follows:

//initializing a list in Java
ArrayList alist = new ArrayList();

//  Add Strings to alist
myList.add("flower");
mList.add("kurdistan");
myList.add("sun");
myList.add("mountain");


for (Iterator it = myList.iterator(); it.hasNext(); ) {
    String s = (String)it.next(); 
    System.out.println(s);
}


Wednesday, September 26, 2012

Microsoft Bing reminds me of beggars in Tehran




    Microsoft Bing reminds me of my undergraduate years in Tehran.  I remember whenever my car was stuck behind a red light in heavy traffic of Tehran, multiple beggars would run to my window and try all new tricks to make me give them some money.  They were actually very smart.  They were not pretending to be poor and asking for money, they were creative in getting your attention...so you had to learn their tricks to not fall into their traps.

    Nowadays Microsoft’s Bing tries to sneak into my computer.  Anytime I install anything I have to make sure Bing has not changed my browser's default search engine, or by sneaked into my router DNS, or attached itself as a free tool with other applications such as facebook!

   Dear Microsoft...I noticed that you have worked hard to make your search engine better, but I just don't wanna switch from Google!  If I want to use Bing, I will let you know, please leave me alone!

Tuesday, September 25, 2012

Difference of "Hosted AdSense for Content" and "AdSense for Content"

I love Google. I think they are great at their job, but there is something which Google is not very good at...naming its products or choosing the right word for their features.

I think lots of Google's products didn't make it to the mainstream just because of their stupid names.
For instance: Orkut, iGoogle, Goolge mini, Google Play ,Google Plus,Google Adsense, Google Site...

Today I was checking out the Google Adsense control panel and I saw this:










After lots of research in forums, I found out "Hosted Adsense for Content" means Youtube ads and "Adsense for content" means actual ads on your site/blog.  Who is in charge of choosing the names in Google?!  

Sunday, September 23, 2012

How to add custom icon for specific application in a unity ubuntu 12.04

I installed a new icon theme for ubuntu 12.04 using "My Unity" i found a very beautiful theme named Breathe, the only problem is it doesn't show an icon for one of my favorite applications (PulseAudio Equalizer) and its icon in unity  shows as a folder icon . (which very annoying)
Here is how to add a custom icon for a specific application in ubuntu 12.04 Unity (hopefully works for all previous unity verions)

First: Find an icon

Fir we need to find an icon for your icon-less application, you can do one of the following:


  1. Steal from another icon theme set
    the location of icon images for icon themes are like this : (Humanity is the name of the icon theme set) :
                                 /usr/share/icons/Humanity/apps/32
  2. Search in google images or in flicker
  3. Take a screenshot of the application (my favorite)
  • Run the application
  • Make sure it is the active window
  • Press alt+print , you will have something like this:


Second: Set the icon


1- Open a root nautilus
sudo nautilus
2- Go to
/usr/share/applications
3- find your application's name in my case (PulseAudio Equalizer), right click and click on properties

4- click on the current icon
5- change it to the image that you found in Step 1 .


now you will see your custom icon for the application that was missing icon file for your icon theme.

Thursday, September 20, 2012

How to see what is on line number # in Linux?

Quick terminal tip:

Sometimes you get errors in compiling a program and it complains something is going on in line number something , let say line number 139   if you want to see what is on the line number 139, in file myProgram.c

tail --lines=+139 myProgram.c

This really saves time, (imagine each time opening a text editor and trying to find line number something, thats a pain in the neck!)

Saturday, September 15, 2012

Useful Chrome Extension : Save chrome tabs and state without hibernation

Today I wanna share with you one of my most favorite extentions for google chrome, Seassion Buddy, which lets say you save the state of your chrome tabs and windows, with a single click and name it and restore it anytime later very fast anytime.

So it feels like you hibernated your computer, except it is extremely fast and also you can save the state and then close and use chrome again.


One of the use cases of session buddy for me is, to save links about each lecture for my courses at school.

Let say I study I have a course "concepts of programming languages" for each lecture I open lots of links in wikipedia and other sites, I used to print all my links and lable them in each folder "lecture one material" and store them (tons of paper very hard to search though them) but now I just use "Session Buddy" to save each lecture's links and name it "session for lecture 1 Course CSC447". it makes reviewing for midterm and final exam a

Sunday, September 9, 2012

How to return current URL without args & queries in PHP?


Today I needed to find out how to return the URL of current page without queries and variables and here is what I learnt:

The difference of URL  and URI in php  .

Example Let say this address:  http:://shevin.info/blog/album.php?album_id=2
 $_SERVER['REQUEST_URI']

will return /album.php?album_id=2

$_SERVER['REQUEST_URL']

will return /album.php

$_SERVER['REQUEST_URL'] returns no queries or arguments or variables or strings attached .

A Suggestion For Google Plus (Max page show in stream )


Google Plus has lots of new features that are totaly new in social world and I like it,
here is an idea for G+ that I came up with :

We should be able to limit the maximum number of posts of a page (that we fallow) in Google+ stream page.

for example I the "wisdom" page, but they show up just too many times in my steam page, I don't want to mute this page but I rather be able to make it show in my stream page every often. I would like to have a set of rules for diffrent set of pages ,for example  here is how I would define my stream page.

"Funny pages"  (maximum 3 times in a row) or (max 3 times out of 10 posts)
"Computer-related pages"   (maximum 10 times in a row) or (max 3 times out of 10 posts)
"Philosophy " (maximum 1 times in a row) ...

I wouldn't be surprise if I see that Google is already working on this feature, because so far any feature idea that came up to me a few months or years later Google implemnted it. that's why I love Google, we feel the same for the features that should be added to Google products.

Wednesday, September 5, 2012

How to use PHP code in phpBB template?

phpBB is a popular free open source forum software, by default for the security measures , they have disabled using PHP code inside the template and you are limitted jsut for a few phpBB tags and syntax for controlling the phpBB conditions:

here is how you can override this security measurement:
if you are sure that nobody is gonna put any malcious php code into your template , do this :
Go to ACP (adminstractip control panel) ,
Go to General
On the left choose Security
now find  Allow php


another important thing to do is now

Instead of normal php syntax in html which is
you have to use


echo "Hello World!"; 


for example here is a code to return the current page in php to put in phpBB template.



echo "Hello World!";
$currentpage = $_SERVER['REQUEST_URI'];

Related

Labels

computer (48) ubuntu (46) linux (28) tutorial (20) opinion (17) programming (14) software overview (13) terminal (12) troubleshooting (8) life (7) literature (7) poem (7) human languages (6) vim (6) bash (5) google (5) python (5) android (4) cars (4) phpBB (4) suggestion (4) tips (4) 12.04 (3) Chef (3) extension and addons (3) firefox (3) java (3) personal (3) russian (3) shell (3) windows (3) 64bit (2) Calligraphy (2) Chicago (2) Vagrant (2) apple (2) backup (2) bug (2) code (2) eclipse (2) funny (2) google chrome (2) idea (2) monitor (2) php (2) phpBB3 (2) shorter prompt (2) ssh (2) virtualbox (2) $_SERVER['REQUEST_URI'] (1) 2.7 (1) ALT+Backspace (1) AVR (1) Alt-Printscreen-K (1) AutoRotate (1) CTRL+ALT+DELETE (1) DRM (1) Debugging (1) Gimp (1) Gimp 2.8 (1) Microcontroler (1) Restart X (1) UML (1) Ventra (1) adsense (1) amazon (1) audio (1) aws (1) background process (1) battery (1) bing (1) blank (1) blogging (1) bmw (1) boot (1) business review (1) car (1) cd (1) chrome (1) comcast (1) computer kubuntu (1) conference (1) cookie (1) cron (1) database (1) date (1) display (1) domain name (1) download manager (1) dual boot (1) dual monitor (1) extensions (1) feature request (1) file (1) folder (1) freeze (1) gimp single window (1) git (1) gnome 3.10 (1) google docs (1) google plust (1) google+ (1) grep (1) icon (1) install (1) iterator (1) links (1) linu (1) linux links (1) list (1) mac os (1) media server (1) microsoft (1) moonlight (1) music (1) mysql (1) name (1) nautilus (1) netflix (1) notepad++ (1) parking (1) permission (1) philosophy (1) photo (1) prompt (1) protest (1) ps3mediaserver (1) putty (1) read from file (1) realtek (1) resolution (1) roku (1) samsung (1) scala (1) screenshot (1) security (1) selinux (1) server (1) skype (1) space (1) spam (1) spambot (1) sql (1) suspension (1) system monitor (1) tar (1) task manager (1) template design (1) th23 domain (1) thinking (1) ubuntu 13.10 (1) unity (1) vimrc (1) virtual machine (1) weblogic (1) wget (1) with space (1) xorg (1) xrand (1)