Skip to content

Instantly share code, notes, and snippets.

@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>
import codecs
import logging
import os
import os.path as P
from gensim.models import FastText
from gensim.models.callbacks import CallbackAny2Vec
class EpochSaver(CallbackAny2Vec):
'''Callback to save model after each epoch and show training parameters '''
@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:
"""Check whether each line contains tab-separated decodable JSON."""
import sys
import json
import logging
logging.basicConfig(level=logging.ERROR)
for i, line in enumerate(sys.stdin, 1):
try:
#!/usr/bin/env python
#
# Check if a file contains a set of chars
#
import argparse
import logging
import sys
import time
import collections
import unittest
@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 / main.py
Created January 19, 2016 05:16
dispatch.py
#
@mpenkov
mpenkov / fiddle.html
Last active January 1, 2016 10:39
Coding for Interviews: Bit Manipulation
<body>
<p>Decimal: <input type="text" id="txtDecimal" value="5"><input type="submit" id="btnGoDecimal" value="Go"></p>
<p>Binary (MSB first): <input type="text" id="txtBinary" value="101"><input type="submit" id="btnGoBinary" value="Go"></p>
<p>
Bit position (LSB is zero): <input type="number" id="numBit" value="0" min="0" max="128"><input type="submit" id="btnGet" value="Get">
<input type="submit" id="btnSet0" value="Set to 0"><input type="submit" id="btnSet1" value="Set to 1">
</p>
<p id="pResult"></p>
</body>
@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: