Skip to content

Instantly share code, notes, and snippets.

View ritesh's full-sized avatar
:electron:
Small language model powered by biriyani

Ritesh Sinha ritesh

:electron:
Small language model powered by biriyani
View GitHub Profile
@ritesh
ritesh / update_trusted_ips.py
Created June 12, 2020 13:11
update_trusted_ips.py
import boto3
import logging
import click
from urllib.parse import urlparse
@click.command()
@click.option('--iplist', prompt='Location of the IP list in S3', help='A file with a CIDR per line of trusted IPs (only TXT supported for now)')
@click.option('--name', default='KnownIPs', prompt='Name', help='Name of the threat list')
def update_threat_list(iplist, name):
if not valid_list(iplist):
@ritesh
ritesh / main.rs
Created April 14, 2020 10:53
Brute force anagram
use std::fs::File;
use std::io::{self, BufRead};
use std::path::Path;
use rand::{thread_rng, Rng};
use std::collections::HashSet;
use trie_rs::TrieBuilder;
// A silly program that finds words in a single word anagram using brute-force
// We use a data structure called a Trie: https://en.wikipedia.org/wiki/Trie
// to store a dictionary of words
@ritesh
ritesh / params.yaml
Created October 9, 2019 13:53
ParamSelection
AWSTemplateFormatVersion: 2010-09-09
Description: |
Creates an IAM role with a fixed set of parameters
Parameters:
RoleName:
Type: String
Description: Name of the role you want to create
EC2Policy:
Type: String
@ritesh
ritesh / anim.sh
Created June 17, 2019 13:42
Quick animation
# Use imagemagick convert for this
# Flop flips an image around the X axis (i.e. mirror image)
convert -flop yourimage.png yourimageflop.png
# Make it loopy
convert -loop 0 -delay 100 yourimage.png yourimageflop.png out.gif
@ritesh
ritesh / envvars
Created June 12, 2019 15:47
Testing function-shield
# Source these to pretend you're running in AWS Lambda
# Tested on Linux, might work on OSX
AWS_EXECUTION_ENV=AWS_Lambda_python2.7
_HANDLER=handler
FUNCTION_SHIELD_TOKEN='base64encoded token you can get from puresec'
# you will also need to create a dir for the function code under /var
# mkdir -p /var/task && ln <fullpath to your the file above> /var/task/handler.py
@ritesh
ritesh / main.go
Created October 23, 2018 14:42
Go-sdk-v2 set log group retention to 1 day
package main
import (
"fmt"
"os"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
"github.com/aws/aws-sdk-go-v2/service/cloudwatchlogs"
)
@ritesh
ritesh / main.go
Created October 18, 2018 15:29
Expire CloudWatch logs after X days
package main
import (
"fmt"
"log"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/cloudwatchlogs"
)
@ritesh
ritesh / s3signer.go
Created June 14, 2018 11:08
s3signer
package main
import (
"flag"
"fmt"
"log"
"time"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/aws/aws-sdk-go-v2/aws/external"
@ritesh
ritesh / sample.go
Created April 9, 2018 10:17
goformation example
package main
import (
"log"
"github.com/awslabs/goformation"
)
func main() {
@ritesh
ritesh / readf.go
Created March 26, 2018 15:25
read_enc_data
package cmd
import (
"bytes"
"encoding/binary"
"fmt"
"io"
"log"
"github.com/fatih/structs"