Wednesday, October 23, 2013

Want to learn basics about git?

Try this : http://try.github.io


Monday, October 14, 2013

Automatically scale image to fit all Android screen types

If you're new to Android development, you will learn that, for each image resource you want to use (for a button for example), you need to provide it scaled to fit all screen resolution. A little bit complicated in fact.

So, take this online tool. It will ask your to which screen your image fits and then adapt it to all other.

http://android-ui-utils.googlecode.com/hg/asset-studio/dist/nine-patches.html

I hope Google with simplify the process and let the IDE do that behind the scene.

Tuesday, October 01, 2013

Manual installation of SVN connector with Subversive for Eclipse and SpringSource Tools Suite

In the last installation of STS I made, when I had the support of SVN by installing Subversive (from Menu > Help > Install New Software), Eclipse (Kepler) didn't ask me for the SVN connector I wanted to use. In this kind of situation, I discovered that it's possible to install it from an update site provided by Polarion.

So, go to to Polarion, and check out the url from the Download section. Here is the one I used :

http://community.polarion.com/projects/subversive/download/eclipse/3.0/kepler-site/

Then you can install your SVN connector (for me, it's always SVNKit which is a pure Java implementation connector).

Wednesday, July 24, 2013

Look for 'delete' statements in Oracle history

That's what I had to found in production today. Hopefully, I had access to v$sql

So, here is the miracle :

select v.SQL_TEXT,
           v.PARSING_SCHEMA_NAME,
           v.FIRST_LOAD_TIME,
           v.DISK_READS,
           v.ROWS_PROCESSED,
           v.ELAPSED_TIME,
           v.service
      from v$sql v
where v.SQL_TEXT like '%delete%' OR v.SQL_TEXT like '%delete%'

Wednesday, July 17, 2013

How to add System Properties with Spring Framework

A cool example grabbed on the web :



<bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject">
        <bean class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
            <property name="targetClass" value="java.lang.System" />
            <property name="targetMethod" value="getProperties" />
        </bean>
    </property>
    <property name="targetMethod" value="putAll" />
    <property name="arguments">
        <util:properties>
            <prop key="org.apache.cxf.stax.allowInsecureParser">true</prop>
        </util:properties>
    </property>
</bean>

Tuesday, June 25, 2013

Keep web sites readable on mobiles HD screens

As I was working on a new web project which mixed mobiles devices and PCs, I realized that it could be a problem to keep working in pixels to define page elements. Let's take an example :

Create a basic website not specific to mobile devices. Open it on a low resolution screen (such as a Samsung Galaxy Mini). Consider that the text is readable. Now, let's open the same page on a high resolution screen. Text will be too small.

What's the fuck???

By defaut, mobiles (and tablets) lie about their screen resolution

The first thing to know is that 1 pixel is 1 pixel on PCs (for the moment). On mobiles, 1 pixel = 1 "CSS pixel". Hey, what are "CSS pixels". It's easy to understand. Here are real screen resolutions :

  • 320x480px on iPhone 3
  • 640x960px on iPhone 4
  • 640x1136px on iPhone 5
  • 768x1024px on iPad 2
  • 1536x2048px on iPad 3

But, if you ask for the current resolution in javascript (screen.width), you will retrieve :

  • 320x480px on iPhone 3
  • 320x480px on iPhone 4
  • 320x568px on iPhone 5
  • 768x1024px on iPad 2
  • 768x1024px on iPad 3

You understand : that's how Apple handles Retina screens.

Okay, Okay... 320px, it's cool. But my Galaxy Mini has a lower width (240px)...

Don't worry : you can force mobiles to lie even more about their screen resolution

I'll show how your Galaxy Mini will emulate a 320px width screen.

I discovered this excellent blog post : http://sunpig.com/martin/archives/2012/03/18/goldilocks-and-the-three-device-pixel-ratios.html ; which introduced the meta"viewport". This meta tag allows mobile device a send a fake screen resolution in pixel. This resolution is made to keep screen readable. Behind the scene, the browser adapts the pixel/inch ratio automatically.

The solution is quite easy to implement. You just have to add this tag into your current "head" tag :


<meta name="viewport" content="width=device-width"> 


Don't be too happy, this "fake" resolution depends on the browser behind and the zoom factor (small, medium, large) selected by the user. But, it's simple.

So, what should you do ?

My opinion is to work with this meta tag and to consider that the user has the default zoom factor. I think it's the best compromise.

I can't conclude this post without giving you a link to this excellent post (sorry, it's in french) : http://www.alsacreations.com/article/lire/1490-comprendre-le-viewport-dans-le-web-mobile.html

Wednesday, June 19, 2013

Colorize your MacOS X shell

I was tired of my green shell on my Mac and I really prefer the default shell on Ubuntu. So, I googled a few minutes and find a solution.

First of all, each time you open a new shell, MacOS executes your .bach_profile. (It's quite different on Mac compared to Linux. On Linux, the .bash_profile is executed when you open a new session while .bash_rc is executed each time you launch a shell. On Mac, there's no .bash_rc so we use .bash_profile).

So, let's create/edit your .bash_profile with nano .bash_profile and copy paste the following lines. Restart your shell and enjoy the difference.

export CLICOLOR=1
export LSCOLORS=ExFxBxDxCxegedabagacad


Thursday, June 13, 2013

How to know if you have a 32 bits or a 64 bits Linux kernel?

Want to install an application on your favorite Linux but you forgot if it a 32 bits or a 64 bits one and you don't know which package you have to download? Don't panic. Just type in a console :

file /sbin/init

This will check /sbin/init file type and you will see if it is a 32 bits or a 64 bits executable file. I tested it on Ubuntu 13.04 and CentOS 6.4.

Monday, May 27, 2013

Insert code into your Blogger posts

Programmers know that blogger doesn't support code insertion (usefull if you need to demonstrate how to program something by copy/pasting code samples). Thus, you need to swicth  Blogger's editor to HTML and paste HTMLized text.

The nicest solution I found to format your code to HTML is to use this online code formatter : http://hilite.me/

So, let's show an example:


 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
         http://maven.apache.org/maven-v4_0_0.xsd">
 <modelVersion>4.0.0</modelVersion>
 <groupId>com.horstmann.violet</groupId>
 <artifactId>parent</artifactId>
 <name>Violet UML Editor Parent Maven Project</name>
 <version>1.0.0</version>
 <packaging>pom</packaging>
 <modules>
     <module>violet-framework</module>
     <module>violetplugin-activitydiagram</module>
     <module>violetplugin-classdiagram</module>
     <module>violetplugin-objectdiagram</module>
     <module>violetplugin-sequencediagram</module>
     <module>violetplugin-statediagram</module>
     <module>violetplugin-usecasediagram</module>
     <module>violetproduct-swing</module>
     <module>violetdistrib-rpm</module>
 </modules>
 <properties>
     <applicationVersion>2.0.0-SNAPSHOT</applicationVersion>
   </properties>
 <build>
  <resources>
            <resource>
                <directory>src/main/resources</directory>
            </resource>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.gif</include>
                    <include>**/*.jpg</include>
                    <include>**/*.properties</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>
        </resources>
  <pluginManagement>
         <plugins>
             <plugin>
                 <artifactId>maven-compiler-plugin</artifactId>
                 <version>2.0.2</version>
                 <configuration>
                     <source>1.6</source>
                     <target>1.6</target>
                 </configuration>
             </plugin>
         </plugins>
  </pluginManagement>
 </build>


 <distributionManagement>
  <repository>
   <id>web.sourceforge.net</id>
   <name>Violet's Maven Repository</name>
   <url>
                sftp://web.sourceforge.net/home/groups/v/vi/violet/htdocs/maven2/repo
            </url>
  </repository>
 </distributionManagement>
 <repositories>
  <repository>
   <id>violet.repo</id>
   <name>Violet's Maven repository (public access)</name>
   <url>http://violet.sourceforge.net/maven2/repo/
            </url>
  </repository>
 </repositories>
</project>

So nice!

Wednesday, May 22, 2013

How to secure REST services exposed with Jersey (JAX-RS) using Spring Security

This is the challenge I had to perform. I have to open services to business partners and I want to secure them. I use a Java based application with Jersey API (JAX-RS).

The first thing to consider is : what kind of solution offers the best compromise between security and the effort I'll have to provide to maintain this solution?
After some discussions with developers and experts, the conclusion is : expose your services over https and use Basic authentication (Digest authentication and certificate based authentication are too complex for partners)

So, how to implement that? I delegate "https" to my Apache http servers. But I still need to handle authentication (and authorization of course). After long hours on Google, I understood that it is possible to manage security with Jersey by many many ways. Here is a short list :

  1. Delegate simple authentication and authorization to your container (Tomcat) or to your frontend (Apache)
  2. Delegate authentication to your container or frontend and let Jersey manage authorization with JSR-250 annotations such as @PermitAll, @DenyAll, @RolesAllowed written on methods. (For example : http://www.butonic.de/2010/06/18/a-simple-jax-rs-security-context-example-in-glassfish/)
  3. Be agnostic from any container  and let your "Jersey-based" application take in charge authentication and authorization by implementing your own ContainerRequestFilter. You can read these two excellents posts : http://simplapi.wordpress.com/2013/01/24/jersey-jax-rs-implements-a-http-basic-auth-decoder/ and http://anismiles.wordpress.com/2012/03/02/securing-versioning-and-auditing-rest-jax-rs-jersey-apis
  4. Be agnostic from any container like the solution 3 but let Spring Security manage authentication and authorization.
Of course, I choose the solution 4. With this solution, I didn't have to filter any URL (like I commonly do when I configure Spring Security with "url-interceptor"). I  let all URLs opened to anonymous user BUT I told Spring Security to filter method calls. As Jersey maps one service to one method, I  obtained what I needed : security over Jersey services.

Here are the stepsto implements that :
  1. Update your maven configuration (optional)
  2. Add a servlet filter to enable Spring Security (web.xml)
  3. Update my Spring configuration (dedicated applicationContext-security.xml file)
  4. Add annotation on methods I want to secure (Java code)
Dependencies to add to the pom.xml

 <!-- SECURITY (start) -->
 <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-config</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-web</artifactId>
            <version>${spring.version}</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.2.2</version>
        </dependency>
 <!-- SECURITY (end) -->



In the web.xml :

    <!-- Filter to secure Jersey (JAX-RS) services -->
    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>
            org.springframework.web.filter.DelegatingFilterProxy
        </filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping> 

The applicationContext-security.xml file :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:security="http://www.springframework.org/schema/security"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
  http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security-3.1.xsd">

 <!-- To allow public access by default and to set authentication mode to basic login/password -->
 <security:http>
  <security:anonymous enabled="true" />
  <security:http-basic />
 </security:http>

 <!-- To delegate authorization to method calls rather than to urls -->
 <!-- (Thus, we don't need to set any url-interceptor in this conf) -->
 <security:global-method-security pre-post-annotations="enabled" />
 
 <!-- To create user/password with roles -->
 <security:authentication-manager alias="authenticationManager">
  <security:authentication-provider>
   <security:user-service>
    <security:user authorities="ROLE_DUMMY
name="user1" password="strongpassword1" />
   </security:user-service>
  </security:authentication-provider>
 </security:authentication-manager>
</beans>

A Java method exposed as REST service with Jersey

@Component
@Path("/userinfo")
public class UserInfoService {
 
@Autowired
private UserInfoDao dao;
 
@GET @Path("{userid}")
@Produces({MediaType.TEXT_XML})
@PreAuthorize("hasRole('ROLE_DUMMY')")
public UserInfo findUserInfoByCode(@PathParam("userid") String userid) {
  return dao.getUserInfo(userid);
}
...



If I want to expose a service to anonymous users, I just have to change @PreAuthorize("hasRole('ROLE_DUMMY')") to @PreAuthorize("permitAll") or simply remove the annotation.


That's all! Of course, Spring saved my day once again...


A good presentation about Spring Security


Friday, February 15, 2013

Solution for unreadable Eclipse tooltips content under gnome with a dark theme

After some googlings, I finally found the easiest solution to fix a well known problem with Eclipse code assistant under my Linux with gnome (Mint Mate).

The problem symptom is black text written over dark gray background : simply unreadable.

To fix that, just install gnome-color-chooser, open it, go to "specifics" tab and change tooltips foreground and background colors. Restart Eclipse and enjoy!

PS : to install gnome-color-chooser

sudo apt-get install gnome-color-chooser

This tip also works on Linux Mate.


Thursday, January 31, 2013

Remap 'Eject' key to 'Forward Delete' on Mac

I've been trying to program on me Macbook Air for a few weeks. The keyboard is really unacceptable on this laptop and I really prefer to use my HP with a real keyboard that my Mac. But, my HP is fat... too fat and I let it at home. So,  I need to find solution to work with this ugly keyboard.

Today,  I decided to remap the unused 'eject' key to 'forward delete'(why is there an 'eject' key on a Macbook Air???? There's no DVD player...).

To do that, you have to install and configure two free softwares :

Each software will need to restart the system.

Monday, January 14, 2013

How to make an antislash, a backward delete, a 'start of line' and an 'end of line' on a Mac keyboard

This a two minutes post with my precious Mac keyboard shortcuts :

  • antislash '\' = ALT + MAJ + /
  • backward delete = FN + DEL or (alternate mode) CTRL + D
  • go to start of line = CTRL + A
  • go to end of line = CTRL + E
If you need other shortcuts, you have to know that Cocoa use Emacs shortcuts.

By the way, I definitely hate Mac keyboards.

Wednesday, January 02, 2013

My Linux Mate 14 config with compiz activated

Today, I share my Linux Mate 14.1 config.

I'm switching from Ubuntu to Mate and I'm a little bit disappointed. So, the first thing for me was to get a desktop theme similar to my Ubuntu. I found Crunchy-orange which is like Ubuntu Human dark theme. Very nice.

Then, I activated compiz. I installed Compiz and CompizConfig Settings Manager (ccsm) from the integrated software center. I opened ccsm and I needed to :

  • activate windows decoration and change the window decorator command to "/usr/bin/compiz-decorator" to avoid that windows borders disappeared.
  • activate widnows move and resize because, if not, you cannot move anything
  • activate compiz on startup with mateconf-editor and change /desktop/mate/session/required_components/windowmanager from 'marco' to 'compiz'
Wooo... I backed to the future!!! This looks like Ubuntu 10.04 ... but with a kernel up to date  :) :) :)