Skip to content

Instantly share code, notes, and snippets.

View jorijn's full-sized avatar

Jorijn Schrijvershof jorijn

View GitHub Profile
@jorijn
jorijn / routes.php
Created September 13, 2012 08:30
Laravel paste
Route::filter('after', function($response)
{
if (($requested_type = Input::get('datagrid_download_as', false)) !== false && isset($response->content->data['datagrid']))
{
$original_datagrid = $response->content->data['datagrid'];
$requested_class = '\\UI\\DataGrid\\'.strtoupper($requested_type);
if (class_exists($requested_class) === false)
{
// return the original response, we have no point on
@jorijn
jorijn / plugin.php
Created November 30, 2012 07:49
Bijgewerkte Moneybird API voorbeeld code (namespace toegevoegd)
if (isset($_POST['opmerkingen']) && !empty($_POST['opmerkingen']))
{
$note = new Moneybird\Invoice_History(array(
'description' => 'Opmerking vanaf de website: '.$_POST['opmerkingen'],
));
$note->save($invoiceService, $invoice);
}
@jorijn
jorijn / functions.php
Created December 27, 2012 08:03
get_unique_meta
/**
* returns an array of unique items of meta_value, this was originally
* built for a filter machanism.
*
* @param string $post_type example: post
* @param string $meta_key example: _wp_page_template
* @return array
*/
function get_unique_meta($post_type, $meta_key)
{
@jorijn
jorijn / tbl.php
Created January 16, 2013 06:01
formats filesize
function filesize_formatted($path, $rounding = 2)
{
$size = filesize($path);
$units = array( 'B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
$power = $size > 0 ? floor(log($size, 1024)) : 0;
return number_format($size / pow(1024, $power), $rounding, '.', ',') . "\xC2\xA0" . $units[$power];
}
@jorijn
jorijn / gist:5194678
Last active December 15, 2015 03:29
Create a password rating
<?php
/**
* test - score: 4
* tESt - score: 4
* TeSt - score: 4
* TeS342 - score: 12
* T34@$sTD - score: 72
* :saR%8jmc9UjeK - score: 504
*/
@jorijn
jorijn / clearfix.css
Created April 15, 2013 06:30
Modern clearfix
/**
* For modern browsers
* 1. The space content is one way to avoid an Opera bug when the
* contenteditable attribute is included anywhere else in the document.
* Otherwise it causes space to appear at the top and bottom of elements
* that are clearfixed.
* 2. The use of `table` rather than `block` is only necessary if using
* `:before` to contain the top-margins of child elements.
*/
.cf:before,
@import "compass/utilities/sprites"; // Include compass sprite helpers
@import "compass/css3/background-size"; // Include helper to calc background size
@mixin retina-sprite($name, $hover: false, $active: false) {
@include _retina-sprite($name, $sprites, $sprites2x, $hover, $active);
}
@mixin _retina-sprite($name, $sprites, $sprites2x, $hover, $active, $dimensions: true, $pad: 0) {
@if $dimensions == true {
@include sprite-dimensions($sprites, $name);
@jorijn
jorijn / criticalcss-bookmarklet-devtool-snippet.js
Created March 21, 2017 12:21 — forked from PaulKinlan/criticalcss-bookmarklet-devtool-snippet.js
CriticalCSS Bookmarklet and Devtool Snippet.js
(function() {
var CSSCriticalPath = function(w, d, opts) {
var opt = opts || {};
var css = {};
var pushCSS = function(r) {
if(!!css[r.selectorText] === false) css[r.selectorText] = {};
var styles = r.style.cssText.split(/;(?![A-Za-z0-9])/);
for(var i = 0; i < styles.length; i++) {
if(!!styles[i] === false) continue;
var pair = styles[i].split(": ");
@jorijn
jorijn / to-blob-multipart.js
Created May 19, 2017 11:25
This javascript snippet will convert a base64 data string to Blob for submitting a multipart form through ajax.
// I needed some way to take a picture using the getUserMedia() API,
// save it to a canvas and then upload it to a server using a multipart
// form for it to be validateable by Laravel.
//
// the function that returns a blob
//
function toBlob(dataURL) {
var array, binary, i;
binary = atob(dataURL.split(',')[1]);
array = [];
@jorijn
jorijn / commit-msg
Created May 29, 2017 19:01 — forked from wesbos/commit-msg
ESLint 3.0 Git Pre Commit Hook
#!/bin/bash
files=$(git diff --cached --name-only | grep '\.jsx\?$')
# Prevent ESLint help message if no files matched
if [[ $files = "" ]] ; then
exit 0
fi
failed=0
for file in ${files}; do