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 type { Typeof } from './typeof'; | |
| type TypeofString = TypeofStringDefined | 'undefined'; | |
| type TypeofStringDefined = 'object' | 'function' | 'string' | 'number' | 'bigint' | 'boolean' | 'symbol'; | |
| type Recursive = { next: Recursive }; | |
| type RecursiveTest = Test<Same<Typeof<Recursive>, 'object'>>; | |
| type Conditional<T> = T extends string ? number : boolean; |
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 Box<T> = { t: string, value: T } | |
| type A =1; | |
| type B= {a:0} | |
| type C= 'hi' | |
| const boxes1 = [ | |
| { t: 'number', value: 1 satisfies A } , | |
| { t: 'object',value: {a:0} satisfies B }, | |
| { t: 'string',value: 'hi' satisfies C }, | |
| ] as const satisfies Box<any>[]; |
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
| function density(x: unknown) { | |
| const paths = new Set<string>(); | |
| const children = Array.from(gChildren(x)); | |
| // discover paths | |
| for (const [, child] of children) { | |
| for (const [path] of gPaths(child, 'primitives')) { | |
| paths.add(JSON.stringify(path)); | |
| } | |
| } |
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 { expect, describe, it } from 'bun:test'; | |
| import jsonVariantsHandler, { JSON_VARIANTS, variantToFormat } from '../../src/handlers/jsonVariants.js'; | |
| import CommonFormats from '../../src/CommonFormats.ts'; | |
| import { FileFormat } from '../../src/FormatHandler.js'; | |
| describe('jsonVariants', () => { | |
| const encoder = new TextEncoder(); | |
| const decoder = new TextDecoder(); | |
| const jsonFormat = CommonFormats.JSON.supported('json', true, true, true); |
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
| interface Config { | |
| port: number | |
| log_file: string; | |
| log_level: 'error' | 'warning' | 'info' | |
| } | |
| const config = exact<Config>(['port','log_file','log_level']); | |
| const src = {port: 1000, log_file: 'stdout', log_level: 'info', junk: 'more'} as Config | |
| const x = config(src); |
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
| #include <stdio.h> | |
| #include <time.h> | |
| #include <stdlib.h> | |
| #include <math.h> | |
| #include <stdbool.h> | |
| int randexp() { | |
| double lambda = 0.05; | |
| double u = (double)rand() / RAND_MAX; | |
| int sign = rand() % 2 == 0 ? 1 : -1; |
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
| // This visitor implementation attemps to make the best of both worlds, between C#'s functional features and compile-time safety. | |
| // Using extension methods as visitors makes it a runtime error for there not to be an equivalent visitor for every subclass of the element hierarchy. | |
| // This approach ensures compile-time safety, while minimizing boilerplate. It's a step closer to the ideal of "if it compiles, it works". | |
| using System; | |
| Room room = new Bathroom(10); | |
| RoomVisitor visitorPrintSurface = new( | |
| bathroom => Console.WriteLine($"Surface of bathroom: {bathroom.Surface}"), |
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
| public static bool IsInDirectory(this FileInfo file, DirectoryInfo directory) => file.Directory?.IsInDirectory(directory) ?? false; | |
| [SuppressMessage("Globalization", "CA1309", Justification = "Path comparison")] | |
| public static bool IsInDirectory(this DirectoryInfo path, DirectoryInfo directory) | |
| => path.Parent != null && (path.Parent.FullName.Equals(directory.FullName, StringComparison.InvariantCultureIgnoreCase) || path.Parent.IsInDirectory(directory)); |
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
| /// <typeparam name="TSender">The type of the source of the event.</typeparam> | |
| /// <typeparam name="TEventArgs">The type of event data generated by the event.</typeparam> | |
| /// <remarks>Type-safe variation from <see cref="EventHandler{TEventArgs}"/>.</remarks> | |
| /// <inheritdoc cref="EventHandler{TEventArgs}"/> | |
| [Serializable] | |
| [SuppressMessage("Naming", "CA1711", Justification = "Type-safe event handler pattern")] | |
| public delegate void TypeEventHandler<TSender, TEventArgs>(TSender sender, TEventArgs e); | |
| /// <typeparam name="TSender">The type of the source of the event.</typeparam> | |
| /// <remarks>Type-safe variation from <see cref="EventHandler"/>.</remarks> |
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
| private static void EnsureAdminPrivileges() | |
| { | |
| if (new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator)) | |
| { | |
| return; | |
| } | |
| ProcessStartInfo processInfo = new(Environment.ProcessPath.NotNull()) | |
| { | |
| UseShellExecute = true, | |
| Verb = "runas" |
NewerOlder