Skip to content

Instantly share code, notes, and snippets.

View rednafi's full-sized avatar
🏠
Working from home

Redowan Delowar rednafi

🏠
Working from home
View GitHub Profile
@msullivan
msullivan / view_patterns.py
Last active December 9, 2023 12:47
A few related schemes for implementing view patterns in Python. view_patterns_explicit.py is probably the least dodgy of them
"""Hacky implementation of "view patterns" with Python match
A "view pattern" is one that does some transformation on the data
being matched before attempting to match it. This can be super useful,
as it allows writing "helper functions" for pattern matching.
We provide a class, ViewPattern, that can be subclassed with custom
`match` methods that performs a transformation on the scructinee,
returning a transformed value or raising NoMatch if a match is not
possible.
@Kalimaha
Kalimaha / proxy.py
Last active January 29, 2024 17:05
Simple Proxy server in Python
import time
from threading import Thread
try:
import socketserver as SocketServer
import http.server as SimpleHTTPServer
except ImportError:
import SocketServer
import SimpleHTTPServer
@rednafi
rednafi / Makefile
Last active February 6, 2024 15:22
Applying Black, Flake8, Isort and typechecking with mypy
.PHONY: help
help:
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-20s\033[0m %s\n", $$1, $$2}'
.PHONY: venvcheck ## Check if venv is active
venvcheck:
ifeq ("$(VIRTUAL_ENV)","")
@echo "Venv is not activated!"
@echo "Activate venv first."
@echo
@pierre-b
pierre-b / config.fish
Created March 6, 2017 10:03
golang fish shell config
# config file
# vim ~/.config/fish/config.fish
# reload the config
# source ~/.config/fish/config.fish
# set the workspace path
set -x GOPATH /users/my-username/go
# add the go bin path to be able to execute our programs
@Integralist
Integralist / Python Asyncio Timing Decorator.py
Last active March 17, 2024 10:02
Python Asyncio Timing Decorator
import asyncio
import time
def timeit(func):
async def process(func, *args, **params):
if asyncio.iscoroutinefunction(func):
print('this function is a coroutine: {}'.format(func.__name__))
return await func(*args, **params)
else:
@2minchul
2minchul / proxy.py
Created October 29, 2019 07:48
Python HTTPS proxy server with asyncio streams
import asyncio
import re
from asyncio.streams import StreamReader, StreamWriter
from contextlib import closing
from typing import Tuple, Optional
import async_timeout
StreamPair = Tuple[StreamReader, StreamWriter]
@Bobmajor
Bobmajor / gist:319e89e9c876cccdb1b77f1783e9a820
Created April 25, 2020 16:06
HOW TO INSTALL POSTMAN ON LINUX WITHOUT SNAP
1. Go to the Postman app download page at https://www.getpostman.com/apps. You can choose the os version from the drop-down. x64 for 64 bit Operating System and x84 for the 32 bit based Linux
2. Open the terminal and go to the directory where you have downloaded the tar file. If you have downloaded on the Downloads folder
cd ~/Downloads/
3. Run the following commands,
sudo rm -rf /opt/Postman/
@quad
quad / 0-interceptors-are-functions-too.md
Last active April 10, 2024 09:06
Interceptors Are Functions Too

Interceptors Are Functions Too

I could not agree more with my colleague and friend Travis Johnson's opinion that "[INTERCEPTORS ARE SO COOL][iasc]!" In that post, he succinctly describes the [Interceptor pattern][pattern] as used adroitly by [OkHttp][okhttp]. But, as is often the case, I believe a complicated object-oriented pattern obscures the simple functional gem within it.

What is an Interceptor?

I'll quote liberally from [OkHttp's documentation on the topic][okhttp-interceptor]:

Interceptors are a powerful mechanism that can monitor, rewrite, and retry calls. […] >

@amatellanes
amatellanes / celery.sh
Last active April 19, 2024 11:31
Celery handy commands
/* Useful celery config.
app = Celery('tasks',
broker='redis://localhost:6379',
backend='redis://localhost:6379')
app.conf.update(
CELERY_TASK_RESULT_EXPIRES=3600,
CELERY_QUEUES=(
Queue('default', routing_key='tasks.#'),
@rednafi
rednafi / dysfunc.go
Last active April 22, 2024 06:02
Dysfunctional option pattern in Go
package src
import (
"testing"
)
// Apply functional options pattern
type config struct {
// Required
foo, bar string