Skip to content

Instantly share code, notes, and snippets.

View superbiche's full-sized avatar
🕹️
Working from everywhere

Michel Tomas superbiche

🕹️
Working from everywhere
View GitHub Profile
@superbiche
superbiche / placeholder.scss
Last active May 8, 2017 11:20
Cross-browser placeholder sass mixin
@mixin placeholder() { // using a mixing cause extending a class will result in parse failure
// your styles go here
}
[placeholder] {@include placeholder()}
:-moz-placeholder {@include placeholder()}
::-moz-placeholder {@include placeholder()}
:-ms-input-placeholder {@include placeholder()}
::-o-placeholder {@include placeholder()}
::-webkit-input-placeholder {@include placeholder()}
@superbiche
superbiche / querySelector.polyfill.js
Created March 11, 2015 08:34
querySelector and querySelectorAll polyfill (working with IE7, @todo test with IE6)
if (!document.querySelectorAll) {
document.querySelectorAll = function (selectors) {
var style = document.createElement('style'), elements = [], element;
document.documentElement.firstChild.appendChild(style);
document._qsa = [];
style.styleSheet.cssText = selectors + '{x-qsa:expression(document._qsa && document._qsa.push(this))}';
window.scrollBy(0, 0);
style.parentNode.removeChild(style);
// ECMA-262, Edition 5, 15.4.4.18
// Référence: http://es5.github.io/#x15.4.4.18
if (!Array.prototype.forEach) {
Array.prototype.forEach = function(callback, thisArg) {
var T, k;
if (this === null) {
throw new TypeError(' this vaut null ou n est pas défini');
@superbiche
superbiche / regex_alpha_underscores.php
Created March 29, 2015 16:13
Validate string that must contain only alphanumeric values and eventually an underscore as separator. From http://stackoverflow.com/questions/1330693/validate-username-as-alphanumeric-with-underscores
$is_valid = preg_match('/^[A-Za-z][A-Za-z0-9]*(?:_[A-Za-z0-9]+)*$/', $str);
@superbiche
superbiche / npm_upgrade.sh
Created March 29, 2015 23:46
Upgrade all outdated npm packages.
#!/bin/sh
set -e
set -x
for package in $(npm -g outdated --parseable --depth=0 | cut -d: -f2)
do
npm -g install "$package"
done
@superbiche
superbiche / brew-relink-all.sh
Created March 29, 2015 23:48
Re-link every Homebrew installed package
@superbiche
superbiche / subl.sh
Created March 29, 2015 23:50
Command-line Sublime Text 3.
ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl /usr/local/bin/subl
chmod a+x /usr/local/bin/subl
# OR
ln -s /Applications/Sublime Text.app/Contents/SharedSupport/bin/subl ~/bin/subl
chmod a+x ~/bin/subl
@superbiche
superbiche / diff-create-patch.sh
Created March 30, 2015 10:45
Create a patch with diff
diff -Naur standard_moodle my_moodle > patch.txt
body {
font: font-style font-variant font-weight font-size/line-height font-family;
}
@superbiche
superbiche / infinite-scroll-down.js
Last active August 29, 2015 14:21
Scroll down an infinite scroll page each 5 seconds, stop if bottom reached.
(function() {
var interval = 2000;
var failLimit = 20;
var stopped = 0;
var tick = setInterval(function() {
var ph = document.body.clientHeight;
var top = window.pageYOffset;
var ih = window.innerHeight;
if (ph > top + ih) {