Skip to content

Instantly share code, notes, and snippets.

@rsirres
rsirres / levensthein.nim
Created November 23, 2018 21:31
Implementation of levensthein automata in nimlang
# http://julesjacobs.github.io/2015/06/17/disqus-levenshtein-simple-and-fast.html
import sugar
import sequtils
import tables
import strutils
import hashes
type
SparseLevenshteinAutomaton = object
@rsirres
rsirres / test_requests.py
Created August 31, 2018 09:20
Test Requests
import requests
URL = "https://www.doabooks.org/oai?verb=ListRecords&from=2012-01-01&metadataPrefix=marcxml"
#URL = "https://publishing.cdlib.org/ucpressebooks/oai?verb=ListRecords&set=public&metadataPrefix=oai_dc"
#headers = {'Host': 'www.doabooks.org:443'}
r = requests.get(URL, verify=True)
print( r.text )
@rsirres
rsirres / output.txt
Created January 7, 2018 16:22
Python3 XML subdocument incremental processing
{'country.rank': ['1'], 'country.year': ['2008'], 'country.gdppc': ['141100'], 'country.neighbor.@name': ['Austria', 'Switzerland'], 'country.neighbor.@direction': ['E', 'W'], 'country.@name': ['Liechtenstein']}
{'country.rank': ['4'], 'country.year': ['2011'], 'country.gdppc': ['59900'], 'country.neighbor.@name': ['Malaysia'], 'country.neighbor.@direction': ['N'], 'country.@name': ['Singapore']}
{'country.rank': ['68'], 'country.year': ['2011'], 'country.gdppc': ['13600'], 'country.neighbor.@name': ['Costa Rica', 'Colombia'], 'country.neighbor.@direction': ['W', 'E'], 'country.@name': ['Panama']}
@rsirres
rsirres / sample4.xml
Created January 7, 2018 15:44
Python3 Script (without dependencies) to parse XML File incrementally and transform it to key-value pairs
<?xml version="1.0"?>
<data>
<country name="Liechtenstein">
<rank>1</rank>
<year>2008</year>
<gdppc>141100</gdppc>
<neighbor name="Austria" direction="E"/>
<neighbor name="Switzerland" direction="W"/>
</country>
<country name="Singapore">
@rsirres
rsirres / await_example.nim
Created March 24, 2017 21:38
Nimlang Nim await example
import os, asyncnet, asyncdispatch
proc callback1(): Future[int] =
var retFuture = newFuture[int]("callback1")
echo "Callback1: Waiting"
sleep(3000)
retFuture.complete(10)
return retFuture
@rsirres
rsirres / posture.py
Created January 13, 2015 12:47
ROS & NAO: Speech Recognition, Marker tracking(ar_pose), Follow Commands
# -*- coding: utf-8 -*-
# Author : Sirres Raphael
# Date: 16.12.2014
# Description: Basic Posture Class
from naoqi import ALProxy
class NaoPosture:
def __init__(self, IP, PORT=9559):
self.postureProxy = ALProxy("ALRobotPosture", IP, PORT)
self.speed=0.7
# -*- coding: utf-8 -*-
# Author : Sirres Raphael
# Date: 16.12.2014
# Description: Launch Server which serves a web page that performs the text recognition with the Web Speech API (Google Chrome).
# Recognized text is send to the server which on the other hand fowards the command to the NAO.
#
# How to use:  0. (Install pip: easy_install pip) Dont need this if pip is already installed  
# 0. (Install bottle: pip install bottle)
# 1. Adapt the IP address in the main function.
# 2. Run the following command: python speech.py