Skip to content

Instantly share code, notes, and snippets.

View iksi's full-sized avatar
🤞

Jurriaan iksi

🤞
View GitHub Profile
@iksi
iksi / async-css.js
Last active August 29, 2015 14:10
Load css file without blocking rendering.
(function (s) {
"use strict";
var e,
p;
// Load CSS
e = document.createElement("link");
p = document.getElementsByTagName("head")[0];
e.rel = "stylesheet";
e.href = s;
e.media = "only x";
<?php
/**
* Instructions:
*
* 1. Put this into the document root of your Kirby site
* 2. Make sure to setup the base url for your site correctly
* 3. Run this script with `php statify.php` or open it in your browser
* 4. Upload all files and folders from static to your server
* 5. Test your site
@iksi
iksi / map-array-to-key.php
Last active August 29, 2015 14:11
Map a multidimensional array to a certain key.
<?php
$results = array();
array_walk($array, function ($value, $key, $field) use(&$results) {
$results[$value[$field]] = $value;
}, $field);
@iksi
iksi / price-to-float.php
Created December 23, 2014 12:39
Price to float
// Returns False if no number given, number before decimal is
// missing and when the decimal shorter than two digits
function price_to_float($string)
{
// Remove leading and trailing whitespace
$string = trim($string);
// Check for decimal with comma first
if ( (bool) preg_match('/[+-]?[0-9]\,[0-9]{2}(\w|\b)/D', $string))
{
.hide-text {
text-indent: 100%;
white-space: nowrap;
overflow: hidden;
}
@iksi
iksi / detect-svg.js
Created January 5, 2015 16:42
Detect svg support.
document.implementation.hasFeature('http://www.w3.org/TR/SVG11/feature#Image', '1.1');
// using a for loop on an object
for (key in object) {
if (object.hasOwnProperty(key)) {
object[key];
}
}
@iksi
iksi / poor-mans-cron.php
Created January 15, 2015 21:48
Poor man’s cron
<?php
/**
* Simple PHP if statement to execute recurring tasks
* by executing those when visited by a bot
*/
if (preg_match('/slurp|googlebot/i', $_SERVER['HTTP_USER_AGENT'])) {
// tasks to execute
}
@iksi
iksi / minify-kirby.php
Last active June 2, 2018 23:40
Minify Kirby’s HTML output
/**
* Uses Alan Moore's regexp:
* http://stackoverflow.com/questions/5312349/minifying-final-html-output-using-regular-expressions-with-codeigniter
*
* Replace `echo $kirby->launch();` in Kirby’s index.php by
* the following code to minify the HTML output
* (it leaves whitespace within `<pre>` and `<textarea>` tags untouched)
*/
echo preg_replace(
'/(?>[^\S ]\s*|\s{2,})(?=(?:(?:[^<]++|<(?!\/?(?:textarea|pre)\b))*+)
<style>
rect, line { shape-rendering: crispEdges; }
</style>