Skip to content

Instantly share code, notes, and snippets.

View courtneymyers's full-sized avatar
:electron:
🤔🤔🤔

Courtney Myers courtneymyers

:electron:
🤔🤔🤔
View GitHub Profile
// https://www.youtube.com/watch?time_continue=24&v=YSni7t2ktMA
const puppeteerChrome = require('puppeteer');
const puppeteerFirefox = require('puppeteer-firefox');
(async function() {
try {
async function test(browser) {
const page = await browser.newPage();
await page.goto('https://reactjs.org/');
@courtneymyers
courtneymyers / chunkArray.js
Last active January 10, 2019 20:39
Utility function for spitting an array into chunks.
// Helpful if you're working with a very large array, that you need to send to a web server for processing.
// For example, after chunking the array, you can send a number of request to a web server in in parallel,
// and handle the response after all the chunks have been processed (see example below).
function chunkArray(array, chunkLength) {
const length = array.length;
const chunks = [];
let index = 0;
while (index < length) {
chunks.push(array.slice(index, (index += chunkLength)));
@courtneymyers
courtneymyers / ethereum.sh
Last active April 10, 2018 01:05
Dockerized Ethereum Node
#!/bin/sh
### run shell in temporary geth container (run 'geth' after attaching)
# docker run -it --rm --entrypoint "/bin/sh" ethereum/client-go
### run geth JavaScript console
# docker run -it -p 30303:30303 ethereum/client-go console
### run containerized ropsten (proof-of-work) test network
# docker run -it -p 30303:30303 ethereum/client-go --testnet
@courtneymyers
courtneymyers / acf_modifications.php
Created February 28, 2018 18:36
Reduces initial height of Advanced Custom Fields WYSIWYG fields to 100px, and enables autoresizing of WYSIWYG field, as text is entered. Best practice would be to include this function in a site-specific plugin.
<?php
/*
* -----------------------------------------------------------------------------
* Advanced Custom Fields Modifications
* -----------------------------------------------------------------------------
*/
function PREFIX_apply_acf_modifications() {
?>
<style>

Keybase proof

I hereby claim:

  • I am courtneymyers on github.
  • I am courtneymyers (https://keybase.io/courtneymyers) on keybase.
  • I have a public key whose fingerprint is B3B1 C8A9 DDE6 F355 A64F C0BF 8CA0 7DC4 74E4 B5C1

To claim this, I am signing this object:

const partial = (f, ...args) => (...rest) => f(...args, ...rest)
@courtneymyers
courtneymyers / promise-handle-error-hof.js
Created February 1, 2018 23:20
Higher order function to pass to Promise w/ .catch() to handle errors
const handleError = fn => (...params) => fn(...params).catch(err => console.error(err));
@courtneymyers
courtneymyers / utilities.js
Created November 29, 2017 15:33
JavaScript utility functions
// helper function for initializing default values of an object's key
function init(object, key, fallback) {
(object[key] != null) ? object[key] : object[key] = fallback;
}
@courtneymyers
courtneymyers / searchpdfs.sh
Last active January 12, 2017 14:17
Bash script for searching for specific terms found within PDFs in the current directory. Relies on the 'pdftotext' command line utility.
#!/bin/bash
#echo "This script will search PDFs in this directory. Enter search term:"
#read term
#echo "Results found for \"${term}\":"
#find . -name '*.pdf' -exec sh -c "pdftotext '{}' - | grep --label='{}' --color --with-filename --line-number --ignore-case '${term}'" \;
# check for input arguments
if [ $# -eq 0 ] ; then
echo "You must enter a search term."
@courtneymyers
courtneymyers / THEMENAME.theme
Last active December 6, 2016 19:34
Custom function for Drupal 8 theme (functions) file that returns the URL of the next or previous node of a given content type, based on the value of a given date field's timestamp. Returned values can then be saved as variables in a preprocess node function, for use in the content type's Twig template.
<?php
/**
* Custom function to get the URL of the next or previous node of a content type
*
* Based on: http://mattkorostoff.com/article/simple-next-previous-nav-for-drupal-8
*
* @param string $content_type the machine name of a content type to query
* @param string $field_name the machine name of the field to query
* @param string $field_timestamp time from the date field (YYYY-MM-DD) to query