Sunday, October 18, 2015

My Programming Adventure | Android and Python | Page 2

Move to Next Activity in AndEngine (Android)

Tags

I was developing the game using AndEngine. I had two activity Welcome screen(Welcome.java) and Game Screen(Game.java) when user clicks on Start button in Welcome Screen he should be moved to next activity.
I end up with the following code. You can also use the following code to change the activity in AndEngine.
Place this code somewhere on suitable event such as onClick() event after which you want to change the activity.
Welcome.this.startActivity(new Intent(Welcome.this, Game.class));
Welcome.this.finish();
Change the class name to yours and fix the import Error that will occur.
And finally add this code in AndroidManifest.xml before </application>
<activity android:name="com.example.myGame.Game"> </activity>
Don’t forget to change your package name and Class name.

E: Sub-process /usr/bin/dpkg returned an error code (1)

Tags

I recently ran into the following error in Ubuntu (v 13.10).
E: Sub-process /usr/bin/dpkg returned an error code (1)
Due to this error i was not able to run the update. Here is the fix to this error.
First run:
$ sudo apt-get remove install-info
Then run this command to clear apt archives:
$ sudo apt-get clean
Then finally run
$ sudo apt-get update
$ sudo apt-get upgrade

How to remove /public/ from URL in Laravel

Tags

By default in Laravel the URL to access your site is http://example.com/public/. It is not good to keep public in URL as it makes URL ugly and longer.
So, let’s talk about the solution to remove /public/ from the URL.
Method I : Using .htaccess
Create a .htaccess file your Laravel root directory if it does not exists already. (Normally it is under your public_html folder)
And add the following code to it:
<IfModule mod_rewrite.c>
    RewriteEngine On

    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>
Now you can access your site via http://example.com.
Method II : Moving the contents of public folder to root directory
Actually i prefer this method because the above method is not so good to use in production environment.
So now lets make a new folder laravelfiles in your root directory and move all the files and folder except public directory to laravelfiles.
And move everything of public directory to root folder. Now your root directory will look something like this:
Remove Laravel Public url
Now we have to change the paths in laravelfiles/bootstrap/paths.php file and index.php.
Find these lines in laravelfiles/bootstrap/paths.php
    'app' => __DIR__.'/../app',
    'public' => __DIR__.'/../public',
Change these two lines to:
    'app' => __DIR__.'/../app',
    'public' => __DIR__.'/../../',
Find these lines in index.php
    require __DIR__.'/../bootstrap/autoload.php';

    $app = require_once __DIR__.'/../bootstrap/start.php';
And change to:
    require __DIR__.'/laravelfiles/bootstrap/autoload.php';

    $app = require_once __DIR__.'/laravelfiles/bootstrap/start.php';

Setup Google App Engine Python SDK in Ubuntu

Tags
,
First of all download Google App Engine SDK for Linux.
Extract it anywhere within your local folder. It can be anywhere such as in your home directory or Documents directory.
Open terminal (ctrl+alt+t) and navigate to your home directory and open .bashrc to edit with this command:
$ sudo gedit .bashrc
At the end of the file, add these lines by changing the directory to your google_appengine folder. The first line is just a comment and in the second line /usr/local/google_appengine is the path to the google_appengine folder.
### Added for GAE
export PATH="/usr/local/google_appengine:$PATH"
Now restart your computer and then you should be able to use $ dev_appserver.py command from anywhere.

JavaScript code to display Multiplication table

Tags

Through JavaScript you can easily write the html code in html document using document.write(). Using document.write() and for loop it is easy to print the table of user input number.
First of all “promt” box will appear and then this value will be parse to integer and the multiplication table is displayed.
The source code for JavaScript is as follows:
<script type='text/javascript'>
var num = prompt("Enter Number", "0") //prompt user to enter the number

var num = parseInt(num); //parse the num to number
var i = 0;

document.write('<table border="1" cellspacing="0">');
for(i=1;i<10;i++) {
    document.write("<tr><td>" + num + " x " + i + " = " + num*i + "</td></tr>");
}

document.write("</table>");
</script>

Follow

Get every new post delivered to your Inbox.
Join 237 other followers