Skip to content

Instantly share code, notes, and snippets.

View donavon's full-sized avatar
🏁
nothing is happening

Donavon West donavon

🏁
nothing is happening
View GitHub Profile
@donavon
donavon / ObjectFromEntries.js
Created April 1, 2020 12:53
buildUrl - constructs a URL from an href and a search query object, e.g. {foo: 'bar'}
// https://github.com/tc39/proposal-object-from-entries/blob/master/polyfill.js
if (!Object.fromEntries) {
Object.fromEntries = function ObjectFromEntries(iter) {
const obj = {};
for (const pair of iter) {
if (Object(pair) !== pair) {
throw new TypeError('iterable for fromEntries should yield objects');
}
@donavon
donavon / reverseArray.js
Last active March 6, 2020 04:54
Reverse an Array in place. Note: No need to swap middle element if there is an off number of elements.
const reverseArray = arr => {
const len = arr.length;
const halfLen = Math.floor(len / 2);
for (let i = 0; i < halfLen; i++) {
const temp = arr[i];
arr[i] = arr[len - i - 1];
arr[len - i - 1] = temp;
}
return arr;
};

Slack Etiquette Tips

Here are some guidelines to think about when deciding to use @here or @channel.

@here Here is a funny article about cats

🚫 Ask yourself “is this timely?” No. An article on funny cats will be there tomorrow, but thx for interrupting my meeting.

@here Leaving for Bob’s going away happy hour in 15 mins 🍷

@donavon
donavon / test_runner.js
Last active January 22, 2020 23:08 — forked from joakimbeng/test_runner.js
A small and simple Javascript test runner
/**
* A Javascript test runner in 20 lines of code
* From http://joakimbeng.eu01.aws.af.cm/a-javascript-test-runner-in-20-lines/
*/
(function () {
// The test queue:
var tests = [];
// Function to add tests:
this.test = function test (name, cb) {
class SignInForm extends React.Component {
constructor() {
super();
this.state = {
username: "",
password: ""
};
}
onChange(key, value) {
@donavon
donavon / index.js
Last active August 29, 2015 14:27
requirebin sketch
var crypto = require("crypto");
function encrypt(data, key, algorithm, encoding) {
algorithm = algorithm || "aes256";
encoding = encoding || "base64";
var cipher = crypto.createCipher(algorithm, key);
return cipher.update(data, "utf8", encoding) + cipher.final(encoding);
}
function decrypt(data, key, algorithm, encoding) {
@donavon
donavon / index.js
Last active August 29, 2015 14:25
requirebin sketch
var Keen = require("keen-js");
var client = new Keen({
projectId: "55b29d1b46f9a76aaee2b60c",
readKey: "3b027fb718e707742d4b21a52138cec2a7b2fc03cc61a68d2712ace541ab511b0e79ba7f5807d919d1bba4f0099e9b2de99ac8e082516ad529767a1c70bc5de0efc71a9c0194748a384d57a576c4d487746aa9a0ef34418f41d84a931228d1620cb58c7b005cee1c76190e824b7426c0"
});
Keen.ready(function(){
var query = null;
@donavon
donavon / index.js
Last active January 25, 2016 20:01
requirebin sketch
var console = require("consoleit"); // remove when running in Node
var crypto = require("browserify-cipher"); // requiring just "cipher" _should_ work, but doesn't
function encrypt(data, key, algorithm, encoding) {
algorithm = algorithm || "aes256";
encoding = encoding || "base64";
var cipher = crypto.createCipher(algorithm, key);
return cipher.update(data, "utf8", encoding) + cipher.final(encoding);
}
@donavon
donavon / index.js
Last active August 29, 2015 14:20
requirebin sketch
// require() some stuff from npm (like you were using browserify)
// and then hit Run Code to run it on the right
var console = require("consoleit");
var compareVersions = require("compare-versions");
function isBricked(appVersion, brickedVersion) {
return brickedVersion && compareVersions(appVersion, brickedVersion) < 1;
}
var brickedVersion = "1.7.4";