Skip to content

Instantly share code, notes, and snippets.

View mattbasta's full-sized avatar
🌭
Still writing JavaScript

Matt Basta mattbasta

🌭
Still writing JavaScript
View GitHub Profile
@mattbasta
mattbasta / codegen.py
Created January 22, 2011 18:16
A module to "unparse" a Python AST tree.
# -*- coding: utf-8 -*-
"""
codegen
~~~~~~~
Extension to ast that allow ast -> python code generation.
:copyright: Copyright 2008 by Armin Ronacher.
:license: BSD.
"""
@mattbasta
mattbasta / tilegame.cpp
Created April 20, 2011 01:50
tilegame.cpp
#include <cstdlib>
#include <iostream>
#include <cmath>
using namespace std;
int checkCompletion(int pos[3][3]);
int dist(int num, int x, int y);
int bestTile(int tiles[3][3], int & x, int & y);
void printBoard(int tiles[3][3]);
@mattbasta
mattbasta / tilegame.py
Last active September 25, 2015 13:38
A python version of the tile game solver
def completion(board):
"Returns a score of how far the board is from completion"
total = 0
for pos in range(9):
i, j = pos // 3, pos % 3
val = board[i][j] - 1
if val < 0: continue
v1, v2 = val % 3 - j, val / 3 - i
total += (v1 if v1 > 0 else -1 * v1) + (v2 if v2 > 0 else -1 * v2)
return total
@mattbasta
mattbasta / dvd.vb
Created April 28, 2011 01:24
DVD selection
Public Class frmDvd
Private myParent As frmMain
Private Sub frmCustomer_Activated(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Activated
Dim idx As Integer
Dim panel As ToolStripStatusLabel
idx = myParent.searchForPanel("DVDs")
If idx <> -1 Then
@mattbasta
mattbasta / quantum_computer.py
Created July 12, 2011 18:21
Quantum Computer simulator
def quantumify(evaluator, answers):
quantum_value = evaluator()
if any(map(lambda a: a in quantum_value, answers)):
pass
return "BOTH"
@mattbasta
mattbasta / prefix.py
Created September 20, 2011 01:20
Prefix notation math interpreter.
def gen(data):
def g():
for token in data.split(" "):
yield token
return g().next
defs = {"+": lambda x, y: x + y,
"-": lambda x, y: x - y,
"*": lambda x, y: x * y,
var irc = require('irc');
var client = new irc.Client('irc.mozilla.org', 'hugbot', {
channels: ['#amo', '#webdev', '#interns'],
});
huggable = {};
hugdelay = {};
function contains(message, list) {
for(var i=0;i<list.length;i++) {
@mattbasta
mattbasta / reducer.py
Created October 5, 2012 23:42
Validator Reducer
def reduce(a, b):
return "%s\n%s" % (a, b)
def log_gen(n):
import math
y = 1
while y < n:
adder = max(1, 10 ^^ int(math.log10(y)))
yield int(y)
y += adder
@mattbasta
mattbasta / simple_arg_parser.js
Last active December 12, 2015 08:08
Now with defaults
var argv = ['damper.js', '--host', '0.0.0.0', '--port', '8675'];
var opts = argv.slice(1);
function options(opts, defaults) {
var out = defaults || {}, last;
for(var i = 0; i < opts.length; i++) {
var is_flag = opts[i].substr(0, 1) === '-';
if (is_flag && last) {
out[last] = true;
} else if (!is_flag && last) {