Don't bother like my brother

Just another WordPress weblog

 

OpenFrameworks ofProject tab completion September 1, 2010

Filed under: IT, code, interesting, tips — Artem @ 11:26 am

I prefer to do many things in console and am used to tab completion in programs. It felt uncomfortable to type the plugin and project names in ofProject, especially when you have many of them. So I have created a small script that looks into appropriate directories and then autocompletes the names when you press tab.

_ofProject()
{
 local cur prev

 COMPREPLY=()
 cur="${COMP_WORDS[COMP_CWORD]}"
 prev="${COMP_WORDS[COMP_CWORD-1]}"
 opts="add"
 local ADDON_DIRS=$(ls -l /home/alius/Code/openframeworks/addons/ | grep '^d' | awk '{ print $8 }')
 local APP_DIRS=$(ls -l /home/alius/Code/openframeworks/apps/myApps/ | grep '^d' | awk '{ print $8 }')

 case "${prev}" in
    add)
        COMPREPLY=( $(compgen -W "${ADDON_DIRS}" -- ${cur}))
        return 0
        ;;
    *)
        COMPREPLY=( $(compgen -W "${APP_DIRS}" -- ${cur}))
        return 0
        ;;
 esac
}
complete -F _ofProject ofProject

What you need is just change the paths and place this script into /etc/bash_completion.d/ as ofProject

 
 

Android PopupWindow example

Filed under: IT, code, tips — Artem @ 11:04 am

I’ve struggled for some time to get the PopupWindow to work on Android. For all of those who have trouble making it to work here is a short tutorial.

First, create an XML layout, name it popup_layout.xml and in the res/layout/ folder:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/popup_menu_root"
    android:background="#FFFFFF"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <Button android:id="@+id/popup_menu_button1"
        android:text="close"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <Button android:id="@+id/popup_menu_button2"
        android:text="ok2"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
    <Button android:id="@+id/popup_menu_button3"
        android:text="ok3"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" />
</LinearLayout>

Here I have created a linear layout and put three buttons inside. So that the popup is visible I have made the background white.

Now to the code. You probably already have a class where you need to create a popup. You can declare it wherever you need. I needed to show the popup window after user clicks a button, so I made it class-level and declared in the beginning:

private PopupWindow pw;

Next in the appropriate onClickListener I create the PopupWindow and show it:

// get the instance of the LayoutInflater
LayoutInflater inflater = (LayoutInflater) PopupWindowClass.this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate our view from the corresponding XML file
View layout = inflater.inflate(R.layout.popup_menu, (ViewGroup)findViewById(R.id.popup_menu_root));
// create a 100px width and 200px height popup window
pw = new PopupWindow(layout, 100, 200, true);
// set actions to buttons we have in our popup
Button button1 = (Button)layout.findViewById(R.id.popup_menu_button1);
button1.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View vv) {
        // close the popup
        pw.dismiss();
    }
});
Button button2 = (Button)layout.findViewById(R.id.popup_menu_button2);
button2.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View vv) {
        Toast.makeText(PopupWindowClass.this, "Hello", Toast.LENGTH_LONG).show();
    }
});
Button button3 = (Button)layout.findViewById(R.id.popup_menu_button3);
button3.setOnClickListener(new OnClickListener() {
    @Override
    public void onClick(View vv) {
        finish();
    }
});
// finally show the popup in the center of the window
pw.showAtLocation(layout, Gravity.CENTER, 0, 0);

Hope this helps you :-)

 
 

Android Secret Codes July 6, 2010

Filed under: IT, interesting, tips — Artem @ 11:41 pm

There are some secret codes that you can dial in you Android dialer app. All these codes have the following mask: *#*#SOME_NUMBERS#*#*

  • *#*#4636#*#* - Testing application, which has phone information and some settings (imei, network name, type, location, etc), battery information including history, and usage statistics
  • *#*#8351#*#* - Turn on voice dial logging
  • *#*#8350#*#* - Turn off voice dial logging
  • *#*#7262626#*#* - FieldTest application
  • *#*#225#*#* - Calendar information
 
 

IPv6 October 1, 2009

Filed under: tips — Artem @ 9:22 pm

A lot of software is already IPv6-aware and sometimes tries to use the IPv6 first instead of bad old v4. This already confused me once in Vista as I described here. This time it was Firefox in Linux. It took me a while to find the reason why it can connect to google and few other pages but not the rest of the Internet while I can ping these addresses. The solution is simple, just go to about:config and set the “network.dns.disable.ipv6″ key to true :-)