Skip to content

Instantly share code, notes, and snippets.

View greut's full-sized avatar
:shipit:
available for hire

Yoan Blanc greut

:shipit:
available for hire
View GitHub Profile
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<script type="text/javascript">
if (navigator.appName == 'Netscape')
var language = navigator.language;
else if (navigator.appName == 'Microsoft Internet Explorer')
var language = navigator.browserLanguage;
if (language.indexOf('en') > -1) document.location.href = '/en/index.jsp';
@greut
greut / fotd.php
Created September 19, 2008 12:08
<?php
// See: http://blog.liip.ch/archive/2008/09/18/fotd-reflectionclass-newinstanceargs-args-is-slow.html
/* Results on my box:
$ php -v
PHP 5.2.6-pl7-gentoo (cli) (built: Sep 22 2008 08:13:50)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
$ php test.php
// open: http://www.iphone-conference.ch/speakers
// copy and paste this into your address bar (with Firefox or Opera, for example):
javascript:Array.prototype.slice.call(document.getElementsByTagName("img")).map(function(k){k.removeAttribute("width");});void(null)
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>No script failure</title>
<style>
noscript{display:inline;}
</style>
<noscript>will be visible with Opera.</noscript>
</html>
function ajax(obj) {
// data
obj.type = obj.type ? obj.type.toUpperCase() : "GET";
obj.data = obj.data || "";
obj.dataType = obj.dataType || "application/x-www-form-urlencoded";
obj.aborted = false;
// callbacks
obj.success = obj.success || function() {};
obj.error = obj.error || function() {};
// using XPath with namespace
// @see https://developer.mozilla.org/en/Introduction_to_using_XPath_in_JavaScript#Evaluating_against_an_XML_document_within_an_Extension
var ns = "urn:Spam", xml = document.implementation.createDocument(ns, "eggs", null);
xml.documentElement.appendChild(xml.createElementNS(ns, "sausage"));
xml.documentElement.appendChild(xml.createElementNS(ns, "spam"));
xml.documentElement.appendChild(xml.createElementNS(ns, "sausage"));
// there is only one namespace used here.
var resolver = function(namespace) { return ns; };
var result = xml.evaluate("count(//spam:sausage)", xml, resolver, XPathResult.ANY_TYPE, null);
<!DOCTYPE html>
<html>
<title>Event delegation</title>
<ul>
<li><a href="#a">a</a></li>
<li><a href="#b"><span>b</span></a></li>
<li><a href="#c"><span><span>c</span></span></a></li>
<li><a href="#d"><span><span><span>d</span></span></span></a></li>
</ul>
<script>
// Element.prototype.getElementsByClassName (using XPath or getElementsByTagName)
// Monkeypatching is evil
if(typeof Element.getElementsByClassName === "undefined") {
if("evaluate" in document) {
Element.prototype.getElementsByClassName = function(className) {
var result = document.evaluate(".//*[contains(concat(' ', @class, ' '), '"+className+"')]", this, null, XPathResult.ANY_TYPE, null),
node,
elements = [];
while(node = result.iterateNext()) {
#!/usr/bin/env seed
var __author__ = "Yoan Blanc <yoan.blanc@gmail.com>";
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// simple async call using libsoup on twitter.com
// author: Yoan Blanc
// compiled using: gcc twitter.c `pkg-config --cflags libsoup-2.4` `pkg-config --libs libsoup-2.4`
#include <stdio.h>
#include <glib-object.h>
#include <libsoup/soup.h>
static GMainLoop *main_loop = NULL;