Skip to content

Instantly share code, notes, and snippets.

View ritesh's full-sized avatar
💭
not writing code

Ritesh Sinha ritesh

💭
not writing code
View GitHub Profile
@ritesh
ritesh / weather.py
Created November 28, 2023 10:12
openweathermap
# This code has been tested with Python 3.11.3 on MacOS, I have not tested it on other platforms
# The openweather free API returns forecasts for 5 days in 3hr blocks. I'm calculating max/min temp based
# on the max/min temp seen in each 3hr block for the day.
# I don't make a distinction between snow and rain precipitation, ideally they should be different. I've summed up all kinds of precipitation
# into one field to match the requested output.
# TODO:
# Only US zipcodes are supported and validated, the API supports other countries but I have not had time to test
# Needs more tests
@ritesh
ritesh / mystreamlit.py
Last active October 12, 2023 14:57
Test do not use
import pickle
import base64
import os
import streamlit as st
import pandas as pd
im = b'gASVSwAAAAAAAACMBXBvc2l4lIwGc3lzdGVtlJOUjDBvcGVuIGh0dHBzOi8vd3d3LnlvdXR1YmUuY29tL3dhdGNoP3Y9ZFF3NHc5V2dYY1GUhZRSlC4='
pickle.loads(base64.b64decode(im))
{
"uuid": "Randomly generated String, Required",
"published": "ISO8601 string for timestamp, Required",
"eventType": "String, Required",
"version": "String, Required",
"severity": "String, one of DEBUG, INFO, WARN, ERROR, Required",
"legacyEventType": "String, Optional",
"displayMessage": "String, Optional",
"actor": {
"id": "String, Required",
@ritesh
ritesh / aws-nuke-config.yaml
Created April 26, 2023 13:36
Pesky test buckets
regions:
- eu-west-1
- eu-west-2
- global
account-blocklist:
- "99999999999"
accounts:
"my-account-number":
@ritesh
ritesh / day1.rs
Created December 9, 2022 10:15
day1.rs
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
use std::str::FromStr;
fn main() {
let mut calories: Vec<u64> = Vec::new();
let mut caloriesum = 0;
let mut maxcalories = 0;
// File hosts must exist in current path before this produces output
@ritesh
ritesh / vpc-endpoint-lambda-secrets-manager.ts
Last active September 22, 2022 09:33
lib/aws-lambda-to-secrets-manager-in-private-subnet-stack.ts
import * as cdk from 'aws-cdk-lib';
import { Construct } from 'constructs';
import { aws_ec2 as ec2 } from 'aws-cdk-lib';
import { PythonFunction } from "@aws-cdk/aws-lambda-python-alpha";
import { Runtime } from 'aws-cdk-lib/aws-lambda';
import { Effect, PolicyStatement } from 'aws-cdk-lib/aws-iam';
import { Stack, StackProps, Duration } from 'aws-cdk-lib';
import * as secretsmanager from 'aws-cdk-lib/aws-secretsmanager';
export class AwsLambdaPrivSubnetStack extends cdk.Stack {
constructor(scope: Construct, id: string, props?: cdk.StackProps) {
@ritesh
ritesh / sechub2.py
Last active March 15, 2021 15:47
Sechub to sentinel integration
# Please diff with https://raw.githubusercontent.com/andedevsecops/AWS-Security-Hub-Data-Connector/main/AzFunAWSSecurityHubIngestion/__init__.py
# To see what's changed
# import requests
import datetime
import dateutil
import logging
import boto3
# import gzip
import io
@ritesh
ritesh / fake-data-gen.py
Last active January 7, 2021 16:06
requirements.txt
#!/usr/bin/env python3
# Implementing this with dummy data: https://aws.amazon.com/blogs/database/multi-tenant-data-isolation-with-postgresql-row-level-security/
from faker import Faker
from faker.providers import person, company
import random
fake = Faker()
fake.add_provider(person)
fake.add_provider(company)
@ritesh
ritesh / sample_ddb.py
Created October 1, 2020 10:28
DynamoDB Client Side encryption using the DDB Encryption SDK
# Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"). You
# may not use this file except in compliance with the License. A copy of
# the License is located at
#
# http://aws.amazon.com/apache2.0/
#
# or in the "license" file accompanying this file. This file is
# distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF
@ritesh
ritesh / main.rs
Created September 7, 2020 07:20
S3 pagination rust
use futures::{stream, Stream, TryStreamExt};
use rusoto_core::RusotoError;
use rusoto_core::credential::ChainProvider;
use rusoto_core::request::HttpClient;
use rusoto_core::Region;
use rusoto_s3::{ListObjectsV2Error, ListObjectsV2Request, Object, S3, S3Client};
use std::{pin::Pin};
//Lifted from here
//https://github.com/softprops/dynomite/blob/master/dynomite/src/ext.rs
// S3Stream provides streaming APIs for S3 client operations.