- A = [xA, yA] is a point on the 2D plane. Same for B, C, ...
- lengths are in any unit (ex: pixels)
- code snippets are in JavaScript
angleRad = angleDeg * Math.PI / 180;
| JSON.fix = function(obj) { | |
| return obj.replace(/(['"])?([a-zA-Z0-9_]+)(['"])?:/g, '"$2": '); | |
| }; |
| function* crossBridge() { | |
| const reply = yield 'What is your favorite color?'; | |
| console.log(reply); | |
| if (reply !== 'yellow') return 'Wrong!' | |
| return 'You may pass.'; | |
| } | |
| { | |
| const iter = crossBridge(); | |
| const q = iter.next().value; // Iterator yields question |
| function getUserId(fbid) { | |
| return fbid.split(':')[1]; | |
| } | |
| requireLazy( | |
| ['MercuryTypingReceiver', 'MercuryThreads', 'ShortProfiles'], | |
| (MercuryTypingReceiver, MercuryThreads, ShortProfiles) => { | |
| MercuryTypingReceiver | |
| .get() |
| var noteValues = { | |
| 'C0': 16.35, | |
| 'C#0': 17.32, | |
| 'Db0': 17.32, | |
| 'D0': 18.35, | |
| 'D#0': 19.45, | |
| 'Eb0': 19.45, | |
| 'E0': 20.60, | |
| 'F0': 21.83, | |
| 'F#0': 23.12, |
| import { h, Component } from 'preact'; | |
| /** Creates a new store, which is a tiny evented state container. | |
| * @example | |
| * let store = createStore(); | |
| * store.subscribe( state => console.log(state) ); | |
| * store.setState({ a: 'b' }); // logs { a: 'b' } | |
| * store.setState({ c: 'd' }); // logs { c: 'd' } | |
| */ |
| var fs = require('fs'); | |
| var crypto = require('crypto'); | |
| fs.readFile('file.pdf', function(err, data) { | |
| var checksum = generateChecksum(data); | |
| console.log(checksum); | |
| }); | |
| function generateChecksum(str, algorithm, encoding) { | |
| return crypto |
As you start out with your Electron app, you'll start to notice some features which have been carried directly across from the browser realm but make less sense for a desktop app. Here are the ones I can remember:
In Electron just like in Chrome, if you hold down the Ctrl key (or ⌘ on Mac) while clicking a link it opens in a new window. For many SPA apps, this is undesired and will load another full copy of your app in another window. You can disable this by calling the following code once you've created a BrowserWindow
win = new BrowserWindow({ ... });| # below is my prompt-y bit of choice: `current-dir ~ ` | |
| #export PS1="\[\e[33m\]\W \[\e[35m\]~ \[\e[m\]" | |
| #export PROMPT_COMMAND='echo -ne "\033]0;${PWD/#$HOME/~}\007"' | |
| # or something a little fancier: `current-dir <random fruit>` | |
| #FRUITS=(🍎 🍐 🍊 🍋 🍌 🍉 🍇 🍓 🍒 🍑 🍍 🥝) | |
| #export PS1="\[\e[33m\]\W \[\e[35m\]${FRUITS[$(echo $RANDOM%12 | bc)]} \[\e[m\]" | |
| # for a new fruit on each line, rather than one per session | |
| # export PROMPT_COMMAND='echo -ne "${FRUITS[$(echo $RANDOM%12 | bc)]} "' | |
| alias zed="open -a /Applications/zed.app" |