Skip to content

Instantly share code, notes, and snippets.

Avatar

John Slegers jslegers

View GitHub Profile
@jslegers
jslegers / superglobals.php
Last active Aug 29, 2015
Create a formatted list of all superglobals
View superglobals.php
<?php
// Generate a formatted list with all superglobals
//----------------------------------------------------
// Custom superglobal variable $_CUSTOM
$_CUSTOM = array('USERNAME' => 'john', 'USERID' => '18068416846');
// List here whichever superglobals you want to print
// This could be your own custom superglobals
$globals = array(
'$_SERVER' => $_SERVER, '$_ENV' => $_ENV,
View __math.scss
// Some code is my own
// Some code is coming from https://github.com/adambom/Sass-Math/blob/master/math.scss
// Some code is coming from http://thesassway.com/advanced/inverse-trigonometric-functions-with-sass
// Some code coming from http://thesassway.com/advanced/math-sequences-with-sass
@function power($base, $exponent) {
$ret: 1;
@if $exponent > 0 {
@for $i from 1 through $exponent {
$ret: $ret * $base;
View jslegers-responsive-mixin.scss
/*
Scoped Media Query Mixins - an element query workaround.
@mixin respond-to-all : generates @media () {}
@mixin respond-to-screen : generates @media screen and () {}
@mixin respond-to-screen-only : generates @media screen only and () {}
Accepts the following input :
@jslegers
jslegers / selfdescriptive.php
Last active Jan 8, 2016
self descriptive number
View selfdescriptive.php
<?php
// PHP implementation of my solution for James Grimes's puzzle @ https://www.youtube.com/watch?v=K6Qc4oK_HqY
// The following function calculates the (only) self descriptive number for any number of digits
//
// With "self descriptive number", I mean :
// -------------------
// The first digit tells me how many zeros are in the number
// The second digit tells me how many ones are in the number
// The third digit tells me how many twos are in the number
View jquery.qsParameters.js
(function ( $ ) {
$.qsParameters = function(str) {
var qso = {};
var qs = (str || document.location.search)
// Check for an empty querystring
if (qs == ""){
return qso;
}
View contains.php
function contains($haystack, $needle, $caseSensitive = false) {
return $caseSensitive?
(strpos($haystack, $needle) === FALSE ? FALSE : TRUE):
(stripos($haystack, $needle) === FALSE ? FALSE : TRUE);
}
var_dump(contains('bare','are')); // Outputs : bool(true)
var_dump(contains('stare', 'are')); // Outputs : bool(true)
var_dump(contains('stare', 'Are')); // Outputs : bool(true)
var_dump(contains('stare', 'Are', true)); // Outputs : bool(false)
View helper.string.js
var helper = {};
helper.string = {
contains : function (haystack, needle) {
return !!~haystack.indexOf(needle);
},
...
};
@jslegers
jslegers / style.scss
Created Jul 26, 2013
A CodePen by Hugo Giraudel. Sass mixin for scrollbar styling - Because I can't ever remember the right syntax for scrollbars styling in WebKit, here is a little Sass mixin to do it for you.
View style.scss
@import "compass";
/**
* Mixin scrollbar
*/
@mixin scrollbar($size, $primary, $secondary: lighten($primary, 25%)) {
::-webkit-scrollbar {
width: $size;
height: $size;
}
@jslegers
jslegers / parsequery.js
Last active Apr 10, 2018
How to parse a query string
View parsequery.js
function parseQuery(str) {
var qso = {};
var qs = (str || document.location.search);
// Check for an empty querystring
if (qs == "") {
return qso;
}
// Normalize the querystring
qs = qs.replace(/(^\?)/, '').replace(/;/g, '&');
while (qs.indexOf("&&") != -1) {
@jslegers
jslegers / _clearfix.scss
Last active Oct 30, 2018
Clearfix code without duplication
View _clearfix.scss
%display-block-hacked {
display: block;
*zoom: 1;
}
%clear-both {
clear : both;
}
%blank-as-table {
You can’t perform that action at this time.