Skip to content

Instantly share code, notes, and snippets.

Avatar
🕛
Code

Salvatore dested

🕛
Code
View GitHub Profile
View fancytypes.ts
export type Discriminate<T, TField extends keyof T, TValue extends T[TField]> = T extends {[field in TField]: TValue}
? T
: never;
type UnionToIntersection<U> = (U extends any ? (k: U) => void : never) extends (k: infer I) => void ? I : never;
type IsUnion<T, U extends T = T> = T extends unknown ? ([U] extends [T] ? false : true) : false;
type IsStringUnion<T> = IsUnion<T> extends true ? (T extends string ? true : false) : false;
View process-assets.js
let glob = require('glob');
let fs = require('fs');
const prettier = require('prettier');
var readJson = (path, cb) => {
fs.readFile(require.resolve(path), (err, data) => {
if (err) cb(err);
else cb(JSON.parse(data));
});
};
View sort-bools.js
const m = [
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 10},
{firstOrder: false, secondOrder: true, thirdOrder: false, rank: 15},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 12},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 16},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 21},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 54},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 13},
{firstOrder: false, secondOrder: false, thirdOrder: false, rank: 30},
{firstOrder: true, secondOrder: false, thirdOrder: false, rank: 35},
View react-native-with-css-full.tsx
import React from 'react';
import {Image, ScrollView, StyleProp, TextStyle, View, ViewProps, ViewStyle} from 'react-native';
export interface WithCssProps {
classNames?: string[];
parentComponentTree?: ComponentTree;
siblingsLength?: number;
childIndex?: number;
style?: StyleProp<TextStyle>;
}
View react-native-with-css.tsx
import React from 'react';
import {StyleProp, TextStyle, View, ViewProps, ViewStyle} from 'react-native';
export interface WithClassProps {
classNames?: string[];
componentTree?: ComponentTree;
style?: StyleProp<TextStyle>;
}
type ComponentTree = {
View react-native-css-attempt
export class Screen extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {};
}
render() {
return (
<CView classNames={['a']}>
<CView classNames={['b']}>
View typescript-validate.ts
/*! *****************************************************************************
Copyright (C) Microsoft. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
View js-virtual-machine.js
function Evaluate(method, parameters) {
var instructionsOld = method.Instructions;
var stack = new Array(method.MaxStack);
var locals = new Array(method.LocalCount);
// var True = this.True;
// var False = this.False;
var lastStack;
var tempQ;
var tempIndex1;
var tempParameters;
View dotgame.js
const width = 7;
const height = 7;
let grid = new Array(width * height);
const WALL = 0;
const DOT = 1;
const EMPTY = 2;
for (let x = 0; x < width; x++) {
for (let y = 0; y < height; y++) {
View color-sorter.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Color Sorter</title>
<style>
body {
background-color: black;
flex: 1;
display: flex;;