Skip to content

Instantly share code, notes, and snippets.

@jeznag
jeznag / GhostStack
Created August 17, 2021 07:43
CDK for Ghost CMS on Fargate with EFS for persistent attachments
import { Dictionary } from './utility/Dictionary'
import { Secret } from '@aws-cdk/aws-secretsmanager'
import { LogDriver } from '@aws-cdk/aws-ecs'
import { LogGroup } from './constructs/LogGroup'
import { Alarm } from '@aws-cdk/aws-cloudwatch'
import { AwsAccount } from './OkraInfra'
import cdk = require('@aws-cdk/core')
import ec2 = require('@aws-cdk/aws-ec2')
import ecs = require('@aws-cdk/aws-ecs')
import ecs_patterns = require('@aws-cdk/aws-ecs-patterns')
@jeznag
jeznag / gist:3dc00c7c8bfbb7c1f1ad20e3208b9b3a
Created October 26, 2020 03:53
merge parquet files in S3
import pyarrow
import pyarrow.parquet as pq
import signal
import tarfile
import sys
import boto3
import io
import json
import re
import pandas as pd
@jeznag
jeznag / stack.ts
Created October 16, 2020 08:46
ApplicationLoadBalancedFargateService with two SSL certs
const grafanaService = new ecs_patterns.ApplicationLoadBalancedFargateService(this, 'Grafana', {
cluster: this.props.ecsCluster,
taskDefinition: taskdef,
domainZone: this.props.hostedZone,
domainName: this.grafanaDns,
publicLoadBalancer: true
})
const sslListener = grafanaService.loadBalancer.addListener('SSL', {
port: 443,
@jeznag
jeznag / LambdaFunctions.ts
Created October 2, 2020 05:50
CDK for tagging model lambda
function setupAutoTripTagging(parentStack: BackendAPIStack) {
const databaseUsernameSecret = new Secret(parentStack, 'databaseUsername');
const databasePasswordSecret = new Secret(parentStack, 'databasePassword');
const tripTaggingModelBucket = new Bucket(parentStack, 'gofar-auto-trip-tag-models');
// sklearn etc. are MASSIVE and therefore exceed the lambda
// limit (250MB). We upload the dependencies to S3 instead and the lambda will pull it down
const rebuildModelDependencies = new Asset(parentStack, 'rebuildAutoTaggingModelLambdaDependencies', {
path: './handlers/auto_trip_tagging_model_builder/dist/lambda_dependencies.tar.gz'
@jeznag
jeznag / package_lambdas.sh
Created October 2, 2020 05:46
package fat handler
mkdir -p dist
tar -czvf dist/build_tag_model_lambda.tar.gz build_tagging_model.py
@jeznag
jeznag / Pipfile
Last active October 2, 2020 05:41
package dependencies
[[source]]
url = "https://pypi.python.org/simple"
verify_ssl = true
name = "pypi"
[packages]
pandas = "*"
sklearn = "*"
xgboost = "*"
"psycopg2_binary" = "*"
@jeznag
jeznag / slim_handler.py
Created October 2, 2020 05:36
lambda slim handler
from __future__ import unicode_literals
import boto3
import importlib
import inspect
import json
import logging
import os
import sys
import tarfile
!function(o) {
var d = null
, l = null;
function n(e) {
e = e || 10;
for (var t = "", a = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", i = 0; i < e; )
t += a.charAt(Math.floor(Math.random() * a.length)),
i++;
return t
}
@jeznag
jeznag / gist:64453d74f4c28b46b8a6c23b5118c14c
Created August 12, 2020 01:16
send automated reply to first reply from lead
info has_replied_before;
if(has_replied_before.toString() == "false")
{
update_payload = {"Has_replied_before":true};
update_resp = zoho.crm.updateRecord("Leads",lead_id,update_payload);
// now SMS the lead back
lead_data = zoho.crm.getRecordById("Leads",lead_id);
// From: the Twilio number you will use to send the message
from_number = "+61 123 457 686";
// To: the number to which the SMS should be sent
@jeznag
jeznag / zoho crm function
Created June 13, 2020 08:56
Code for Zoho Flow to invoke Twilio SMS function
info lead_type;
lead_id = lead_id_str.toLong();
lead_data = zoho.crm.getRecordById("Leads",lead_id);
// From: the Twilio number you will use to send the message
from_number = "+61429357123";
// To: the number to which the SMS should be sent
to_number = lead_data.get("Phone");
// The To Name will appear in the SMS Message title, e.g. "Sent to John Smith on 23-Mar-2020"
to_name = lead_data.get("First_Name") + " " + lead_data.get("Last_Name");
// get the template ID from the URL of a template record