This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Ported from https://github.com/jquense/react-big-calendar/blob/7e6ee161b516ed62bbce5ba6923f53eae8323c37/src/localizers/date-fns.js | |
| import { Culture, DateLocalizer, DateRange, Formats } from 'react-big-calendar'; | |
| import { getDay, Locale, startOfWeek, format as _format, isSameMonth, FormatOptions } from 'date-fns'; | |
| import { ensureDate } from 'src/Utils/time'; | |
| function ensureDate(d: string | number | Date): Date { | |
| if (d instanceof Date) { | |
| return d; | |
| } else if (is(Number, d)) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| open Npgsql | |
| connectionString = "..." | |
| let builder = new NpgsqlDataSourceBuilder(connectionString) | |
| let dataSource = builder.EnableUnmappedTypes().UseNodaTime().Build() | |
| let mappingSchema = MappingSchema() | |
| let inline optionToDataParameter<'T> (d: 'T option) = |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| var formatter = new ExpressionTemplate("{ {@t, @m, @r, @l: if @l = 'Information' then undefined() else @l, @x: if Length(@x) > 10000 then Concat(Substring(@x, 0, 9997), '...') else @x, ..@p} }\n") | |
| LoggerConfiguration().WriteTo.Console(formatter) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // from https://stackoverflow.com/a/50612218 | |
| export function binarySearch<X>(xs: X[], x: X) { | |
| let start = 0; | |
| let end = xs.length - 1; | |
| while (start <= end) { | |
| let mid = Math.floor((start + end) / 2); | |
| if (xs[mid] === x) { | |
| return mid; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // from https://github.com/Gautam-Arora24/resize-observer-hook/blob/master/src/index.js | |
| type UseResizeObserverMode = 'borderBoxSize'|'contentBoxSize'|'contentRect'; | |
| export function useResizeObserver<T extends Element>(option: UseResizeObserverMode = 'contentRect') | |
| : [React.MutableRefObject<T|null>, number|undefined, number|undefined] { | |
| const ref = useRef<T|null>(null); | |
| const [height, setHeight] = useState<number|undefined>(); | |
| const [width, setWidth] = useState<number|undefined>(); | |
| const handleResize: ResizeObserverCallback = useCallback(entries => { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #ifndef UTIL_SUBJECT_H | |
| #define UTIL_SUBJECT_H | |
| #include <memory> | |
| #include <forward_list> | |
| #include <functional> | |
| /** | |
| * Simple observer pattern in modern C++ without pointers. | |
| * Register functions with make_observer() and call notify() to call them. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| export interface MultiLineTextProps extends React.SVGProps<SVGTextElement> { | |
| children: string[]; | |
| } | |
| export function MultiLineText({ children, ...rest }: MultiLineTextProps) { | |
| if(children.length === 0) { | |
| return <></>; | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| export function computeTextLength(content: string, fontSize?: string) { | |
| const svgns = "http://www.w3.org/2000/svg"; | |
| // create elements | |
| const svg: SVGSVGElement = document.createElementNS(svgns, 'svg'); | |
| const text: SVGTextElement = document.createElementNS(svgns, 'text'); | |
| text.textContent = content; | |
| if(fontSize) { | |
| text.style.fontSize = fontSize; | |
| } | |
| // hook them into dom |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import React from 'react'; | |
| import { isArray } from 'lodash'; | |
| export function wrapText(s: string|undefined, maxLength: number): string[] { | |
| if(s === undefined) { | |
| return []; | |
| } else if(s.length < maxLength) { | |
| return [s]; | |
| } else { | |
| const lastSpaceIndex = s.lastIndexOf(' ', maxLength); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| type SuaveSerilogAdapter(logger: Serilog.ILogger) = | |
| let parser = Serilog.Parsing.MessageTemplateParser() | |
| let write (level: Suave.Logging.LogLevel) (messageFactory: Suave.Logging.LogLevel -> Suave.Logging.Message) = | |
| let message = messageFactory level | |
| let level = | |
| match level with | |
| | Suave.Logging.LogLevel.Debug -> Serilog.Events.LogEventLevel.Debug | |
| | Suave.Logging.LogLevel.Verbose -> Serilog.Events.LogEventLevel.Verbose | |
| | Suave.Logging.LogLevel.Info -> Serilog.Events.LogEventLevel.Information |
NewerOlder