This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# brew or apt-get install gh jq fzf | |
CACHE_FILE=~/.gh_repos.json | |
CACHE_DURATION=$((60*60*24*3)) # 3 days in seconds | |
if [ ! -f "$CACHE_FILE" ] || [ $(( $(date +%s) - $(stat -c %Y "$CACHE_FILE") )) -ge $CACHE_DURATION ]; then | |
echo "Refreshing cache..." | |
gh api user/repos --paginate > "$CACHE_FILE" | |
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from typing import Protocol | |
class PybitesSearchProtocol(Protocol): | |
def match_content(self, search: str) -> list[str]: | |
"""Implement in subclass to search Pybites content""" | |
... | |
class CompleteSearch: | |
def match_content(self, search: str) -> list[str]: | |
# Implementation of search method |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# prior step done: | |
# python manage.py dumpdata auth.User --output=users.json --format=json | |
from collections import Counter | |
import json | |
import plotext as plt | |
def aggregate_users_by_year_month(filename="users.json"): | |
cnt = Counter() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.core.management.base import BaseCommand | |
import feedparser | |
from django.db.utils import IntegrityError | |
from blog.models import Article | |
FEED_URL = "https://pybit.es/feed/" | |
class Command(BaseCommand): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
>>> def gen(): | |
... yield from [1, 2, 3] | |
... | |
>>> g = gen() | |
>>> for i in g: print(i) | |
... | |
1 | |
2 | |
3 | |
# generator exhausted: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
repos: | |
- repo: https://github.com/pre-commit/pre-commit-hooks | |
rev: v4.0.1 | |
hooks: | |
- id: check-yaml | |
- id: end-of-file-fixer | |
- id: trailing-whitespace | |
- id: debug-statements | |
- repo: https://github.com/pycqa/flake8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cProfile | |
from functools import wraps | |
from pstats import Stats, SortKey | |
from time import time | |
def timing(f): | |
"""A simple timer decorator""" | |
@wraps(f) | |
def wrapper(*args, **kwargs): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Script to retrieve new titles from O'Reilly Media (formerly Safari Books Online)""" | |
from collections import namedtuple | |
from pathlib import Path | |
from datetime import datetime, timedelta | |
from urllib.request import urlretrieve | |
from xml.etree.ElementTree import parse | |
RSS_FEED = "https://www.oreilly.com/feeds/recently-added.rss" | |
NOW = datetime.now() | |
DT_FMT = "%a, %d %b %Y %H:%M:%S" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import asyncio | |
import os | |
import aiofiles | |
import aiohttp | |
# saved links from https://pybit.es/archives in urls | |
URLS = [u.rstrip() for u in open('urls', 'r').readlines()] | |
async def fetch(session, url): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from importlib import import_module | |
from keyword import kwlist | |
import builtins | |
from typing import Dict, List | |
scores = { | |
"builtin": 1, | |
"keyword": 2, | |
"module": 3, | |
} |
NewerOlder