Skip to content

Instantly share code, notes, and snippets.

View tmaiaroto's full-sized avatar

Tom Maiaroto tmaiaroto

View GitHub Profile
@tmaiaroto
tmaiaroto / embedded-file-viewer.md
Created December 30, 2019 19:18 — forked from tzmartin/embedded-file-viewer.md
Embedded File Viewer: Google Drive, OneDrive

Office Web Apps Viewer

('.ppt' '.pptx' '.doc', '.docx', '.xls', '.xlsx')

http://view.officeapps.live.com/op/view.aspx?src=[OFFICE_FILE_URL]

<iframe src='https://view.officeapps.live.com/op/embed.aspx?src=[OFFICE_FILE_URL]' width='px' height='px' frameborder='0'>
</iframe>

OneDrive Embed Links

@tmaiaroto
tmaiaroto / gcp-cloud-build-multiple.yaml
Created August 10, 2019 05:41
GCP Cloud Build - multiple builds from directories
# If a directory has a cb-deploy.yaml file, it will run for CD
steps:
- name: 'gcr.io/cloud-builders/gcloud'
entrypoint: 'bash'
args:
- '-c'
- |
for d in */; do
config="${d}cb-deploy.yaml"
if [[ ! -f "${config}" ]]; then
@tmaiaroto
tmaiaroto / upperlower.go
Created November 9, 2014 04:53
Golang: somewhat faster string uppercase / lowercase (for certain strings)
// See: https://groups.google.com/forum/#!topic/golang-nuts/Il2DX4xpW3w
// A slightly faster lowercase function.
func toLower(s string) string {
b := make([]byte, len(s))
for i := range b {
c := s[i]
if c >= 'A' && c <= 'Z' {
c += 'a' - 'A'
}
@tmaiaroto
tmaiaroto / verify_cognito_jwt.go
Last active April 12, 2018 05:33
Example Cognito JWT Verification
// The following pakcages are used by the function below
// https://github.com/dgrijalva/jwt-go
// https://github.com/lestrrat/go-jwx
// ParseAndVerifyJWT will parse and verify a JWT, if an error is returned the token is invalid,
// only a valid token will be returned.
//
// To verify the signature of an Amazon Cognito JWT, search for the key with a key ID that matches
// the key ID of the JWT, then use libraries to decode the token and verify the signature.
//
@tmaiaroto
tmaiaroto / callback.go
Created April 12, 2018 05:26
Example Aegis Cognito Callback Handler
// Handle oauth2 callback, will exchange code for token
func cognitoCallback(ctx context.Context, d *aegis.HandlerDependencies, req *aegis.APIGatewayProxyRequest, res *aegis.APIGatewayProxyResponse, params url.Values) error {
// Exchange code for token
tokens, err := d.Services.Cognito.GetTokens(req.QueryStringParameters["code"], []string{})
if err != nil {
log.Println("Couldn't get access token", err)
res.JSONError(500, err)
} else {
// verify the token
_, err := d.Services.Cognito.ParseAndVerifyJWT(tokens.IDToken)
@tmaiaroto
tmaiaroto / cognito_trigger_types.go
Last active April 5, 2018 23:50
Cognito Lambda Trigger Types
// https://docs.aws.amazon.com/cognito/latest/developerguide/cognito-user-pools-lambda-trigger-syntax-shared.html
// CognitoTriggerCallerContext contains information about the caller (should be the same for all triggers)
type CognitoTriggerCallerContext struct {
AWSSDKVersion string `json:"awsSdkVersion"`
ClientID string `json:"clientId"`
}
// CognitoTriggerCommon contains common data from events sent by AWS Cognito (should be the same for all triggers)
type CognitoTriggerCommon struct {
@tmaiaroto
tmaiaroto / main.go
Created March 28, 2018 17:23
Go Lambda GeoIP
package main
import (
"github.com/oschwald/geoip2-golang"
"github.com/fatih/structs"
aegis "github.com/tmaiaroto/aegis/framework"
"net"
"context"
"net/url"
"log"
// $base-font-size: 16px; // not sure this ever did anything
$base-line-height: 1.5;
// this value may vary for each font
// unitless value relative to 1em
$cap-height: 0.68;
@mixin baseline($font-size, $scale: 2) {

Setting up a SSL Cert from Comodo

I use Namecheap.com as a registrar, and they resale SSL Certs from a number of other companies, including Comodo.

These are the steps I went through to set up an SSL cert.

Purchase the cert

@tmaiaroto
tmaiaroto / pre-commit
Last active July 30, 2016 22:29
A Go Commit Hook for Less Future Headaches
#!/bin/bash
#
# Check a "few" things to help write more maintainable Go code.
#
# OK, it's fairly comprehensive. So simply remove or comment out
# anything you don't want.
#
# Don't forget to install (go get) each of these tools.
# More info at the URLs provided.
#