OSX app dev : Verify that your app is signed

Little dev note here.

To verify that your app is correctly signed, you can use the codesign command.

The –verify will only output something if your app is not signed.

In XCode, verify in your app settings, under Build Settings -> Code Signing, that the signing options are correctly set. If you got no options there, go to XCode Preferences -> Accounts tab and enter your account info. XCode should then retrieve your certificates.

More on app signing

Android Lollipop Recyclerview touch effect on items

The new Recyclerview in Android Lollipop is nice. And it’s even more neat if you can get the “touch effect” on each item of your list.

I had troubles to find how to do that so here is a little reminder.

Simply add

into your list item root layout.

And you should have this nice touch animation.

Android : Use your device to debug your app

Because this should be really easy, but it’s a real PAIN, here are steps you have to go through to use your own device to debug your app. Useless to say that as the emulator is crap very slow, this is really necessary to develop in good conditions.

This is for windows, but some steps are the same for each OS.

Get you device into developer mode

Go to parameters, about the phone/tablet/whatever, tap several times on Build number. This will activate the developer mode.

Activate USB Debug mode

Now in your device parameters, you have a developer menu at the bottom. Go there and simply activate the USB debug mode.

Install drivers on your computer

Download the ADB USB drivers from Google page. Extract it somewhere safe.

Plug your device on your computer. On your computer, go to the device manager. Right click on your device which should have a yellow icon on it. Install the driver from a location. Select the ADB USB driver location. All should install fine.

Verify your environment variables

You need to have the ANDROID_SDK_HOME variable on your computer in order to make this work.

This variable value should point on C:\Users\LouWii\.android. Of course, replace LouWii by your windows account.

Make your PC to detect the device

Open up cmd.exe. Go to your Android SDK folder. I don’t remember the default path; I installed mine separately. Here are the command I needed to enter : (the first two are to go inside my Android SDK folder)

This made a popup appeared on my phone to accept the debug apps from the computer.

If not, try to change the USB mode of your device : go to parameters, stockage and tap on the three dots on the top right on your screen. Change from MTP to PTP.

You’re done

That’s the steps I made to get this work. This is a real pain compared to iOS dev, but whatever…

Make an image fill a div entirely without blanks, keep its ratio and be responsive

I thought this would be simple but I was wrong ! There is no CSS to do this easily, you’ll need some JS to make it work properly.

First, we have a div with several img inside. In fact, it’s a slider.

This slider is a background slider, it takes all the browser window space. And we you resize your browser, the images need to be sized so they keep their ratio, but they fill the entire background without leaving any space. Of course, that means the image will be cropped.

Then, I found this blog with a nice function to do the maths.

http://selbie.wordpress.com/2011/01/23/scale-crop-and-center-an-image-with-correct-aspect-ratio-in-html-and-javascript/

The trickiest part is that you need to resize the image depending on the div size and each time you have to verify if you need to set the width or the height.

Embed Twitter timeline into a website without OAuth

To embed a twitter timeline or a tweet feed, you have 2 choices : use the widget provided from Twitter or use their 1.1 API.

Using the REST API

This requires an OAuth or an app token, and is limited in queries quantity. But it’s very complete and you can do whatever you want with the data you get.

All info about available data : https://dev.twitter.com/docs/api/1.1

Each query has a rate limiting, divided into 15 minutes intervals : https://dev.twitter.com/docs/rate-limiting/1.1

You can use this to display tweets on your website. But as it’s limited, if there are to many visitors, your queries will be rejected.

The best way would be to get tweets on server side every 5 minutes, save it into the DB so you won’t query twitter api each time the page is loaded.

Using the Twitter widget

The twitter widget is very limited. Its first drawbacks is that you can’t customize the way tweets are displayed. You can always use CSS but it’s limited. It has a few customization options but nothing really advanced.

More info there : https://dev.twitter.com/docs/embedded-timelines

Cheating the Twitter widget

To avoid REST API and its limitations, Jason Mayes has created a JS script to get only tweets from the widget. So you avoid OAuth and limited queries and you get only tweet data so you can process it the way you want.

http://jasonmayes.com/projects/twitterApi/

 

Backup and restore a mysql database from command line

Because we all love SSH, here is a little reminder of how to backup a MySQL database from command line.

This is to know !

It will simple dump all database tables into a file called database-name-backup.sql using login mysqlLogin and the given password.

I made a simple bash script that creates a backup file, so no need to remember that command line :

 

To restore it, it’s pretty simple :

 

Install PHP4 and PHP5 on Linux Debian

As it took me quite a lot of time to do this, I’ll post it here so I can find it later if needed.

I tried it on Squeeze but it should be OK on Wheezy too.

We can’t install both PHP 4 and PHP 5 as Apache module. So what we’re going to do is install PHP 5 as Apache module and PHP 4 as CGI.

First, install apache 2.

Secondly, install MySQL server and phpmyadmin if needed.

Then, don’t forget to install FCGID for Apache

Hardest part now : install PHP 4. You can’t imagine how many hours I waste onto trying to install this old s****. But I clearly had no choice.

There is a nice dude which shares packages of PHP 4 online. The best part is, you can add it as a repo for apt.

Packages are there for 64bits versions : http://www.cecak.cz/debian/squeeze/php4/amd64/

Then, just edit you /etc/apt/sources.lists and add

In a terminal, go for

Then you’re good to go !

And then all extensions you need :

Now, let’s tell Apache to use PHP 4 on a separate virutal host, so you keep PHP 5 by default and PHP 4 only on a special address.

I just copied the default site config. You can call the new file whatever you want.

My virtual host files will be stored in /var/www/php4. My config file looks like this :

The most important part is FilesMatch, which will tell Apache to use PHP CGI (PHP 4 here) to execute php files.

Save the file and enable it using

Then restart Apache so it takes all modifications into account.

Last part, we need to edit /etc/hosts file to add our virtual host address to point it to localhost. Simply add

at the end of the file.

Now you should be good to go !

You can show php version putting this code

into a file and go for it into your browser.