This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Gunar C. Gessner | |
@gunar 2016 | |
INSTALL: https://script.google.com/macros/s/AKfycbym7IaTORzJ7LQPcxMx1LV1SQEC6RVGv5tzLOgYS8iQe8XAJxM/exec | |
After installation, the script will, every 10 minutes, search for all files that have duplicates (shift+z) and remove them from the root directory ("My Drive"). | |
This Google Apps Script webapp aims to solve the problem that when transferring ownership of folders & | |
files to another account, duplicate files shown in "My Drive". |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const { HDPublicKey, PublicKey, Address, Networks } = require('bitcore-lib') | |
const xpubkey = 'xpub...' | |
const hdPublicKey = HDPublicKey(xpubkey); | |
// We'll generate the first 20 addresses (default number of addresses that Electrum shows you) | |
for (let i = 0; i < 20; i++) { | |
const orderPublicKey = hdPublicKey.deriveChild(`m/0/${i}`) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
const toUpper = async string => { | |
if (string === 'invalid') return [Error('Invalid input')] | |
return [null, string.toUpperCase()] | |
} | |
const errorHandler = () => { console.log('There has been an error. I\'ll handle it.') } | |
const print = console.log | |
const foo = async input => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
// ref https://en.wikipedia.org/wiki/Cycle_sort | |
const cycleSort = array => { | |
// last item will already be in place | |
for (let cycleStart = 0; cycleStart < array.length-1; cycleStart++) { | |
let item = array[cycleStart] | |
// find where to put the item | |
let pos = cycleStart |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Currying Functions with Named Parameters. | |
* @gunar, @drboolean, @dtipson 2016 | |
* | |
* Why does it return a thunk, though? | |
* Because in JS named arguments are opaque. There is no way of getting a function's named arguments list. | |
* e.g. | |
* const foo = function ({ a, b }) { } | |
* console.log(foo.arguments) // Throws. Ideally would return ['a', 'b']. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState, createRef } from "react"; | |
const Form = () => { | |
const emailRef = createRef<HTMLInputElement>() | |
return ( | |
<div> | |
Email: | |
<input type="text" ref={emailRef}/> | |
<button | |
onClick={() => { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { useState } from 'react' | |
const Form = () => { | |
const [key, setKey] = useState(0) | |
return ( | |
<div key={key}> | |
<input type='text' /> | |
<button onClick={/* ... */}>Submit</button> | |
<button onClick={() => { setKey(key + 1) }}>Reset</button> | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Property-based test | |
describe('properties', () => { | |
it('is a bijection', () => { | |
fc.assert(fc.property( | |
fc.integer(1, Number.MAX_SAFE_INTEGER), | |
seed => decode(encode(seed)) === seed | |
)) | |
}); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Proof: https://www.typescriptlang.org/play/#src=type%20Woman%20%3D%20%7B%0D%0A%20%20id%3A%20Number%0D%0A%20%20husband%3F%3A%20string%0D%0A%7D%0D%0A%0D%0Atype%20With%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20(Required%3CPick%3CT%2C%20K%3E%3E%20%26%20Exclude%3CT%2C%20K%3E)%0D%0Atype%20Without%3CT%2C%20K%20extends%20keyof%20T%3E%20%3D%20Pick%3CT%2C%20Exclude%3Ckeyof%20T%2C%20K%3E%3E%0D%0A%0D%0Aconst%20processMrs%20%3D%20(mrs%3A%20With%3CWoman%2C%20'husband'%3E)%20%3D%3E%20%7B%0D%0A%20%20%20%20const%20%7B%20husband%20%7D%20%3D%20mrs%0D%0A%20%20%20%20console.log(%60I%20now%20for%20a%20fact%20%24%7Bmrs%7D%20is%20married.%60)%0D%0A%7D%0D%0AprocessMrs(%7B%20id%3A%201%2C%20husband%3A%20'John'%20%7D)%20%20%20%20%2F%2F%20passes%0D%0AprocessMrs(%7B%20id%3A%202%2C%20husband%3A%20undefined%20%7D)%20%2F%2F%20fails%20(with%20strictNullChecks%3A%20true)%0D%0AprocessMrs(%7B%20id%3A%203%20%7D)%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%2F%2F%20fails%20(with%20strictNullChecks%3A%20true)%0D%0A%0D%0Aconst |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Property-based Testing example (pseudo-code). | |
test([Number], anArrayOfNumbers => { | |
// ↑↑↑↑↑↑↑↑↑↑ ↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑↑ | |
// The schema. The generated test-data. | |
assert.deepEqual( | |
mySort([anArrayOfNumbers]), | |
Array.prototype.sort.call(anArrayOfNumbers) | |
) | |
}) |
NewerOlder