Skip to content

Instantly share code, notes, and snippets.

View asimihsan's full-sized avatar

Asim Ihsan asimihsan

View GitHub Profile
@asimihsan
asimihsan / office_365_notifications.js
Created May 14, 2013 09:59
A Greasemonkey script to show notifications when there is any new mail in an Office 365 Outlook Web App tab.
// ==UserScript==
// @name Office 365 notifications
// @namespace http://use.i.E.your.homepage/
// @version 0.1
// @description Show a Google Chrome notification when there is any unread mail.
// @match https://*/owa/*
// @copyright 2012+, You
// ==/UserScript==
var current_unread_count = 0;
@asimihsan
asimihsan / Vagrantfile
Created June 16, 2013 14:20
Vagrant + Puppet config for setting up Fedora 18 x64 with Python, pip, and virtualenv.
# -*- mode: ruby -*-
# vi: set ft=ruby :
Vagrant.configure("2") do |config|
config.vm.box = "fedora-18-x64"
config.vm.box_url = "http://puppet-vagrant-boxes.puppetlabs.com/fedora-18-x64-vbox4210.box"
config.vm.provision :puppet do |puppet|
puppet.manifests_path = "manifests"
puppet.manifest_file = "init.pp"
end
@asimihsan
asimihsan / test.py
Created June 23, 2013 12:03
Start of something that'll use phantomjs to get performance info about getting a site, and then capture packets in the background.
import multiprocessing
import pprint
import time
import scapy.all as scapy
import subprocess
import sys
import os
import signal
import psutil
@asimihsan
asimihsan / init.pp
Created July 18, 2013 16:13
Puppet module class for installing OpenCV from source on Ubuntu.
class opencv {
Exec { path => "/usr/local/bin:/usr/local/sbin:/usr/bin:/usr/sbin:/bin:/sbin", }
$version = "2.4.6.1"
$libopencv_core_filename = "libopencv_core.so.2.4.6"
case $operatingsystem {
# Install OpenCV from source. This is an instructive example
# and may come in handy if we need to move to a version of
@asimihsan
asimihsan / _naughty.py
Last active December 20, 2015 00:19
Get a Python C extension to segfault
from cffi import FFI
def _make_divide():
libraries = ['c']
extra_compile_args = []
extra_link_args = []
ffi = FFI()
ffi.cdef(r"""
int divide(int a, int b);
@asimihsan
asimihsan / logging_test.py
Created August 20, 2013 14:04
First draft attempt at benchmarking logging vs. sys.stderr.write'ing. See: https://pypi.python.org/pypi/benchmark/
import logging
import sys
logger = logging.getLogger('simple_example')
logger.setLevel(logging.DEBUG)
ch = logging.StreamHandler()
ch.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
ch.setFormatter(formatter)
logger.addHandler(ch)
@asimihsan
asimihsan / r_tutorial.md
Last active November 10, 2019 18:00
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).
@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 / 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 / !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.