Skip to content

Instantly share code, notes, and snippets.

View mendes5's full-sized avatar
๐Ÿ“‰
[object Object]

mendes5

๐Ÿ“‰
[object Object]
View GitHub Profile
@mendes5
mendes5 / ugh...md
Created May 11, 2021 18:55
Regex flags
'abcdefghijklmnopqrstuvwxyz'
  .split('')
  .map(x => { try { new RegExp('0', x); return x } catch { return false } } )
  .filter(Boolean)
  .join('')

Chrome

dgimsuy (sorted automatically)

@mendes5
mendes5 / parse.js
Last active April 25, 2021 05:26
Parses the data from NCDU dump file https://dev.yorhel.nl/ncdu/jsonfmt, the folder sizes are probably wrong tho....
var computeDirSize = (list) =>
list.reduce((prev, curr) => {
if (curr.type === "FOLDER") {
return computeDirSize(curr.children) + prev;
} else {
return curr.value + prev;
}
}, 0) || 0;
var readFile = file => ({
type LoadedKey<Key extends string> = `is${Key}Loaded`;
type SuccessKey<Key extends string> = `is${Key}Success`;
type ErrorKey<Key extends string> = `is${Key}Error`;
type LoadingKey<Key extends string> = `is${Key}Loading`;
type Entity<Name extends string> = {
[_ in LoadedKey<Name>]: boolean;
} & {
[_ in SuccessKey<Name>]: boolean;
} & {
let ctx = document.createElement('canvas')
document.body.appendChild(ctx)
ctx.width = 500
ctx.height = 500
let gl = ctx.getContext('webgl')
gl.viewport(0, 0, 500, 500)
gl.clearColor(0.0, 0.0, 0.0, 1.0)
export type PropsOf<P> = P extends React.ComponentType<infer T> ? T : P extends React.Component<infer T> ? T : never;
@mendes5
mendes5 / add.rs
Last active February 5, 2021 05:03
V8 vs Deno Call Overhead Test
fn add(
scope: &mut v8::HandleScope,
args: v8::FunctionCallbackArguments,
mut rv: v8::ReturnValue,
) {
let first = match v8::Local::<v8::Number>::try_from(args.get(0)) {
Ok(s) => s.value(),
Err(_) => {
let msg = v8::String::new(scope, "Invalid argument").unwrap();
let exception = v8::Exception::type_error(scope, msg);
const cycleValue = (value: number, cycleLength: number): number => {
if (value > 0) return value % cycleLength;
if (value < 0) return value + cycleLength;
return 0;
};
/**
* Given a cycleLength, this hook will return a value that is
* in the range of 0 and cycleLength. It also return methods to change
export const urlToImageFile = (url: string, { backgroundColor = '#000' }): Promise<File> => {
const image = new Image();
const promise = new Promise<File>((resolve, reject) => {
image.addEventListener('load', function () {
const canvas = document.createElement('canvas');
canvas.width = this.width;
canvas.height = this.height;
const context = canvas.getContext('2d');
export const svgToFile = (svg: SVGElement): Promise<File> => {
const canvas = document.createElement('canvas');
canvas.width = Number(svg.getAttribute('width') || '0');
canvas.height = Number(svg.getAttribute('height') || '0');
const context = canvas.getContext('2d');
const xml = new XMLSerializer().serializeToString(svg);
@mendes5
mendes5 / driller.cs
Created October 26, 2020 04:55
SpaceEngineers fully automatic quarry
string drilsGroupName = "Drills";
string mergeBlockTopName = "Merge Block (Top)";
string mergeBlockBottomName = "Merge Block (Bottom)";
string bodyPistonGroupName = "Pistons (Body)";
string drillPistonGroupName = "Pistons (Drill)";
string connectorsGroupName = "Connectors (Main)";
string rotorName = "Rotor Main";
struct DrillState {
public float lastAngle;