Skip to content

Instantly share code, notes, and snippets.

void DWT::transform1d(float *src, int length, int step)
{
float *tmp = new float[length];
float W = 1/sqrt(2.0f);
for (int len = length/2; len >= PREVIEW; len /= 2) {
for (int i = 0; i < len; i++) {
float c = src[i*2*step];
float w = src[(i*2+1)*step];
tmp[i] = (c+w)*W;
tmp[i+len] = (c-w)*W;
/**
* Builds a new sudoku instance given a difficulty level
*
* @param level describes the difficulty level of the generated game
* - 1 normal
* - 2 medium
* - 3 hard
*/
def makeSudoku(level: Int): Sudoku = {
var board = new Array[Array[Int]](9, 9)
using System;
namespace Stack
{
public class StackEmpty : Exception { }
public class Stack
{
private object[] arr;
using System;
using System.Diagnostics.Contracts;
namespace Stack
{
public class StackEmpty : Exception { }
public class Stack
{
private object[] arr;
@hoheinzollern
hoheinzollern / sample_contracts.py
Created November 13, 2010 02:16
This is what the result should be
@invariant(lambda self: self.value >= 0)
class PositiveInt(object):
@post(lambda self: self.num_changes == 0 and self.value == 0)
def __init__(self):
self.value = 0
self.num_changes = 0
@post(lambda new, old: new.num_changes == old.num_changes + 1)
def add(self, x):
self.value += x
@hoheinzollern
hoheinzollern / zipper.scala
Created June 1, 2011 01:25
Zipper scala implementation
sealed abstract class Tree[A]
case class Item[A] (item: A) extends Tree[A]
case class Section[A] (s: List[Tree[A]]) extends Tree[A]
sealed abstract class Path[A]
case class Top[A] extends Path[A]
case class Node[A] (l: List[Tree[A]], p: Path[A], r: List[Tree[A]]) extends Path[A]
case class Location[A] (t: Tree[A], p: Path[A])
#include "hg_adv.h"
#define ADV_DEBUG 0
VgHashTable write_buffers_8;
VgHashTable write_buffers_16;
VgHashTable write_buffers_32;
VgHashTable write_buffers_64;
typedef struct _AddrWBNode {
@hoheinzollern
hoheinzollern / admin.py
Created October 4, 2011 07:25
Reordering of tabular inlines in Django administration website.
from django.contrib import admin
class SlaveInline(admin.TabularInline):
model = Slave
extra = 0
class MasterAdmin(admin.ModelAdmin):
inlines = (SlaveInline,)
class Media:
%% instance
place(1).
place(2).
place(3).
place(4).
transition(1).
transition(2).
t_pre(1,1).
t_post(1,2).
from copy import deepcopy
from pprint import pprint
board = [
[-1,-1, 1, 1, 1,-1,-1],
[-1,-1, 1, 1, 1,-1,-1],
[ 1, 1, 1, 1, 1, 1, 1],
[ 1, 1, 1, 0, 1, 1, 1],
[ 1, 1, 1, 1, 1, 1, 1],
[-1,-1, 1, 1, 1,-1,-1],