Skip to content

Instantly share code, notes, and snippets.

View benui-dev's full-sized avatar
🌱

benui benui-dev

🌱
View GitHub Profile
@benui-dev
benui-dev / init.lua
Created July 8, 2012 00:20
Example of subclassing physics objects from Löve2d's Hardoncollider, using Class-Commons. Requires HardonCollider to work.
-- Add this line to the main hardoncollider/init.lua file around line 136
-- to allow you to add preconstructed shapes.
function HC:addExistingShape(shape)
return new_shape(self, shape)
end
@benui-dev
benui-dev / gist:2981095
Created June 24, 2012 02:15
Löve2d code for loading and drawing a tetured polygon
function love.load()
-- Load our repeating texture
local img = love.graphics.newImage("dirt.png")
-- Points for our polygon
local vertices = {12,0, 396,7, 500,375, 195,520, 78,377}
texturedPoly = newTexturedPoly(vertices, img)
end
@benui-dev
benui-dev / knp_file.pl
Created April 9, 2012 06:29
Reading KNP data from a file
# Iterate through pre-parsed KNP output stored in a file. Useful for processing a batch of
# sentences offline, and then dealing with them later.
use strict;
use warnings;
use KNP::File;
# File is the result of "juman | knp -tab > knp.out"
my $knp_file = new KNP::File( file => $ARGV[0], encoding => 'utf-8' )
or die "Couldn't make KNP from file $!";
from mwlib.refine import compat
raw = """
=Sup=
Je suis le voyageur dans le baked beans.
"""
parsed = compat.parse_txt(raw)
@benui-dev
benui-dev / parse_raw_wiki.py
Created February 1, 2012 01:57
Parse wiki markup with mwlib
from mwlib.refine import compat,core
from mwlib.parser import nodes
import pprint
def main():
pp = pprint.PrettyPrinter(indent=2)
raw = """
=Cake=
Modern cake, especially layer cakes, normally contain a
@benui-dev
benui-dev / dict.xml
Created January 25, 2012 06:57
Sample from JEdict
<entry>
<ent_seq>1000220</ent_seq>
<k_ele>
<keb>明白</keb>
<ke_pri>ichi1</ke_pri>
<ke_pri>news1</ke_pri>
<ke_pri>nf10</ke_pri>
</k_ele>
<r_ele>
<reb>めいはく</reb>
@benui-dev
benui-dev / edict.pl
Created January 25, 2012 06:55
Simple example of how to parse Edict XML file with Perl and XML::LibXML
#!/usr/local/bin/perl
use strict;
use warnings;
use XML::LibXML;
use encoding "utf-8";
my $file = $ARGV[0];
my $parser = XML::LibXML->new();
my $doc = $parser->parse_file($file);
@benui-dev
benui-dev / print_tree.py
Created January 20, 2012 00:38
Print the entire tree of a Wiki article using mwlib
# Print the entire tree of a Wiki article using mwlib
from mwlib import wiki
from mwlib.parser import nodes
def print_tree(node, indent):
tabs = indent * " "
print tabs + node.__class__.__name__
indent += 1
for child in node.children:
print_tree(child, indent)
from mwlib import wiki
from mwlib.parser import nodes
env = wiki.makewiki('/home/ben/wiki/simple/wikiconf.txt') # wiki Environment object
a = env.wiki.getParsedArticle('cheese')
for child in a.allchildren():
if isinstance(child, nodes.Section): # Yay global function
print "Section title: " + child.children[0].asText()
if isinstance(child, nodes.LangLink):
<?xml version="1.0"?>
<root>
<list>
<item>
<name>Magical stuff</name>
<identifier>private.magical</identifier>
<!-- Need this explicitly, otherwise the forward delete thing doesn't work -->
<autogen>
--KeyToKey--
KeyCode::SEMICOLON, ModifierFlag::NONE,