Category Archives: Configuration

Vagrant on Windows 10 error when you run Vagrant up

I got Vagrant and Virtual Box running on my laptop running WIndows 10 without an issue.

But when I tried to get a vagrant box up it started giving the following error,

$ vagrant up
Bringing machine 'default' up with 'virtualbox' provider...
==> default: Importing base box 'scotch/box'...
==> default: Matching MAC address for NAT networking...
==> default: Checking if box 'scotch/box' is up to date...
==> default: Setting the name of the VM: my-project_default_1443152333300_24531
==> default: Clearing any previously set network interfaces...
There was an error while executing `VBoxManage`, a CLI used by Vagrant
for controlling VirtualBox. The command and stderr is shown below.

Command: ["hostonlyif", "create"]

Stderr: 0%...
Progress state: E_FAIL
VBoxManage.exe: error: Failed to create the host-only adapter
VBoxManage.exe: error: Operation canceled by the user
VBoxManage.exe: error: Details: code E_FAIL (0x80004005), component VirtualBoxWrap, interface IVirtualBox
VBoxManage.exe: error: Context: "enum RTEXITCODE __cdecl handleCreate(struct HandlerArg *)" at line 71 of file VBoxManageHostonly.cpp

To fix this I followed these steps,

Went to VirtualBox window and,

  1. Open VirtuaBox
  2. Go to File->Preferences->Network->Host-only Networks
  3. Create Manually a new adapater like as follow:

IPv4: 192.168.2.1 (in my example my vm ip is 192.168.2.2 you must use the 3 first parts equal as your ip address and replace the last one by 1)

Mask: 255.255.255.0

BTW I was trying to up the LAMP box given by Scotch.io. You can get here, https://box.scotch.io/

Google Cloud Storage – Set ACL for objects in a bucket

Hi I have been trying to upload files to Google Cloud Storage from my Google App Engine App (PHP) and got stuck when trying to set the ACL for those files. I tried to set the ACL manually in my code at the time of file upload and it was proving to be tricky as my app is using Laravel which is using a different way to handle file uploads.

For people using normal php scripts can use following method given in GCS docs.

 

<?php
use google\appengine\api\cloud_storage\CloudStorageTools;

$object_url = 'gs://my-bucket/'.time().rand(0,1000).'.txt';
$options = stream_context_create(['gs'=&gt;['acl'=&gt;'public-read']]);

$my_file = fopen($object_url, 'w', false, $options);
for($i=0;$i&lt;900;$i++) {
  fwrite($my_file, 'Number '.$i.' - '.rand(0,1000).'\n');
}
fclose($my_file);

$object_public_url = CloudStorageTools::getPublicUrl($object_url, false);

header('Location:' .$object_public_url);

But there is a different, much easier option using GSUTIL tool. With this tool we can give a command on a bucket to set the default ACL for that bucket. So in my case that was public access.

First before giving the command follow steps given in this url to install the gsutil tool.

After installing set up your credentials as per this link.

To setup the connection first run this command:

C:\Python27>python c:\gsutil\gsutil config

Then give the following command.

 

C:\Python27>python c:\gsutil\gsutil defacl set public-read gs://your-bucket-name

This will make all your future uploads public read enabled.

If you want to further learn about gsutil acl commmands you can read up here.

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]

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]

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. 🙂

Set the JDK/JRE for netbeans

My default JRE got changed when I was configuring my Eclipse to work with Google App Engine. This resulted in an error in Netbeans as it was not able to find the old JRE. To fix this you need to do this,

Go to [Netbeans installation directory]/etc/ folder and open the netbeans.conf file.

in that find this line and,

netbeans_jdkhome=”set the path to the new JRE folder here”

Save and restart/start netbeans. 🙂

Configuring Aptana with SVN

Hi guys,

this is my first post on my new coding blog, I changed jobs recently and started working on php mysql based projects. I use Aptana Studio 3 as my IDE.

My new office didn’t have any SVN or CVS setup when I joined. And it was really hard to find the proper source code for doing changes. And they were copying the source from the server every-time they wanted to edit something and then uploading the files. No changes were being tracked.

So I decided to install a versioning system and using that to manage the code. I have used CVS in the past but wanted to try out SVN in my new office. I searched the net on how to do this and found many articles that helps to setup SVN in an Linux environment and as there was no Linux box available in our office for immediate use I decided to find a Windows based SVN server. After some searching I decided to use Visual SVN for my SVN repostory management. It was really easy to setup,

1) download the installer from,

http://www.visualsvn.com/server/getting-started/

2) install like you install any other windows based application

3) create a user login

4) give a repository path

then setup subversion in Aptana studio, you can refer one of the following links for reference,

http://wiki.appcelerator.org/display/tis/Subversion
then committing your project to the SVN using Apatana you can have a centralized code.

will update this post in the future with more details, just noting down what i did before i forget them 🙂