Skip to content

Instantly share code, notes, and snippets.

View eriwen's full-sized avatar

Eric Wendelin eriwen

View GitHub Profile
@eriwen
eriwen / vertical_center.css
Created June 6, 2012 01:27
Vertical centering with Flexbox + margin fallback
/**
* Vertical centering with Flexbox + margin fallback
* Lea Verou & David Storey
*/
html, body { height: 100%; }
body {
width: 100%; /* needed for FF */
margin: 0;
@eriwen
eriwen / cors.js
Created May 26, 2012 15:54
Simple cross-domain Javascript function
/**
* Make a X-Domain request to url and callback.
*
* @param url {String}
* @param method {String} HTTP verb ('GET', 'POST', 'DELETE', etc.)
* @param data {String} request body
* @param callback {Function} to callback on completion
* @param errback {Function} to callback on error
*/
function xdr(url, method, data, callback, errback) {
@eriwen
eriwen / css3-grid.css
Created March 28, 2012 22:49
Classy CSS3 Grid
.grid {
width: 100%;
height: 100%;
background-color: white;
background: radial-gradient(circle, transparent 20%, white 20%, white 80%, transparent 80%, transparent),
radial-gradient(circle, transparent 20%, white 20%, white 80%, transparent 80%, transparent) 0 0,
linear-gradient(#ddd 1px, transparent 1px) 0 -0.5px,
linear-gradient(0, #ddd 1px, transparent 1px) -0.5px 0;
background-size: 20px 20px, 40px 20px, 10px 10px, 10px 10px;
}
@eriwen
eriwen / test_dns_speed.sh
Created February 26, 2012 04:49
Test DNS speed of a given domain
#!/bin/sh
for i in "lifehacker.com" "facebook.com" "manu-j.com" "reddit.com" "tb4.fr" "bbc.co.uk" "eriwen.com"
do
for j in "4.2.2.2" "8.8.8.8" "68.87.85.98" "68.87.69.146"
do
echo $j $i `dig @$j $i | grep Query | awk -F ":" '{print $2}'`
done
done
@eriwen
eriwen / ftp_upload.sh
Last active February 14, 2016 06:17
FTP Upload via shell
ftp -n -v $HOST << EOT
ascii
user $USER $PASSWD
prompt
cd /
put $LOCAL_SOURCE $TARGET_FILE
bye
EOT
sleep 1
@eriwen
eriwen / run_jstd.sh
Created November 30, 2011 22:15
Run JsTestDriver
Xvfb :2 &
/usr/bin/env DISPLAY=:2 java -jar test/lib/JsTestDriver-1.3.3d.jar --config test/jsTestDriver.conf --port 4224 --browser /Applications/Firefox.app/Contents/MacOS/firefox --tests all --testOutput target --runnerMode INFO
@eriwen
eriwen / gist:1391529
Created November 24, 2011 15:02 — forked from robflaherty/gist:1129904
Stylus conversion of Normalize.css
/*
* Normalize.css converted to Stylus
* http://github.com/necolas/normalize.css
*/
article, aside, details, figcaption, figure, footer, header, hgroup, nav, section
display: block
audio, canvas, video
display: inline-block
@eriwen
eriwen / qunit-to-junit-for-phantom.js
Created November 14, 2011 02:33
JUnit XML output for QUnit tests compatible with PhantomJS 1.3
var module, moduleStart, testStart, testCases = [],
current_test_assertions = [];
console.log('<?xml version="1.0" encoding="UTF-8"?>');
console.log('<testsuites name="testsuites">');
QUnit.begin = function() {
// That does not work when invoked in PhantomJS
}
QUnit.moduleStart = function(context) {
moduleStart = new Date();
@eriwen
eriwen / totype.js
Created September 22, 2011 13:35
Fixing typeof by Angus Croll
Object.toType = (function toType(global) {
return function(obj) {
if (obj === global) {
return "global";
}
return ({}).toString.call(obj).match(/\s([a-z|A-Z]+)/)[1].toLowerCase();
}
})(this);
@eriwen
eriwen / relativePath.js
Created September 12, 2011 16:11
Get relative file path in JavaScript
/**
* Given a source directory and a target filename, return the relative
* file path from source to target.
* @param source {String} directory path to start from for traversal
* @param target {String} directory path and filename to seek from source
* @return Relative path (e.g. "../../style.css") as {String}
*/
function getRelativePath(source, target) {
var sep = (source.indexOf("/") !== -1) ? "/" : "\\",
targetArr = target.split(sep),