Skip to content

Instantly share code, notes, and snippets.

🐍

Gus Caplan devsnek

🐍
Block or report user

Report or block devsnek

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 proposals.md
  • iterator helper methods
  • import.meta
  • function.sent
  • repl parse goal
  • Math methods for bigint
  • Number.range, BigInt.range
View x.js
new Promise((resolve, reject) => {
const timeout = setTimeout(() => {
clearInterval(interval);
reject(new Error('timed out'));
}, 5000);
const interval = setInterval(() => {
const x = doSomething();
if (x !== undefined) {
clearInterval(interval);
clearTimeout(timeout);
View WeakValueMap.mjs
const KEYS = 1;
const VALUES = 2;
const KEYS_VALUES = 3;
export default class WeakValueMap {
#map = new Map();
#group = new FinalizationGroup((iterator) => {
for (const key of iterator) {
this.#map.delete(key);
}
View ZoneWithPromiseTracking.mjs
import EventEmitter from 'events';
import {
AsyncResource,
executionAsyncId,
createHook,
} from 'async_hooks';
const zones = new Map();
export default class Zone extends EventEmitter {
View Zone.js
'use strict';
const {
AsyncResource,
executionAsyncId,
createHook,
} = require('async_hooks');
const EventEmitter = require('events');
const util = require('util');
View react_hooks_but_not_broken.js
'use strict';
const stateMap = new WeakMap();
function useState(key, init) {
const update = (v) => stateMap.set(key, v);
if (stateMap.has(key)) {
return [stateMap.get(key), update];
}
stateMap.set(key, init);
return [init, update];
View step.diff
diff --git a/.eslintrc.js b/.eslintrc.js
index fee700a..37d2a52 100644
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -29,6 +29,8 @@ module.exports = {
'no-restricted-syntax': 'off',
'no-use-before-define': 'off',
'no-continue': 'off',
+ 'no-extra-parens': 'error',
+ 'require-yield': 'off',
View IteratorStuff.js
'use strict';
const IteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf(
[][Symbol.iterator](),
),
);
const AsyncIteratorPrototype = Object.getPrototypeOf(
Object.getPrototypeOf(
View eshost.js
'use strict';
const {
initializeAgent,
inspect,
Realm,
Value,
Descriptor,
Abstract,
Completion,
View Zone.js
'use strict';
const {
AsyncResource,
executionAsyncId,
createHook,
} = require('async_hooks');
const EventEmitter = require('events');
const util = require('util');
You can’t perform that action at this time.