Skip to content

Instantly share code, notes, and snippets.

View erikbgithub's full-sized avatar

Erik Bernoth erikbgithub

View GitHub Profile
import re
sep = re.compile(r"[^ |]+")
# a possible string that might be delivered by one of my collegues over http
test_text = "q1w2e3r4t5z|11°11.111'N 22°22.222'W"
def parse_all(text, dispatcher):
"""
parses over a given text using a dispatch table. the logic itself is in the dispatch table.
#! /bin/tcsh -f
set i=1
while { i <= $#argv }
@ i = $i + 1
if ( -d $argv[$i] ) then
rm -R $argv[$i]
else
echo Das $i. Argument ist kein Verzeichnis.
endif
/**
* the normally used way to add different types in a function
*
* @param $nr1 - the first summand
* @param $nr2 - the second summand
* @param $type - the number type. default='decimal'
*/
function add_classical($nr1, $nr2, $type='decimal'){
$sum = NULL;
switch($type){
function add_classical($nr1, $nr2, $type='decimal'){
$sum = NULL;
switch($type){
case 'decimal':
$sum = (int)$nr1 + (int)$nr2;
case 'binary':
$sum = bindec($nr1) + bindec($nr2);
}
return $sum;
}
<?php
$res = mysql_pconnect("localhost","root","root");
mysql_query("DROP Database 'ddpadd'",$res);
echo ":\n<br>create:".mysql_query("CREATE DATABASE IF NOT EXISTS ddpadd", $res);
echo ":\n<br>select:".mysql_select_db("ddpadd", $res);
echo mysql_query("DROP TABLE IF EXISTS decimal");
echo ":\n<br>table:".mysql_query("CREATE TABLE decimal_add (
no1 TINYINT(1),
no2 TINYINT(1),
>>> parse_gramar('[HANZI],[PINYIN],[ENGL]#NEWLINE#')
{
'text': '[HANZI],[PINYIN],[ENGL]#NEWLINE#',
'type': 'Gramar',
'children': [
{
'text': 'HANZI',
'type': 'Variable',
'children': []
},
>>> parse_input(input, gramar)
{
'text': '\xe4\xbd\xa0\xe5\xa5\xbd,ni3hao3,hello\n\xe8\xb0\xa2\xe8\xb0\xa2,xie4xie0,thanks\n\xe5\xaf\xb9\xe4\xb8\x8d\xe8\xb5\xb7,dui4bu0qi3,sorry',
'type': 'InputText',
'children': [
{
'text': '\xe4\xbd\xa0\xe5\xa5\xbd,ni3hao3,hello\n',
'type': 'TextBlock',
'children': [
{'text': '\xe4\xbd\xa0\xe5\xa5\xbd', 'type': 'A', 'children': []},
import warnings
STATE_CLEAR = 1
STATE_VAR = 2
STATE_SPECIAL = 3
VAR_ALLOWED_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
# special chars make it more usable for non programmers, who probably never heard about \n and so on
# more can and will be added later on
special_char_map = {'NEWLINE' : '\n'}
class Hausaufgabe {
public static int anzahl(String vieleZeichen, String b) {
if((vieleZeichen == null) || (vieleZeichen.isEqual("")) return 0;
String w = vieleZeichen.subString(0,vieleZeichen.length()-2);
String a = "" + vieleZeichen.getChar(vieleZeichen.length()-1);
if(a.isEqual(b)) return anzahl(w, b)+1;
if(!a.isEqual(b)) return anzahl(w,b);
}
}
#Words
<Inner_Block> ::= <Block_Start><Block><Block_End>
<Block>* ::= <Expression>(<Exp_Sep><Expression>)*
<Expression> ::= <Sum>|<Assignment>
<Assignment> ::= <Name><Assign_Op><Inner_Block>
<Sum> ::= <Difference>(<Add_Op><Difference>)*
<Difference> ::= <Product>(<Sub_Op><Product>)*
<Product> ::= <Quotient>(<Mul_Op><Quotient>)*
<Quotient> ::= <Term>(<Div_Op><Term>)*
<Term> ::= <Number>|<Call>|<Inner_Block>