Skip to content

Instantly share code, notes, and snippets.

View dotproto's full-sized avatar

Simeon Vincent dotproto

View GitHub Profile
@dotproto
dotproto / functional_helpers.js
Last active February 14, 2024 01:52
Helper functions I didn't realize I wanted until I wrote them a few times in several different projects. Uses ES6 module syntax.
// ====================
// = OBJECT HELPERS =
// ====================
export const set = (obj, prop, val) => {
obj[prop] = val
return obj
}
export const extractObj = (obj, prop) =>
Object.keys(obj).map(key =>
@dotproto
dotproto / .gitconfig
Last active December 5, 2016 18:47
git aliases
[alias]
# List all aliases
aliases = ! git config --get-regexp ^alias\\. | sed -e s/^alias\\.// -e s/\\ /\\ =\\ /
# Edit your git configuration (cfg)
cfg = config -e --global
# Show the (last) commit
last = log -1
# last = show HEAD
@dotproto
dotproto / unicode_string_comparison.js
Last active January 20, 2017 02:38
Examining raw unicode values and their normalized forms. TL:DR; comparing unicode strings using a `.normalized()` and `. localeCompare()`
// References
//
// - https://tc39.github.io/ecma262/#sec-ecmascript-language-types-string-type
// - http://unicode.org/reports/tr15/#Norm_Forms
// - http://unicode.org/faq/normalization.html#7 (What is the difference is between W3C normalization and Unicode normalization?)
// - https://developer.mozilla.org/en-US/docs/Web/API/DOMParser
//
// Resources
//
// - http://stackoverflow.com/questions/8936984/uint8array-to-string-in-javascript
@dotproto
dotproto / proxy_test.js
Last active February 14, 2024 01:53
Some test code generated while trying to wrap my head around how JS proxies work and how I might leverage them
// Resources
//
// - http://exploringjs.com/es6/ch_proxies.html
// - https://github.com/tvcutsem/harmony-reflect/issues/41
// - https://esdiscuss.org/topic/proxies-stratifying-tostring-valueof
// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy
// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/toPrimitive
// - https://console.spec.whatwg.org/#inspection
// NOTE: When Chrome logs "Symbol(Symbol.toPrimitive)", that corisponds to
@dotproto
dotproto / test.js
Created August 11, 2016 21:58
Exploring Proxies & [Symbol.toPrimitive]
// http://www.ecma-international.org/ecma-262/6.0/#sec-symbol.toprimitive
let base = {
[Symbol.toPrimitive] : hint => {
console.log(`toPrimitive hint: ${hint}`)
return 1;
},
valueOf: () => 2,
toString: () => '3',
};
@dotproto
dotproto / ng-util.js
Last active February 14, 2024 01:53
Utilities for working with and debugging Angular.js 1.x apps (ES6)
(function exposeNgUtil(target = window) {
if (!angular) {
console.error(`ERROR: ng-util cannot initialize because "angular" was not found!`);
return null;
}
getScope = el => angular.element( (el || document.getElementsByClassName('ng-scope')[0]) )
let ngUtils = {
// Use Angular.js' DI system to retrieve a provider.
let sourceObject = { foo: { bar: { baz: { qux: { value: "Hit!" } } } } };
sourceObject.foo[Symbol.for('symbol')] = 'symbol value';
function lookup(object, path) {
path = Array.isArray(path) ? path : path.split('.');
for(let i = 0; i < path.length; i++) {
object = object[path[i]];
if (!object) break;
@dotproto
dotproto / property_lookup.js
Last active May 26, 2016 01:11
`lookup` provides a failable wait to retrieve a deep property without throwing (Function version)
var sourceObject = { foo: { bar: { baz: { qux: { value: "Hit!" } } } } };
function lookup(targetObject, targetPath) {
const name = 'o';
const properties = [];
const segments = targetPath.split('.');
for (let i = 1; i <= segments.length; i++) {
const current = `${name}.${segments.slice(0, i).join('.')}`;
properties.push(current);
@dotproto
dotproto / tts.js
Last active February 14, 2024 01:53
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…
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 / inheritance.js
Last active February 14, 2024 01:53
JS Inheritance (ES5)
// == PARENT ===================================================================
// CONSTRUCTOR
// For this demo we'll be inheriting from the Parent class
function Parent() {}
// METHODS
Parent.prototype.foo = function foo() {
return 'FOO';
}