Skip to content

Instantly share code, notes, and snippets.

View spg's full-sized avatar

Simon-Pierre Gingras spg

View GitHub Profile
// ======= WAF
// Based on this example: https://docs.aws.amazon.com/waf/latest/developerguide/waf-using-managed-rule-groups.html
const acl = new waf.CfnWebACL(this, "WebAcl", {
defaultAction: { allow: {} },
scope: "REGIONAL",
visibilityConfig: {
cloudWatchMetricsEnabled: true,
metricName: "MyMetric",
sampledRequestsEnabled: true,
export class LongMessage extends React.Component {
componentDidMount() {
const newMessagesIndicator = document.getElementsByClassName('bpw-new-messages-indicator')[0]
// If the "New Messages" div is present, we should not auto-scroll
if (!newMessagesIndicator) {
const messagesList = document.getElementsByClassName('bpw-msg-list')[0]
messagesList.scrollTop = messagesList.scrollHeight
}
}
render() {
@spg
spg / getviews.sh
Created November 22, 2019 20:38
Get views
#!/bin/sh
GH_TOKEN=$1
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=1\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=2\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=3\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=4\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=5\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
curl -s -H "Authorization: token $GH_TOKEN" https://api.github.com/users/sindresorhus/repos\?page\=6\&per_page\=100 | jq -r '.[] | .name' >> repos.txt
@spg
spg / user-data.sh
Created May 31, 2018 03:19
user-data.yml
#!/bin/bash -x
yum -y install mysql # provisioning example
# Signal that the instance is ready
INSTANCE_ID=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
aws ec2 create-tags --resources $INSTANCE_ID --tags Key=UserDataFinished,Value=true --region ${AWS::Region}
@spg
spg / sample.yaml
Created May 31, 2018 03:03
CloudFormation AMI usage example
MyAMI:
Type: Custom::AMI
Properties:
ServiceToken: !ImportValue AMILambdaFunctionArn
Image:
Name: my-image
Description: some description for the image
TemplateInstance:
ImageId: ami-467ca739
IamInstanceProfile:
AWSTemplateFormatVersion: '2010-09-09'
Transform: AWS::Serverless-2016-10-31
Description: A serverless Gift Idea as a Service API
Resources:
MyApi:
Type: AWS::Serverless::Api
Properties:
StageName: prod
DefinitionBody:
swagger: 2.0
import json
import random
from collections import namedtuple
Object = namedtuple(field_names=['determiner', 'object'], typename='Object')
objects = [
Object('A', 'Star Wars Mug'),
Object('A', 'Mickey Mouse Toaster'),
Object('Some', 'Socks'),
import json
import os
import uuid
from botocore.vendored import requests
SUCCESS = "SUCCESS"
FAILED = "FAILED"
class HeartbeatAlreadyExistsError(Exception):
AWSTemplateFormatVersion: '2010-09-09'
Description: Provisions OpsGenie Heartbeats using CloudFormation
Parameters:
OpsGenieHeartbeatApiKey:
Type: String
NoEcho: true
Resources:
HeartbeatLambdaExecutionRole:
@spg
spg / counter.elm
Created November 27, 2015 01:03
Elm counter
import Html exposing (div, button, text, input)
import Html.Events exposing (onClick)
import StartApp.Simple as StartApp
main =
StartApp.start { model = model, view = view, update = update }
model = 0