osx Command Files
copy #!/ bin/ bash cd "$(dirname " $0")" . ~/ .nvm / nvm.sh nvm use stable && npm run dev
Then name that file “whatever.command”. When you double-click it, it’ll launch a terminal and run the command. I pop these in my dock for projects I’m always opening…
Escape HTML
copy const el = document.createElement ( 'div' ) const txt = document.createElement ( 'textarea' ) txt.innerHTML = '× © <script>alert("bang!")<\/ script>' el.innerText = txt.innerText document.body .appendChild ( el) const theHtml = document.createElement ( 'div' ) theHtml.innerText = txt.innerHTML document.body .appendChild ( theHtml)
Try it out…
Just a hack to escape html strings… guessing most would use a lib for this…
Label Thoughts
copy main: { header: { { 'Tasker' } newCol: { 'New Column' } } columns: { scroll: { NoteCols: { } } } } NoteCol: { title: { [ 'editable' , 'focus' ] close: { { '×' } } } newNote: { [ 'editable' , 'placeholder="New Note..."' ] } hr: { } noteContainer: { Notes: { } } } Note: { [ 'focus' ] close: { { '×' } } checkbox: { } content: { [ 'edtiable' ] } } console.log ( 'no errors :D' ) ;
Try it out…
The above is actually valid javascript, just a bunch of labels, blocks and a few arrays
selectAll Thoughts
copy const lookup = new WeakMap( ) let id = 0 ; export const els = selectAll( document.body ) export const parentOf = el => lookup.get ( el) export function selectAll( parent) { const els = { id, el: parent, all: { } } const allEls = [ ...parent .querySelectorAll ( '*' ) ] id++ for ( let i in allEls) { const el = allEls[ i] // any element can lookup `els` lookup.set ( el, els) const tag = el.tagName .toLowerCase ( ) if ( el.id ) { els[ el.id ] = el tag === 'template' && ( els[ el.id + 'Tmpl' ] = ( ) => { const instanceEl = el.content .cloneNode ( true ) .firstElementChild return selectAll( instanceEl ) } ) } if ( el.classList .length > 0 ) { const name = el.classList [ 0 ] if ( ! els[ name] ) { els[ name] = el els.all [ name] = [ el] } else { els.all [ name] .push ( el) } } } return els; }
Whenever I code a vanilla gui for some personal project/experiment I write some variation of this. I did this one a few days back to see how it would work with template
tags.
charAt
copy '0123' .charAt ( '1' ) // -> '1' '0123' .charAt ( 1.45 ) // -> '1' '0123' .charAt ( true ) // -> '1' '0123' .charAt ( ) // -> '0' '0123' .charAt ( NaN ) // -> '0' '0123' .charAt ( - 1 ) // -> '' Number .prototype .charAt = String .prototype .charAt NaN .charAt ( ) // -> 'N' Boolean .prototype .charAt = Boolean .prototype .charAt true .charAt ( ) // -> t
Funny snippet from Räphael’s creator Dmitry Baranovskiy’s talk Zen of JavaScript
Here is the part where he talks about this:
VIDEO