Skip to content

Instantly share code, notes, and snippets.

@nmn
nmn / utilities.stylex.ts
Created December 12, 2023 09:37
Tailwind Utilities in StyleX
import * as stylex from '@stylexjs/stylex'
export default stylex.create({
sr_only: {
position: 'absolute',
width: 1,
height: 1,
padding: 0,
margin: -1,
overflow: 'hidden',
@nmn
nmn / good-ternaries.js
Created November 30, 2023 10:02
Prettier Experimental Ternaries - Good Cases
const header =
useLayers ?
'\n@layer ' +
grouped.map((_, index) => `priority${index + 1}`).join(', ') +
';\n'
: '';
return useLayers ?
`@layer priority${index + 1}{\n${collectedCSS}\n}`
: collectedCSS;
@nmn
nmn / bad-ternaries.js
Created November 30, 2023 10:02
Prettier Experimental Ternaries - Bad Cases
const exprs =
pathUtils.isTemplateLiteral(path) ? path.get('expressions')
: pathUtils.isTaggedTemplateExpression(path) ?
path.get('quasi').get('expressions')
: [];
// I would want that formated as:
const exprs =
pathUtils.isTemplateLiteral(path) ?
path.get('expressions')
@nmn
nmn / Noteplan.js
Created May 7, 2021 17:38
Noteplan.js Flow Type Declrations
// @flow
type Range = {
start: number;
end: number;
+length: number;
};
declare var Paragraph: TParagraph;
@nmn
nmn / setup.sh
Last active October 2, 2020 23:46
Mac Set-up
#!/usr/bin/env bash
# install Xcode Command Line Tools
# https://github.com/timsutton/osx-vm-templates/blob/ce8df8a7468faa7c5312444ece1b977c1b2f77a4/scripts/xcode-cli-tools.sh
# touch /tmp/.com.apple.dt.CommandLineTools.installondemand.in-progress;
# PROD=$(softwareupdate -l |
# grep "\*.*Command Line" |
# head -n 1 | awk -F"*" '{print $2}' |
# sed -e 's/^ *//' |
# tr -d '\n')
@nmn
nmn / CallFormEditable.user.js
Last active March 8, 2018 07:02
TamperMonkey Scripts for IC
// ==UserScript==
// @name Call Form Editable Still
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Make all View Buttons Edit Buttons
// @author You
// @match https://ic.bdsmarketing.com/IC.DataCollection/HoursCollection.aspx*
// @grant none
// ==/UserScript==
@nmn
nmn / CallFormEditable.js
Created March 1, 2018 08:43
TamperMonkey Scripts for IC
// ==UserScript==
// @name Call Form Editable Still
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Make all View Buttons Edit Buttons
// @author You
// @match https://ic.bdsmarketing.com/IC.DataCollection/HoursCollection.aspx*
// @grant none
// ==/UserScript==
@nmn
nmn / FunctionValue.ts
Last active November 3, 2017 12:25
Magic Flow Type 1: $FunctionXValue —— A magic flow type that takes a function type that takes one arg, the type of that arg, and returns the return value type of the function.
/* @flow */
type $Function1<A, B> = (arg: A) => B;
type _Function1Value<A, B, F: $Function1<A, B>> = B; // eslint-disable-line
type $Function1Value<F: $Function1<*, *>, A> = _Function1Value<A, *, F>;
var toString = (value) => String(value)
var toNumber = (value) => parseFloat(value) || 0
type NumberXString = ((value: number) => string) & ((value: string) => number)
@nmn
nmn / $Values.ts
Last active September 11, 2017 10:48
something like $Keys but for values.
// @flow
/*
This magic type will give you the union of the types of all the values in an object type.
This is still far from a fully dynamic $PropertyType, but it's a lot better than just using `any`
*/
/*
Link:
https://flow.org/try/#0C4TwDgpgBAJA8gIwFYQMbADwDUB8UC8UA3gNQDaA1hCAFxQDOwATgJYB2A5gLp1YC+AKFCQoAfRhYAhgBsArhHrYANFDh14yNJlx5CWIeGgSZ8xWtWb0uscbkKMAKhVwcAt8OiIkBYgKhQSVDo2WQBbBAgmJT8AhDpGVk5o-xJJOgQAewzpCEk2aMEBABM0aUkmaAA3cqhaWCk7M2RXAG4ACjqE9g4oAB8oTOzctj6oEPDIgEo3AHoZ9rqAQSYmSRAMcYimHEmoOagAURWMpgYACwyAdxHUE4r0aRAoM8iIATmF4LCt0a7OXf2RyYJ3OVxudy0j2er3e8w6XwmTABM0Ox1O9Au1ygtxWkKeLwqsM+AyyOTyyNRwPRmPBuIe+JhH3hDGY3QpQJBGLB2Ih9OhhKAA
*/
@nmn
nmn / HOF1.ts
Created April 25, 2017 19:32
a higher-order-function that almost maintains the function signature, but not quite.
type ITask<I: $ReadOnlyArray<mixed>, O> = {
(...r: I): ?O,
lastError?: Error
}
function task <I: $ReadOnlyArray<mixed>, O>(inner: (...r: I) => O): ITask<I, O> {
const wrapped: any = function wrapped() {
try {
return (inner: any).apply(this, arguments)
} catch (err) {