This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const lut: string[] = []; | |
function getLut(): string[] { | |
if (lut.length === 0) { | |
for (let i = 0, hex = ''; i < 256; i++) { | |
hex = i.toString(16); | |
lut.push(hex.length === 1 ? `0${hex}` : hex); | |
} | |
} | |
return lut; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const pairs = { | |
'{': '}', | |
'(': ')', | |
'[': ']', | |
'<': '>', | |
} | |
function isValid(input: string) { | |
const chars = input.split(''); | |
let stack: string[] = [], last: string; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{# | |
Examples in order: | |
createQueryUrl('tags', 'online') // {url}?tags=online | |
createQueryUrl('tags', 'in-store', true) // {url}?tags=online,in-store | |
createQueryUrl('tags', 'omnichannel', true) // {url}?tags=online,in-store,omnichannel | |
createQueryUrl('tags', 'in-store', true) // {url}?tags=online,omnichannel | |
createQueryUrl('tags', null) // {url} | |
#} | |
{% macro createQueryUrl(key, value, toggleValue = false, fullPath = false) %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* @param {HTMLVideoElement} videoElement | |
*/ | |
export function waitForVideoPlaying(videoElement, duration = 500) { | |
return new Promise((resolve, _reject) => { | |
const seconds = duration / 1000; | |
const timeUpdateHandler = (evt) => { | |
if (evt.target.currentTime > seconds) { | |
evt.target.removeEventListener('timeupdate', timeUpdateHandler); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set currentDay = date(now)|date('Y-m-d') %} | |
{% set comingQuery = craft.entries.section('agenda') | |
.geplandeDatum(['and', '>= '~currentDay]) | |
.orderBy('geplandeDatum ASC') | |
.ids() | |
%} | |
{% set pastQuery = craft.entries.section('agenda') | |
.geplandeDatum(['and', '<'~currentDay]) | |
.orderBy('geplandeDatum DESC') | |
.ids() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$dateParam = $this->request->getRequiredBodyParam('date'); | |
$timezone = new \DateTimeZone($dateParam['timezone']); | |
$date = new \DateTime($dateParam['date'], $timezone); | |
// don't know why, but the date needs the offset | |
// otherwise it gets stored as the previous day | |
$date->add(new \DateInterval('PT'.$date->getOffset().'S')); | |
$element->uid = StringHelper::UUID(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set labels = ['welcome', 'ok', 'cancel'] %} | |
{% set obj = labels|reduce((carry, key) => carry|merge({ (key): key|t|ucfirst }), {}) %} | |
{{ obj|json_encode }} | |
{# as a macro #} | |
{% macro translateToJSON(labels) %}{% spaceless %} | |
{{ labels|reduce((carry, key) => carry|merge({ (key): key|t|ucfirst }), {})|json_encode }} | |
{% endspaceless %}{% endmacro %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* translate(dictionary, key, params) | |
* | |
* Used to bridge twig translations into Vue files where we want to use the pre-translated values of keys in the vue component's template | |
@example | |
props: { | |
labels: { type: String } | |
}, | |
setup() { | |
const state = reactive({ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{% set address = { firstName: 'Stack', lastName: 'Overflow', address: 'here', zipCode: '1234' } %} | |
{% set addressLines = address|keys|reduce((carry, key) => carry|merge({ (key): attribute(address, key) }), []) %} | |
{# results in: [ 'firstName' => 'Stack', 'lastName' => 'Overflow', 'address'=> 'here', 'zipCode' => '1234' ] #} | |
{% set allowedKeys = ['firstName', 'lastName', 'address'] %} | |
{% for key, line in addressLines|filter((v, k) => k in allowedKeys) %} | |
{{ line }}<br/> | |
{% endfor %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mixin for setting the gutter size | |
@mixin row-gutters($size) { | |
margin-right: -$size; | |
margin-left: -$size; | |
> .col, | |
> [class*='col-'] { | |
padding-right: $size; | |
padding-left: $size; | |
} |