Skip to content

Instantly share code, notes, and snippets.

View netdesign's full-sized avatar

Netdesign netdesign

View GitHub Profile
// La posizione del punto viene dichiarata con due variabili x ed y
int x = 100;
int y = 100;
void setup(){
size(640, 360);
}
void draw(){
background(0);
@netdesign
netdesign / gist:1457076
Created December 10, 2011 23:37
Esempio Uno
void setup(){
size(640, 360);
}
void draw(){
background(0);
point(100, 100); // La posizione del punto viene dichiarata all'interno della funzione point
}
$data = "http://feeds.feedburner.com/metroq?format=xml";
$ch = curl_init($data);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_POST, false);
$result = curl_exec($ch);
curl_close($ch);
$xmlRawDoc = $result;
$xmlDoc = new DOMDocument();
$xmlDoc->loadXML($xmlRawDoc);
@netdesign
netdesign / Traceback
Created October 7, 2011 10:53
What's the problem?
ERROR:root:Uncaught exception, closing connection.
Traceback (most recent call last):
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/iostream.py", line 301, in wrapper
callback(*args)
File "/usr/local/lib/python2.6/dist-packages/tornado-2.1.1-py2.6.egg/tornado/httpserver.py", line 248, in _on_headers
self.request_callback(self._request)
File "nauauProxy.faster.async.py", line 22, in handle_request
self.client.fetcher(req)
AttributeError: httpProxy instance has no attribute 'client'
ERROR:root:Exception in callback <tornado.stack_context._StackContextWrapper object at 0x1a6fd60>
#Async Version with AsyncHTTPClient as url fetcher
from tornado import httpserver, ioloop
from tornado.httpclient import AsyncHTTPClient, HTTPClient
class httpProxy():
def __init__(self, iolp):
self.myserv = httpserver.HTTPServer(self.handle_request)
self.myserv.listen(8080)
self.httpclient = AsyncHTTPClient()
@netdesign
netdesign / gist:1248689
Created September 28, 2011 18:01
text stats
text = TokenizedText
def textStats(text):
length = 0
punctuation = 0
smallWordsCount = 0
for word in text:
if(word == "," or word == "." or word == ";" or word == ":"):
punctuation += 1
else:
@netdesign
netdesign / gist:1245606
Created September 27, 2011 16:57
roboparser example
import robotparser
toget = "http://johannburkard.de/blog/www/spam/The-top-10-spam-bot-user-agents-you-MUST-block-NOW.html"
roboturl = "http://johannburkard.de/robots.txt"
userAgent = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/534.30 (KHTML, like Gecko) Ubuntu/10.04 Chromium/12.0.742.112 Chrome/12.0.742.112 Safari/534.30"
pars = robotparser.RobotFileParser()
pars.set_url(roboturl)
pars.read()
import lxml.etree as jq
string = "<p><b>HTTP header fields</b> are components of the message header of requests and responses in the <a href=\"/wiki/Hypertext_Transfer_Protocol\" title=\"Hypertext Transfer Protocol\">Hypertext Transfer Protocol</a> (HTTP). They define the operating parameters of an HTTP transaction.</p>"
html = jq.fromstring(string)
for par in html.xpath("//p"):
print par.text_content()
Traceback (most recent call last):
File "/usr/lib/python2.6/multiprocessing/process.py", line 232, in _bootstrap
self.run()
File "/usr/lib/python2.6/multiprocessing/process.py", line 88, in run
self._target(*self._args, **self._kwargs)
File "xmlFasterParser.py", line 19, in mainParser
for event, elem in context:
File "iterparse.pxi", line 515, in lxml.etree.iterparse.__next__ (src/lxml/lxml.etree.c:86643)
File "parser.pxi", line 565, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:64088)
XMLSyntaxError: xmlParseCharRef: invalid xmlChar value 11, line 28153825, column 161
@netdesign
netdesign / tr
Created September 26, 2011 12:20
Why This?
def dataExtractor(node):
XMLNS_D = '{http://purl.org/dc/elements/1.0/}'
elem = tr.fromstring(node)
title = elem.find(XMLNS_D + 'Title').text
if title is not None:
title = title
else:
title = "nnn"
descr = elem.find(XMLNS_D + 'Description').text
if descr is not None: