Skip to content

Instantly share code, notes, and snippets.

View dysfunc's full-sized avatar
:octocat:
No talent clown 🤡

Kieran Boyle dysfunc

:octocat:
No talent clown 🤡
View GitHub Profile
@dysfunc
dysfunc / app.svelte
Last active February 23, 2024 22:23
Svelte - Simple pull to refresh
<script>
import Refresher from './refresher.svelte';
const onRefresh = async () => {
await new Promise(res => setTimeout(res, 2000));
}
</script>
<Refresher {onRefresh}>
<div id="app">This is my cool Svelte app! (switch to mobile emulator)</div>
@dysfunc
dysfunc / IMPORT-GITHUB-LABELS.md
Last active May 14, 2024 00:40
Importing labels collection into GitHub Repo

Useful labeling system used in all my repositories.

const labels = [
  {
@dysfunc
dysfunc / EXPORT-IMPORT-GITHUB-LABELS.md
Last active February 20, 2021 17:58
Export & Import GitHub Labels
  • Visit the labels page you want to copy
  • Open the Developer Console
  • Paste this snippet and hit enter
const labels = [];
const list = [].slice.call(document.querySelectorAll(".js-label-link"));

list.forEach((element) => {
  labels.push({
@dysfunc
dysfunc / aspect-ratio.js
Created March 15, 2020 23:17
Determine the aspect ratio of something
/**
* Finds the greatest common divisor (GCD) by determining the highest
* number that evenly divides both numbers
* @param {Number} width Width of the object
* @param {Number} height Height of the object
* @return {Number} GCD number
*/
const gcd = (width, height) => height === 0 ? width : gcd(height, width % height);
/**
@dysfunc
dysfunc / simple-drag.MD
Created March 12, 2019 18:48
Simple JS Draggable Script

JS:

const setTranslate = (x, y, element) => {
  element.style.transform = `translate3d(${x}px, ${y}px, 0)`;
};

/**
 * Simple Draggable Utility
 * @param {String}   selector    CSS Selector of the container element
 * @param {String}   dragElement CSS Selector of the drag handler element (optional)
@dysfunc
dysfunc / angular-deep-extend.js
Last active March 2, 2017 01:30
angular.extend - shallow + deep copy (supports merging of arrays and deduping)
/**
* Deep copy example:
* angular.extend(true, { hello: 'world', app: { id: '1234', groups: [{ id: 1},2,3,4,5] }, ids: [1,2,3] }, { app: { name: 'bond', groups: [6, 7, {hello:'world', test: [1,2,3,4, [12,34,45]]}, 9] }, ids: [4,5,6,3] });
* => "{"hello":"world","app":{"id":"1234","groups":[{"id":1},2,3,4,5,6,7,{"hello":"world","test":[1,2,3,4,[12,34,45]]},9],"name":"bond"},"ids":[1,2,3,4,5,6,3]}"
*
* Deep copy and dedup arrays
* angular.extend(true, true, { hello: 'world', app: { id: '1234', groups: [{ id: 1},2,3,4,5] }, ids: [1,2,3] }, { app: { name: 'bond', groups: [6, 7, {hello:'world', test: [1,2,3,4, [12,34,45]]}, 9] }, ids: [4,5,6,3] });
* => "{"hello":"world","app":{"id":"1234","groups":[{"id":1},2,3,4,5,6,7,{"hello":"world","test":[1,2,3,4,[12,34,45]]},9],"name":"bond"},"ids":[1,2,3,4,5,6]}"
*
* vs jQuery deep copy