Android hackathon

Yesterday I was watching last episode of Sherlock and suddenly my phone rang. My friend called me to tell me that I have to join him in the pub to solve some sort of programmers problem. So I did. The problem was that he was suffering of lack of programmers.

Long story short, he asked me to help him with an android app. Firstly he had planned to use Titanium SDK but he found out that this is not working solution for him after all and he has to ship the app for iOS and Android asap. Actually the deadline has been missed already.

So we made a deal – I will try to develop an android app and he will be working on an iOS version at the same time. The latest possible deadline is 14 days.

So my android hackathon started. I got designs today and worked on the layouts and the basic functionality. And prepared most of the resources. Tomorrow (day 3) I would like to implement  something more complicated (there’s an augmented reality in the app, so I will be coding camera stuff).

Will post more about implementation later, there’s a lot of interesting things to share.

GIT deployment for PHP apps

I would like to describe how I set up my VPS for GIT deployment. Needless to say, you will need a VPS, I recommend Digital Oceans. Cheap, fast (SSD) & simple to manage. I use Debian on my servers, if you have experience with another distro, simply use that.

I am developing with PHP (allright, I am developing with Nette framework) and a while ago I was pissed off ’bout all the FTP deployment (it’s pain in the ass) so I’ve decided to use something more efficient. And discovered GIT deployment.

As I mentioned in another post I use Lighty + PHP + MySQL, but if you are running on LAMP it makes no difference. Because I’ve got multiple domains I created these directories:

/home
  /domains
     /vyvazil.eu
        /git
        /ssl
        /web
           /subdomains
               /blog
               /www
     /another.tld

I store GIT repositories in

/var/git/repo.git

I access GIT repos via SSH. There was a little problem (I working on Windows) because TortoiseGIT (GIT client) didn’t accept my private key so I had to convert it to the correct format using puttygen.

You will have to set up hooks for deployment. For simple deployment post-receive  will do. In the hooks directory is more examples if you are interested and I will post more ’bout hooks too, for now we just create post-receive (will be executed after push is received):

 nano /var/git/vyvazil.eu.git/hooks/post-receive

And write your desired script. My script is really simple, firstly it does checkout to /home/domains/vyvazil.eu/git. Then it rsync data to www root, I use –delete, but be carefull, if you have something on subdomain, it will be deleted (like the wordpress installation I run on subdomain blog). Use it wisely.

And of course it deletes the temp folder used by Nette (for caching, etc). And create temp and log folder if not exists. The real script is much more complex, I actually update database tables using hooks and much more, but I just wanted to show you the simple way how to use it. So the actual post-receive:

#!/bin/sh
#
# POST RECEIVE SCRIPT

# variables
domain="vyvazil.eu"

# checkout
GIT_WORK_TREE=/home/domains/$domain/git git checkout -f

# rsync deploy
rsync -arvx --delete /home/domains/$domain/git/ /home/domains/$domain/web

# check if temp exists and create it if not
if [ ! -d "/home/domains/$domain/web/temp" ]; then
        mkdir /home/domains/$domain/web/temp
        chmod -R 777 /home/domains/$domain/web/temp
fi

# delete temp
rm -rf /home/domains/$domain/web/temp/*

# check if log exists and create it if not
if [ ! -d "/home/domains/$domain/web/log" ]; then
        mkdir /home/domains/$domain/web/log
        chmod -R 777 /home/domains/$domain/web/log
fi

Make sure that the script is executable, you have got the rights for the script set up right and let’s deploy.

What solutions do you use?

 

Android Studio – Could not create plugin of type ‘AppPlugin’

Problem

I’ve updated Android Studio & SDK, then updated build.gradle to be using latest build tools and gradle plugin. And because IDE showed me some errors about using auto import for gradle, I’ve decided to install latest gradle and use it locally. But when I tried build my project I got this error.

A problem occurred evaluating project ':Project'.
> Could not create plugin of type 'AppPlugin'.

 Solution

Don’t use latest Gradle (version 1.10), downgrade to 1.9.

New Year with new technologies – mostly lighttpd

My old VPS was kinda meeting it’s limits so I’ve decided to order new one.  Actually I’ve ordered new VPS a few months ago at Digital Ocean for a project I am not able to complete and won’t be ready for a few months, so I decided to use this server for this blog and several more domains.

Digital Ocean offers really great deals (20GB SSD & 512MB RAM for $5, really easy scalable) and after few months of testing I have no other choice than recommend. About creating droplets (means VPS) and managing web server maybe some other time, it’s like two clicks of mouse.

My old VPS is running LAMP (Linux, Apache 2, MySQL & PHP) and I’ve ordered only 512MB of RAM, I’ve decided to try Lighttpd instead of Apache just to save some memory. And it looks amazing.

At this very moment I’ve got three websites (powered by PHP framework – Nette), one WordPress site (this blog) and  flyspray site (bugtracking) on the VPS and it’s using 190MB of RAM.

The only thing I had to really resolve was the mod rewrite for WordPress. As a matter of fact it was really easy, check how to run wordpress on lighttpd.

Few hours ago I’ve  changed MX records and the blog is now running on the Lighty provided by Digital Ocean. Hooray.

WordPress on Lighty (lighttpd) with cool uri

If you wants to run WordPress site on Lighty (lighttpd) instead of Apache, you will find out that there is one little problem. Ligthy does not support .htaccess for mod_rewrite, so you will have to configure rewriting some other way. And it’s really simple, the only thing you really have to do is add this lines to your config file (/etc/lighttpd/lighttpd.conf):

        url.rewrite = (
                "^/(.*)\.(.+)$" => "$0",
                "^/(.+)/?$" => "/index.php/$1"
        )

And check if you have mod_rewrite enabled in the same config file:

server.modules = (
        "mod_access",
        "mod_accesslog",
        "mod_fastcgi",
        ... ,
        "mod_rewrite",
)

The complete record for this blog in lighttpd.conf is:

# this is the settings for blog subdomain running wordpress
$HTTP["host"] =~ "(blog\.)vyvazil\.eu$" {
        # these three lines below should be pointing at real paths 
        server.document-root = "/home/domains/vyvazil.eu/web/subdomains/blog/" 
        server.errorlog = "/home/domains/vyvazil.eu/web/log/error.log"
        accesslog.filename = "/home/domains/vyvazil.eu/web/log/access.log"

        url.rewrite = (
                "^/(.*)\.(.+)$" => "$0",
                "^/(.+)/?$" => "/index.php/$1"
        )
}

 Don’t forget to restart your web server after saving changes in configuration file.

Android Studio not using built in SDK

If you download Android Studio you’re probably ready to develop the apps instantly, because there is built in SDK (android) in the software. That’s sweet for new developers, not for me, because I have used Eclipse and sometimes I run this IDE too. And that means I already downloaded SDK, unzipped it in different path, download all important images and set up all virtual devices.

And there’s a problem. Even if I set up Android studio to use my SDK path, it sometimes doesn’t work and it uses Android Studio path (../android_studio/sdk/). That means I have to create demanded virtual device (and sometimes download correct API version images). And because Android Studio is EAP, the settings might not work and sometimes I’m not able to change the path.

Here’s the quick fix. Delete the SDK folder from Android Studio folder and create junction (in Windows). That means run command prompt (press button with windows logo at keyboard, type cmd, press enter) and type in this command:

MKLINK /J [destination path] [sdk path]

In my case it was:

MKLINK /J C:\Java\android_studio\sdk C:\Java\sdk

Here we are, problem succesfully solved.

junction

Six months sober

Six months sober

Began as an innocent support for my suffering friend (he was suffering because he has to stop drinking) and turned into a great lifetime experience.

So now sixth month passed on and because this was the target I have to say, it worths the try.

Next target – quit smoking. This one will be tough, because I am really addicted to a nicotine. Will post an update on this.

Android Studio – connection error

If you are experiencing a connection error trying to update Android Studio ( – Connection error. Please check your network connection and try again), you probably googled that’s an error in Android Studio.

connection-error.fw

Quick fix

Just add the following line to .vmoption file. It is located in your installation path (aka C:\Program Files (x86)\Android\android-studio\bin). There are two files you should check: studio.exe.vmoptions and studio64.exe.vmoptions.  Change the one you are using or both just to be sure.

-Djava.net.preferIPv4Stack=true

or you prefer IPv6 (if you don’t know what IPv6 is, just use the first line)

-Djava.net.preferIPv6Addresses=true

 Still not working?

Try to run your Android Studio directly from installation path (C:\Program Files (x86)\Android\android-studio\bin) by clicking studio.exe or studio64.exe and update the Android Studio then. After update you are able to run Android Studio the usual way.

Android studio – Project Wizzard

I’ve prepared some screenshots from Android studio’s project wizzard, as you can see, the functionality is the same like in Eclipse.

Android studio is better than Eclipse, you should try it. It’s faster, smoother, not ugly and have nice dark theme (darcula).