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 / 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 / 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) {
@nmn
nmn / $HOC.ts
Created March 4, 2017 01:30
A generalized type-def for Higher-Order Components in React.
type HOC<InjectedProps, ExtraProps, Args: $ReadOnlyArray<*>> = <D, P, C: React$Component<D, P, any>>(
component: Class<C>,
...rest: Args
) => Class<React$Component<D, $Diff<P, InjectedProps> & ExtraProps, any>>;
declare var injectName: HOC<{name: string}, {bla: Array<number>}, [string, number]>;
type Props = {
name: string,
age: number,
@nmn
nmn / HaskellySkewHeap.swift
Last active December 22, 2016 02:06
Swift Skew Heap
// https://en.wikipedia.org/wiki/Skew_heap#Implementation
import Foundation
indirect enum SkewHeap<T> where T: Equatable, T: Comparable {
case Empty
case Node(T, SkewHeap<T>, SkewHeap<T>)
}
func singleton<T>(_ a: T) -> SkewHeap<T> where T: Equatable, T: Comparable {
return .Node(a, .Empty, .Empty)
@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
*/