Skip to content

Instantly share code, notes, and snippets.

View yanbab's full-sized avatar

yanbab

  • Nantes, France
View GitHub Profile
<!-- Get the favicon image of any website with various services -->
<img src="http://g.etfv.co/http://www.google.com">
<img src="https://getfavicon.appspot.com/http://www.google.com?defaulticon=lightpng">
<img src="http://www.google.com/s2/favicons?domain=google.com">
@yanbab
yanbab / netslow.sh
Created January 16, 2014 12:21
Network conditionning on Linux and OSX
# set bandwidth limit, response delay and lost packages :
sudo ipfw pipe 1 config bw 56Kbit/s delay 200 plr 0.2
sudo ipfw add 1 pipe 1 ip from any to any
# Restore by removing the pipe :
# sudo ipfw delete 1
@yanbab
yanbab / shim.localStroge.js
Created December 14, 2013 14:17
HTML5 localStorage shim
// https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Storage
if (!window.localStorage) {
window.localStorage = {
getItem: function (sKey) {
if (!sKey || !this.hasOwnProperty(sKey)) { return null; }
return unescape(document.cookie.replace(new RegExp("(?:^|.*;\\s*)" + escape(sKey).replace(/[\-\.\+\*]/g, "\\$&") + "\\s*\\=\\s*((?:[^;](?!;))*[^;]?).*"), "$1"));
},
key: function (nKeyId) {
return unescape(document.cookie.replace(/\s*\=(?:.(?!;))*$/, "").split(/\s*\=(?:[^;](?!;))*[^;]?;\s*/)[nKeyId]);
@yanbab
yanbab / symbols.txt
Last active December 31, 2015 08:19
UTF8 Symbols
// ☰ &#9776;
// ‣▴▾✖︎✕✔︎✓►◀︎▼▲
@yanbab
yanbab / osx-sudo
Created November 30, 2013 22:32
Getting sudo to ask for password via the GUI
/usr/bin/osascript -e 'do shell script "/path/to/myscript args 2>&1 etc" with administrator privileges'
@yanbab
yanbab / anacrontab
Last active December 29, 2015 20:19
Gandi simple hosting daily mysql backup
# Sample anacrontab usage on Gandi Simple hosting
#
# Does a daily mysql backup and delete 1 week old backups
#
# SFTP : lamp0/etc/cron/anacron/anacrontab
# SSH : /srv/data/etc/cron/anacron/anacrontab
@daily 0 mysql_backup mkdir /srv/data/tmp/mysql_backup ; mysqldump -h localhost -u root {-pPASSWORD} --all-databases > /srv/data/tmp/mysql_backup/`date '+%F'`.databases.sql ; rm /srv/data/tmp/mysql_backup/`date '+%F' --date '1 weeks ago'`.databases.sql
@yanbab
yanbab / gist:7542073
Last active December 28, 2015 18:19
Pure javascript add/remove/toggle class on an element - Needs a shim on IE8/9 : https://github.com/eligrey/classList.js or https://gist.github.com/devongovett/1381839
document.getElementById('id').classList.add('class');
document.getElementById('id').classList.remove('class');
document.getElementById('id').classList.toggle('class');
@yanbab
yanbab / shim.console.js
Last active December 18, 2015 21:48
Avoid `console` errors in browsers that lack a console.
// Avoid `console` errors in browsers that lack a console.
(function() {
var method;
var noop = function () {};
var methods = [
'assert', 'clear', 'count', 'debug', 'dir', 'dirxml', 'error',
'exception', 'group', 'groupCollapsed', 'groupEnd', 'info', 'log',
'markTimeline', 'profile', 'profileEnd', 'table', 'time', 'timeEnd',
'timeStamp', 'trace', 'warn'
];