Skip to content

Instantly share code, notes, and snippets.

Avatar

Simon simonpainter

View GitHub Profile
@simonpainter
simonpainter / gist:d0867ed32c051cb1877d4919bee9f8ad
Created Jul 17, 2020
Inserting unique value into DynamoDB list.
View gist:d0867ed32c051cb1877d4919bee9f8ad
$marshaler = new Marshaler();
$UpdateExpression = "
SET #subscribers = list_append(if_not_exists(#subscribers, :empty_list), :subscriber)
";
$ConditionExpression = "
NOT contains (#subscribers,:subscriberStr)
";
View summary.py
from netaddr import IPNetwork, cidr_merge
import re, sys
try:
filename = sys.argv[1]
except:
print("Please specify a file name for input")
sys.exit()
with open (filename, "r") as file:
table = file.read().replace('\n', '')
View gist:08a4946a16ddb1c9b402f40aa5dafdb6
import json,uuid,time
import boto3
zone = 'XXXXXXXXXXXX'
def lambda_handler(event, context):
if ((event['name'] == "api") or (event['name'] == "www") or (event['name'] == "")):
return {
"statusCode": 403,
View gist:2406dab74a16234df20f9545ebc6f1ea
import json, uuid, time
import boto3
zone = 'XXXXXXXXXXXXX'
def lambda_handler(event, context):
dynamodb = boto3.client('dynamodb')
if ((event['name'] == "api") or (event['name'] == "*") or (event['name'] == "www") or (event['name'] == "")):
return {
View dark sky.py
import requests, urllib
class Forecast:
def __init__(self,apikey):
self.apikey=apikey
self.parameters={}
self.timeparam=""
def get(self,latitude,longitude):
self.latitude = latitude
self.longitude = longitude
self.encodedparameters = urllib.urlencode(self.parameters)
@simonpainter
simonpainter / IFTTT.py
Created Aug 3, 2017
Trigger IFTTT from Python
View IFTTT.py
class MakerTrigger(object):
def __init__(self,key,trigger):
self.key = key
self.trigger = trigger
self.maker =https://maker.ifttt.com/trigger/+ self.trigger +/with/key/+ self.key
def alert(self,value1=0,value2=0,value3=0):
self.value1 = value1
self.value2 = value2
self.value3 = value3
self.json={“value1”: self.value1, “value2”: self.value2, “value3”: self.value3}