Skip to content

Instantly share code, notes, and snippets.

View rainabba's full-sized avatar
🎧
Working from home

Michael Richardson rainabba

🎧
Working from home
  • Asurion
  • Manassas, VA
View GitHub Profile
@rainabba
rainabba / gist:9996443
Created April 5, 2014 19:06
WKHTMLTOPDF 1.12 using Google-Hosted .woff (Roboto)
<html>
<head>
<title>WKHTMLTOPDF Font Test</title>
<style>
@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 100;
src: local('Roboto Thin'), local('Roboto-Thin'), url(http://themes.googleusercontent.com/static/fonts/roboto/v10/vzIUHo9z-oJ4WgkpPOtg1_esZW2xOQ-xsNqO47m55DA.woff) format('woff');
}
@rainabba
rainabba / gist:3f4fe16cc40bf98b2272
Created May 29, 2014 01:37
G+ Comments on any page
// Simplified version of what I found at http://dashburst.com/how-to-add-google-comments-to-any-webpage-or-blog-unofficially/
// This assumes jQuery support as $
<script src="https://apis.google.com/js/plusone.js"></script>
<div id="commentscounter"></div>
<div id="gpcomments"></div>
<script>
$(function() {
gapi.comments.render('gpcomments', { href: window.location, first_party_property: 'BLOGGER', view_type: 'FILTERED_POSTMOD' });
gapi.commentcount.render('commentscounter', { href: window.location });
@rainabba
rainabba / testdeferredpromise.html
Last active September 23, 2015 19:18
Example and differences for A+ Promise using Resolve/Reject and a Bluebird promisify wrapper
<html>
<head>
<script src="https://www.promisejs.org/polyfills/promise-7.0.1.min.js"></script>
<script src="http://requirejs.org/docs/release/2.1.2/minified/require.js"></script>
</head>
<body>
<h1>Open the console</h1>
<script>
@rainabba
rainabba / gist:ba2a56dbfc64498c8c033a2615a2afe8
Created April 18, 2017 07:47
Windows Explorer search for GSHEET and GDOC remnants
name:~"*.docx.URL" OR name:~"*.doc.URL" OR name:~"*.gdoc" OR name:~"*.gsheet" OR name:~"*xlsx.URL" OR name:~"*.xls.URL"
@rainabba
rainabba / drive-api-test
Last active May 9, 2018 19:34
google-api-nodejs-client examples using JWT and service account
const README = '\n\nThis script is intended to help you use a google API \
client_secret.json file to obtain an OAUTH token (json data) and \
store it next to the source .json for future use. \n\n\
To acomplish this, you will be given an URL that you can follow to \
get a "code" which can then be used to get a token. As an I/O solution \
I run this script with `node --inspect-brk` and then I catch the debugger \
after the URL is logged to the console. Once I have the code, I can run \
`code="{codeFromUrl}"` and resume the script. \n\n\n';
console.log( README );
@rainabba
rainabba / Promise-all.js
Created June 30, 2017 19:12
Promise.all() demonstration with iterations for refactoring
// Wait for ALL promises to return OR any to crash and then return the array of values to the caller of .all()
// // //Itteration 1
// // function runParallelPromisesSum() {
// // //Our function returns its own promise with our value that needed both the promises to return first
// // return new Promise( ( resolveAll, rejectAll ) => {
// // let promise1 = new Promise( ( resolvePromise1, rejectPromise1 ) => {
// // console.log("resolving 1");
// // resolvePromise1( 1 );
@rainabba
rainabba / saveToDrive.js
Created December 30, 2015 21:37
VERY basic example of how to save content to Google Drive using node.js using googleapis
// This requires a google developers console project. That UI changes regularly and I found it hard to learn, but at the time I'm creating this, the steps are:
// - At the top-right, select or create a new project (can't give step-by-step details here)
// - Visit https://console.developers.google.com/apis/api/drive/overview
// - Enable API with your options (not sure they matter much, but API must be enabled)
// - Visit https://console.developers.google.com/permissions/serviceaccounts
// - Create a new service account if you don't already have one or don't have one you want to use for these API calls. Select the "Furnish new private key" option and the JSON format along with "Enable Google Apps Domain-wide Delegation".
// - Save provided JSON in a SECURE location (don't include in your source code and ensure it's ignored by GIT)
// You can generate new keys and/or revoke this one at https://console.developers.google.com/apis/credentials
@rainabba
rainabba / pdfToImageTest.js
Created February 8, 2019 16:58
Testing common solutions to PDF -> image conversion
// SPOILER: Only 1 of these tests passes at this point and it bypasses
// all the fluff and complication so it's the one I will end up using
const { expect } = require('code'),
Lab = require('lab'),
lab = exports.lab = Lab.script(),
fs = require("fs"),
path = require("path"),
mkdirp = require('mkdirp'),
rimraf = require('rimraf'),
@rainabba
rainabba / cp-error.sh
Created September 16, 2020 23:27
cp - 'are the same file'
## Below is a script/log (anonymized) of an instance where I'm getting "are the same file" errors from `cp`
## Clearly they are not "the same file", but have identical contents and the 2nd is from a `git clone` command
#!/bin/bash
# me@myhost:/mnt/c/prj/someorg/some-project$ ls -lah;
ls -lah;
# total 0
# drwxr-xr-x 1 someuser root 512 Sep 15 10:26 .
# drwxr-xr-x 1 someuser root 512 Jun 3 06:48 ..
# drwxr-xr-x 1 someuser root 512 Apr 16 10:46 .vscode
@rainabba
rainabba / README.md
Last active October 23, 2020 21:40
Quickly and easily map/include field from an array of objects

My use case was an array of objects coming from a document-store so they're extremely variable and we only want a sub-set of the returned fields. There are plenty of ways to go about this and I hope snippet will serve that purpose, but for me this was more about realizing the power of () to do a bit more with the Lambda passed to map(). I regularly pull up ANY chrome page, hit Ctrl+Shift+J and develop small snippets right in the console, which is what led to 1 of 2 discoveries today.

How I would have gone about this in the past

let result = { Items: [{ a: 1, b: 2, x: 3 }] },
 newList = result.map( o => { return { a: o.a, b: o.b }; );

My new solution