Don't bother like my brother

Just another WordPress weblog

 

OpenFrameworks object detection September 1, 2010

Filed under: IT, code, software — Artem @ 12:41 pm

I found out about OpenFrameworks from the project Laser Tag by Graffiti Research Lab. Got curious, and the first thing I created with OF was a bit similar to the Laser Tag :-)

I used OpenCV to detect the button on the wall, and then its coordinates to draw the line. Later I will post the source code.

 
 

OpenFrameworks ofProject tab completion

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

 
 

Quote August 19, 2010

Filed under: IT, interesting — Artem @ 11:31 am

“If I plug the machine into a d/port with two monitors connected, it posts on one monitor and the OS X desktop loads on the other. Now that’s almost as messed up as Barack Obama winning a Nobel Peace Prize.”

By leppy700m at insanelymac.com

 
 

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

 
 

Benchmarking your C code September 11, 2009

Filed under: code — Artem @ 7:57 pm

Ever wondered how long does it take for a piece of your code to execute? It is easy to find out the execution time using the gettimeofday function from the <sys/time.h>. The code is the following:

#include <sys/time.h>

struct timeval t1, t2;
double tdiff;

gettimeofday(&t1, NULL);

<your code here>

gettimeofday(&t2, NULL);
tdiff = (t2.tv_sec - t1.tv_sec) + (t2.tv_usec - t1.tv_usec) / 1000000.0;
printf("Execution time: %2.5f\n", tdiff);
 
 

Quote July 23, 2009

Filed under: IT, interesting — Artem @ 9:43 pm

“[...] big difference between the web and traditional well controlled
collections is that there is virtually no control over what people can
put on the web. Couple this flexibility to publish anything with the
enormous influence of search engines to route traffic and companies
which deliberately manipulating search engines for profit become a
serious problem.”

– Sergey Brin, Lawrence Page (see references, [A])

 
 

HTTP tunnelling over ssh June 11, 2009

Filed under: IT — Artem @ 7:05 pm

It is very easy to tunnel your web traffic over ssh using Firefox and the FoxyProxy plugin. Create your SSH tunnel by executing this command (where “port” is any random port that is not used):

ssh -fND localhost:port al1us.net

“f” key tells SSH to go into the background. If you want to quit later, just kill the process or otherwise don’t use the “f” key.
On the bottom right conrer of the firefox click the FoxyProxy icon with the rght mouse button and go to “Options”, write proxy name, choose SOCKS proxy and in the host field enter “localhost” and the port number your tunnel is running on, save it.
If you want to tunnel also all the DNS queries, in the Firefox address bar write “about:config” and change the key “network.proxy.socks_remote_dns” to true. Voila!

 
 

Copyright regime vs civil liberties June 9, 2009

Filed under: IT, interesting — Artem @ 12:09 am

Congratulations to the Pirate party for winning one place in the EU parliament! Let’s fight for out liberties in the Internet!