Skip to content

Instantly share code, notes, and snippets.

View piraka9011's full-sized avatar
🍍

Anas Abou Allaban piraka9011

🍍
View GitHub Profile

Keybase proof

I hereby claim:

  • I am piraka9011 on github.
  • I am anas9011 (https://keybase.io/anas9011) on keybase.
  • I have a public key ASBLGr_u2a5g4MlUaPfS835crKpGOAQENQLV0UlsVqjYcQo

To claim this, I am signing this object:

@piraka9011
piraka9011 / how-to-squash-commits-in-git.md
Created October 21, 2019 15:30 — forked from patik/how-to-squash-commits-in-git.md
How to squash commits in git

Squashing Git Commits

The easy and flexible way

This method avoids merge conflicts if you have periodically pulled master into your branch. It also gives you the opportunity to squash into more than 1 commit, or to re-arrange your code into completely different commits (e.g. if you ended up working on three different features but the commits were not consecutive).

Note: You cannot use this method if you intend to open a pull request to merge your feature branch. This method requires committing directly to master.

Switch to the master branch and make sure you are up to date:

@piraka9011
piraka9011 / keybase.md
Created November 2, 2019 17:20
keybase

Keybase proof

I hereby claim:

  • I am piraka9011 on github.
  • I am piraka9011 (https://keybase.io/piraka9011) on keybase.
  • I have a public key ASDd9K7I5IP02lGwyyIffqaVXQhE-pXhF2nMYj5vjT9xMQo

To claim this, I am signing this object:

@piraka9011
piraka9011 / check_wave_audio.py
Created December 22, 2019 14:11
Check if file can be read with python wave module
import os
import wave
if __name__ == '__main__':
directory = '/Users/allabana/tarteel_ws/tarteel-recordings/media'
(_, _, filenames) = next(os.walk(directory))
bad_files = []
for filename in filenames:
wave_filename = os.path.join(directory, filename)
try:
@piraka9011
piraka9011 / sentry_filter.py
Last active March 16, 2022 11:39
How to filter Sentry transactions for Django + Celery
"""This is a full example of a trace sampler that filters transactions for:
1. Django views/routes/urls (whatever you want to call them)
2. Celery tasks
Generally, you would put this in your `settings.py` file, but you can put format it as needed for your project of course.
We are assuming you use `django-environ` for secrets management.
"""
import environ
import sentry_sdk
@piraka9011
piraka9011 / test_ios_conversion.py
Created July 23, 2022 18:12
Convert NeMo CitriNet to iOS
from torch.quantization import quantize_dynamic
from torch.utils.mobile_optimizer import optimize_for_mobile
from nemo.collections.asr.models import EncDecCTCModelBPE
# from nemo.collections.asr.parts.preprocessing import FilterbankFeatures
from omegaconf import OmegaConf
import torch
import torchaudio
import math
import random
@piraka9011
piraka9011 / list_keys.py
Last active August 18, 2022 15:53
Transfer from AWS to Wasabi S3 using boto3. Run `list_keys.py` first then `move_keys.py`
import boto3
from tqdm import tqdm
# Estimate from the S3 console
NUM_OBJECTS = 17292115
def list_objects_parallel(bucket, prefix):
objects = []
pbar = tqdm(total=NUM_OBJECTS)
@piraka9011
piraka9011 / start_or_create_ec2.py
Created April 20, 2023 04:51
Start or create an EC2 instance (used as a celery task)
def start_or_create_ec2_instance(self, instance_id=None, region_name="us-west-2", **kwargs):
session = boto3.session.Session(region_name=region_name)
ssm = session.client("ssm")
# Default to open SSH security groups
sg_id_region_map = {
"us-west-2": "sg-xxxx",
"us-east-1": "sg-xxxx",
}
# Default to public subnets
subnet_id_region_map = {
@piraka9011
piraka9011 / next.config.js
Last active May 12, 2023 10:53
Vercel Live Feedback CSP Example
// See https://vercel.com/docs/workflow-collaboration/comments/specialized-usage#using-a-content-security-policy
const VERCEL_BASE_CSP = 'https://vercel.live/ https://vercel.com https://*.vercel.com'
const VERCEL_CSP_DEFAULT_SRC = `${VERCEL_BASE_CSP} wss://*.pusher.com`;
const VERCEL_CSP_IMG_SRC = `${VERCEL_BASE_CSP} https://sockjs-mt1.pusher.com/`;
const GOOGLE_FONTS_BASE_CSP = 'https://*.gstatic.com';
const ContentSecurityPolicy = `
default-src 'self' *.mixpanel.com *.stripe.com *.sentry.io ${VERCEL_CSP_DEFAULT_SRC} ${GOOGLE_FONTS_BASE_CSP};
style-src 'self' 'unsafe-inline';
script-src 'self' '${process.env.VERCEL_ENV === "preview" ? 'unsafe-inline' : 'unsafe-eval'}' *.mixpanel.com *.stripe.com ${VERCEL_BASE_CSP};
img-src 'self' ${VERCEL_CSP_IMG_SRC} data: blob:;
@piraka9011
piraka9011 / wasabi_client.py
Created May 31, 2023 13:02
Python Wasabi Client
from typing import Any, Optional
from urllib.parse import urlparse, urlunparse
from xml.etree import ElementTree
from botocore.auth import S3SigV4Auth
from botocore.awsrequest import AWSRequest
from botocore.credentials import Credentials
from django.conf import settings
from requests import Response, request