A simple TypeScript Grid. Written by Jon Wire for articles on jonwire.com.
This may evolve over time for use in a variety of articles and play. If you'd like this in library form as an NPM package, let me know in the comments.
A simple TypeScript Grid. Written by Jon Wire for articles on jonwire.com.
This may evolve over time for use in a variety of articles and play. If you'd like this in library form as an NPM package, let me know in the comments.
| /** | |
| * Incorrect example from https://x.com/BenjDicken/status/1857449788893286484 | |
| */ | |
| function incorrect(baseLoopSize: number) { | |
| const array = new Array(baseLoopSize); | |
| const innerLoopSize = baseLoopSize * 10; | |
| for (let i = 0; i < baseLoopSize; i++) { | |
| for (let j = 0; j < innerLoopSize; j++) { | |
| array[i] = array[i] + j; | |
| } |
| if [ "$color_prompt" = yes ]; then | |
| # this one should be active. it is ... | |
| # <blue>directory</blue><br /><green>user@host</green>$ | |
| PS1='\n\[\033[00;34m\]\w\[\033[00m\]\n${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]\$ ' | |
| else | |
| PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ ' | |
| fi | |
| unset color_prompt force_color_prompt | |
| # If this is an xterm set the title to user@host:dir |
| /* | |
| * Infects an object with a multi-cast property and method "mirroring". | |
| * | |
| * ``` | |
| * observe(source, ['property_a', 'property_b', 'method_a']).mirror(target); | |
| * ``` | |
| * | |
| * The `target` object will be invoked with the same calls/values as those | |
| * made against the `source` on the listed properties and methods -- or | |
| * ALL enumerable properties and methods if non are given. |
| var node = document.createElement('div'); | |
| node.innerHTML = "you know. hwhatever"; | |
| document.body.insertBefore(node, document.body.firstElementChild); | |
| var subnode1 = document.createElement('div'); | |
| subnode1.innerHTML = "you know. hwhatever again (1)"; | |
| node.appendChild(subnode1); | |
| var subnode2 = document.createElement('div'); | |
| subnode2.innerHTML = "you know. hwhatever again (2)"; |
| var overload = function(...overloads) { | |
| const f = function(...args) { | |
| let constructorArray = args.map(arg => arg.constructor); | |
| let implIndex = f.overloads.findIndex(sig => { | |
| return constructorArray.length === sig.length && | |
| constructorArray.every((o,i) => o === sig[i]) | |
| ; | |
| }) + 1; | |
| if (implIndex > 0 && typeof(f.overloads[implIndex]) === 'function') { | |
| return f.overloads[implIndex].apply({}, args); |
bookmarklet code.| from copy import deepcopy | |
| def insert_dict_leaves(source, additions): | |
| rv = deepcopy(source) | |
| for k, v in additions.items(): | |
| if not (k in rv and isinstance(rv[k], dict)): | |
| rv[k] = v | |
| elif isinstance(v, dict): | |
| rv[k] = insert_dict_leaves(rv[k], v) | |
| else: |
| def map_dict_leafs(d, f): | |
| rv = {} | |
| for k, v in d.items(): | |
| if isinstance(v, dict): | |
| rv[k] = map_dict_leafs(v, f) | |
| else: | |
| rv[k] = f(v) | |
| return rv |