Skip to content

Instantly share code, notes, and snippets.

View sidravic's full-sized avatar

Siddharth sidravic

View GitHub Profile
@sidravic
sidravic / MqttClient.kt
Created December 21, 2022 03:07 — forked from hussanhijazi/MqttClient.kt
Kotlin Mqtt Client
package br.com.hussan.mqttandroid
import android.content.Context
import android.util.Log
import org.eclipse.paho.android.service.MqttAndroidClient
import org.eclipse.paho.client.mqttv3.IMqttActionListener
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken
import org.eclipse.paho.client.mqttv3.IMqttToken
import org.eclipse.paho.client.mqttv3.MqttCallbackExtended
import org.eclipse.paho.client.mqttv3.MqttClient
@sidravic
sidravic / asyncio_loop_in_thread.py
Created December 5, 2022 03:42 — forked from dmfigol/asyncio_loop_in_thread.py
Python asyncio event loop in a separate thread
"""
This gist shows how to run asyncio loop in a separate thread.
It could be useful if you want to mix sync and async code together.
Python 3.7+
"""
import asyncio
from datetime import datetime
from threading import Thread
from typing import Tuple, List, Iterable
@sidravic
sidravic / loadbalancer.py
Created July 13, 2022 01:52 — forked from zhouchangxun/loadbalancer.py
a simple loadbalancer implemention with python.
import sys
import socket
import select
import random
from itertools import cycle
# dumb netcat server, short tcp connection
# $ ~ while true ; do nc -l 8888 < server1.html; done
# $ ~ while true ; do nc -l 9999 < server2.html; done
SERVER_POOL = [('10.157.0.238', 8888)]
@sidravic
sidravic / dask_cloudprovider.py
Created June 17, 2022 03:45 — forked from jcrist/dask_cloudprovider.py
Prefect Example using DaskExecutor with dask-cloudprovider
from prefect import Flow
from prefect.executors import DaskExecutor
with Flow("daskcloudprovider-example") as flow:
# Add tasks to flow here...
# Execute this flow on a Dask cluster deployed on AWS Fargate
flow.executor = DaskExecutor(
cluster_class="dask_cloudprovider.aws.FargateCluster",
cluster_kwargs={"image": "prefecthq/prefect", "n_workers": 5}
@sidravic
sidravic / bash_prompt.sh
Created May 25, 2022 02:35 — forked from romanlevin/bash_prompt.sh
Set color bash prompt according to active pyenv, git branch and return status of last command.
#!/bin/bash
#
# DESCRIPTION:
#
# Set the bash prompt according to:
# * the active virtualenv
# * the branch/status of the current git repository
# * the return value of the previous command
# * the fact you just came from Windows and are used to having newlines in
# your prompts.
@sidravic
sidravic / fastapi_app.py
Created December 22, 2021 06:58 — forked from nguqtruong/fastapi_app.py
Integrate Sentry to FastAPI
import os
from fastapi import FastAPI
from sentry_sdk.integrations.asgi import SentryAsgiMiddleware
import sentry_sdk
sentry_sdk.init(
dsn='your Sentry dns', # CHANGE HERE
environment=os.getenv('ENV', 'dev'), # You should read it from environment variable
@sidravic
sidravic / how-to-copy-aws-rds-to-local.md
Created February 2, 2021 05:26 — forked from syafiqfaiz/how-to-copy-aws-rds-to-local.md
How to copy production database on AWS RDS(postgresql) to local development database.
  1. Change your database RDS instance security group to allow your machine to access it.
    • Add your ip to the security group to acces the instance via Postgres.
  2. Make a copy of the database using pg_dump
    • $ pg_dump -h <public dns> -U <my username> -f <name of dump file .sql> <name of my database>
    • you will be asked for postgressql password.
    • a dump file(.sql) will be created
  3. Restore that dump file to your local database.
    • but you might need to drop the database and create it first
    • $ psql -U <postgresql username> -d <database name> -f <dump file that you want to restore>
  • the database is restored
@sidravic
sidravic / fit_dump_model_to_s3fs.py
Created July 18, 2020 09:11 — forked from sbalnojan/fit_dump_model_to_s3fs.py
Fit model, dump to S3 via s3fs
import s3fs
import pickle
import json
import numpy as np
BUCKET_NAME = "my-bucket"
# definitions, keras/tf/... imports...
if __name__ == "__main__":
@sidravic
sidravic / install-gcc-4.9.3.sh
Created June 7, 2020 06:07 — forked from jtilly/install-gcc-4.9.3.sh
Install GCC 4.9.3
#!/bin/bash
# this script installs GCC 4.9.3
# to use it navigate to your home directory and type:
# sh install-gcc-4.9.3.sh
# download and install gcc 4.9.3
wget https://ftp.gnu.org/gnu/gcc/gcc-4.9.3/gcc-4.9.3.tar.gz
tar xzf gcc-4.9.3.tar.gz
cd gcc-4.9.3
@sidravic
sidravic / config2.json
Created May 30, 2020 06:48 — forked from pmav99/config2.json
Python logging configuration using JSON. If you want an updated example also covering YAML files, check here: https://github.com/pmav99/python-logging-example
{
"logging": {
"version": 1,
"disable_existing_loggers": true,
"formatters": {
"brief": {
"class": "logging.Formatter",
"datefmt": "%I:%M:%S",
"format": "%(levelname)-8s; %(name)-15s; %(message)s"
},