Skip to content

Instantly share code, notes, and snippets.

Kris Selden krisselden

Block or report user

Report or block krisselden

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
View util.rs
use serde::de::DeserializeSeed;
use serde::de::Error;
use serde::de::SeqAccess;
use serde::de::Visitor;
use serde::Deserialize;
use serde::Deserializer;
use std::convert::From;
use std::fmt;
use std::fmt::Display;
use std::marker::PhantomData;
View copy.rs
#[derive(Debug, Clone, Copy)]
enum MyRef<'a> {
String(&'a str),
Bytes(&'a [u8]),
}
impl<'a> Into<&'a str> for MyRef<'a> {
fn into(self) -> &'a str {
if let MyRef::String(s) = self {
s
View lifetime.rs
struct Path<'a> {
path: &'a str,
}
impl<'a> Path<'a> {
fn new(path: &str) -> Path {
Path { path }
}
fn query(&self) -> &'a str {
View shallow.rs
#[derive(Debug, Clone)]
struct SomeTuple<'a>(&'a str, &'a [u8]);
fn main() {
let mut owned = String::new();
owned.push_str("Hello");
owned.push_str(" World");
owned.push('!');
let strref: &str = &owned;
View top_40_bundle_source_size_changes.r
#!/usr/bin/env Rscript
app.name = "My App"
# file you gave source-map-explorer
# source-map-explorer 1.0.1/bundle.js --tsv > bundle-1.0.1.tsv
# source-map-explorer 1.5.0/bundle.js --tsv > bundle-1.5.0.tsv
asset.file = "bundle.js"
before.version = "1.0.1"
before.file = "bundle-1.0.1.tsv"
before.description = "1.0.1 (Jun 01)"
View checknestederror.js
/**
* Create error with caused by and formatted stack trace while preserving
* the laziness of the stack trace serialization.
*/
function createErrorWithCausedBy(name, message, causedBy) {
const error = new Error(message);
error.name = name;
if (Error.captureStackTrace) {
// hides createErrorWithCausedBy from the stack
Error.captureStackTrace(error, createErrorWithCausedBy);
View output.log
❯ ./out/x64.optdebug/d8 --allow-natives-syntax teststack.js
DebugPrint: 0x2bf167d0b3f9: [JS_ERROR_TYPE]
- map: 0x2bf153b4a549 <Map(HOLEY_ELEMENTS)> [FastProperties]
- prototype: 0x2bf15ffc62e1 <Object map = 0x2bf153b40fe9>
- elements: 0x2bf156880c21 <FixedArray[0]> [HOLEY_ELEMENTS]
- properties: 0x2bf156880c21 <FixedArray[0]> {
#stack: 0x2bf1946002f9 <AccessorInfo> (const accessor descriptor)
0x2bf156884a71 <Symbol: (stack_trace_symbol)>: 0x2bf167d0b619 <FixedArray[1]> (const data field 0)
}
0x2bf153b4a549: [Map]
View tag.ts
// requires strict mode
// set false to minimize out runtime checks
const DEBUG = true;
export const enum TagTypes {
A,
B,
// C
/* adding this will cause Tag and unreachable to Error
View monomorphic_wrapper.js
// Monomorphic wrapper for polymorphic value
wrapper = {
type,
value
}
// CheckMap wrapper for .type lookup monomorphic
if (wrapper.type === 1) {
// CheckMap value for .somefield lookup monomorphic because in branch for one type
wrapper.value.somefield
View ustat_exact.js
// Copyright 2019 Kris Selden BSD 2-CLAUSE LICENSE
// math used is public domain just dont copy my code without giving credit.
// @ts-check
/**
* @typedef {{get(U: number, n1: number, n2: number): number; set(U: number, n1: number, n2: number, count: number): void;}} ICache
*/
You can’t perform that action at this time.