Skip to content

Instantly share code, notes, and snippets.

@charsyam
charsyam / fastapi.py
Created July 24, 2022 08:09
FastAPI + aioredis simple settings
from fastapi import FastAPI
import aioredis
app = FastAPI()
async def redis_pool():
# Redis client bound to pool of connections (auto-reconnecting).
return aioredis.from_url(
"redis://localhost", encoding="utf-8", decode_responses=True
)
import boto3
import logging
logger = logging.getLogger('dag')
logger.setLevel(logging.INFO)
def get_url(bucket_name, obj):
return f"s3://{bucket}/{obj.key}"
#include <iostream>
#include <string>
#include <folly/ConcurrentSkipList.h>
static std::string makeRandomeString(int len) {
std::string s;
for (int j = 0; j < len; j++) {
s.push_back((rand() % 26) + 'A');
}
@charsyam
charsyam / timebased_otpcode_generator.go
Created January 13, 2021 13:54
Go Timebased OTP Code Generator
package main
import (
"crypto/rand"
"crypto/hmac"
"crypto/sha1"
"encoding/base32"
"time"
"fmt"
)
from thrift.protocol import TBinaryProtocol
from thrift.transport import TTransport
from schemas.singer.ttypes import LogMessage
fstream = open("./tf.log","rb")
transport = TTransport.TFramedTransport(TTransport.TFileObjectTransport(fstream))
protocol = TBinaryProtocol.TBinaryProtocol(transport)
transport.open()
#include "rocksdb/db.h"
#include <iostream>
int main(int argc, char *argv[]) {
rocksdb::DB* db;
rocksdb::Options options;
options.create_if_missing = true;
rocksdb::Status status = rocksdb::DB::Open(options, argv[1], &db);
std::cout << status.ok() << std::endl;
DAG=$1
START=$2
END=$3
run() {
CMD="airflow backfill $DAG -s $1"
$CMD
RET=$?
return $RET
}
#include <stdint.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <memory>
#include <type_traits>
#include <utility>
#include <iostream>
#include <chrono>
@charsyam
charsyam / jwt.go
Last active September 20, 2020 07:02
package main
import (
"encoding/json"
"fmt"
"strings"
"errors"
"crypto/hmac"
"crypto/sha256"
b64 "encoding/base64"
@charsyam
charsyam / python
Created January 2, 2020 14:19
retrive all versions of bucket
import sys
import boto3
from datetime import datetime, timezone
Bucket = 'BUCKET_NAME'
client = boto3.client('s3')
#prefix = sys.argv[1] + "/"
Prefix = ""