Skip to content

Instantly share code, notes, and snippets.

Simeon Vincent dotproto

Block or report user

Report or block dotproto

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
@dotproto
dotproto / scratchpad.js
Last active Sep 21, 2017
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.
View scratchpad.js
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 Sep 7, 2017
Reflect + some customizations
View silver.js
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 Aug 26, 2017
Stuff I should look into.
View look_into.md

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 / tts.js
Last active Aug 4, 2017
ES2015 Text to Speech bookmarklet (Ctrl+S). Set up: Copy and paste the contents of this gist into a new bookmark. Use: Select some text and click the bookmarklet to start speaking. Once activated on a page, you can use Ctrl+S to speak the selected text. Speech Synthesis API Info: https://developers.google.com/web/updates/2014/01/Web-apps-that-ta…
View tts.js
javascript: {
/* Adjust voice speed. Default = 1 */
var speed = 2.5;
if (window.runTTS === undefined) {
/* Text to Speech function. Adjust the value of msg.rate to increase/decrease the playback speed. */
window.runTTS = () => {
const text = window.getSelection().toString();
@dotproto
dotproto / defaults.js
Created Jul 10, 2017
Ways of handling parameter defaults in JS
View defaults.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
View hash-utils.js
// 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 Jun 6, 2017
Linked List implementation that behaves like a stack (last in, first out)
View linked-list.js
const VOID = Symbol('VOID');
class LinkedItem {
constructor(value) {
this.value = value;
this.next = null;
}
}
class LinkedList {
@dotproto
dotproto / demo.js
Created Mar 15, 2017
Observable -> BehaviorSubject
View demo.js
// 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();
}
});
View setup.js
// 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 Feb 8, 2017
Hlper that attempts to convert a custom element class' name into a valid custom element name.
View class-to-element.js
// 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) {
You can’t perform that action at this time.