Skip to content

Instantly share code, notes, and snippets.

<?php
$data = (object)array(
"html" => "<foo bar=\"baz\"/> &amp;",
"arabic" => "العربية al-ʿarabiyyah, IPA: [æl ʕɑrɑˈbijjɐ], or عربي ʿarabī",
"hebrew" => "עִבְרִית, Ivrit",
"chinese" => "汉语/漢語 Hanyu; 华语/華語 Huáyǔ; 中文 Zhōngwén",
"korean" => "한국어/조선말",
"japanese" => "日本語 Nihongo",
"umlauts" => "äüöãáàß",
@ch-gilbert
ch-gilbert / negotiate_language.php
Created March 4, 2015 05:58
http_negotiate_language: get langauge form Accept Language header
<?php
/*
determine which language out of an available set the user prefers most
$available_languages array with language-tag-strings (must be lowercase) that are available
$http_accept_language a HTTP_ACCEPT_LANGUAGE string (read from $_SERVER['HTTP_ACCEPT_LANGUAGE'] if left out)
*/
function negotiate_language ($available_languages,$http_accept_language="auto") {
// if $http_accept_language was left out, read it from the HTTP-Header
if ($http_accept_language == "auto") $http_accept_language = isset($_SERVER['HTTP_ACCEPT_LANGUAGE']) ? $_SERVER['HTTP_ACCEPT_LANGUAGE'] : '';
#/usr/bin/bash
opt=$1
root=`hg root`
stash=$root/.stash
if [ -z $opt ]
then
opt='save'
fi
@ch-gilbert
ch-gilbert / rmdir_r.php
Created January 15, 2014 02:46
recursively delete a directory
function rmdir_r($dir) {
if (!is_dir($dir)) {
return false;
}
$files = scandir($dir);
foreach ($files as $file) {
if ($file === '.' || $file === '..') {
continue;
}
<html>
<title>Curly Bracket</title>
<script src="http://d3js.org/d3.v3.min.js" charset="utf-8"></script>
<style>
.curlyBrace {
stroke: #000000;
stroke-width: 10px;
@ch-gilbert
ch-gilbert / graphPath.cpp
Created November 3, 2013 23:52
Get all paths between two nodes in the graph. The graph stores in Adjacency List (邻接表) data structure.
struct edgenode
{
int no;
struct edgenode *next;
};
struct vex
{
struct edgenode *first;
};
@ch-gilbert
ch-gilbert / center-image.html
Created September 16, 2013 05:40
纯CSS控制不固定宽高图片div内水平垂直均居中 (http://sandbox.runjs.cn/show/c9zvoil2)
<style>
.img-outSide{
width: 500px;
height: 750px;
border: 1px solid #CDCDCD;
text-align: center;
}
.img-inSide,.img-con{
display: inline-block;
vertical-align: middle;
@ch-gilbert
ch-gilbert / doctypes.txt
Last active December 22, 2015 19:09
HTML Doctype
HTML
HTML 5:
<!DOCTYPE html>
HTML 4.01 transitional:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
HTML 4.01 strict:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
@ch-gilbert
ch-gilbert / .htaccess
Last active December 21, 2015 05:58
Download image file with query string download, e.g logo.jpg?download
<FilesMatch "\.(gif|jpe?g|png)$">
RewriteEngine On
RewriteCond %{QUERY_STRING} ^download$
RewriteRule ^.*$ - [E=DOWNLOAD:1]
Header set Content-Type application/octet-stream env=DOWNLOAD
Header set Content-Disposition attachment env=DOWNLOAD
</FilesMatch>
@ch-gilbert
ch-gilbert / ie.css
Last active December 20, 2015 15:19
IE hacks
/* IE Hacks*/
/**
* slideDown on element with position set to relative, the element will display first and then it will disappear.
* @for IE7
*/
.container {
position: relative;
overflow: hidden; /* hack: BFC or hasLayout issue */
}