Skip to content

Instantly share code, notes, and snippets.

View asimihsan's full-sized avatar

Asim Ihsan asimihsan

View GitHub Profile
@asimihsan
asimihsan / aadhaar_generated_mapper.py
Created February 18, 2014 15:57
Lesson 5 - MapReduce. Mapper and reducer with aadhaar data.
import csv
import sys
import string
def mapper(input=sys.stdin):
reader = csv.DictReader(input)
for row in reader: #cycle through lines of code
print "%s\t%s" % (row["District"], row["Aadhaar generated"])
mapper()
### MATPLOTLIBRC FORMAT
# This is a sample matplotlib configuration file - you can find a copy
# of it on your system in
# site-packages/matplotlib/mpl-data/matplotlibrc. If you edit it
# there, please note that it will be overridden in your next install.
# If you want to keep a permanent local copy that will not be
# over-written, place it in HOME/.matplotlib/matplotlibrc (unix/linux
# like systems) and C:\Documents and Settings\yourname\.matplotlib
# (win32 systems).
@asimihsan
asimihsan / lessons-learned.md
Created February 14, 2014 16:33
Web administered test automation - lessons learned

Web-administered test automation - lessons learned

Summary

  • All processes require checklists.
  • Automate everything, and continuously test your automation.
  • Do not reinvent the wheel. Defer to idiomatic or popular solutions.
  • Everything fails. Anticipate this and offer degraded service.
  • Instrument everything.
@asimihsan
asimihsan / !stdout
Last active September 2, 2018 21:25
NSA codeword generator.
HOMOGENAKA
SPALLYILL
ENEUCHSTROKY
BOBACHUELESS
SYNAPTEPIERAGE
HUMBLEENCRATY
EMITTERSOMEDAY
BUGLETINNLESS
BEAUPAINTER
TOXEMIASHALLOW
@asimihsan
asimihsan / CodingForInterviewsBitManipulation.java
Created December 14, 2013 22:31
Coding for Interviews - Bit Manipulation
class CodingForInterviewsBitManipulation {
public static int setBit(int number, int index, boolean set) {
if (set)
return number | (1 << index);
else
return number & (~(1 << index));
}
public static boolean getBit(int number, int index) {
int result = (number & (1 << index)) >> index;
@asimihsan
asimihsan / python_resources.md
Last active April 18, 2017 15:37
Python resources

Python resources

  • "Courses" are intended for learning Python via an online interactive course.
  • "Learning books" are intended for learning Python by reading them cover-to-cover.
  • "Reference books" are intended for dipping into randomly as you face particular problems in Python or in general.

All material are specified in order of preference (most to least); all of these

@asimihsan
asimihsan / !nqueens_introduction.md
Last active December 29, 2015 02:29
Coding for Interviews - N-Queens - Java

N-Queens solution using naive recursion.

We know all queens must be on distinct columns. Hence for each column recursively attempt each row, terminating if the current configuration with the current subset of columns is invalid.

Validity checking does not need to check if any columns overlap (by definition they do not); we only check if both conditions are false:

  1. any rows overlap, placement[i] == placement[j], and
  2. any queen lies on the same diagonal as another, Math.abs(i - j) == Math.abs(placement[i] - placement[j])

This is not the worst solution (the worst involves 64 choose 8 ~= 4 * 10^9!!), but not the best (a DFS graph search would do better). Indeed results show this code is too inefficient above n=14.

@asimihsan
asimihsan / tesseractcli.cpp
Created November 19, 2013 17:42
Noddy little Tesseract wrapper.
// ----------------------------------------------------------------------------
// Noddy little Tesseract wrapper.
//
// Usage:
//
// ./tesseractcli <path to screenshot image> [left] [top] [width] [height]
//
// - Screenshot path is mandatory, can be relative to current working
// directory or absolute.
// - Left, top, width, and height are optional integers that set a
@asimihsan
asimihsan / LevelOrderTreePrint.java
Last active December 28, 2015 08:59
Level Order Tree Print
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Queue;
class KTreeNode {
Integer value;
Collection<KTreeNode> children = new ArrayList<KTreeNode>();
@asimihsan
asimihsan / r_tutorial.md
Last active May 22, 2024 12:48
R tutorial

R tutorial

Introduction

R is a software environment for statistical computing and graphics. The kinds of things people do in R are:

  • Plot charts,
  • Create and evaluate statistical models (linear, nonlinear),
  • Perform statistical analyses (tests, classification, clustering).