Skip to content

Instantly share code, notes, and snippets.

View dayyass's full-sized avatar
🚀
Rocket Science

Dani El-Ayyass dayyass

🚀
Rocket Science
View GitHub Profile
# Ideally, we would manage async access to stdin/stdout/stderr *without*
# setting them to non-blocking mode, because that can break other processes.
# (See https://github.com/python-trio/trio/issues/174 for much more detail.)
# Of course we can call read/write in a separate thread, but then we lose
# cancellation support.
# This file demonstrates a weird hack to make blocking read/write cancellable,
# and thus at least theoretically possible to integrate into Trio as ordinary
# first-class operations.
@jamescalam
jamescalam / flask_api.py
Last active September 10, 2024 20:13
A example API using Flask
from flask import Flask
from flask_restful import Resource, Api, reqparse
import pandas as pd
import ast
app = Flask(__name__)
api = Api(app)
class Users(Resource):
def get(self):
@4OH4
4OH4 / tfidf_adv.py
Last active January 27, 2025 07:38
TF-idf model with stopwords and lemmatizer
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import linear_kernel
from nltk import word_tokenize
from nltk.stem import WordNetLemmatizer
import nltk
from nltk.corpus import stopwords
# Download stopwords list
nltk.download('punkt')
stop_words = set(stopwords.words('english'))
@yaroslavvb
yaroslavvb / install_pdb_handler.py
Created October 11, 2019 17:53
install_pdb_handler
def install_pdb_handler():
"""Signals to automatically start pdb:
1. CTRL+\\ breaks into pdb.
2. pdb gets launched on exception.
"""
import signal
import pdb
def handler(_signum, _frame):
@Tushar-N
Tushar-N / hook_activations.py
Created August 3, 2018 00:06
Pytorch code to save activations for specific layers over an entire dataset
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision.models as tmodels
from functools import partial
import collections
# dummy data: 10 batches of images with batch size 16
dataset = [torch.rand(16,3,224,224).cuda() for _ in range(10)]
@HarshTrivedi
HarshTrivedi / pad_packed_demo.py
Last active April 17, 2025 01:26 — forked from Tushar-N/pad_packed_demo.py
Minimal tutorial on packing (pack_padded_sequence) and unpacking (pad_packed_sequence) sequences in pytorch.
import torch
from torch import LongTensor
from torch.nn import Embedding, LSTM
from torch.autograd import Variable
from torch.nn.utils.rnn import pack_padded_sequence, pad_packed_sequence
## We want to run LSTM on a batch of 3 character sequences ['long_str', 'tiny', 'medium']
#
# Step 1: Construct Vocabulary
# Step 2: Load indexed data (list of instances, where each instance is list of character indices)
@ro31337
ro31337 / docker_completion_for_zsh.md
Created August 13, 2017 02:12
Zsh docker completion

Docker Completion for Zsh (Official)

  • mkdir -p ~/.oh-my-zsh/plugins/docker/
  • curl -fLo ~/.oh-my-zsh/plugins/docker/_docker https://raw.githubusercontent.com/docker/cli/master/contrib/completion/zsh/_docker
  • Add docker to plugins section in ~/.zshrc
  • exec zsh
@Miserlou
Miserlou / flask_binary.py
Created February 17, 2017 19:07
Flask serving binary data example
import io
from flask import Flask, send_file
app = Flask(__name__)
@app.route('/logo.jpg')
def logo():
"""Serves the logo image."""
with open("logo.jpg", 'rb') as bites:
@BretFisher
BretFisher / present.zsh-theme
Last active December 27, 2024 18:01
oh-my-zsh theme for presentations (hides prompt features based on path)
# problem: when presenting, I want to obscure
# my prompt to act like it's at root of file system
# and be very basic with no git info, etc.
# solution: this theme lets you set a ENV to the path
# of your presentation, which will help remove unneeded prompt
# features while in that path
# oh-my-zsh theme for presenting demos
# based off the default rubbyrussell theme
@citrusui
citrusui / dropdown.md
Last active May 10, 2025 18:03
"Dropdowns" in Markdown
How do I dropdown?
This is how you dropdown.

<details>
<summary>How do I dropdown?</summary>
<br>
This is how you dropdown.