Skip to content

Instantly share code, notes, and snippets.

@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 / rcc.py
Last active December 19, 2015 14:17
#
# reddit comment cleaner
# Delete my comments from a particular subreddit
#
import argparse
import getpass
import praw
import logging
logging.basicConfig(level=logging.DEBUG)
@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 / 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
@mpenkov
mpenkov / hanoi.html
Last active December 12, 2015 06:28
Coding Interview Practice: Stacks
<!--
vim: shiftwidth=2
-->
<html>
<head>
<title>Tower of Hanoi</title>
</head>
<body>
<script src="hanoi.js"></script>
Number of disks:
@mpenkov
mpenkov / clobber.html
Last active December 12, 2015 05:19
Character encoding
<!--
vim: shiftwidth=2
-->
<html>
<head><title>Clobber</title></head>
<body>
<form>
<textarea id="textArea" readonly="true" rows="10" cols="70"></textarea><br/>
<input id="inputText" type="text" text="Enter some text here" size="50" value="Enter some Unicode here...">
<input id="checkbox" type="checkbox">clobber the submitted text</input>
@mpenkov
mpenkov / trie.py
Last active December 11, 2015 22:49
Coding Interview Practice: Tries
import sys
#
# Lessons learned:
#
# - must override object class to get __sizeof__ to work
#
class TrieNode(object):
def __init__(self, leaf):
@mpenkov
mpenkov / traversal.cpp
Last active December 11, 2015 03:09
Coding Interview Practice: Tree Traversals
#include <map>
#include <set>
#include <algorithm>
#include <iostream>
using namespace std;
//
// Lessons learned:
//