Skip to content

Instantly share code, notes, and snippets.

View jongacnik's full-sized avatar

Jon jongacnik

View GitHub Profile
@jongacnik
jongacnik / cache-element.js
Last active March 9, 2017 19:55
Working cache-element implementation #js #nanocomponent #nanomorph @classnic
var update = require('nanomorph/update')
var widget = require('cache-element/widget')
var h = require('bel')
function superWidget (content) {
return widget({
onload: function (el) {
console.log('hello!')
},
onunload: function (el) {
@jongacnik
jongacnik / kirby-routes.php
Created March 7, 2017 01:39
Define Kirby routes in external files #kirby #routes @classnic
<?php
// add to config.php
DEFINE('ROUTES', realpath(__DIR__) . '/../routes');
c::set('routes', array_map(function ($f) {
return require_once($f);
}, glob(ROUTES . DS . '*.php')));
@jongacnik
jongacnik / various-spaces.md
Last active February 22, 2017 22:46
Various Spaces #unicode @classnic

Various Spaces

Frequently used in css pseudo-elements

Space

\0020
@jongacnik
jongacnik / attachers.js
Created February 15, 2017 01:44
Attachers #js @classnic
/**
* Attachers
* Makes positioning fixed elements eZ. Given a DOM structure like:
*
* <div data-attach-basis="some-id"></div>
* <div data-attach="some-id"></div>
*
* $([data-attach="some-id"]) will have its width, top, and left set to
* $([data-attach-basis="some-id"])'s width, offset top, and offset left.
* If a `data-attach-class` attribute is included on $([data-attach="some-id"]),
@jongacnik
jongacnik / chromebook.md
Last active March 9, 2017 01:45
Chromebook Setup #linux @classnic
@jongacnik
jongacnik / tag.php
Created February 8, 2017 00:57
Simple Kirby wrap tag implementation #kirby #tag @classnic
<?php
/**
* Extremely simple kirby wrap implementation
* Just add html tags. Javascript does the rest.
*/
kirbytext::$pre[] = function($kirbytext, $value) {
return str_replace(
array('(block)', '(/block)'),
array('<div class="block">', '</div>'),
$value
@jongacnik
jongacnik / gr8-setup.js
Created February 4, 2017 08:12
ⓖⓡ⑧ Development
var gr8 = require('gr8')
var dev = require('gr8dev')
var rst = require('recsst')
var css = gr8()
rst.attach()
dev.attach()
css.attach()
@jongacnik
jongacnik / tinyBars.js
Last active August 19, 2017 03:51
Tiny templating for the v basic needs! #template @classnic
function tinyBars (str, data) {
var regex = /{{\s*([\w\.]+)\s*}}/gi
return str.replace(regex, function (match, val) {
return data[val.trim()] || ''
})
}
// or
var tinyBars = (s, d) => s.replace(/{{\s*([\w]+)\s*}}/gi, (m, v) => d[v] || '')
@jongacnik
jongacnik / linx.md
Last active February 17, 2017 20:19
Linx @classnic
@jongacnik
jongacnik / elebyclass.php
Last active March 23, 2023 16:16
Get element by classname #php @classnic
<?php
function getElementByClassname ($html, $classname) {
$dom = new DOMDocument();
$dom->loadHTML($html);
$xpath = new DOMXpath($dom);
$nodes = $xpath->query('//div[@class="' . $classname . '"]');
$tmp_dom = new DOMDocument();