Skip to content

Instantly share code, notes, and snippets.

View fpfaende's full-sized avatar

Fabien Pfaender fpfaende

View GitHub Profile
@fpfaende
fpfaende / new_gist_file.java
Created December 19, 2013 08:08
jsoup analyse html page in processing
import org.jsoup.safety.*;
import org.jsoup.examples.*;
import org.jsoup.helper.*;
import org.jsoup.*;
import org.jsoup.parser.*;
import org.jsoup.select.*;
import org.jsoup.nodes.*;
Document doc = null;
try {
@fpfaende
fpfaende / new_gist_file
Created September 29, 2013 22:38
compress inline svg for display
data:image/svg+xml;charset=utf-8'+encodeURIComponent(svg)
@fpfaende
fpfaende / new_gist_file
Created August 25, 2013 00:43
copy psql query to csv
\copy (
select *
from table1 left join table2 on table1.id = table2.id
) To '/Path/to/heaven/machin.csv' With CSV;
import urllib
import urllib2
headers = {"Accept":"text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8",
"Accept-Charset":"ISO-8859-1,utf-8;q=0.7,*;q=0.3",
"Accept-Language":"fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4",
"User-Agent":"Your Very Own Robot"}
baseUrl = "http://query.yahooapis.com/v1/public/"
urlPattern = "yql?%s"
@fpfaende
fpfaende / manipulateJson.py
Created December 20, 2012 03:13
basic json manipulation to get some information from any json file
import json
dataJson = '{"title":"json example", "content":[{"number":"1", "key":"value"}, {"number":"2", "key":"another value"}]}'
data = json.loads(dataJson)
print json.dumps(data, sort_keys=True, indent=4, separators=(',', ': '))
print data['title']
for content in data['content']:
for key in content:
@fpfaende
fpfaende / queryHTMLWithXPath.py
Created December 20, 2012 02:31
query HTML page with bad tagging using lxml and xpath feature
from lxml import etree
data = "<html>"
data += "<head>"
data += "<title>I love python</title>"
data += "</head>"
data += "<body>"
data += "<p class='language'><span id='good-rating'>good!</span> python</pp><br />"
data += "<p class='language'><span id='hard-rating'>hard!</span>lisp</p>"
data += "<p class='editor'>CodeRunner for mac os x is very useful</p>"
@fpfaende
fpfaende / url2String.py
Created December 20, 2012 02:10
read file from simple url into string in python
import urllib, urllib2
dataStream = urllib.urlopen("http://www.google.com")
data = dataStream.read()
print data