Yet Another Blog

February 17, 2015

Setting environment variables in OpenShift

Filed under: computer, Java, linux, Software — Tags: , , , , — guilleml @ 12:51 pm

If you need to set some environment variables in your GEAR you can use an action hook.
The pre-start action hook will serve you well but if you need to restore those variables after a gear restart, pre-start action hook won’t work.
Post-restart action hook, on the other hand, will execute its actions but I haven’t managed to get the environment variables working. After its execution all environment variables that should have a value were empty.

What I did was to modify pre-start action hook to create environment variables as files under $HOME/.env/user_vars

# Actual script

# Added script for post restart variables

After this, if you execute gear restart, the environment variables will exist and will be accesible from your application.

January 21, 2015

Asking for root in your Android app

Filed under: Android, computer, Java, Software — Tags: , , , , , — guilleml @ 12:34 pm

If your app needs root permissions to execute any command, you can do this using something like:

Process p;
try {
   p = Runtime.getRuntime().exec("su");
   DataOutputStream os = getRootSession(p);
   os.writeBytes("any command you want\n");
} catch (IOException e1) {
   Log.d(MainActivity.class.getName(), "Error: " + e1.getMessage());

After running Runtime.getRuntime().exec(“su”) a dialog will appear to ask for permissions so the user can accept it.
What happens if you’re writing a service that will need root access anytime, even if the screen is off? The user won’t be able to accept the dialog so the app will fail.

To solve this you can do your app to ask for root permissions when it runs so, if the user accepts forever, the app will be able to run normally without asking the user anytime.
I know it’s better the user knows when an app is doing something as root but there are cases where you need to do this, for example, I’m writing an app that will disable charging for a phone when
the battery is charget at 100% in order to avoid microcharges. If you let the phone charging at night you won’t be there to disconnect the phone when it gets to 100% so this app monitors battery charge level and will use root permissions when the battery is 100%.

What I’ve done is to create an initial activiy to ask for permissions:

public class AskingRootActivity extends ActionBarActivity {
private static final String TAG = AskingRootActivity.class.getName();

protected void onCreate(Bundle savedInstanceState) {
private void nextScreen(){
   Intent intent = new Intent(getApplicationContext(), NextActivity.class);

public void checkRoot(View v) {
   Process p;
   try {
      p = Runtime.getRuntime().exec("su");
      DataOutputStream os = new DataOutputStream(p.getOutputStream());
      os.writeBytes("ls /data\n");
      try {
         if (p.exitValue() != 1) {/
         Log.d(TAG, "success getting root");
      else {
         TextView tv = (TextView) findViewById(;
         Log.d(TAG, "failing getting root");
   } catch (InterruptedException e) {
      Log.d(TAG, "failing getting root");
} catch (IOException e) {
   Log.d(TAG, "failing getting root");

When the user clicks on the button, the app will try to get a root session so a dialog asking for root will appear.

After the user accepts or denies it, we try to do something we can only do as root, like listing files in /data directory. If the command runs succesfully, we navigate to the next screen/activity/logic/whatever, if not, we can show an error or finish the app.
As the app won’t do anything untill the user accepts or denies it, we can be sure when the app gets to the point when it needs root access, it will have it, at least if the user didn’t set a timeout for the permission.


<RelativeLayout xmlns:android=&quot;;
    xmlns:tools=&quot;; android:layout_width=&quot;match_parent&quot;
    android:layout_height=&quot;match_parent&quot; android:paddingLeft=&quot;@dimen/activity_horizontal_margin&quot;

        android:layout_height=&quot;wrap_content&quot; />



This layout only defines an info message and a button to ask for root permissions.

May 30, 2014

Tuning Android Disk Encryption Feature

Filed under: Android, Security, Software — Tags: , , , , — guilleml @ 3:04 pm

I use my phone, like most of you, as my personal assistant so it carries all kind of information regarding banks, passwords, services, purchases, friends, photos, etc. Most of this information is private and I am very concerned about what would happen if someone gain access to this package of private information. Probably they would only want the hardware, but let’s be honest, if I couldn’t keep myself from taking a look to a lost phone and I know it can be done, no matter what password are you using, I expect anyone would do the same and they might have other intentions, as stealing passwords.

I was looking for a way to avoid this if my phone is stolen or lost. Of course I use cerberus but I need a way to really be sure no one can extract my information. Of course I’m not thinking in NSA or USA Gov as we all know they already have access to all of this.

Like linux, Android support crypted filesystems natively. is used in order to crypt, decrypt and manage the volume.

Android encryption feature will crypt all user data in order to avoid anyone to access your storage unit without a password.

It’s important to note that if you want to disable this feature you’ll need to reset your phone and restore all your data.

System Performance

In a nexus4 I haven’t noticed any performance impact but when installing apps. Installing apps is a little slower process but in the general use the interface, apps loading and use is unnoticeable.

How to Enable Android Disk Encryption Feature

You can enabled Android disk encryption feature under Security settings.


This process needs pin screen lock so it will ask you to set a pin. You cannot use face recognition unlock or leave unlocked the phone.

This pin will be used to crypt the password that will be used to crypt all the volume. Google decided so in order to avoid users to remember several passwords just to boot and unlock their phones, the problem is that a 4 digits password is quite easy to break using brute force so we’ll see how to change this password to improve security.

Once you’ve selected the encryption feature and configured the password the system will reboot itself and begin the crypting process. This process may be long, so be sure to be able to let the phone working and connected to the AC charger for an hour or so.

When completed, the phone will ask for the password when booting, when it asks for it, type your pin code previously selected.

Install Cryptfs Password app from the Play Store to help you to change the password. You’ll need to be root so this process can be done.


Just introduce your pin and your new safe long password using alphanumeric characters and symbols, this way you’ll have a secure password to mount the crypted phone storage memory and a 4 digits pin to unlock the screen making a brute force attack much more difficult to carry out.

With this, not so popular, feature you can be sure your data won’t be stolen if you lose your phone.

I found information about this process and link to the app from nelenkov’s blog.

August 26, 2011

Freshman with an iPad

Filed under: Android, ios, Software — Tags: , , , , , — guilleml @ 10:50 pm

I recently got an iPad, this is my first iOS device so I’m going to write my firsts impressions with this device and this system.

I must say I’m not an Apple fanboy and I have quite experience with Android (1.5-2.3).

First impressions:
  • It’s heavy, heavier than I imagined but it can be held on one hand easily.
  • Build quality seems very good.
  • Touch screen sensitivity is amazing.
  • It’s fast, very fast, shifting screen, opening and closing apps, web browsing…FAST
Needless to say I’m used to the weight already, I really like the smoothness and speed of iOS on the iPad, I don’t know if it’s so fast on iPhone.
After configuring accounts, wifi, etc…first thing was to install apps from the App Store, I used iTunes on a PC at first, now I use the App Store iPad application.
  • First thing I noted on the Apple App Store is that there are very little user comments and punctuations, I really find these useful since I used them on Android Market to know if the app is what I’m looking for.
  • Maybe there is but I haven’t found it yet, I would like to have a method to get a refund for apps, I may want to try them to know if they’re useful or I like them, if not I would like to uninstall them and get my money back since there is little user feedback.
  • Autocompletion on the search box could be nicer if it includes other users searches, not only apps names.
First apps I installed:
  • Google Search:
    Well…you get a link to google apps, they run on Safari so it’s like browsing Google Apps. You have a push Gmail notifier that will open your inbox in Safari.
    I guess I was hoping for something more, Google apps on Android are a real beauty.
  • IM+:
    An IM client, I have used it with Gtalk, it works fine most of the time.
    I got lot of FC (Force Close) at first, after an update it seems quite stable but I don’t like very much the interface.
    Here I noted how the notifications on iOS suck, I will talk about this later on this post.
    Now it works fine, when I’m browsing and someone talks to me, I change to IM+ app and I have to wait some seconds until the new messages are shown on the conversation window, it bothers me when I’m browsing and chatting because I can’t have a fast conversation, iPad is fast, IM+ is not.
  • Angry birds: Nothing to say here, it works great, fast and nice graphics.
  • Dropbox: I like this app, not very integrated in system as Dropbox for Android is, but it works fine.
  • Evernote: Very nice, fast, no problem at all.
Multitasking and notifications
Multitasking works fine with IM applications, IM+ uses push but it still drains the battery.
You can double press the button to see all apps “loaded in memory” and keep the finger on one of them to kill them.
Notifications are a joke, at least what I’ve seen, come on, it’s 2011!! notifications show a popup message or a number on the app icon. So I have to take a look to my desktop to know what’s happening or I see my web browsing interrupted when someone talks to me.
I think iOS5 implements notifications like Android or WebOS…that’s nice, nice and late!
This is what I really don’t like about iOS user experience, they really need to redesign all the notifications and information system. I know GUIs Apple policy but I really hate notifications now.

May 26, 2011

Increasing Debugging Eclipse PermSize while developing plugins

Filed under: computer, Java, Software — Tags: , , , , — guilleml @ 8:57 pm

The configuration is quite simple, I just got tired of permgens errors while developing a plugin in Eclipse.
This is how I’m launching and debugging a plugin.

April 27, 2011

nVidia PowerMizer on Linux

Filed under: computer, linux, Software — Tags: , , , , , , — guilleml @ 11:20 pm

Nvidia settings panel has a tab called powermizer where you can set a power policy. It will change Graphics Clock, Memory Clock and Processor Clock depending on the system graphics load.

First get what modes do your card and driver support:

nvidia-settings -q GPUPerfModes -t

perf=0, nvclock=50, memclock=135, processorclock=101 ; perf=1, nvclock=405, memclock=324, processorclock=810 ; perf=2, nvclock=405,
memclock=1800, processorclock=810 ; perf=3, nvclock=715, memclock=1800, processorclock=1430

I have 4 levels, 0, 1, 2 and 3. 0 is the one I want to set as it sets the clocks to the lower frequency.

If you want to set it to a powersave mode with no scaling you can do it by editing /etc/X11/xorg.conf like this:

Section "Device"
    Identifier     "Device0"
    Driver         "nvidia"
    VendorName     "NVIDIA Corporation"
Option  "Coolbits" "1"
 Option  "RegistryDwords" "PowerMizerEnable=0x1; PerfLevelSrc=0x2222; PowerMizerLevel=0x3; PowerMizerDefault=0x3; PowerMizerDefaultAC=0x3"

enables PowerMizer feature (0×0 would disable it instead). This entry may not be needed since in recent driver versions PowerMizer is enabled by default.


sets the governor approach. 0×2222 means fixed frequencies for both battery and AC mode.


sets the current mode. 0×3 is the lowest, least power intensive mode.


sets the default level on battery. 0×3 is the lowest, least power intensive mode.


sets the default level while with an AC plug. 0×3 is the lowest, least power intensive mode.


March 22, 2011

Opera Mini 6 – First Impressions on Android

Filed under: Android, Software — Tags: , , , — guilleml @ 9:39 am

Opera Mini 6 was released today and I’m a big fan so I’ve already downloaded and I’ve been playing with it for a while.The update can be found on the market and on the opera website.

After installing you can notice the new look, the color now is black, an opera icon on the settings menu, not much, I think the interface was and is good.

Loading on Android is faster, much faster. With version 5.x everytime you change the focus, for example if someone talks to you on gtalk, you had to reload Opera which tooks a few seconds and a loading screen. Most of the time you lose the page you were in.

Now, in version 6, loading is near instantaneous, no more fear to use several apps at the same time even on my old G1.

Speed Dial is still there, loading web pages is as fast as version 5, I didn’t notice neither faster nor slower.

First change on browsing, you need double tap to zoom in, and double to zoom out, just like chrome for android. You can click links in the zoom out view, again just like the stock browser.

It’s a multitouch enabled browser so you can pinch zooming.

Another think I liked a lot is the posibility to hide the navigation and address bar but keeping the android status bar, so you will still be able to see incoming notifications while having a near-full screen browser, you can always open the menu and address bar by pressing the menu button. I really needed this on version 5, thank you Opera, good work.

On the menu is another button to share links through the android share menu, so you can choose between bluetooth, dropbox, evernote, gmail, sms, reader, twitter, whatsapp…or whatever social software you have installed. I used to copy the link and paste it on a new mail, this is easier and faster.

For the moment this is the differences I’ve notices at first view, I’m sure there will be more. If you like Opera browser I recommend you to try this version, if not, I recommend you to try it anyway, Opera Mini uses very little data traffic since web pages are processed and adapted in their servers, it uses much less power because less processing is needed and well…it is fast, the fastest I’ve ever tried on android.

March 11, 2011

Tree Style Tab and Firefox 4.0

Filed under: computer, hacks, Software — Tags: , , , — guilleml @ 2:55 pm

It seems Tree Style Tab is not working with firefox 4.0 yet, it works just for the betas, you can make it work easily and fast if you want to.

First of all, you have to have firefox 4 installed. You will also need the Tree Style Tab xpi file, download the last version from the download section.

Once you have the treestyletab.xpi file, open it with a zip archiver like 7zip, winrar or just rename it as and double click it.

Localize the file install.rdf inside the zip file, it’ll be in the root level. Then you just have to edit it, go to line 157 (it may change depending on the Tree Style Tab version).

em:maxVersion=”4.0b12pre” />

Change the maxVersion to one equal or higher than your firefox installed.

em:maxVersion=”4.1″ />

Save the file overwriting the old install.rdf and drop treestyletab.xpi to the firefox window, the installation will succeed.

Now you just have to restart firefox. You can follow the same procedure with any firefox extension, of course, it may not work, that’s why the programmer didn’t include the new firefox version.

February 8, 2009

Setting up Hibernate with MySQL under GNU/Linux

Filed under: linux, Software — guilleml @ 1:01 am

We’ll need to have installed mysql packages, of course, as long as the java libraries for hibernate, mysql jdbc connector or any other things needed for the project as struts, spring…maybe an IDE as Eclipse or Netbeans.

Query browser may be useful to check database updates, modify tables o whatever you could need, anyway, what I wish to comment is the hibernate.cfg.xml file:

<?xml version=”1.0″ encoding=”UTF-8″?>
<!DOCTYPE hibernate-configuration PUBLIC “-//Hibernate/Hibernate Configuration DTD 3.0//EN” “”&gt;
<property name=”hibernate.dialect”>org.hibernate.dialect.MySQLDialect</property>
<property name=”hibernate.connection.driver_class”>com.mysql.jdbc.Driver</property>
<property name=”hibernate.connection.url”>jdbc:mysql://localhost:3306/empresas</property>
<property name=”hibernate.connection.username”>root</property>
<property name=”hibernate.connection.password”>toor</property>
<mapping resource=”hibernate.hbm.xml”/>

Take a look I’m using JDBC driver for MySQL, you should change the hibernate.connection.url with your own following the same format, let’s sayour database’s name is “enterprises”, then your connection url will be jdbc:mysql://localhost:3306/enterprises

netbeans - hibernate

The classes and tables mapping will be in hibernate.hbm.xml with its own format, for example:

<class dynamic-insert=”false” dynamic-update=”false” mutable=”true” name=”com.myapp.struts.Empresa” table=”empresahib” optimistic-lock=”version” polymorphism=”implicit” select-before-update=”false”>
<id name=”id” column=”id” type=”long”>
<generator class=”increment”/>
<property name=”nif” type=”java.lang.String”/>
<property name=”fecha” type=”java.sql.Date”/>
<property name=”rep_legal” type=”java.lang.String”/>
<property name=”denomsocial” type=”java.lang.String”/>
<property name=”telefono” type=”java.lang.String”/>
<property name=”email” type=”java.lang.String”/>

October 8, 2008

Dell Inspiron 1525 hotkeys in KDE 4.1.1 Debian

Filed under: computer, linux, Software — Tags: , , , , , , , , , — guilleml @ 7:57 am

In Kubuntu 8.04 my laptop multimedia keys worked fine but in KDE 4.1.1 under Debian they didn’t, I couldn’t assign them to actions in system preferences.

To solve it I’ve used xbindkeys, it works pretty nice and now I can control the volume with the volume keys. To do so, type:

#aptitude install xbindkeys xbindkeys-config

Now you can use xbindkeys-config to configure using a graphical interface or you can configure in ~/.xbindkeysrc.

To configure volume keys under kde 4.1.1 you will need to assign some actions to each key in order to increase, decrease or mute the volume, I’ve used qdbus and kmix to do that, for example, if you want to  mute the audio:

$qdbus org.kde.kmix /Mixer0 org.kde.KMix.toggleMute Master:0

So you need to assign that to the mute key. To increase the volume:

$qdbus org.kde.kmix /Mixer0 org.kde.KMix.increaseVolume Master:0

And to decrease the volume:

$qdbus org.kde.kmix /Mixer0 org.kde.KMix.decreaseVolume Master:0

So the xbindkeysrc file will be:

“qdbus org.kde.kmix /Mixer0 org.kde.KMix.toggleMute Master:0”
m:0x0 + c:160

“qdbus org.kde.kmix /Mixer0 org.kde.KMix.increaseVolume Master:0”
m:0x0 + c:176

“qdbus org.kde.kmix /Mixer0 org.kde.KMix.decreaseVolume Master:0”
m:0x0 + c:174

After that you want to run xbindkeys daemon every time you login with your user, so add it to ~/.xinitrc, ~/.kde4/Autostart or any way you know to do so.

Older Posts »

Create a free website or blog at