Skip to content

Instantly share code, notes, and snippets.

@mpenkov
mpenkov / jquery-1.10.2.min.js
Last active December 30, 2015 02:59
Coding for Interviews: N Queens
/*! jQuery v1.10.2 | (c) 2005, 2013 jQuery Foundation, Inc. | jquery.org/license
//@ sourceMappingURL=jquery-1.10.2.min.map
*/
(function(e,t){var n,r,i=typeof t,o=e.location,a=e.document,s=a.documentElement,l=e.jQuery,u=e.$,c={},p=[],f="1.10.2",d=p.concat,h=p.push,g=p.slice,m=p.indexOf,y=c.toString,v=c.hasOwnProperty,b=f.trim,x=function(e,t){return new x.fn.init(e,t,r)},w=/[+-]?(?:\d*\.|)\d+(?:[eE][+-]?\d+|)/.source,T=/\S+/g,C=/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,N=/^(?:\s*(<[\w\W]+>)[^>]*|#([\w-]*))$/,k=/^<(\w+)\s*\/?>(?:<\/\1>|)$/,E=/^[\],:{}\s]*$/,S=/(?:^|:|,)(?:\s*\[)+/g,A=/\\(?:["\\\/bfnrt]|u[\da-fA-F]{4})/g,j=/"[^"\\\r\n]*"|true|false|null|-?(?:\d+\.|)\d+(?:[eE][+-]?\d+|)/g,D=/^-ms-/,L=/-([\da-z])/gi,H=function(e,t){return t.toUpperCase()},q=function(e){(a.addEventListener||"load"===e.type||"complete"===a.readyState)&&(_(),x.ready())},_=function(){a.addEventListener?(a.removeEventListener("DOMContentLoaded",q,!1),e.removeEventListener("load",q,!1)):(a.detachEvent("onreadystatechange",q),e.detachEvent("o
@mpenkov
mpenkov / bfs.py
Last active December 28, 2015 07:09
Coding for Interview: Level Order Tree Print
def bfs(root):
nodes = [(0,root)]
prev_level = 0
while nodes:
level, node = nodes.pop(0)
if level > prev_level:
print
print node.value,
prev_level = level
for c in node.children:
@mpenkov
mpenkov / spiral.py
Last active December 27, 2015 08:49
Coding for Interviews: Outward Counterclockwise Spiral Matrix Traversal
UP = (-1, 0)
LEFT = ( 0, -1)
DOWN = ( 1, 0)
RIGHT = ( 0, 1)
class Turtle:
"""The turtle crawls over the matrix starting at some position.
The turtle knows how to turn left and go forward."""
def __init__(self, nrows, ncols, x, y):
self.x = x
@mpenkov
mpenkov / mcs.html
Last active October 14, 2019 19:57
Coding for Interviews: Max Consecutive Sum
<html>
<head>
<title>Max Consecutive Sum</title>
</head>
<body>
Enter some integers:
<input type="text" id="txtInput" value="-1 5 6 -2 20 -50 4"></input>
<button onClick="btnOnClick();">Calculate</button>
<p>
Max consecutive sum is: <span id="divResult"></span>
@mpenkov
mpenkov / google_asr.sh
Last active February 17, 2016 02:35
Automatic Speech Recognition with Google ASR
#!/bin/sh
#
# Adapted from: http://sunilkumarkopparapu.wordpress.com/2012/09/11/using-google-asr/
#
LANGUAGE="en-US"
echo "1 SoX Sound Exchange -- Convert $1.wav to $1.flacC with 16000"
sox $1.wav $1.flac rate 16k
echo "2 Submit to Google Voice Recognition $1.flac"
wget -q -U "Mozilla/5.0" --no-proxy --post-file $1.flac --header="Content-Type: audio/x-flac; rate=16000" -O $1.ret "http://www.google.com/speech-api/v1/recognize?lang=${LANGUAGE}&client=chromium"
echo "3 SED Extract recognized text"
@mpenkov
mpenkov / reverse_words.c
Last active December 16, 2015 05:39
Coding for Interviews: Reverse Words
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <assert.h>
#define SPACE ' '
void
reverse_words(char *sent, size_t len)
{
@mpenkov
mpenkov / Makefile
Last active April 9, 2018 12:56
Quicksort in C
CFLAGS=-ggdb -Wall
all: quicksort.out
# $< the dependencies
# $@ the target
quicksort.out: quicksort.o
gcc -Wall -ggdb $< -o $@
clean:
@mpenkov
mpenkov / oku.py
Created March 16, 2013 08:35
Currency conversion from Japanese units into metric
if __name__ == "__main__":
pass
@mpenkov
mpenkov / binsearch.html
Last active December 14, 2015 04:19
Coding Interview Practice: the Singleton pattern
<html>
<head>
<title>Binary search</title>
</head>
<body>
Enter a space-separated list of integers in increasing order:<br/>
<input id="txtArray" type="text" size="80" value="0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25"><br/>
Enter an integer to search for:
<input id="txtKey" type="text" size="4" value="22"><br/>
<input type="button" value="Initialize" onclick="onSearch();">
@mpenkov
mpenkov / nightly_backup.py
Last active December 13, 2015 22:19
cp with regular expression
"""Behaves pretty much like cp -Pruv , except supports skipping directories.
Copy one directory to another recursively. If any subdirectories match a
specified regular expression pattern, they are not copied.
Also, directories containing a file called .nobackup are not backup up.
"""
import os
import os.path as P
import re