Skip to content

Instantly share code, notes, and snippets.

View tforster's full-sized avatar
🏠
Working from home

Troy Forster tforster

🏠
Working from home
View GitHub Profile
@tforster
tforster / tumblr2mongo.js
Last active September 8, 2018 14:51
[Tumblr to Mongo] NodeJS script to fetch all posts from multiple tumblr blogs into a single MongoDB collection. It saves the sorted data to disk as a .JSON file as well as bulk inserting into a MongoDB collection. #tumblr #mongo
/*
* Edit these variables to suit your environment
*/
var blogs = ["x.tumblr.com", "y.tumblr.com", "z.tumblr.com"];
var apiKey = "**************************************************";
var databaseName = "node-blog";
var databaseHost = "localhost";
var databasePort = 27017;
var databaseCollection = "posts";
@tforster
tforster / mattermost-bookmarklet.js
Last active March 5, 2022 05:17
[Mattermost Sharing Bookmarklet] Quick-n-dirty Bookmarklet to share the current page to MatterMost #mattermost #sharethis #share #bookmarklet
/*******************************************************************************
* Quick-n-dirty Bookmarklet to share the current page to MatterMost
*
* Limitations
* -----------
* - Doesn't work in mixed content yet so don't try and share an
* HTTPS URL if your MatterMost is running on HTTP (which it really should
* not be).
* - Only tested on Chrome. Uses some ES6 stuff so your mileage will vary
* - Doesn't check for classes called ti-input, ti-post or ti-cancel so it may
@tforster
tforster / signature.html
Last active September 8, 2018 14:49
[Gmail Signature] Copy/paste Gmail signature markup
<table border="0" cellpadding="0" cellspacing="0" width="445" style="font-family:'Times New Roman'">
<tbody>
<tr>
<td height="65" valign="top" width="65" style="padding-right:8px;vertical-align:top">
<table border="0" cellpadding="0" cellspacing="0">
<tbody>
<tr>
<td height="65" width="65"><img alt="photo" height="65" width="65" style="vertical-align:initial;border-radius:0px;max-width:90px"
src="https://ci5.googleusercontent.com/proxy/5oomNlZNp3iyPEopuZyMtittq7y2tOgN3Gr8GNJ3Xx9D_EvoYh3fJlhCvmboDzi7gHDd2ZyyhLdE0sd1uZ07pS8F3rsReC2MxGszQUyE5c8Wlvb4FpCP1ps7UXdhzkE7X3dSgOk4Qfblslu7LKKd0TzaSnYbIBq1NOIsOYzE-9es4Ue2O6sesogA9fKv0nZ-lbY=s0-d-e1-ft#https://s3.amazonaws.com/ucwebapp.wisestamp.com/42a7f41a-9cca-437d-a291-f0fc0f4a9097/sidefacew500.format_png.resize_200x.png"></td>
</tr>
@tforster
tforster / new-linux-setup.md
Last active December 27, 2021 20:28
[New Linux Setup] A collection of shell snippets useful when setting up a new Linux instance #linux #setup

New Linux Setup

Setting up Linux systems is a frequent activity for me. Whether it is configuring a Docker image, setting up a new SDCard for a Raspberry Pi or migrating from one laptop to another. This README is an ongoing record of installation snippets that I copy and paste.

Create Some Useful Directories

md ~/dev
md ~/temp
@tforster
tforster / CORS.js
Created February 4, 2021 20:30
CORS for AWS Lambda using Serverless Framework
// Because I can never remember the precise syntax and the Serverless Framework docs are out of date (at least when I wrote this)...
// Handler.js
resSuccess(data = {}, statusCode = 200) {
return {
statusCode,
body: JSON.stringify(data),
headers: {
"Content-Type": "application/json",
"Access-Control-Allow-Headers": "*",
@tforster
tforster / s3-limit-bucket-to-user.json
Last active February 12, 2021 18:05
Useful AWS IAM policies
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"s3:GetObject",
"s3:PutObject",
"s3:GetObjectAcl",
"s3:PutObjectAcl",
@tforster
tforster / README.md
Last active January 27, 2022 00:01
Lambda@Edge function to redirect requests for a naked domain to the www subdomain

Naked Redirector Lambda@Edge Function

THIS GIST HAS BEEN DEPRECATED

AWS introduced CloudFront Functions as an alternative (but not replacement) to Lambda@Edge functions. Both have their pros and cons but for naked-domain-to-www redirection a CloudFront Function is a better choice. Please see Naked Redirector CloudFront Function for an implementation example.

Intended to run on CloudFront as Lambda@Edge, naked redirector checks the incoming hostname and if it is naked, e.g. somedomain.com and not www.somedomain.com, it will redirect to the www subdomain with preserved path and query string variables.

Table of Content

@tforster
tforster / README.md
Last active February 26, 2021 18:39
Lambda@Edge function to implement basic auth

Basic Auth Lambda@Edge Function

Implements a simple basic auth function to attach to an AWS CloudFront distribution. Note that basic auth is inherently insecure and should not be used to protect content of value. It does work well to keep search engines and crawlers out of stage websites.

Usage

  1. Create a new Lambda function in us-east-1 (AWS does not support @Edge functions from other regions at this time.)
  2. Copy the contents of index.js to the new Lambda
  3. Replace {your-shared-username} and {your-shared-password} with actual values
  4. Attach to CloudFront as a viewer request function
@tforster
tforster / .env
Created November 19, 2021 22:23
WordPress with XDebug inside Docker
# Debug state
DEBUG=true
# MySQL configuration
DB_USER=
DB_PASSWORD=
DB_NAME=
DB_HOST=db:3306
# WordPress configuration
@tforster
tforster / MailChimp.postman_collection.json
Last active July 25, 2023 08:21
MailChimp PostMan Collection
{
"info": {
"_postman_id": "e5d286ab-6f35-46dd-a9f0-9c3c55b5db18",
"name": "MailChimp",
"schema": "https://schema.getpostman.com/json/collection/v2.1.0/collection.json"
},
"item": [
{
"name": "Get lists info",
"request": {