Interview Questions

Scripting

Python - Rest Client (GET/POST)

Use the following code to make GET/POST request on a REST interface in python

'''
Created on Aug 8, 2013

@author: Administrator
'
''
import urllib2
import json

class RestClient(object):
    '''
    classdocs
    '
''


    def __init__(self):
        '''
        Constructor
        '
''
       
    def performGET(self,url):
        #url = 'http://www.acme.com/products/3322'
        response = urllib2.urlopen(url).read()
        return response
   
   
    def performPOST(self,url):
             
        jdata = json.dumps({

Python - Django Model Creation

The following code illustrates a sample ORM object model in Django.
This class can be used for persisting objects in DB.

from django.db import models
import datetime,uuid

class Device(models.Model):
    '''
    classdocs
    '
''
   
    id = models.CharField(max_length=70,primary_key=True)
     
    name = models.CharField(max_length=70)
   
    status = models.CharField(max_length=70)
   
    ipAddress = models.CharField(default=False)
   
    createdOn = models.DateTimeField(datetime.datetime.now,blank=True)
   
   

Python - Display current date/time

Use the following code to display current datatime in python.

import datetime
print(datetime.datetime.now())

Python - List Prime Numbers

Use the following Python script to list Prime numbers in a given range.

#!/usr/bin/env python3

for n in range(2, 1000):
    h = int(n / 2);
    for x in range(2, h):
        if n % x == 0:
            print (n, 'equals', x, '*', n / x)
            break
    else:
        print (n , 'is a prime number')

Linux Interview Questions & Answers

Linux Interview Questions & Answers

SSH Interview Questions & Answers

SSH stands for Secure Shell.

This tutorial provides the set of interview questions for the Shell Scripting Language.

Responsive UI - Using Bootstrap

Use the following HTML template which uses Bootstrap (CSS) Framework to develop responsive UI (supporting all devices) for developing your website layout.

<!DOCTYPE html>
<html>
<head>
<title>The Company</title>
<meta name="viewport"
        content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
        <link rel="stylesheet" href="css/bootstrap.css" type="text/css" />
        <link rel="stylesheet" href="css/bootstrap-responsive.css" type="text/css" />
</head>
<body>
<body>

    <div class="navbar navbar-inverse navbar-fixed-top">

Jquery - Select nth child in an HTML Table

The following code example illustrates modifying an nth child in an HTML table

<!DOCTYPE html>
<html>
<head>
        <script src="js/jquery-1.9.1.min.js"></script>
<script>
$(document).ready(function(){


$('table td:nth-child(2) input').focus(
function() {

   $(this).parent().next().css("background-color","#00FF00");

});
$('table td:nth-child(2) input').blur(
function() {

   $(this).parent().next().css("background-color","#FFFFFF");

});




});
</script>
</head>

<body>
<table>
<tr>
<td>Input</td>
<td>Type</td>
<td>Current</td>
</tr>

BackBoneJS - Basic User Form Example

The following code example illustrates how to add user form data to collections using backboneJS.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en">

        <head>

                <script src="js/jquery-1.9.1.min.js"></script>
                <script src="js/underscore.js"></script>
                <script src="js/backbone-min.js"></script>
                <script src="js/backbone.syphon.js"></script>

                <script type="text/javascript">
                        $(document).ready(function() {

                                var Person = Backbone.Model.extend({

IUI - Basic Example using IUI Framework

IUI is a web framework used for creating mobile websites and webapps providing a native look-alike in a lesser time. It supports IOS, android etc.,

The following is a basic example application in html which uses IUI framework. Please download IUI framework to run this example application.

    <!DOCTYPE html>
    <html>
    <head>
       <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
       <meta name="viewport" content="width=device-width; initial-scale=1.0; maximum-scale=1.0; user-scalable=0;"/>