Skip to content

Instantly share code, notes, and snippets.

View arunenigma's full-sized avatar

Shan arunenigma

  • Silicon Valley
View GitHub Profile
@arunenigma
arunenigma / Circle.java
Created June 9, 2012 03:05
Java - Creating a simple class with static and instance fields/methods
/**
*
* @author arunprasathshankar
* fields(variables) and methods are members of a class
* 2 types of members
* i) class members
* ii) instance members(members associated with objects) — also called static members
*/
public class Circle {
// class field : static is a must for class field(a.k.a static field)
@arunenigma
arunenigma / ConstructorOverloading.java
Created June 12, 2012 02:28
Constructor Overloading
// Constructor Overloading
class Rectangle {
int l,b;
double p,q;
// Constructor 1
public Rectangle(int x,int y) {
l = x;
b = y;
}
public int first() {
@arunenigma
arunenigma / This.java
Created June 12, 2012 03:05
Use of 'this' operator in java
// Use of 'this' operator
// class Rectangle2 shouldn't be declared public
class Rectangle2 {
int length,breadth;
// 'this' is equivalent to self in python
void show(int length,int breadth) {
this.length = length;
this.breadth = breadth;
}
@arunenigma
arunenigma / ThreadExample.java
Created June 12, 2012 03:30
Threads in java
// Threads in java
public class ThreadExample {
public static void main(String[] args) {
// note Thread below is class name for Thread(pre-defined in library) and not the class name of this program
Thread th = new Thread();
System.out.println("Numbers are printing line by line after 5 seconds : ");
try {
@arunenigma
arunenigma / blogger_redirection.php
Created June 19, 2012 13:44
Redirecting blogger posts to wordpress/self hosted domain posts
<?php
/*
Template Name: Blogger Redirection
*/
global $wpdb;
$old_url = $_GET['q'];
if ($old_url != "") {
$permalink = explode("blogspot.com", $old_url);
@arunenigma
arunenigma / blogger_redirection.html
Created June 19, 2012 13:47
Redirecting blogger posts to wordpress/self hosted domain posts
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="<$BlogLanguageDirection$>">
<head>
<script type="text/javascript">
<mainorarchivepage>window.location.href='http://www.yourdomain.com/'</mainorarchivepage>
<blogger><itempage>
window.location.href='http://www.yourdomain.com/blogger/?q=< $BlogItemPermalinkURL$>'
</itempage></blogger>
</script>
@arunenigma
arunenigma / MatMux.java
Created July 2, 2012 01:49
Java Program for Matrix Multiplication
class MatMux {
public static void main(String[] args) {
int array[][] = {{5,6,7},{3,4,5}};
int array1[][] = {{1,2},{3,4},{5,6}};
/* array2 is the resulting product matrix.. assign any random dimension.. here i have used 12 X 12
int array2[][] = new int[12][12];
int x = array.length;
System.out.println("Array Length --> "+ array.length);
System.out.println("Array1 Length -->"+ array1.length);
System.out.println("Array Length -->"+ array2.length);
@arunenigma
arunenigma / reverse_string.cpp
Created February 24, 2013 17:56
Reverse a given string without using pointers
#include <iostream>
#include <string>
using namespace std;
string reverse(string str);
int main() {
string s;
cout << "Enter string to be reversed: " << endl;
cin >> s;
s = reverse(s);
@arunenigma
arunenigma / reverse.cpp
Created February 24, 2013 22:15
reverse a string using C++ <algorithm> library
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main()
{
string s;
cout << "Enter string to be reversed: " << endl;
cin >> s;
reverse(s.begin(), s.end());
@arunenigma
arunenigma / dyn_mem_alloc.cpp
Created March 8, 2013 01:07
Dynamic Memory Allocation for objects in C++
// Dynamic Memory Allocation for objects
#include <iostream>
using namespace std;
class Box {
public:
Box() {
cout << "Constructor called!" << endl;
}
~Box() {