Skip to content

Instantly share code, notes, and snippets.

@alcedo
alcedo / JavaScript Quirks and notes
Last active December 21, 2015 01:59
JavaScript Quirks and notes
/*********** Checking for not defined / undefined **********/
foo
// ReferenceError: foo is not defined
if(foo == null) console.log('this wont work');
// ReferenceError: foo is not defined
if (typeof foo == 'undefined' ) console.log('foo is undef');
// this is the only way to check for not defined
function Node (data) {
this.left = void(0);
this.right = void(0);
this.data = data;
}
var root = new Node ('F');
root.left = new Node('B');
root.right = new Node('G');
@alcedo
alcedo / bash_profile for hadoop
Last active December 21, 2015 14:19
cshell script / linux related scripts
# .bash_profile
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc
fi
#JDK related exports
export JAVA_HOME=/bin/jdk1.6.0_31/bin/java
export PATH=$PATH:$HOME/bin
@alcedo
alcedo / JavaSnippets.java
Last active February 8, 2018 23:38
Java function snippets, Matrix, LCM, GCD
// used to print format print. %n is new line. dont use \n
// http://docs.oracle.com/javase/tutorial/java/data/numberformat.html
System.out.format("The value of sum is: %.2f%n", 4650/100);
//Rotates a matrix right
public static void rotateRight(char[][] matrix) {
int cols = matrix[0].length;
int rows = matrix.length;
@alcedo
alcedo / Problem_541.java
Last active December 21, 2015 17:09
Problem_541.java error collection
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.System.out;
/**
* Idea: if any col or row is odd, then set row or column to be corrupted
*
* if more than 1 row or col is corrupted, then its deadEnd.
* else
* output the particular row or col to be flipped in order to fix it
import java.util.Arrays;
import java.util.Scanner;
import java.util.BitSet;
import static java.lang.System.out;
/**
* Exhaustive search is used here.
* Spent 30 mins thinking about how to optimize the nasty N^2 maxtrix traversal but to no avail.
* So i simply submitted a brute force method and surprisingly got an AC :)
*
import java.util.Arrays;
import java.util.Scanner;
import static java.lang.System.out;
/**
* mistake: never read question properly. we need to calculate i upto and including j.
* hence for(; i<= j; i++) not for(; i< j; i++)
* the latter is done out of habbit =/
*/
public class Main {
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;
import static java.lang.System.out;
/**
* mistake: did not use BufferedReader to read in large files, resulting in very slow run time :-(
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Scanner;
import static java.lang.System.out;
/**
@alcedo
alcedo / FastInputOutput.java
Last active December 21, 2015 22:38
Fast I/O utility classes for UVa online
import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.Writer;
import java.util.Arrays;
import java.util.InputMismatchException;