Skip to content

Instantly share code, notes, and snippets.

@aib
aib / sudoku.py
Created January 1, 2019 20:17
Sudoku CNF
import collections
import itertools as it
import subprocess
import sys
class Sudoku:
def __init__(self, size):
self.width = size*size
self.height = size*size
self._opts = size*size
import functools as ft
import itertools as it
import operator as op
def generate_factors(b, n, smallest_number=1):
if n == 1:
yield [b]
else:
for i in range(smallest_number, b // 2 + 1):
for s in generate_factors(b-i, n-1, i):
class Piped:
def __init__(self, fn, terminal=False):
self.fn = fn
self.terminal = terminal
self.args = []
self.gotval = False
self.val = None
def __call__(self, *args):
self.args = list(args)
@aib
aib / route
Last active February 13, 2018 16:26
Selective IP routing for those who live in interesting times
#!/bin/bash
update_gist() {
GITHUB_USERNAME=aib
GIST_ID=1881c25137724b47f916aec3e87028de
python -c "import json, sys; json.dump({ \"files\": { sys.argv[1]: { \"content\": sys.stdin.read() } } }, sys.stdout)" $(basename "$0") <"$0" | curl -f -s -H "Accept: application/vnd.github.v3+json" -H "Content-Type: application/json" -u "$GITHUB_USERNAME" -X PATCH "https://api.github.com/gists/$GIST_ID" -d@- >/dev/null
}
if [ -z "$1" ]; then
printf "Usage:\n" >&2
#!/usr/bin/env python
import math
import pygame
import random
import rtmidi
from rtmidi.midiconstants import *
import time
TAU = 2 * math.pi
@aib
aib / aibUtils.as
Created January 7, 2017 19:56
My old ActionScript Utility file
/*
* A static class with misc. utilities
*
* aib, 20071120
*/
package
{
import flash.display.DisplayObject;
import flash.display.Graphics;
@aib
aib / hmm.c
Created January 6, 2017 14:25
stagger test
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <time.h>
#define PROCS 10
int child(int n)
{
while (1) {
@aib
aib / aib.py
Last active November 30, 2016 16:38 — forked from doobeh/aib.py
add_url_rule
from flask import Flask, request, jsonify
app = Flask(__name__)
app.secret_key = 'aib'
def homer():
def home():
return 'Ok'
return home
--
-- Table structure for table "site_cities"
--
DROP TABLE IF EXISTS "site_cities" CASCADE;
CREATE TABLE "site_cities" (
"city_id" serial NOT NULL,
"city_name" varchar(20) NOT NULL,
"plate_code" smallint NOT NULL,
"area_code" smallint NOT NULL,
"lat" decimal(20,8) NOT NULL,
@aib
aib / gist:5b29531a1e083e8b57ae
Last active August 29, 2015 14:16
PythonChallenge
let a0 = 2^38
let a1 = "lost in my ghci history"
let a2 = simpleHTTP (getRequest "http://www.pythonchallenge.com/pc/def/ocr.html") >>= getResponseBody >>= return . filter isAlpha
let a3 = simpleHTTP (getRequest "http://www.pythonchallenge.com/pc/def/equality.html") >>= getResponseBody >>= return . concatMap (!!1) . ((=~ "[^A-Z][A-Z]{3}([a-z])[A-Z]{3}[^A-Z]") :: String -> [[String]])
let a4_a = let dorq x = simpleHTTP (getRequest ("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" ++ x)) >>= getResponseBody in iterateUntilM (\x -> Debug.Trace.trace (show x) (not (x =~ "next nothing is")::Bool)) (dorq . last . words) "next nothing is 12345"
let a4_b = let dorq x = simpleHTTP (getRequest ("http://www.pythonchallenge.com/pc/def/linkedlist.php?nothing=" ++ x)) >>= getResponseBody in iterateUntilM (\x -> Debug.Trace.trace (show x) (not (x =~ "next nothing is")::Bool)) (dorq . last . words) "next nothing is 8022"