Skip to content

Instantly share code, notes, and snippets.

View davidgilbertson's full-sized avatar

David Gilbertson davidgilbertson

  • Sydney, Australia
View GitHub Profile
@davidgilbertson
davidgilbertson / Python-List.py.groovy
Last active August 23, 2023 20:37
Custom extractor for PyCharm - copy tables to a list of dicts
View Python-List.py.groovy
import static com.intellij.openapi.util.text.StringUtil.escapeStringCharacters as escapeStr
SEPARATOR = ", "
QUOTE = "\""
NEWLINE = System.getProperty("line.separator")
def record(columns, dataRow) {
OUT.append(" {").append(NEWLINE)
columns.eachWithIndex { column, idx ->
View KeyframeLR.py
import timeit
import math
from typing import Sequence, Mapping, Literal, Callable
from torch.optim import Optimizer
from torch.optim.lr_scheduler import LRScheduler
class KeyframeLR(LRScheduler):
def __init__(
View deconstructions.csv
Word Deconstruction
it's it ~is
years year ~s
going go ~ing
that's that ~is
i'm i ~am
things thing ~s
states state ~s
including include ~ing
called call ~ed
View testing.py
print('Hello from testing.py')
View Select.tsx
type Nullable<IdType, RequiredType> = RequiredType extends true ? IdType : IdType | null;
export type SelectProps<IdType extends string, RequiredType extends boolean> = {
options: Array<{id: IdType; name: string}>;
selectedItemId: Nullable<IdType, RequiredType>;
onSelect: (id: Nullable<IdType, RequiredType>) => void;
required?: RequiredType;
};
const Select = <IdType extends string, RequiredType extends boolean>(
View SelectConsumer.tsx
<Select
selectedItemId={selectedItemId}
onSelect={setSelectedItemId}
options={[
{value: Size.Small, children: 'Small'},
{value: Size.Medium, children: 'Medium'},
{value: Size.Large, children: 'Large', disabled: true},
]}
required
/>
View Select.tsx
type Nullable<IdType, RequiredType> = RequiredType extends true ? IdType : IdType | null;
type OptionProps<IdType> = React.ComponentProps<'option'> & {
value: IdType;
};
const Select = <IdType extends string, RequiredType extends boolean>(props: {
options: Array<OptionProps<IdType>>;
selectedItemId: Nullable<IdType, RequiredType>;
onSelect: (id: Nullable<IdType, RequiredType>) => void;
View Select.tsx
type BaseProps<IdType> = {
options: Array<{id: IdType; name: string}>;
};
type PropsWhenOptional<IdType> = BaseProps<IdType> & {
required?: false;
selectedItemId?: IdType | null;
onSelect: (id: IdType | null) => void;
};
View makeBigger.ts
const makeBigger = <T extends string | number>(stringOrNumber: T) => {
if (typeof stringOrNumber === 'string') {
return stringOrNumber.toUpperCase();
}
return (stringOrNumber * 4);
};
View makeBigger.ts
const makeBigger = (stringOrNumber: string | number) => {
if (typeof stringOrNumber === 'string') {
return stringOrNumber.toUpperCase();
}
return stringOrNumber * 4;
};