Skip to content

Instantly share code, notes, and snippets.

View dotproto's full-sized avatar

Simeon Vincent dotproto

View GitHub Profile
@dotproto
dotproto / async_playground.js
Created November 15, 2017 17:50
An async iteration experiment. I was thinking about RxJS-like observables.
function clickPromise(el) {
// Create pointers for proimse chain methods
let _resolve = null
let _reject = null
const p = new Promise((resolve, reject) => {
// Cache the promise chain methods for future use
_resolve = resolve
_reject = reject
@dotproto
dotproto / scratchpad.js
Last active February 17, 2024 15:31
Simple in-browser scratch pad with bookmark-based "saving." To use, copy and paste the this gist into your URL bar. Once loaded, you can save by dragging the link in the top left corner onto your bookmarks bar.
data:text/html,
<!-- See https://gist.github.com/svincent/699c0a9027bb6bc8298b076e638718f1/edit -->
<a id="link" title="Drag this link onto your bookmark bar to save!">save scratchpad</a>
<div id="editor" contenteditable>Type something here!<div>To save, drag the link in the top right onto your bookmark bar.</div></div>
<style>
:root {
--line-height: 1.5em;
}
* {
@dotproto
dotproto / silver.js
Created September 7, 2017 03:34
Reflect + some customizations
export default var Silver = Object.create(Reflect, {
// ownEntries has a similar API to Object.entries, but it uses the same
// enumeration logic as Reflect.keys
ownEntries: {
writable: true,
enumerable: false,
configurable: true,
value: function(obj) {
return Reflect.ownKeys(obj).map(key => [key, obj[key]]);
}
@dotproto
dotproto / look_into.md
Last active August 26, 2017 00:46
Stuff I should look into.

Project ideas

  • Project boilerplate that has all the basics set up including
    • Set up CI - or at least provide instructions to make it as painless as possible
    • Watch task for linter
    • Watch task for unit tests
    • Integration test
    • Using headless Chrome to do screenshot diffing for CSS regressions
    • Precommit hooks and/or CI hooks for prettier
@dotproto
dotproto / defaults.js
Created July 10, 2017 22:20
Ways of handling parameter defaults in JS
/*
I was just reading through Eric Elliott's ["10 Tips for Better Redux Architecture"](https://medium.com/javascript-scene/10-tips-for-better-redux-architecture-69250425af44) and found myself a little thrown by some of his sample code. Rather than justshrug it off, I took a few minutes to break down the pros/cons of his appoach and a couple other implimentations I was kicking around.
*/
// Eric's original implimentation
const createChat_v1 = ({
id = 0,
msg = '',
user = 'Anonymous',
timeStamp = 1472322852680
// Generate a random hex string of the specified length
var randomHashReadable = function(length = 32) {
const hashLength = Math.ceil(length / 2);
const buffer = crypto.getRandomValues(new Uint8Array(hashLength));
const hex = [].slice.call(buffer).map(val => val.toString(16).padStart(2, '0'));
return hex.join('').substring(0, length);
};
var randomHash = (length = 32) => {
return hex = [].slice.call(crypto.getRandomValues(new Uint8Array(Math.ceil(length / 2)))).map(val => val.toString(16).padStart(2, '0')).join('').substring(0, length);
@dotproto
dotproto / linked-list.js
Last active February 14, 2024 01:52
Linked List implementation that behaves like a stack (last in, first out)
const VOID = Symbol('VOID');
class LinkedItem {
constructor(value) {
this.value = value;
this.next = null;
}
}
class LinkedList {
@dotproto
dotproto / demo.js
Created March 15, 2017 16:27
Observable -> BehaviorSubject
// Open http://reactivex.io/rxjs/manual/overview.html to run this code
var timer = new Rx.Observable((obs) => {
var counter = 0;
var int = setInterval(() => obs.next(++counter), 1000);
return () => {
clearInterval(int);
obs.complete();
}
});
// TODO: I was going through various alternative forms when I realized I was spending too much time on this.
let data = {
"a": "alpha",
"b": "beta,",
"c": "gamma",
"d": "delta",
"e": "epsilon",
"g": "eta",
"h": "theta",
@dotproto
dotproto / class-to-element.js
Created February 8, 2017 10:30
Hlper that attempts to convert a custom element class' name into a valid custom element name.
// PCENChar comes from the Custom Element spec
// PCEN = Potential Custom Element Name
// https://www.w3.org/TR/custom-elements/#custom-elements-core-concepts
const PCEN_CHAR = /[-a-z._0-9\u00B7\u00C0-\u00D6\u00D8-\u00F6\u00F8-\u037D\u037F-\u1FFF\u200C-\u200D\u203F-\u2040\u2070-\u218F\u2C00-\u2FEF\u3001-\uD7FF\uF900-\uFDCF\uFDF0-\uFFFD\u10000-\uEFFFF]/
const VALID_PCEN = new RegExp(`^[a-z]${PCEN_CHAR.source}*-${PCEN_CHAR.source}*$`)
const CAPS = /([A-Z])/g
const INNER_CAPS = /((?!^|[a-z]))([A-Z])/g
function classNameToElementName(Class) {