Skip to content

Instantly share code, notes, and snippets.

View o0101's full-sized avatar
πŸ–οΈ
Netscaping

Cris o0101

πŸ–οΈ
Netscaping
View GitHub Profile
@o0101
o0101 / explanation.md
Created April 18, 2018 10:03
Switch Branch + Block Scope : ECMAScript

Block scope can be used in switch statements. It's sort of a nice syntax that allows you to defined same-named variables without getting 'already defined' errors.

The example is not so great because data could be rewritten to be let data; at the top of the function, rather than in each case block.

Blocking scoping is pretty useful.

@o0101
o0101 / redact.js
Last active August 28, 2020 10:30
"use strict";
{
const forbidden = new Set(["Facebook", "Zuckerberg", "Trump", "alt-left", "Syria", "Trump's", "racist", "liberal", "alt-right"]);
const tw = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); const actions = [];
while( tw.nextNode() ) {
const text = tw.currentNode;
if ( text.parentElement.tagName !== 'SCRIPT' && text.parentElement.tagName !== 'STYLE' ) {
actions.push( () => redact( text, forbidden ));
}
}; actions.forEach( a => a() );
@o0101
o0101 / global_error_catcher.js
Created March 29, 2018 15:17
Add this 1 liner to your front end code to catch and display errors when debugging on mobile.
window.onerror = (m,u,l,c,e) => (alert(`Exception: ${m} @ ${u} line ${l} column ${c}\n${e ? e.stack : ''}`), true);
@o0101
o0101 / record format
Last active August 28, 2020 10:31
format
recordname:product-detail
repeatall:nextpage click:.nav-nxt-btn
name:string innerText:.name-prd
price:float innerText:.sale-price
pageuri:url attr:href:.detail-view-lnk
// i want to create something viral
// and interesting
// for other developers to do and get behind
// people don't need frameworks - we have enough
// we don't need prop formats, such as b64, etc
// we have enough
// what if i mix both?
// a framework, a website, a delivery system in a format?
@o0101
o0101 / sketch.js
Created November 1, 2017 15:35
download page html
"use strict";
{
const page = document.documentElement.outerHTML;
const pageBlob = new Blob([page]);
const objectURL = URL.createObjectURL(pageBlob);
const anchor = document.createElement('a');
anchor.target = "_new";
anchor.setAttribute('download','page.html');
anchor.href = objectURL;
anchor.innerText = 'download page.html';
@o0101
o0101 / index.js
Last active November 1, 2017 07:55
requirebin sketch
"use strict";
{
const {get:edit_distance} = require('fast-levenshtein');
const SEN_MARK = {
en: [ ".", "!", "?", "()", "[]" ],
zh: [ "。", "γ€Œγ€", "!", "?", "οΌˆοΌ‰", "οΌ»οΌ½", "【】", "γ€Šγ€‹", "γ€ˆγ€‰"],
es: [ ".", "'", '"', ";", "Β‘!", "ΒΏ?", "β€œβ€", "β€˜β€™" ],
hi: [ "|", ";", "?", "!", "”" ],
ar: [ ".", "؟", ":", "β€œβ€" ]
};
@o0101
o0101 / domimage.js
Last active November 4, 2017 05:26
(async function (){
try {
const {width,height} = getDOMRect();
const doc = document.implementation.createHTMLDocument('');
doc.write(document.head.outerHTML);
const dom = getSelectedDOMOrBody();
doc.write(dom.outerHTML);
doc.documentElement.setAttribute('xmlns', doc.documentElement.namespaceURI);
const page = `<article id=fantasticprogress style="z-index:1000000000;width:100vw;height:100vh;position: fixed;top:0;left:0;background:rgba(50,50,50,0.5);display:flex;justify-content:center;align-items:center;">
@o0101
o0101 / index.js
Created October 25, 2017 09:31
requirebin sketch
"use strict";
{
const doc = document.implementation.createHTMLDocument('');
let html;
html = document.documentElement.innerHTML;
doc.write(html);
doc.documentElement.setAttribute('xmlns', doc.documentElement.namespaceURI);
html = (new XMLSerializer).serializeToString(doc);
console.log(html);
@o0101
o0101 / index.js
Last active March 6, 2018 04:39
requirebin sketch
const dc = require("dosycrypt");
self.dc = dc;
const page = ({message:message = ''}={}) => `
<title>DOSYCRYPT</title>
<meta name=viewport content="width=device-width, initial-scale=1">
<style>
:root, body, input, textarea, button {
background: orange; color: white;
}