Skip to content

Instantly share code, notes, and snippets.

View ben182's full-sized avatar

Ben ben182

View GitHub Profile
@ben182
ben182 / pre-commit
Created January 17, 2019 23:12
PHP-CS-Fixer pre-commit
#!/usr/bin/env bash
EXECUTABLE_NAME=php-cs-fixer
EXECUTABLE_COMMAND=fix
CONFIG_FILE=.php_cs
CONFIG_FILE_PARAMETER='--config'
ROOT=`pwd`
# possible locations
locations=(
@ben182
ben182 / math.random.js
Created January 9, 2018 11:09
Better Math.random
(function () {
var MathRandom = Math.random;
Math.random = function() {
var crypto = window.crypto || window.msCrypto;
if (crypto !== undefined) {
return crypto.getRandomValues(new Uint32Array(1))[0] / 4294967296;
}
return MathRandom();
}
})();
@ben182
ben182 / onScroll.js
Created March 20, 2017 10:41
Plain Javascript on scroll event
var getScroll = function() {
if (window.pageYOffset != undefined) {
return [pageXOffset, pageYOffset];
} else {
var sx, sy, d = document,
r = d.documentElement,
b = d.body;
sx = r.scrollLeft || b.scrollLeft || 0;
sy = r.scrollTop || b.scrollTop || 0;
return [sx, sy];
@ben182
ben182 / scrollTo.js
Created March 9, 2017 13:28
jQuery Scroll To
$.fn.goTo = function() {
$('body').animate({
scrollTop: $(this).position().top + 'px'
}, 'slow');
return this;
}
@ben182
ben182 / chance.php
Last active March 20, 2017 10:42
Gives the possibility to perform actions according to a certain probability
class Chance
{
private $_aData;
public function addData($sName, $fPercentage)
{
$fPercentage = (float) $fPercentage;
if ($fPercentage < 1 && $fPercentage > 0) {
$fPercentage = $fPercentage * 100;