Skip to content

Instantly share code, notes, and snippets.

Cheat sheet: JavaScript Array methods

Deriving a new Array from an existing Array:

['■','●','▲'].slice(1, 3)           ['●','▲']
['■','●','■'].filter(x => x==='■')  ['■','■']
    ['▲','●'].map(x => x+x)         ['▲▲','●●']
    ['▲','●'].flatMap(x => [x,x])   ['▲','▲','●','●']
@pgib
pgib / README.md
Created May 21, 2020 20:23
Clean up the bloated Backblaze bzfileids.dat

Place in /Library/Backblaze.bzpkg/bzdata/bzbackup, and run with:

ruby purge_nonexistent.rb

It will process bzfileids.dat placing any file that exists in bzfileids.dat-found and any missing file in bzfileids.dat-missing. You can then back up your original file and replace it with bzfileids.dat-found.

My original file was almost 1.4GB. It had grown so large that the backup would cause all my fans spin and it never seemed to complete. Backblaze support suggested I delete my entire backup with them and start over. After running this script, my new bzfileids.dat file is 301MB. Still huge, but about 1/5th the size. The backup seemed to go much more smoothly.

@yosriady
yosriady / SimpleToken.sol
Last active October 19, 2019 06:27
Sample code for 'Getting Started with Smart Contracts' talk at geekcamp.sg
pragma solidity ^0.5.11;
contract SimpleToken {
string public constant name = "GeekCamp Token";
string public constant symbol = "GEEK";
uint8 public constant decimals = 0;
address public minter;
mapping (address => uint) private _balances;
@souporserious
souporserious / window-zoom.js
Created October 15, 2019 22:00
Checks if window has been zoomed.
// modified from https://stackoverflow.com/a/52008131/1461204
const zoomEvent = new Event('zoom')
let currentRatio = window.devicePixelRatio
function checkZooming() {
if (currentRatio !== window.devicePixelRatio) {
window.dispatchEvent(zoomEvent)
}
}