Skip to content

Instantly share code, notes, and snippets.

@hugotkk
hugotkk / READMD.md
Last active May 9, 2023 23:30
setup guide of amazon-eks-pod-identity-webhook
@hugotkk
hugotkk / client.py
Created May 8, 2023 00:33
simple rpc - server and client
import time
import grpc
import video_service_pb2
import video_service_pb2_grpc
def generate_messages():
for i in range(5):
print("Get Video " + str(i))
yield video_service_pb2.VideoID(id=str(i))
print("Sleeping for 5 seconds")
@hugotkk
hugotkk / metrics.py
Created April 25, 2023 22:40
Expose metrics with prometheus client library
from prometheus_client import start_http_server, Counter, Gauge, Histogram, Summary, Info
import random
import time
import threading
# Define a counter metric
REQUESTS = Counter('http_requests_total', 'The total number of HTTP requests')
# Define a gauge metric
USERS = Gauge('active_users', 'The number of active users')
@hugotkk
hugotkk / index.html
Last active April 18, 2023 22:58
Lab - WebSocket Gateway
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>WebSocket Chat Client</title>
</head>
<body>
<h1>WebSocket Chat Client</h1>
<label for="roomId">Room ID:</label>
<input type="text" id="roomId" placeholder="Enter room ID">
@hugotkk
hugotkk / nginx.conf
Created April 14, 2023 16:49
Nginx config to serve proxy protocol v2
user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
events {
worker_connections 768;
# multi_accept on;
}
@hugotkk
hugotkk / amazon-cognito-identity.min.js
Last active April 13, 2023 23:12
Update file to S3 with Cognito: Login and Non-Login Approaches
/*!
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
* SPDX-License-Identifier: Apache-2.0
*/
!function(t,e){"object"==typeof exports&&"object"==typeof module?module.exports=e(function(){try{return require("crypto")}catch(t){}}()):"function"==typeof define&&define.amd?define(["crypto"],e):"object"==typeof exports?exports.AmazonCognitoIdentity=e(function(){try{return require("crypto")}catch(t){}}()):t.AmazonCognitoIdentity=e(t.crypto)}("undefined"!=typeof self?self:this,function(t){return function(t){var e={};function n(r){if(e[r])return e[r].exports;var i=e[r]={i:r,l:!1,exports:{}};return t[r].call(i.exports,i,i.exports,n),i.l=!0,i.exports}return n.m=t,n.c=e,n.d=function(t,e,r){n.o(t,e)||Object.defineProperty(t,e,{configurable:!1,enumerable:!0,get:r})},n.n=function(t){var e=t&&t.__esModule?function(){return t.default}:function(){return t};return n.d(e,"a",e),e},n.o=function(t,e){return Object.prototype.hasOwnProperty.call(t,e)},n.p="",n(n.s=20)}([function(t,e,n){"use strict";(function(t
@hugotkk
hugotkk / auth_iam_policy.json
Last active April 13, 2023 17:29
Script to upload, download, and generate pre-signed URLs for files in an S3 bucket using temporary AWS credentials obtained from Cognito.
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": [
"mobileanalytics:PutEvents",
"cognito-sync:*",
"cognito-identity:*"
],
@hugotkk
hugotkk / server.py
Created April 13, 2023 13:13
Playground - AWS API Gateway
import http.server
import json
from urllib.parse import urlparse, parse_qs
class MyHttpRequestHandler(http.server.SimpleHTTPRequestHandler):
def do_POST(self):
self.do_GET()
def do_GET(self):
@hugotkk
hugotkk / sign.py
Created April 13, 2023 12:30
Example of aws ec2 describe-instances with curl and aws signature V4
import datetime
import hashlib
import hmac
import urllib.parse
def sign_request(method, url, region, service, access_key, secret_key, data='', headers=None):
if headers is None:
headers = {}
# Create a new datetime object and convert it to ISO format
@hugotkk
hugotkk / 1-question.md
Last active January 31, 2021 03:48
Write a SQL query to count the number of unique user per day who logged in from both iPhone and web