Skip to content

Instantly share code, notes, and snippets.

View fdb's full-sized avatar

Frederik De Bleser fdb

View GitHub Profile
@fdb
fdb / escape_html.py
Created June 9, 2009 16:11
Escape all the tags from the HTML string, leaving only the allowed tags. Also, convert links in the text to <a> tags.
import re
import urllib
import string
import cgi
import hashlib
word_split_re = re.compile(r'(\s+)')
LEADING_PUNCTUATION = ['(', '<', '&lt;']
TRAILING_PUNCTUATION = ['.', ',', ')', '>', '\n', '&gt;']
@fdb
fdb / MainPanel.java
Created June 12, 2009 10:51
Examining Swing's container events.
package events;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ContainerEvent;
import java.awt.event.ContainerListener;
/**
@fdb
fdb / java-text-rendering-bug
Created August 11, 2009 11:52
Demonstrates a text rendering bug on the OS X Java implementation.
import javax.swing.*;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import java.awt.*;
import java.awt.font.FontRenderContext;
import java.awt.font.LineBreakMeasurer;
import java.awt.font.TextAttribute;
import java.awt.font.TextLayout;
import java.awt.geom.AffineTransform;
import java.text.AttributedString;
import gc
import weakref
_destroyed = False
_superDestroyed = False
class MyClass(object):
'''A simple class that sets a global variable when it is destroyed.
@fdb
fdb / terrain.py
Created April 22, 2011 10:02
Perlin noise terrain engine in Pyglet/OpenGL
# Terrain generation based on noise.
# The terrain is a simple line grid.
# Noise generation using Casey Duncan's noise library:
# http://pypi.python.org/pypi/noise/1.0b1
# Use WASD to move through the scene
# Use Q and E to move up/down
# Use the mouse to look in the view
# Use the arrow keys to offset the noise grid
@fdb
fdb / simple-bitmap-image.clj
Created July 5, 2012 21:12
Writing a bitmap image in Clojure
; This example shows how to write a bitmap image using Clojure
; Import the necessary classes.
(import 'java.awt.image.BufferedImage 'javax.imageio.ImageIO 'java.awt.Color 'java.io.File)
; Create a new image with a 100x100 size. The image is going to have four color channels.
(def img (BufferedImage. 100 100 BufferedImage/TYPE_INT_ARGB))
; Draw on the image by getting the graphics object and invoking methods on it.
(doto (.getGraphics img)
@fdb
fdb / Command.java
Created September 19, 2012 08:00
Solving the expression problem in Java using maps.
package sandbox;
public interface Command {
}
@fdb
fdb / commands.clj
Created September 19, 2012 08:09
Solving the expression problem in Clojure using maps.
(defn move-formatter [command]
(format "<MoveCommand %s,%s>" (:x command) (:y command)))
(defn stop-formatter [command]
"<StopCommand>")
(defn default-formatter [command]
(format "<Unknown command %s>" command))
(use 'overtone.live)
(def rkick-id (int (rand 10000)))
(def rsnare-id (int (rand 10000)))
(println "Kick id " rkick-id)
(println "Snare id " rsnare-id)
(def rkick (sample (freesound-path rkick-id)))
(def rsnare (sample (freesound-path rsnare-id)))
(def metro (metronome 80))
(defn player [beat]
(at (metro beat) (rkick))
@fdb
fdb / index.html
Created August 24, 2014 12:26
watchify case mismatch proof-of-concept
<!DOCTYPE html>
<html>
<head>
<script src="bundle.js"></script>
</head>
<body>
</body>
</html>