Skip to content

Instantly share code, notes, and snippets.

View yckart's full-sized avatar

Yannick Albert yckart

View GitHub Profile
@yckart
yckart / README.md
Last active October 26, 2016 14:06
Interesting concept to wrap strings around each array-item.

This is something I fiddled with during development. A really helpful thing if we need to wrap strings around array items.

var values = [1, 3, 3, 7];
var open = '<span>';
var close = '</span>';
var html = open + values.join(close + open) + close;

console.log(html); // => "<span>1</span><span>3</span><span>3</span><span>7</span>"
@yckart
yckart / README.md
Last active August 29, 2015 14:06
A simple function to get the viewport-dimensions, including some pre-calculated values.
Property Description
ww Window Width
wh Window Height
dw Document Width
dh Document Height
pw Page Width
ph Page Height
fw Factor Width (A value between 0-1, which represents the percentage-value)
fh Factor Height (A value between 0-1, which represents the percentage-value)

The usage is quite simple, just add a new listender to the node you want to observe and manipulate the classes as usually:

var $node = $('div')

  // listen to class-manipulations
  .on('addClass toggleClass removeClass', function (e, oldClass, newClass) {
    console.log('Changed from %s to %s due %s', oldClass, newClass, e.type);
  })
@yckart
yckart / LICENSE.txt
Last active August 29, 2015 13:59 — forked from 140bytes/LICENSE.txt
Getting the document width and height in less than 140 bytes.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2014 Yannick Albert <http://yannick-albert.com>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@yckart
yckart / LICENSE.txt
Last active March 8, 2018 11:38 — forked from 140bytes/LICENSE.txt
undo/redo manager
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) 2011 YOUR_NAME_HERE <YOUR_URL_HERE>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
@yckart
yckart / README.md
Last active May 19, 2023 06:37
Checks if an element is inside another or if it collides with another. - http://stackoverflow.com/a/19614185/1250044

Usage:

var player = new Rect(0, 0, 100, 100);
var target = new Rect(50, 50, 100, 100);
player.is = new AABB(player);

player.is.inside(target);
player.is.colliding(target);
player.is.containing(target);
<?
wire()->addHookProperty('Page::readingTime', null, 'readingTime');
function readingTime($event) {
$page = $event->object;
$words = str_word_count(strip_tags($page->body));
$m = floor($words / 200);
$s = floor($words % 200 / (200 / 60));
$minutes = $m == 1 ? __('Minute') : __('Minutes');
$seconds = $s == 1 ? __('Second') : __('Seconds');
$event->return = "$m {$minutes}, $s {$seconds}";
@yckart
yckart / functions.php
Last active December 26, 2015 02:49
ProcessWire page slug
<? $input->slug = $input->urlSegments ? end($input->urlSegments) : $page->name; ?>
@yckart
yckart / Log.module
Last active January 31, 2016 06:38
Log.module - A lightweight logging wrapper around ProcessWire's session message/error
<?php
class Log extends WireData implements Module {
/**
* getModuleInfo is a module required by all modules to tell ProcessWire about them
*
* @return array