Google App Engine Rollback update

Sometimes when your uploading your app to Google App Engine if something goes wrong during the process, And when you retry to upload you get an error asking to rollback previous action. This is how to run that command.

C:\Program Files (x86)\Google\google_appengine> C:\Python27\python.exe appcfg.py
rollback d:\wamp\www\projectname --oauth2

you can simplify this by adding python.exe and appcfg.py paths to your system path variables.

For mac

/usr/local/google_appengine/appcfg.py rollback [your-project-directory]
Advertisements

Google App Engine Upload Error – This application does not exist

If you started getting the error “This application does not exist” after you started using OAuth to authenticate and upload your application, This is the solution.

Cause – Its only saving the OAuth token for a single account. So if you like me is using multiple app engine accounts you might want to follow this instructions.

App engine launcher saves the OAuth token on your home folder and its named –

.appcfg_oauth2_tokens

You need to find and delete this file. On windows machines it will be under C:\Users\admin or C:\Users\[Username]

Installing Zurb Foundation gem on Ruby on Rails

HI guys, today I am going to list down the steps on how to install foundation (http://foundation.zurb.com/) for a ruby on rails projects.

1. Go to your rails project folder and open the Gemfile. And add the following line,

gem <span class="string">'foundation-rails'</span>

2. then go to terminal and run the following command from your project folder,

rails g foundation:install

This should add foundation into your project. More info on the installation can be found here. But like me if you get an error when you go to your project on the browser saying,

Invalid CSS after "...ules: $modules ": expected "}", was "!global;"

you might want to do some adjustments, because above error is caused by a sass version included in ruby on rails by default and the sass version on foundation being mismatched. So you might want to specify an earlier version of foundation like following on your GemFile,

gem 'sass-rails', '&gt;= 4.0.4'

gem 'foundation-rails', '5.4.5'

More info on fixing this error can be found here.

Google Recaptcha – Defeating spam got a lot easier

Earlier version of the recaptcha was just a pain in the ass. For developers to implement and also for users who had to squint and type distorted text. Remember this?

2015-04-10 09_07_07-Customizing the Look and Feel of reCAPTCHA - reCAPTCHA — Google Developers

 

Well Google changed that with this new version where the user only had to Tick a check box and some magic happened and it checked if the user is authentic. (Its not clear on their website how exactly they do it, but i think they check for data that has been captured by their analytics tools or cookies or something to make sure that your human)

2015-04-10 09_10_56-reCAPTCHA_ Easy on Humans, Hard on Bots

Here also it falls back to a captcha text if it cant determine if your human so there is a fail safe built in.

Anyway the good news for developers is we can quickly add captcha to our pages without going through a tedious process. So I’m going to give the steps down here that I used to implement recaptcha on my free invoicing tool. (Invoicer)

Step 1.

Go to https://www.google.com/recaptcha/intro/index.html and click the get Recaptcha buton.

2015-04-10 09_14_19-reCAPTCHA_ Easy on Humans, Hard on Bots

Step 2.

Enter the Label and domains that this recaptcha needs to be active on, and click register.

2015-04-10 09_15_43-reCAPTCHA_ Easy on Humans, Hard on Bots

Step 3.

On the next screen you will get the instructions on how to add the recaptcha into your page. But Ill list down the steps here as well.

On client side,

add the script file in the head tag.

 <script src='https://www.google.com/recaptcha/api.js'></script>

Add the following code at the end of the form where you want the captcha widget to appear,

 <div class="g-recaptcha" data-sitekey="6LddIgUTAAAAAEky5noUKqsnA3QPysdXQ05WFsnB"></div> 

On server side,

You need to capture the value generated by client side code and post it to google for verification. This bit can be a bit tricky.

How I did it on Google App Engine is to do a url fetch. Think you will be able to do the same by using curl. Or also ajax.

 <?php

/* recaptcha validation */
<pre>$data = ['secret' => 'YOUR OWN SECRET KEY', 'response' => $_REQUEST['g-recaptcha-response']];
$data = http_build_query($data);
$context = [
    'http' => [
        'method' => 'POST',
        'header' => "custom-header: custom-value\r\n" .
            "custom-header-two: custom-value-2\r\n",
        'content' => $data
    ]
];
$context = stream_context_create($context);
$result = file_get_contents('https://www.google.com/recaptcha/api/siteverify', false, $context);

You will get a json response and if the success attribute it true you can proceed with processing the form values.

<pre>$success_status = json_decode($result)->success;

if($success_status) {

}</pre>

 

More information can be found here regarding verification.

The trickiest part is handling it on server side. If you have any problems with that please post on the comments section and I will try and help. 🙂

Invoicer by Suren Dias – Free invoicing tool for freelancers

HI I created this free invoicing tool aimed at freelancers. Its currently at a very early stage. Can only create pdf invoice at the moment from the data that user enters.

Tool – http://invoicer.surendias.com/

Source – https://github.com/surendias/Invoicer

Sorting multidimensional arrays by multiple keys in PHP

This is a very cool method to sort a multidimensional array by multiple keys. I didn't think of this though. :) Found this while searching for a solution on stackoverflow link is given here.
$mylist = array(
    array('ID' => 1, 'title' => 'Boring Meeting', 'event_type' => 'meeting'),
    array('ID' => 2, 'title' => 'Find My Stapler', 'event_type' => 'meeting'),
    array('ID' => 3, 'title' => 'Mario Party', 'event_type' => 'party'),
    array('ID' => 4, 'title' => 'Duct Tape Party', 'event_type' => 'party')
);

# get a list of sort columns and their data to pass to array_multisort
$sort = array();
foreach($mylist as $k=>$v) {
    $sort['title'][$k] = $v['title'];
    $sort['event_type'][$k] = $v['event_type'];
}
# sort by event_type desc and then title asc
array_multisort($sort['event_type'], SORT_DESC, $sort['title'], SORT_ASC,$mylist);

2014 in review

The WordPress.com stats helper monkeys prepared a 2014 annual report for this blog.

Here’s an excerpt:

A New York City subway train holds 1,200 people. This blog was viewed about 7,700 times in 2014. If it were a NYC subway train, it would take about 6 trips to carry that many people.

Click here to see the complete report.