Skip to content

Instantly share code, notes, and snippets.

View delivrance's full-sized avatar
🐈
ฅ^•ﻌ•^ฅ

Dan delivrance

🐈
ฅ^•ﻌ•^ฅ
View GitHub Profile
@delivrance
delivrance / speedtest.py
Created May 1, 2020 14:04
Pyrogram upload speedtest
from pyrogram import Client
import time
app = Client("...")
async def main():
async with app:
m = await app.send_message("pyrogramchat", "uploading 1500 MB...")
s = time.time()
@delivrance
delivrance / xkcd.py
Created April 28, 2020 00:21
Download all available xkcd comics metadata as json list
import asyncio
import aiohttp
import json
async def main():
async with aiohttp.ClientSession() as session:
n = (await (await session.get("https://xkcd.com/info.0.json")).json())["num"]
@delivrance
delivrance / gh-pages-deploy.md
Created March 2, 2020 23:52 — forked from cobyism/gh-pages-deploy.md
Deploy to `gh-pages` from a `dist` folder on the master branch. Useful for use with [yeoman](http://yeoman.io).

Deploying a subfolder to GitHub Pages

Sometimes you want to have a subdirectory on the master branch be the root directory of a repository’s gh-pages branch. This is useful for things like sites developed with Yeoman, or if you have a Jekyll site contained in the master branch alongside the rest of your code.

For the sake of this example, let’s pretend the subfolder containing your site is named dist.

Step 1

Remove the dist directory from the project’s .gitignore file (it’s ignored by default by Yeoman).

@delivrance
delivrance / clean_code.md
Created June 26, 2019 21:20 — forked from wojteklu/clean_code.md
Summary of 'Clean code' by Robert C. Martin

Code is clean if it can be understood easily – by everyone on the team. Clean code can be read and enhanced by a developer other than its original author. With understandability comes readability, changeability, extensibility and maintainability.


General rules

  1. Follow standard conventions.
  2. Keep it simple stupid. Simpler is always better. Reduce complexity as much as possible.
  3. Boy scout rule. Leave the campground cleaner than you found it.
  4. Always find root cause. Always look for the root cause of a problem.

Design rules

@delivrance
delivrance / tgcrypto_bench.py
Last active August 10, 2022 02:09
TgCrypto benchmark
# https://github.com/pyrogram/tgcrypto
import os
import time
import tgcrypto
def fmt(d, s):
return f"{len(d) / (time.time() - s) / 1024 / 1024 :.2f} MB/s"
@delivrance
delivrance / welcome_bot.hy
Last active April 23, 2019 17:13
This is the Welcome Bot in @PyrogramChat (Telegram) written in Hy
;; This is the Welcome Bot in @PyrogramChat (Telegram) written in Hy
;;
;; Example ported from
;; https://github.com/pyrogram/pyrogram/blob/c2da2a61ece6711bd7ed51d68249995843ff5dec/examples/welcome_bot.py
;;
(import [pyrogram [Client Emoji Filters]])
(setv MENTION "[{}](tg://user?id={})")
(setv MESSAGE "{} Welcome to [Pyrogram](https://docs.pyrogram.ml/)'s group chat {}!")
@delivrance
delivrance / pyrogram.hy
Created October 9, 2018 16:15
Pyrogram example written in Hy
;; Example ported from https://github.com/pyrogram/pyrogram
(import [pyrogram [Client Filters]])
(setv app (Client "my_account"))
(with-decorator (.on_message app (. Filters private))
(defn hello [client message]
(.reply message (.format "Hello {}" (. message from_user first_name)))))
# From: https://github.com/pyrogram/pyrogram/blob/ffd67ed40839d82c133b6abc5529305385a74a4e/pyrogram/client/client.py#L54-L55
# Custom format for nice looking log lines
LOG_FORMAT = "[%(asctime)s.%(msecs)03d] %(filename)s:%(lineno)s %(levelname)s: %(message)s"
@delivrance
delivrance / PostgreSQL_index_naming.rst
Created September 15, 2018 20:08 — forked from popravich/PostgreSQL_index_naming.rst
PostgreSQL index naming convention to remember

The standard names for indexes in PostgreSQL are:

{tablename}_{columnname(s)}_{suffix}

where the suffix is one of the following:

  • pkey for a Primary Key constraint;
  • key for a Unique constraint;
  • excl for an Exclusion constraint;
  • idx for any other kind of index;
@delivrance
delivrance / ainput.py
Last active June 13, 2024 09:18
Python async input
import asyncio
from concurrent.futures import ThreadPoolExecutor
async def ainput(prompt: str = "") -> str:
with ThreadPoolExecutor(1, "AsyncInput") as executor:
return await asyncio.get_event_loop().run_in_executor(executor, input, prompt)
async def main():