Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Java: Clear the console and control attributes On Win9x

public class WindowsCLS {
  public static void main(String args[])
    String ANSI_CLS = "u001b[2J";
    String ANSI_HOME = "u001b[H";

Java: read from the keyboard using StreamTokenizer class

import java.io.*;
public class ReadKeayboard
   public static void main (String args[]) 
      StreamTokenizer entree=new StreamTokenizer(Sys

Python: convert python byte codes using the dis Module

import dis
def function(x):
     print  'Hello world!'

Python: return data for a specified group(Unix only)

import grp
import os
print grp.getgrgid(os.getgid())
print grp.getgrnam("programmer")

Java: The minimum and maximum of a generic array

 import java.util.*;
 public class MinMaxDate Arrays
     public static void main(String[] args)
          GregorianCalendar[] birthda

Python: create a functions to be called at program termination

import atexit
def exit(*args):
    print "Done!", args
atexit.register(exit, 1)
atexit.register(exit, "Python", "Tutorial")

Python: Insert into database table via dbhash module

import dbhash
# Create and open database
db = dbhash.open("dbhash", "c")
# Insert into databse file
db ["element-> 1"] = "Banana"
db ["element-> 2"

Python: Print date and time

import time
now = time.time()
print "Date and time:", time.localtime(now)
print "utc:", time.gmtime(now)

Python: Compiling and Executing a compiled Code File

code_script = """
print 'Learn to program'
# Compile the script
    code = compile(code_script, "", "exec")
except SyntaxError, v:

Python: Manipulate a database file with dbm module

import dbm
db = dbm.open("dbm", "c")
db ["element-> 1"] = "Banana"
db ["element-> 2"] = "Tomato"
db ["element-> 3 '] =' Onion"
db ["element-> 4"] =

Java: Sorting Arrays

public class SortArray {
  public static int MAXSIZE = 25;
  public static void main(String args[]) {
    Integer iArr[] = new Integer[SortArray.

Python: compile Script to Check Syntax

script_name = "script.py"
code_script = """
prnt 'Welcom to tubedir.com'
    compile(code_script, script_name, "exec")
except SyntaxError,

Python: Find the Current Platform

import sys
print sys.platform,"=> ",
if sys.platform == "win32":
    import ntpath
    pathmodule = ntpath
elif sys.platform == "mac":
    import m

Python: Find Imported Modules

import sys
print sys.modules.keys()

Python: check Python source files for ambiguous indentation

import tabnanny
FILE = "example/script.py"
file = open(FILE)
for line in file.readlines():
    print repr(line)
# check the file