Skip to content

Instantly share code, notes, and snippets.

View rbk's full-sized avatar

Richard Keller rbk

View GitHub Profile
@rbk
rbk / dom-utils.js
Created April 1, 2024 17:10
Remove all CSS styles from the DOM
Array.from(document.querySelectorAll('style, link')).map(x => x.remove());
Array.from(document.querySelectorAll('*')).map(x => {
x.setAttribute('stlye', "")
});
@rbk
rbk / download.js
Created October 18, 2022 03:06
Download a file with node
const files = [
"https://archive.org/download/OTRR_Gunsmoke_Singles/Gunsmoke%2052-04-26%20%28001%29%20Billy%20the%20Kid.mp3"
]
const exec = require('child_process').exec;
const downloadFile = (url) => {
return new Promise((resolve) => {
console.log(`wget ${url} --no-check-certificate`)
exec(`wget ${url} --no-check-certificate`, function(err, stdout, stderr) {
@rbk
rbk / async-localstorage.js
Created August 28, 2022 12:34
Simple async localStorage.
const asyncLocalStorage = {
setItem: function (key, value) {
return Promise.resolve().then(function () {
localStorage.setItem(key, value);
});
},
getItem: function (key) {
return Promise.resolve().then(function () {
return localStorage.getItem(key);
});
window.onerror = function(errorMessage, filePath, lineNumber, offset, stackObject) {
console.log(stackObject)
console.log({
'errorMessage' : errorMessage,
'filePath' : filePath,
'lineNumber' : lineNumber,
'offset' : offset,
'stackObject' : stackObject,
})
}
/**
* Say you have this: {"key": "123", "limit": 20}
* But you need this: ?key=123&limit=20
* Use objectToParams...
*/
const objectToParams = (obj) => {
const params = Object.keys(obj).reduce((acc, key) => {
return `${acc}&${key}=${obj[key]}`;
}, '');
return params.replace(/&/, '?');
@rbk
rbk / apartment-data.json
Created April 13, 2020 21:27
Apartment Data - Downtown Tulsa
[
{
"formatted_address": "211 S Greenwood Ave, Tulsa, OK 74120, United States",
"geometry": {
"location": {
"lat": 36.1567677,
"lng": -95.9840401
},
"viewport": {
"south": 36.15535762010728,
@rbk
rbk / index.php
Last active February 27, 2020 18:01
Turn input placeholders into floating labels for WP Contact Form 7 fields
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
Plugin name: WPCF7 FLoating Labels
Author: Richard Keller
URI: http://richardkeller.net
Description: Adds floating lables to all text inputs
*/
@rbk
rbk / index.html
Created August 21, 2019 13:01
Example of a great HTML document header
<!DOCTYPE html>
<html lang=en>
<head>
<meta charset=utf-8 />
<meta content="IE=edge" http-equiv=X-UA-Compatible />
<meta content="width=device-width, initial-scale=1" name=viewport />
<title>Schedule | JAMstack_conf_sf</title>
<meta content="A two day conference, and a day of workshops in San Francisco for learning to design, develop, &amp; deploy modern web projects without servers." name=description />
<meta content="jamstack, pwa, progressive web apps, apis, api, react, reactjs, react.js, react conf, conference, conf, workshop, netlify, github, eventbrite, webpack, freecodecamp, redux, vue, vue.js, workshop, learn to code, learn to program, learn react, san francisco, learn programming, learn javascript, learn coding, code, coding, programming, software engineer, software developer, web development, development, engineering, coding bootcamp, javascript, open source, microservices, serverless, gatsby, contentful, angular, angular.js, angularjs" name=keywords />
<meta content="https://jamstackconf.com/sf" pr

DynamoDB Examples

Create DynamoDB Table

def create_user_table():
    """Create the user table."""
    try:
        result = client.create_table(
            TableName='user_table',
            BillingMode='PAY_PER_REQUEST',
@rbk
rbk / index.js
Created July 24, 2019 20:32
Last N Dates
/*
*
* Starting today, get each date for the last N days.
*
*/
const lastNDates = (n) => {
let result = []
let d = new Date()
let rd = `${d.getFullYear()}-${d.getMonth()+1}-${d.getDate()}`
result.push(rd)