Skip to content

Instantly share code, notes, and snippets.

Avatar

James Irwin rebolyte

View GitHub Profile
View reimplement-bind.js
Function.prototype.myBind = function myBind(ctx, ...baseArgs) {
const that = this;
return function (...args) {
that.call(ctx, ...baseArgs, ...args);
}
}
function tester(...args) {
console.log(this.aProp, ...args);
View crypto.js
const crypto = require("crypto");
const algorithm = "aes-256-ctr";
const password = "Password used to generate key";
// Key length is dependent on the algorithm. In this case for aes192, it is
// 24 bytes (192 bits). For ae256, 32 bytes.
// Use async `crypto.scrypt()` instead.
const key = crypto.scryptSync(password, "salt", 32);
// Use `crypto.randomBytes()` to generate a random iv instead of the static iv
// shown here.
View zmq.js
const { Publisher, Subscriber } = require('zeromq');
const PORT = 5000;
const args = process.argv.slice(2);
const TOPIC = args[0] || 'doc1';
let n = 0;
@rebolyte
rebolyte / DefaultKeyBinding.dict
Created Nov 4, 2020 — forked from trusktr/DefaultKeyBinding.dict
My DefaultKeyBinding.dict for Mac OS X
View DefaultKeyBinding.dict
/* ~/Library/KeyBindings/DefaultKeyBinding.Dict
This file remaps the key bindings of a single user on Mac OS X 10.5 to more
closely match default behavior on Windows systems. This makes the Command key
behave like Windows Control key. To use Control instead of Command, either swap
Control and Command in Apple->System Preferences->Keyboard->Modifier Keys...
or replace @ with ^ in this file.
Here is a rough cheatsheet for syntax.
Key Modifiers
View DropZone.tsx
import React, { useState, FunctionComponent, createRef, DragEvent, ChangeEvent } from 'react';
import classNames from 'classnames';
import { useOnMount, isIE } from '@utilities';
export interface Props {
onFileAdded?: (value: File) => any;
disabled?: boolean;
classes?: string;
accepts?: string;
}
View browser-log.ts
export type LogLevel = 'error' | 'warn' | 'info' | 'debug';
export interface LoggerOpts {
level: LogLevel;
}
export type LogMethods = {
[key in LogLevel]: (...messages: any) => void;
};
@rebolyte
rebolyte / typescript-intro.md
Last active May 13, 2020
TypeScript basic intro
View typescript-intro.md

TypeScript intro

James Irwin
7-Jun-2018

TypeScript is a typed superset of JavaScript. All JavaScript is valid TypeScript, and TS transpiles to JS to run in browsers (much like Babel transpiles ES6+ to ES5). In transpilation, all types are stripped out; you get type-checking at compile-time only (but run-time type-checking is needed much less because of it). It is developed by Microsoft, powers apps you know like VS Code, and is in use at companies like Lyft, Reddit, and Slack.

Definition files

TypeScript lets you use existing JavaScript libraries in a strongly-typed manner by providing type definition files, which are separate files that annotate a given library's API. When you go to import lodash, you will likely also want to import @typings/lodash, which will install a lodash/index.d.ts file in your dependencies. So

View await-promise-sequential.js
// Promise.resolve(ids).then(ids => {
// return ids.reduce((cur, next) => {
// return cur.then(() => {
// return doThingThatReturnsPromise(next);
// });
// }, Promise.resolve());
// }).then(() => {
// console.log('all done');
// }).catch(err => {
// console.error(err);
@rebolyte
rebolyte / UserAlerts.js
Last active May 13, 2020
Webpack script-loader problems
View UserAlerts.js
if (Ext4 === undefined) { window.Ext4 = Ext; }
Ext4.define('UserAlerts', (function () {
return {
extend: 'WidgetBase',
height:40,
data: {},
cls: 'UserAlerts',
listeners: {