Skip to content

Instantly share code, notes, and snippets.

Avatar
🎯
Focusing

Timothy Mugayi timothymugayi

🎯
Focusing
View GitHub Profile
View localstack_dask.py
import os
import math
import dask.dataframe as dd
import numpy as np
import pandas as pd
from dask.distributed import Client
client = Client('tcp://scheduler:8786')
View serverless_deploy_localstack.sh
$ serverless invoke --function currentTime --log --profile localstack --stage local
Serverless: config.options_stage: local
Serverless: serverless.service.custom.stage: undefined
Serverless: serverless.service.provider.stage: ${opt:stage, 'local'}
Serverless: config.stage: local
Serverless: Using serverless-localstack
Serverless: Reconfiguring service apigateway to use http://localhost:4567
Serverless: Reconfiguring service cloudformation to use http://localhost:4581
Serverless: Reconfiguring service cloudwatch to use http://localhost:4582
Serverless: Reconfiguring service lambda to use http://localhost:4574
View serverless.yml
service: simple-http-endpoint
frameworkVersion: ">=1.2.0 <2.0.0"
plugins:
- serverless-localstack
# - serverless-python-requirements
provider:
name: aws
View localstack_sqs.py
import os
import json
import uuid
import boto3
# Inside docker use docker dns name localstack
# os.environ['LOCALSTACK_SQS_ENDPOINT_URL'] = 'http://localstack:4576'
# If your connecting to the localstack outside docker use host dns
# each aws service has its own endpoint url ensure boto3 client is configured accordingly
View localstack-entrypoint.sh
#!/usr/bin/env bash
printf "Configuring localstack components..."
readonly LOCALSTACK_S3_URL=http://localstack:4572
readonly LOCALSTACK_SQS_URL=http://localstack:4576
sleep 5;
set -x
View docker-compose.yml
version: "3.7"
services:
localstack:
container_name: "${LOCALSTACK_DOCKER_NAME-localstack}"
image: localstack/localstack
hostname: localstack
networks:
- localstack-net
ports:
- "4566-4599:4566-4599"
View medium_zmq_sub.py
# Subscribers are created with ZMQ.SUB socket types.
# A zmq subscriber can connect to many publishers.
import sys
import zmq
port = "5556"
if len(sys.argv) > 1:
port = sys.argv[1]
int(port)
View medium_zmq_pub.py
# Publishers are created with ZMQ.PUB socket types
# Data is published along with a topic.The subscribers usually
# sets a filter on these topics for topic of their interests.
# A publisher has no connected subscribers, then it will simply drop all messages.
# If you’re using TCP, and a subscriber is slow, messages will queue up on the publisher.
# In the current versions of ØMQ, filtering happens at the subscriber side, not the publisher side.
import zmq
import random
View medium_zmq_video_receiver.py
import cv2
import zmq
import numpy as np
port = "5555"
context = zmq.Context()
footage_socket = context.socket(zmq.SUB)
footage_socket.connect("tcp://localhost:%s" % port)
footage_socket.setsockopt_string(zmq.SUBSCRIBE, np.unicode(''))
View medium_zmq_video_server.py
import cv2
import zmq
context = zmq.Context()
footage_socket = context.socket(zmq.PUB)
footage_socket.bind("tcp://*:5555")
camera = cv2.VideoCapture(0) # init the camera
You can’t perform that action at this time.