Skip to content

Instantly share code, notes, and snippets.

@lamchau
lamchau / random-sha1.js
Created January 29, 2014 15:05
random sha1 string generator for testing
function sha1() {
function random() {
var characters = "abcdef0123456789";
return (function () {
var index = Math.floor(Math.random() * characters.length);
return characters.charAt(index);
})();
}
var MAX_LENGTH = 40;
@lamchau
lamchau / shuffle.js
Created January 29, 2014 15:19
Fisher-Yates Shuffle
function shuffle(array) {
var counter = array.length - 1;
var tmp;
var index;
for (; counter > 0; counter--) {
index = Math.floor(Math.random() * counter);
tmp = array[counter];
array[counter] = array[index];
array[index] = tmp;
}
@lamchau
lamchau / example.py
Created March 3, 2014 04:40
simple interview questions with unittests (pyunit)
#/usr/bin/python env
import abc
import unittest
class StringUtilities(object):
@staticmethod
def is_palindrome(s):
if not isinstance(s, str):
from datetime import datetime
import csv
import math
import sys
import time
class Record(object):
EARTH_RADIUS_IN_KM = 6371
function min(array) {
if (Array.isArray(array)) {
return Math.min.apply(null, array.filter(isFinite));
}
throw {
name: "Illegal argument",
message: "Argument must be an array"
}
}
"""
Copyright (c) 2012 Anthony Wu, twitter.com/anthonywu
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
int main() {
// create alphabet (lowercase)
char letters[26];
for (int i = 0; i < 26; i++) {
letters[i] = 'a' + i;
@lamchau
lamchau / random-extract.py
Last active August 29, 2015 14:01
Random extraction of zipfile contents
#!/usr/bin/env python
import os
import random
import zipfile
def is_zipfile(f):
return os.path.isfile(f) and os.path.splitext(f)[1].lower() == ".zip"
@lamchau
lamchau / phonetic-alphabet.md
Last active August 29, 2015 14:02
Phonetic Alphabet Tables

NATO

Letter Phonetic letter
A Alpha
B Bravo
C Charlie
D Delta
E Echo
F Foxtrot
G Golf
package com.lchau;
public class Permutations {
public static void main(String[] args) {
String str = "Hello, world";
Permutations.permute(0, str.length() - 1, str.toCharArray());
}
private static boolean match(int i, int j, char[] chars) {