[Android-ADT] Can not generate R file after update to ADT 22.

Don’t worry , Stackoverflow is always beside you.

http://stackoverflow.com/questions/16584015/java-eclipse-no-more-r-file-ever/16584243#16584243
– Open SDK manager.

– Install something called Android SDK Build-tools.

– Restart  Eclipse.
– Enjoy.

 

Advertisements

[Git] Check out a branch in git

mkdir $BRANCH
cd $BRANCH
git init
git remote add -t $BRANCH -f origin $REMOTE_REPO
git checkout $BRANCH

http://stackoverflow.com/questions/1911109/git-clone-a-specific-branch

[Ubuntu] Install ant 1.8 on Ubuntu 12.10 ( from repo)

ant-apache

– Make sure you have set JAVA_HOME env. variable before. For my case, I’m having open-jre and open-jdk install.

I need to append to file /etc/profile one more line

export JAVA_HOME=”/usr/lib/jvm/java-1.7.0-openjdk-i386;”

Save and we’re done with JAVA_HOME variable.

Next,

install ant from repo with:

sudo apt-get install ant

Let’s test, type into terminal   ant -version

>> Apache Ant(TM) version 1.8.2 compiled on May 18 2012


[android] Full-screen mode on ICS and above not working on 2.3

That is when you got error like :

java.lang.NoSuchMethodError: android.view.View.setSystemUiVisibility

when you try to hide the task bar on your system with “

getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);

And here is how I fixed it:

if(SDK_INT >= 11 && SDK_INT < 14) {
getWindow().getDecorView().setSystemUiVisibility(View.STATUS_BAR_HIDDEN);
}else if(SDK_INT >= 14){
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE);
}

 

Or you can find the well-formated snippet here:

https://gist.github.com/tttoan/5428334

 

 

 

 


[android] Setting up project with Sliding Menu — got some errors

1/ For the error

“The method getSupportActionBar() is undefined for the type BaseActivity”

Inside the SlidingMenu library, edit the class SlidingFragmentActivity to extend SherlockFragmentActivity (like below). Then clean and rebuild, this method should now be found.

public class SlidingFragmentActivity extends SherlockFragmentActivity implements SlidingActivityBase {


2/  http://boroniatechnologies.com/installing-slidingmenu-android-library-and-example/ 

[Ubuntu] How to share internet connection in Ubuntu 12.x with another ubuntu client.

For an Ubuntu client, you probably only need to add DNS servers.

  • Right click on your network configuration applet in your tool bar and select Edit Connections.
  • Select your network adapter and click Edit.
  • Click on IPv4 Settings, and change the method to Automatic (DHCP) Addresses only.
  • Then either add your ISP DNS servers, or you can use OpenDNS -> 208.67.222.222

[Android] Solving problem when setup ActionBarSherlock libs and sample project.

The hierarchy of the type ‘Class name’ is inconsistent

My Eclipse, together with Android SDK has settings for java compiler:

– Compiler compliance level : 1.6  ( Ubuntu + openjdk) ( Window –> Pref –> Java –> Compiler)

when import ActionBarSherlock project, I must change it back to this compliance level.
–> Enable Project Specific Setting.
–> Set Compiler Compliance level of this project to be 1.6

Done !

Clear and rebuild project.


[python] Improve performance of application-logging ( Part 1 – server side)

Everybody knows that logging something on screen or to a file is inevitable when you create program. It makes thing visible to you , easy control and for debugging also.

But recently what I have faced is that the performance of my application ( a bunch of services written in python) has decreased so much when I try to print out so many thing to the console ( the primary I/O channel I have ever used).

So I’m finding some ways to make this process become better.

About the context, these log is actually not realtime-critical. I want want to know which step my program is at and what is the result of the executing. That’s all.

The first testing method I try to implement is using UDP broadcasting . Sound so much insanity , right ? I just want to separate the logging process to other task. Not on my main task. And also, that logging should be flexible enough that I can choose to write on the console, write events to database or to the file without any performance-losing from my main jobs.

I have already installed twisted on my machine. So I will take advantage of it.

Let’s build a UDP Event logger server, just modify the class name of UDPEchoServer example.

We have:
from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor
from pprint import pprint
class UDPLogger(DatagramProtocol):
 def datagramReceived(self, datagram, address):
 print 'signal from '
 pprint(address)
 print 'content of msg = ' + repr(datagram)
 self.transport.write(datagram, address)
def main():
 reactor.listenUDP(8000, UDPLogger())
 reactor.run()
if __name__ == '__main__':
 main()

[web.py] Rendering html template.

Moving to this part http://webpy.org/docs/0.3/tutorial#templating

The basic idea of the template things here is just like what I used to work with ASP.NET years ago. 
It’s a mix of python syntax with html tags to insert properly data into html templates.

For example, the given example from tutorial.

$def with (name)

$if name:
    I just wanted to say <em>hello</em> to $name.
$else:
    <em>Hello</em>, world!

    While the $def with(name) is kinda function declaration for html template where you can define the expected parameters that you want to pass into in the future use.
    The rest of this is in python-like syntax, with the $ sign to denote that this is python line of code mixed into html syntax.

They also noticed that we have 2 ways of using variable in this mode, if you use variable like $name , when you pass into some sort of escape html syntax ( like <em>MyName</em>, it will escape your text properly to render in browser. If you want to display exactly what you’re passing into, you may want to try $:name . That’s it. 

Next , we will find out how to deploy this template into our web app.

Let’s move back to our code.py  

We will declare a global variable name renderer

web.template.render('template/')

We got/template’ is the directory ( in a relative direction with our current main function code i.e, code.py)

Next, in our GET method, we will use this renderer to represent data onto the html template.

name = 'Toan'
return render.index(name)

[web.py] How to run our web app.

Ahh, I forget to mention about this.

In development mode ( or debug mode), we can run by submit the comand:

python code.py

This will start our app on debug-built-in server at : 

http://0.0.0.0:8080/   

Or we are also able to specify which port we want to run at by adding the port number.

python code.py  1234

Ola, done.