Skip to content

Instantly share code, notes, and snippets.

@ugate
ugate / array.has.dups.js
Last active July 16, 2020 20:31
Coding Challenges (Arrays)
/**
* Checks an array for duplicates
* @param {*[]} arr The array to check for duplicates
* @returns {Boolean} True when there are duplicates, false when there are none
*/
function hasDuplicate(arr) {
for (let i = 0, j, ln = arr.length; i < ln; ++i) {
for (j = i + 1; j < ln; ++j) {
if (arr[i] === arr[j]) return true;
}
@ugate
ugate / recursive-file-paths-generator.js
Last active June 3, 2020 13:51
Recursively traverses a directory capturing all of the file paths in that directory and sub-directories yielding each path asynchronously
const Fs = require('fs');
const Path = require('path');
/**
* Generates a set of file paths by recursively traversing the given directory
* @param {String} dir The directory to traverse
* @param {Boolean} [join] Truthy to use `path.join` vs the _default_ concatination
* @yields {String} The next file path in the traversal
*/
async function* files(dir, join) {
@ugate
ugate / githubToBitbucket.sh
Last active March 20, 2020 17:47
Migrate repositories from GitHub to Bitbucket
# Clone the Github repository
git clone --mirror https://github.com/<YOUR GITHUB ACCT>/<YOUR GITHUB REPO NAME>.git
# Change working directory to the newly created repo dir
cd <YOUR REPO NAME>.git
# Set the URL to the new repo origin
git remote set-url --push origin https://<YOUR BITBUCKET ACCT>@bitbucket.org/<YOUR BITBUCKET USER OR ORG>/<YOUR BITBUCKET REPO NAME>
# Push the mirror to the Bitbucket repo (should prompt you for your Bitbucket credentials in popup)
git push --mirror
<!DOCTYPE html>
<html lang="en">
<head>
<title>Pixel Editor</title>
<style>
.row {margin-left: auto;margin-right: auto;margin-bottom: 20px;} .row:after {content: "";display: table;clear: both;}
.row .col {float: left;-webkit-box-sizing: border-box;-moz-box-sizing: border-box;box-sizing: border-box;padding: 0 0.75rem;text-align: left;}
.row .col.s1 {width: 8.33333%;margin-left: 0;} .row .col.s2 {width: 16.66667%;margin-left: 0;} .row .col.s3 {width: 25%;margin-left: 0;} .row .col.s4 {width: 33.33333%;margin-left: 0;} .row .col.s5 {width: 41.66667%;margin-left: 0;}
.row .col.s6 {width: 50%;margin-left: 0;} .row .col.s7 {width: 58.33333%;margin-left: 0;} .row .col.s8 {width: 66.66667%;margin-left: 0;} .row .col.s9 {width: 75%;margin-left: 0;} .row .col.s10 {width: 83.33333%;margin-left: 0;}
.row .col.s11 {width: 91.66667%;margin-left: 0;} .row .col.s12 {width: 100%;margin-left: 0;} .row .col.offset-s1 {margin-left: 8.33333%;} .row .col.offset-s2 {margin-left: 16.66667%;} .row .col.offset-
/**
* Contitional directive that evaluates each template literal expression for
* [truthiness](https://developer.mozilla.org/en-US/docs/Glossary/Truthy). Each expression that evaluates to a _truthy_
* value will include the string following the expression in the return value. Any string preceding the first expression
* will be included in the result.
* @example
* truthy`${ it.myValue === 123 }
* <div>
* This will be included in the result when <code>myValue === 123</code>
* </div>
/**
* `String.prototype.replace` alternative that supports `async` _replacer_ functions
* @private
* @ignore
* @param {String} str The string to perform a replace on
* @param {RegExp} regex The regular expression that the replace will match
* @param {Function} replacer An `async` function that operates the same way as the function passed into `String.prototype.replace`
*/
async function replace(str, regex, replacer) {
const mtchs = [];
@ugate
ugate / setup.sh
Last active November 28, 2022 17:53
NTC C.H.I.P. setup script
#!/bin/bash
LC_ALL=en_US.UTF-8
# configures/installs common CHIP features (including enabling disabled ones)
# run 'sudo chmod +x setup.sh && ./setup.sh' to run the installation
clear
res=
dtc=
rboot=
uname -a
cat << _EOF_
@ugate
ugate / gitHubMail.js
Last active August 29, 2015 14:12
Sends an email every time an issue is created or commented on using script.google.com and a GitHub Webhook
var secretToken = 'SECRET';
var sendTo = 'nodejs@googlegroups.com';
var org = 'node-forward';
var repo = 'help';
var prefix = '[' + org + '-' + repo + ']';
var rx = new RegExp('\\[(' + org + ')-(' + repo + ')\\][\\s\\S]+\\(#(\\d+)', 'i');
// recieving issue/comments from GitHub
function doPost(e) {
return toMailingList(e, JSON.parse(e.postData.getDataAsString()));
@ugate
ugate / oraganize.js
Last active August 29, 2015 14:11
Organizes files into directories with a yyyy-mm format
//======================================================================================================
// Looks in the current directory for a move directory, cycles all the files moving them to a new or
// existing directory with the format yyyy-mm using the file name as a date indicator. When the file
// is an MP4 it will be moved to yyyy-mm-VIDS
//
// Can be batched in a Windows organize.bat using the following:
//
// node /your/path/to/files/and/organize.js --stack
// PAUSE
//