Skip to content

Instantly share code, notes, and snippets.

View karlcow's full-sized avatar
⛩️
Working from … anywhere

Karl Dubost karlcow

⛩️
Working from … anywhere
View GitHub Profile
print "validation:", resp['x-w3c-validator-status'], resp['x-w3c-validator-errors'], resp['x-w3c-validator-warnings']
fres.write("validation: " + resp['x-w3c-validator-status'] + " " + resp['x-w3c-validator-errors'] + " " + resp['x-w3c-validator-warnings'] + "\n")
print "encoding: " + respg['content-type'] + " " + encoding
fres.write("encoding: " + respg['content-type'] + " " + encoding+"\n")
@karlcow
karlcow / gist:1345725
Created November 7, 2011 18:23
attempt to log window.onerror on the server with XMLHttpRequest
window.onerror = function(message, url, linenumber) {
if (window.XMLHttpRequest) {
var xhr = new XMLHttpRequest();
var scripturl = "http://127.0.0.1:8069/log";
var log = linenumber + message + url;
xhr.open("POST", scripturl);
xhr.setRequestHeader("Content-Type", "text/plain;charset=UTF-8");
xhr.send(log);
}
@karlcow
karlcow / gist:1706037
Created January 30, 2012 19:09
Linux OR Opera excluded - bad user agent sniffing
On http://map.hackerwatch.org/hwmap/javascript/main.js
// Determine browser type and platform.
if (navigator.appName.indexOf("Netscape")>=0) {
m_sClientBrowserType = 'Netscape';
} else if (navigator.appName.indexOf('Microsoft') >=0) {
m_sClientBrowserType = 'IE';
} else {
window.location = "unsupported.htm";
@karlcow
karlcow / HTTP-304.txt
Created March 30, 2012 12:39
Prose for HTTP 304
4.1. 304 Not Modified
The 304 status code indicates that a conditional GET request has been
received and would have resulted in a 200 (OK) response if it were
not for the fact that the condition has evaluated to false. In other
words, there is no need for the server to transfer a representation
of the target resource because the client's request indicates that it
already has a valid representation, as indicated by the 304 response
header fields, and is therefore redirecting the client to make use of
that stored representation as if it were the payload of a 200
@karlcow
karlcow / gist:2360574
Created April 11, 2012 17:05
curl empty user agent
→ curl -iI -v -A " " "http://www.la-grange.net/"
* About to connect() to www.la-grange.net port 80 (#0)
* Trying 128.30.54.58... connected
* Connected to www.la-grange.net (128.30.54.58) port 80 (#0)
> HEAD / HTTP/1.1
> User-Agent:
> Host: www.la-grange.net
> Accept: */*
>
< HTTP/1.1 200 OK
@karlcow
karlcow / gist:2368714
Created April 12, 2012 16:11
Browsers Market Share on gs.statscounter.com
"Browser","Market Share % March 2011 to March 2012"
"IE",40.99
"Firefox",27.11
"Chrome",23.73
"Safari",5.67
"Opera",1.84
"Maxthon",0.13
"Sony PS3",0.13
"Android",0.11
"Chromium",0.05
@karlcow
karlcow / gradient-prefixes.css
Created July 3, 2012 16:37
gradient - vendor prefixes only
# In http://d2b4ufapzmnxpw.cloudfront.net/build/3751/static/kronos/css/fitnessReports.css
# from the Web site http://runkeeper.com/
.runkeeper .fitnessReports .totalsArea {
width: 729px;
background-color: #333;
-ms-filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#888', endColorstr='#333');
background: -webkit-gradient(linear, left top, left bottom, from(#888), to(#333));
background: -moz-linear-gradient(top, #888, #333);
margin: 30px auto;
@karlcow
karlcow / dnt-status.js
Created July 4, 2012 12:25
DNT status
# Script in http://donottrack.us/js/index.js
var aboutexpanded = false;
var developerexpanded = false;
var policyexpanded = false;
$(document).ready(function() {
// Show browser support region
$('#browser_support').show();
@karlcow
karlcow / lxml-bug.py
Created August 4, 2012 15:21
Silly lxml bug in Python
>>>from lxml import etree
>>> xml = u'<?xml version="1.0" encoding="utf-8" ?><foo><bar/></foo>'
>>> etree.XML(xml)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "lxml.etree.pyx", line 2736, in lxml.etree.XML (src/lxml/lxml.etree.c:54437)
File "parser.pxi", line 1569, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:82685)
ValueError: Unicode strings with encoding declaration are not supported.
>>> etree.HTML(xml)
Traceback (most recent call last):
@karlcow
karlcow / csstest.py
Created August 7, 2012 02:20
Encoding is tough stuff
>>> import cssutils
>>> cssutils.parseUrl("http://m.vk.com/css/s_mb.css?177")
WARNING 'charmap' codec can't decode byte 0x98 in position 810: character maps to <undefined>
>>> import requests
>>> r = requests.get("http://m.vk.com/css/s_mb.css?177")
>>> r.headers
{'content-encoding': 'gzip', 'transfer-encoding': 'chunked', 'expires': 'Tue, 14 Aug 2012 02:14:05 GMT', 'vary': 'Host,Accept-Encoding', 'server': 'nginx/1.2.1', 'connection': 'keep-alive', 'pragma': 'no-cache', 'cache-control': 'max-age=604800', 'date': 'Tue, 07 Aug 2012 02:14:05 GMT', 'x-powered-by': 'PHP/5.3.3-7+squeeze3', 'content-type': 'text/css; charset=windows-1251'}
>>> r.headers['content-type']
'text/css; charset=windows-1251'