Skip to content

Instantly share code, notes, and snippets.

@dzimine
dzimine / gist:5ec60bea2282a640a66dc700eb51c8c1
Created April 27, 2018 18:16
stormless-min-serverless.yml
service: signup-stormless
provider:
name: aws
runtime: python2.7
plugins:
- serverless-plugin-stackstorm
@dzimine
dzimine / greengrass_group_create.py
Last active May 31, 2021 21:23
Create AWS Greengrass group and core.
import json
import yaml
import boto3
gg = boto3.client('greengrass')
iot = boto3.client('iot')
group = gg.create_group(Name="my_group")
keys_cert = iot.create_keys_and_certificate(setAsActive=True)
# ./stepfunction.yml
#
# StepFunction workflow definition file.
# Included in `serverless.yml`, look there for variables definitions
Comment: "Community sign-up workflow"
StartAt: RecordDB
States:
RecordDB:
Type: Task
$ sls stackstorm info --action activecampaign.contact_sync
activecampaign.contact_sync ... Sync a contact.
Parameters
api_action [string] ........ contact_sync
api_key [string] ........... Your API key
api_output [string] ........ xml, json, or serialize (default is XML)
email [string] (required) ... Email of the new contact. Example: 'test@example.com'
field [object] ............. 'value' (You can also use the personalization tag to specify which field you want updated)
first_name [string] ........ First name of the contact. Example: 'FirstName'
service: signup-stormless
provider:
name: aws
runtime: python2.7
timeout: 12
memorySize: 128
environment:
DYNAMODB_TABLE: ${self:service}-${opt:stage, self:provider.stage}
iamRoleStatements:
# ./record_db/handler.py
import json
import logging
import os
import boto3
dynamodb = boto3.resource('dynamodb')
logger = logging.getLogger()
logger.setLevel(logging.INFO)
service: signup-stormless
provider:
name: aws
runtime: python2.7
functions:
InviteSlack:
events:
- http:
@dzimine
dzimine / serverless-compare.yaml
Created December 9, 2017 00:04
StackStorm Exchange Goes Serverless - blog gists
# serverless.yml
...
functions:
# Standard Serverless Python function,
# point `handler` to an entrypoint in your python code:
hello_world:
handler: handler.hello
# With serverless-plugin-stackstorm
# point to an action in a pack from StackStorm Exchange:
@dzimine
dzimine / timeit_list_vs_dict.md
Last active January 31, 2023 04:39
Measure execution time with Python timeit.

Measure execution time with Python timeit module.

Example: compare the sort time between sorting list and sorting dict.

Generate sample dict, sort it:

di = {i:random.randint(1,100) for i in range(0,10)}   
sorted(ls, key=lambda pair: pair[1]) 
[(1, 10),
 (7, 38),
@dzimine
dzimine / github-add-alias.py
Created December 5, 2016 03:04
Add alias to StackStorm-exchange repos so that they continue to work with pre 2.1 versions
#!/usr/bin/env python
import json
import requests
API_EP = "https://api.github.com"
REPO = "/repos/Stackstorm-exchange/"
TOKEN = "&access_token=ADD_VALID_TOKEN_HERE"