Skip to content

Instantly share code, notes, and snippets.

View pfmiles's full-sized avatar
🚀
Busy...may not respond.

pf_miles pfmiles

🚀
Busy...may not respond.
View GitHub Profile
@pfmiles
pfmiles / IterableLexer.java
Created June 22, 2011 10:53
Hand write java Iterable lexer code skeleton
/**
* This is a skeleton code to implement a iterable lexer. Which is able to be processed in a convenient
* for-each loop...
*/
public class ActionLexer implements Iterable<ActionToken> {
private Reader reader;
// 19 status total
private static final int[] stats = new int[19];
@pfmiles
pfmiles / LLStarParser.java
Created June 22, 2011 11:35
Code skeleton for hand write LL parser, with arbitrary lookahead buffer.
/**
*
* This is the code skeleton for arbitrary-lookahead LL parser. Look ahead tokens are cached.
*
*/
public class ActionParser {
private ActionLexer lexer;
// buffered tokens that were look-ahead
private List<ActionToken> aheadBuffer = new ArrayList<ActionToken>();
@pfmiles
pfmiles / jqueryReadonlySelects.js
Created December 12, 2011 06:56
jquery readonly/enabling selects
// hidden inputs created have the same name as the disabled select, so the select must have its 'name' attr
function readOnlySelect(sel) {
if (typeof $(sel).next('input[type=hidden]').attr('name') == 'undefined'
|| $(sel).next('input[type=hidden]').attr('name') != $(sel).attr(
'name')) {
$(sel).after([ '<input type="hidden" name="', $(sel).attr('name'),
'" value="', $(sel).val(), '" />' ].join(''));
}
$(sel).attr('disabled', true);
@pfmiles
pfmiles / ComparingNode.java
Created December 27, 2011 05:18
Flexible visitor interface for AST walking...
public class ComparingNode implements DataFilterNode {
public <P, R> R accept(DataFilterVisitor<P, R> visitor, P param) {
return visitor.visitComparingNode(this, param);
}
}
@pfmiles
pfmiles / lexer.py
Created January 19, 2012 05:57
Python iterable lexer using regexp, code skeleton...
import re
class TokenType(object):
QUANTIFIER, ESCAPE_CHAR, UNICODE_CHAR, LEFT_PAREN, RIGHT_PAREN, OR, ALPHA, DIGIT, DOT, LEFT_BRACKET, NOT_IN, RIGHT_BRACKET, DASH, DERIVES, UNDER_SCORE, EOF, WHITE_SPACE = range(17)
def lexer(code):
"""
The lexical analysis function for itself's lexical rules. This lexer is 'iterable',
thus you can traverse all the tokens in the for..in statement til the EOF token reached.
"""
@pfmiles
pfmiles / astar.py
Created February 19, 2012 13:51
A* algorithm skeleton
def aStarSearch(problem, heuristic=nullHeuristic):
from sets import Set
visited = Set()
start = problem.getStartState()
from util import PriorityQueue
frontLine = PriorityQueue()
startPri = 0 + heuristic(start, problem)
frontLine.push((start, [], 0), startPri)
while not frontLine.isEmpty():
(point, actions, cost) = frontLine.pop()
@pfmiles
pfmiles / MonteCarloLocalization.py
Created February 26, 2012 13:39
The code skeleton for markov localization of robotic car
# the 'map'
colors = [['red', 'green', 'green', 'red' , 'red'],
['red', 'red', 'green', 'red', 'red'],
['red', 'red', 'green', 'green', 'red'],
['red', 'red', 'red', 'red', 'red']]
# the results of sensor
measurements = ['green', 'green', 'green' ,'green', 'green']
# motions
@pfmiles
pfmiles / tag_cloud.rb
Created March 14, 2012 11:57
modified tag_cloud.rb for use with utf-8 encoded blogs.
# Tag Cloud for Octopress, modified by pf_miles, for use with utf-8 encoded blogs(all regexp added 'u' option).
# =======================
#
# Description:
# ------------
# Easy output tag cloud and category list.
#
# Syntax:
# -------
# {% tag_cloud [counter:true] %}
@pfmiles
pfmiles / Test.java
Created August 4, 2012 12:04
Dummy example of dropincc.java
package test;
import com.github.pfmiles.dropincc.Action;
import com.github.pfmiles.dropincc.CC;
import com.github.pfmiles.dropincc.Exe;
import com.github.pfmiles.dropincc.Grule;
import com.github.pfmiles.dropincc.Lang;
import com.github.pfmiles.dropincc.TokenDef;
public class Test {
@pfmiles
pfmiles / Calculator.java
Created August 13, 2012 11:10
Code for a full-featured calculator in dropincc.java
import com.github.pfmiles.dropincc.Action;
import com.github.pfmiles.dropincc.CC;
import com.github.pfmiles.dropincc.Exe;
import com.github.pfmiles.dropincc.Grule;
import com.github.pfmiles.dropincc.Lang;
import com.github.pfmiles.dropincc.TokenDef;
public class Calculator {
private static Exe exe = null;
/**