Skip to content

Instantly share code, notes, and snippets.

@rik0
rik0 / LICENSE
Created August 25, 2011 18:46
Monadic Eratosthenes Sieve
Copyright (c)2011, Enrico Franchi
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright
notice, this list of conditions and the following disclaimer.
@rik0
rik0 / AddNumbers.s
Created July 23, 2011 10:33
Horrible Code Generation from Real Basic
_AtkinSieve.AddNumbers%i4%o<AtkinSieve>i4i4:
0007f688 pushl %ebp
0007f689 movl %esp,%ebp
0007f68b subl $0x00000038,%esp
0007f691 movl %esp,0xffffffcc(%ebp)
0007f697 movl %ebp,%eax
0007f699 movl 0x08(%eax),%eax
0007f69c movl %eax,0xf8(%ebp)
0007f69f movl %ebp,%eax
0007f6a1 movl 0x0c(%eax),%eax
@rik0
rik0 / AtkinSieveArray.java
Created July 22, 2011 11:16
Lots of Atkin and some Erat
import java.lang.Boolean;
import java.lang.Integer;
public class AtkinSieveArray {
static private int count(boolean[] buffer) {
int counter = 0;
for(int i = 2; i < buffer.length; ++i) {
if(buffer[i]) {
counter++;
@rik0
rik0 / atkin_f.py
Created July 22, 2011 11:16
Python Atkin
def atkin(buffer, end):
limit = int(math.ceil(math.sqrt(end)))
for x in range(1, limit + 1):
x2 = x * x
x2_3 = 3 * x2
for y in range(1, limit + 1):
y2 = y * y
@rik0
rik0 / adjacency_list.py
Created June 6, 2011 10:21
Snippets on graph & network theory
class AdjacencyListGraph(object):
def __init__(self):
self.node = {}
self.adj = {}
def add_node(self, node, **attrs):
if node not in self.adj:
self.adj[node] = {}
self.node[node] = attrs
(ns gui-sample
(:import [javax.swing JFrame JButton]
[java.awt.event ActionListener]))
(defn build-gui [title message]
(let [frame (JFrame. title)
button (JButton. "CLICK")]
(.addActionListener button
(proxy [ActionListener] []
(actionPerformed [evt]
(ns example.ClassExample
(:gen-class
:name example.ClassExample
:extends Object
:implements []
:methods [[foo [java.util.Collection] int]
^{:static true} [show [java.util.Collection] void]])
(:import (java.util Collection)))
(defn -foo [this coll]
@rik0
rik0 / badmo.py
Created April 20, 2011 16:03 — forked from rubik/badmo.py
import re
import os
import ast
import glob
import collections
class ImportVisitor(ast.NodeVisitor):
def __init__(self):
self.imports = []
self.modules = collections.defaultdict(list)
@rik0
rik0 / password_guess.py
Created April 17, 2011 13:51
Cleanly separated elementary "guess password" game. Shows extreme separation of concerns and an enhanced generator (coroutines) based solution. The whole structure is as stateless as possible, even when objects are used. Easy stuff made hard. ;)
import sys
class TextualUI(object):
def __init__(self, out=sys.stdout):
self.out = out
def inform_defeat(self, _max_attempts):
message = 'You lost.\n'
self.out.write(message)
(defproject AgentNetSym "1.0.0-SNAPSHOT"
:description "FIXME: write"
:dependencies [[org.clojure/clojure "1.2.0"]
[org.clojure/clojure-contrib "1.2.0"]
[net.sourceforge.collections/collections-generic "4.01"]
[com.cedarsoft.serialization/stax "2.1.0"]
[java3d/vecmath "1.3.1"]
[org.codehaus.woodstox/wstx-asl "3.2.9"]
[colt/colt "1.2.0"]