Skip to content

Instantly share code, notes, and snippets.

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:
@lamchau
lamchau / FileContentAnalyzer.java
Last active September 15, 2016 07:36
Write a function that takes two parameters: (1) a String representing a text document and (2) an integer providing the number of items to return. Implement the function such that it returns a list of Strings ordered by word frequency, the most frequently occurring word first. Use your best judgement to decide how words are separated. Your soluti…
package com.evernote;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.PriorityQueue;
import java.util.Queue;
#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) {
@lamchau
lamchau / index.html
Created August 29, 2014 20:23
D3.js: Barebones crosshair
<!DOCTYPE html>
<html xmlns:xlink="http://www.w3.org/1999/xlink">
<head>
<title>D3: Crosshair</title>
<style type="text/css">
svg {
font: 11px sans-serif;
}
.line .crosshair {

Example of a D3js time series graph with X,Y crosshairs and a threshold line. Just copy the drawLineGraph function and call it with your data. The data shoud be an array of two element arrays. Something like:

var data = [
    [new Date(2014, 01, 10), 404],
    [new Date(2014, 01, 11), 123],
    [new Date(2014, 01, 12), 666]
    ];
    
var warnLine = { lineValue: 200, label: 'my important threshold' };
// https://raw.githubusercontent.com/eligrey/FileSaver.js/master/FileSaver.js
/* FileSaver.js
* A saveAs() FileSaver implementation.
* 2014-08-29
*
* By Eli Grey, http://eligrey.com
* License: X11/MIT
* See https://github.com/eligrey/FileSaver.js/blob/master/LICENSE.md
*/