Skip to content

Instantly share code, notes, and snippets.

@sladg
sladg / merge-deep.spec.ts
Created March 22, 2019 15:36
Merging nested objects
import { assert } from 'chai'
import { mergeDeep as merge } from './'
describe('mergeDeep', () => {
it('should merge object properties without affecting any object', () => {
const obj1 = { a: 0, b: 1 }
const obj2 = { c: 2, d: 3 }
const obj3 = { a: 4, d: 5 }
const actual = { a: 4, b: 1, c: 2, d: 5 }
@sladg
sladg / vast-example.xml
Last active July 2, 2019 10:54
VAST_example
<?xml version="1.0" encoding="utf-8"?>
<VAST version="2.0">
<Ad id="229">
<InLine>
<AdSystem version="4.9.0-10">LiveRail</AdSystem>
<AdTitle><![CDATA[LiveRail creative 1]]></AdTitle>
<Description><![CDATA[]]></Description>
<Impression id="LR"><![CDATA[http://t4.liverail.com/?metric=impression&cofl=0&pos=0&coid=135&pid=1331&nid=1331&oid=229&olid=2291331&cid=331&tpcid=&vid=&amid=&cc=default&pp=&vv=&tt=&sg=&tsg=&pmu=0&pau=0&psz=0&ctx=&tctx=&coty=0&adt=0&scen=&url=http%3A%2F%2Fwww.longtailvideo.com%2Fsupport%2Fopen-video-ads%2F23120%2Fwhat-is-vast%2F&cb=1259.192.118.68.5.0.690&ver=1&w=&wy=&x=121&y=121&xy=0b79&z2=0]></Impression>
<Creatives>
<Creative sequence="1" id="331">
@sladg
sladg / Nested Pick (Typescript)
Created June 20, 2022 09:25
Safely pick nested properties from object using dot-path.
type GetIndexedField<T, K> = K extends keyof T
? T[K]
: K extends `${number}`
? '0' extends keyof T
? undefined
: number extends keyof T
? T[number]
: undefined
: undefined;
type FieldWithPossiblyUndefined<T, Key> =
@sladg
sladg / Keystone6-Tailwind3-integration
Created February 7, 2022 17:46
Simple wrapper for custom Keystone6 routes to provide Tailwind styling for components. Supports core plugins and custom configuration (as long as not relying on additional plugins beside tailwind's core).
import React, { FC, useState } from 'react'
import { PageContainer } from '@keystone-6/core/admin-ui/components'
import Script from 'next/script'
import tailwindConfig from '../tailwind.config.js'
import Head from 'next/head'
import { ApolloProvider } from '@apollo/client'
import client from '../utils/graphql/apollo-client'
const styles = `
@tailwind base;
@sladg
sladg / generate.sh
Created October 14, 2022 14:30
Changelog generator - easy from tags
#!/bin/bash
# Author: Jan Soukup
echo "CHANGELOG"
echo ----------------------
git tag | tr - \~ | sort -V --reverse | tr \~ - | while read TAG; do
echo
if [ $NEXT ]; then
echo [$NEXT]
else
echo "[Current]"
@sladg
sladg / useHover.ts
Created July 27, 2022 14:03
Util function for handling hover for both touch and mouse.
import { useState, HTMLAttributes, useRef, useEffect } from 'react'
export interface UseHoverOptions {
mouseEnterDelayMS?: number
mouseLeaveDelayMS?: number
}
export type HoverProps = Pick<HTMLAttributes<HTMLElement>, 'onMouseEnter' | 'onMouseLeave'>
export const useHover = ({ mouseEnterDelayMS = 0, mouseLeaveDelayMS = 0 }: UseHoverOptions = {}): [boolean, HoverProps] => {
@sladg
sladg / useScroll.ts
Created July 27, 2022 14:03
Simple util function for handling scrolls in react-virtual
import { MutableRefObject, useCallback, useRef } from 'react'
interface UseScrollToProps {
parentRef: MutableRefObject<HTMLDivElement>
}
// https://gist.github.com/gre/1650294
const easeInOutQuint = t => {
return t < 0.5 ? 16 * t * t * t * t * t : 1 + 16 * --t * t * t * t * t
}
@sladg
sladg / CloudCompare from source
Created February 26, 2023 22:07
Build CloudCompare with Conda (Qt5, GDAL, PDAL support). Compiles from source, CLI works.
# meta.yaml (use conda build ./path-to-directory-with-this-file
package:
name: cloudcompare
version: v2.12.4
source:
git_url: https://github.com/CloudCompare/CloudCompare.git
git_rev: v2.12.4
build:
@sladg
sladg / PotreeConverter from source
Last active February 26, 2023 22:26
Build PotreeConverter via Conda. Compatible with Linux (use fork for MacOS)
# meta.yaml (use conda build ./path-to-directory-with-this-file
package:
name: potreeconverter
version: 2.1.1
source:
git_url: https://github.com/potree/PotreeConverter.git
git_rev: 2.1.1
@sladg
sladg / Shopify GTM integration
Created March 29, 2023 10:08
Free way how to connect your GTM onto Shopify without additional plugins or apps.
// use "{{ 'analytics-head.js' | asset_url | script_tag }}" inside your liquid files. Namely `theme.liquid`.
var layerName = 'customDataLayer'
var gtmId = 'GTM-XXXXXX'
// ------------------------------
// Load GTM in head, initialize dataLayer.
;(function (w, d, s, l, i) {
console.log('Initializing GTM ...')
w[l] = w[l] || []