Skip to content

Instantly share code, notes, and snippets.

@jimjam88
jimjam88 / v1.js
Last active November 17, 2023 13:09
Pair Programming Scripts
const contacts = {};
let prospectiveUsersCache = {};
const isZiinaUser = (phoneNumber) => {
return false;
};
const syncContacts = (userId, phoneNumbers) => {
contacts[userId] = phoneNumbers;
@jimjam88
jimjam88 / css-bem.ts
Created July 17, 2023 09:18
CSS BEM class names builder
type Modifiers = {
[key: string]: any,
}
export const toClassNames = (base: string, modifiers: Modifiers = {}): string => {
const mods = Object
.entries(modifiers)
.filter(([, value]) => !!value)
.map(([key, _]) => `${base}--${key}`);
@jimjam88
jimjam88 / _spacing.scss
Created July 13, 2023 10:51
SCSS Baseline spacing units
$baseline: 6px !default;
$xxs: $baseline * 0.5 !default; // 3px
$xs: $baseline * 1 !default; // 6px
$s: $baseline * 2 !default; // 12px
$m: $baseline * 4 !default; // 24px
$l: $baseline * 8 !default; // 48px
$xl: $baseline * 16 !default; // 96px
$xxl: $baseline * 32 !default; // 192px
@jimjam88
jimjam88 / TimeAgo.tsx
Created July 13, 2023 10:44
Update date-fns formatDistanceToNow automatically
import React, {memo, useCallback, useEffect, useRef, useState} from 'react';
import formatDistanceToNow from 'date-fns/formatDistanceToNow';
type TimeAgoProps = {
timestamp: number,
}
const UPDATE_DELTA_MS = 10000; // 10s
const getTimeAgo = (timestamp: number): string => `${formatDistanceToNow(new Date(timestamp))} ago`;
@jimjam88
jimjam88 / PaginationCalculator.ts
Last active July 18, 2024 19:33
TypeScript Pagination Values Calculator
import range from "lodash.range";
type PageRangeArgs = {
size?: number,
last: number,
current: number,
}
type PageRangeReturnValue = number[];
@jimjam88
jimjam88 / usage.js
Created August 9, 2022 14:55
Hook to handle single/double taps in react native
import React from 'react';
import { Pressable, Text } from 'react-native';
import { useDoubleTapHandler } from './useDoubleTapHandler';
const UsageExample = () => {
const onPressHandler = useDoubleTapHandler();
const onPress = () => {
onPressHandler({
onSinglePress: () => console.log('Single Tap'),
@jimjam88
jimjam88 / punctuate.js
Created August 1, 2022 07:54
Punctuation helper
const punctuate = (items = []) => {
const amount = items.length;
return items.reduce((acc, item, index) => {
if (amount === 1) {
return item;
}
return index === (amount - 1)
? `${acc} and ${item}`
Calculating region TransACT...
http://serv-cache.alib.sg3.yahoo.com:4080/tv/1.0/channels;output=json;location=au;provider=0;region=128;begin=1498536768;end=1498547588
92.66KB in 0.763975s
Calculating region Foxtel...
http://serv-cache.alib.sg3.yahoo.com:4080/tv/1.0/channels;output=json;location=au;provider=0;region=168;begin=1498536768;end=1498547588
485.207KB in 1.202114s
Calculating region Optus TV feat. Foxtel...
http://serv-cache.alib.sg3.yahoo.com:4080/tv/1.0/channels;output=json;location=au;provider=0;region=192;begin=1498536768;end=1498547588
273.661KB in 1.413676s
Calculating region Fetch...
@jimjam88
jimjam88 / multibyteUnicode.php
Last active October 7, 2015 00:17
Multibyte unicode as PHP array
<?php
return [
/**
* 2 Byte unicode characters.
*/
'2byte' => [
'À','Á','Â','Ã','Ä','Å','Ă','Æ','Ç','È','É','Ê','Ë','Ì','Í','Î','Ï','Ð',
'Ñ','Ò','Ó','Ô','Õ','Ö','Ő','Ø','Ș','Ț','Ù','Ú','Û','Ü','Ű','Ý','Þ','ß',
'à','á','â','ã','ä','å','ă','æ','ç','è','é','ê','ë','ì','í','î','ï','ð',
@jimjam88
jimjam88 / multibyte-unicode.txt
Created October 6, 2015 23:49
Multi-byte Unicode Examples
2 byte unicode:
---------------
À Á Â Ã Ä Å Ă Æ Ç È É Ê Ë Ì Í Î Ï Ð Ñ Ò Ó Ô Õ Ö Ő Ø Ș Ț Ù Ú Û Ü Ű Ý Þ ß à á â ã
ä å ă æ ç è é ê ë ì í î ï ð ñ ò ó ô õ ö ő ø ș ț ù ú û ü ű ý þ ÿ أ ب ت ث ج ح خ د
ذ ر ز س ش ص ض ط ظ ع غ ف ق ك ل م ن ه و ي α β γ δ ε ζ η θ ι κ λ μ ν ξ ο π ρ σ τ υ
φ χ ψ ω ά έ ί ό ύ ή ώ ς ϊ ΰ ϋ ΐ Α Β Γ Δ Ε Ζ Η Θ Ι Κ Λ Μ Ν Ξ Ο Π Ρ Σ Τ Υ Φ Χ Ψ Ω
Ά Έ Ί Ό Ύ Ή Ώ Ϊ Ϋ
3 byte unicode
--------------