Page 2 of 3

Setting Up Your First Debian/Ubuntu VPS

After you have created your first VPS, your VPS provider should give you the credentials for logging in through ssh. For Linux users you can just type into the terminal:

 ssh [user]@[your-vps-ip]

For Windows user you can download Putty an application that can be used for ssh. Now connect to your VPS through ssh. I assume you are now using the root user.

Update/Upgrade Server

Make sure that your server is updated. Type in:

apt-get update
apt-get upgrade

Change “root” Password

This part is optional, if you want to change the “root” password to something that you will be able to remember then use the below command otherwise move on to “Secure ssh”

passwd

Continue reading

Auto Enter Password For sudo Command

Normally using sudo will request the user a password after executing it but sometimes we might need to run a command with sudo from a script(bash script) or from a program. To auto enter a password for a script that will execute a sudo command you will need to do it like this in your script:

echo [password] | sudo -S echo "Sudo with auto enter of password"

Just replace the “[password]” with your actual password. Notice that we have “-S” as the option we pass for the sudo command. This option enables sudo to read the password from stdin where we have echoed our password.

Just an opinion but if you find yourself needing to auto enter a password in sudo command then maybe you should consider running it as a root user instead.

Access Django Development Server Remotely

By default Django development server will only be accessible through the local machine(127.0.0.1). If you want to access the server remotely then you need to run the the development server with your IP as an argument:

python manage.py runserver [your-ip-here]:8000

Change the “[your-ip-here]” to your actual IP. If you IP address is 174.143.2.123 then you will need to run the server using this:

python manage.py runserver 174.143.2.123:8000

If you have multiple network configured or you want the server to be automatically available on what your IP now currently is. Then enter 0.0.0.0 as your IP, like this:

python manage.py runserver 0.0.0.0:8000

This will bind the development server of Django on all available network/IP address. Then you will the see same message when you use just use python manage.py runserver  upon successfully creating the server but instead of http://127.0.0.1:8000/ you will see a http://0.0.0.0:8000/, then you will now be able to access your server remotely.

Validating models...
 
0 errors found
February 01, 2014 - 10:13:18
Django version 1.5.1, using settings mysite.settings
Development server is running at http://0.0.0.0:8000/
Quit the server with CONTROL-C.

Warning: This server is only meant for development use so you must not use this as a production solution. This is also discouraged by Django team.

Android: Using An Adapter For Dynamic ListView

This a continuation of my Android: Using An Adapter For ListView post. So please read that first you if haven’t done yet. The projects files for this tutorial is also there.

Adding The Dynamic Functionality

To add the dynamic functionality for the ListView we will need to add 2 functions for adding and removing items in our class that implemented the BaseAdapter. For the function of adding strings:

public void addString( String val ) {
 m_data.add(val);
 notifyDataSetChanged();
}

Aside from just normally adding the string to our data container called m_data. We are also calling the notifyDataSetChanged(), this function will notify the View where are our Adapter is connected. For this instance we will notify the ListView that the underlying data has changed and it must refresh its display/content.

Removing items is also the same, we will remove it normally from the List and notify the ListView of the changes done on the data.

public boolean removeString( int location ) {
 if ( location >= m_data.size() ) {
 return false;
 }
 m_data.remove(location);
 notifyDataSetChanged();
 return true;
}

We also added the location of the item that we need to remove. The important part of these 2 function is the line where we call the notifyDataSetChanged() since without calling it your view will not refresh and show the changes you’ve done.

Android: Using An Adapter For ListView

Creating A Custom Adapter

To use an Adapter with a ListView you must first extends an Adapter.

 class MyAdapter extends BaseAdapter {

Create a List member for the data container.

List<String> m_data = ArrayList<String>();

m_data will contain all string items that you will want to be displayed in the ListView. So in our constructor we will populate m_data with the strings we want to be shown.

 public MyAdapter() {
 m_data.add("item 1");
 m_data.add("item 2");
 m_data.add("item 3");
 }

Continue reading

Making Python Datetime Timezone Aware For Django

To make a Python Datetime timezone aware for Django Datetime field. You can use the utc from django.utils.timezone for replacing the tzinfo of Python Datetime but make sure that it is in UTC format. Below is a simple example of how to retrieve the current date and time and make it timezone aware for Django Datetime model field.

from django.db import models
from django.utils.timezone import utc
import datetime 
 
class Foo( models.Model ): 
 #datetime field sample 
 date_posted = models.DateTimeField( auto_now_add=True, blank=True ) 
 def save(self, *args, **kwargs): 
 #the datetime generated by datetime module will now be timezone aware 
 self.last_date_updated = datetime.datetime.utcnow().replace(tzinfo=utc) 
 super(Foo, self).save(*args, **kwargs)

Set Default Network Interface In Ubuntu

If you have two network interface in your Ubuntu eth0 and usb0 and the default network interface is eth0 but you want to use usb0 for internet connection. To make this happen you must set usb0 as your default interface so that when you need to access something that isnt located in the eth0 interface local network, usb0 will be used. For example you have a phone and you want its data connection to be tethered to your Ubuntu desktop. Once connected to your desktop it registered as usb0. So now you have both eth0 and usb0 interface registered and you want usb0 to be used for internet connection but still want to be able to connect to a computer that resides in eth0 local network and eth0 network also have an internet connection. By default eth0 will always be used since it it will be more likely the default interface. Continue reading

Debian/Ubuntu Handy apt Commands

When I first got on the Linux boat I only know that apt-get is a command to either install or remove a package from the system and only used the Synaptic Package Manager for searching packages. After a long time using Debian/Ubuntu I got to know some handy apt commands.

Here are the list of apt commands that I know right off the top of my head.

apt-get install [package name]

I think this is the first command that all people learned when they first tried Linux using Debian or Ubuntu. This command will install the package with the package name you entered

apt-get update

This command will update your systems record/cached packages list using the locations in your sources list.

apt-get remove [package name]

If you want to remove a specific package you can use this command.

apt-get purge [package name]

This command is the same as “remove” and will also remove its configuration files.

 apt-cache search [package name]

You can use this command if you dont know the exact package name. This will search the package in your systems cached packages and return the results so running apt-get update is advisable before you use this.

apt-get upgrade

This will update all packages that are installed in your system.

apt-get dist-upgrade

This will upgrade your system distribution to the latest one if its already available so this also perform the upgrade command

Compiling OGRE3D for Android

Update: 2015-02-18 – ndk version

You can now compile OGRE3D using NDK and the OGRE branch version 1.9. Ive followed the instruction in OGRE wiki for compiling for Android but got stuck several times in several areas and almost just give up. Im new to Android specially using the NDK and all of this just overwhelmed me. So this is a step by step guide Ive decided to make on how to compile OGRE for people that are like me, new to Android.

Requirements:

Continue reading

Django 1.5 Upgrade From 1.4 Problem On DEBUG=False

Ive upgraded the Django version Im using to 1.5 from 1.4.5 several days earlier and since then I was unable to run my app in release mode. Whenever I set DEBUG=False in settings.py a “HTTP Error 500” page is always served but setting it to DEBUG=True will make the app run fine.

Ive found out that now on version 1.5, Django has a new setting in settings.py:

# Hosts/domain names that are valid for this site; required if DEBUG is False
# See https://docs.djangoproject.com/en/1.5/ref/settings/#allowed-hosts
ALLOWED_HOSTS = []

This setting is not included in version 1.4 and is now needed in 1.5. You need to add your domain here ex: www.jamesbaltar.com. See this link for more

« Older posts Newer posts »

© 2024 James Baltar

Theme by Anders NorenUp ↑