Skip to content

Instantly share code, notes, and snippets.

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

Dan delivrance

🐈
ฅ^•ﻌ•^ฅ
View GitHub Profile
@delivrance
delivrance / dir_tree.py
Created November 1, 2017 13:35
Builds a dictionary representing a directory tree
import json
import os
def build(path):
tree = {}
def walk(path, tree):
for i in os.listdir(path):
tree[i] = {}
@delivrance
delivrance / JapaneseRegex.js
Created April 15, 2018 18:05 — forked from ryanmcgrath/JapaneseRegex.js
Regex to test for presence of Japanese characters
// REFERENCE UNICODE TABLES:
// http://www.rikai.com/library/kanjitables/kanji_codes.unicode.shtml
// http://www.tamasoft.co.jp/en/general-info/unicode.html
//
// TEST EDITOR:
// http://www.gethifi.com/tools/regex
//
// UNICODE RANGE : DESCRIPTION
//
// 3000-303F : punctuation
@delivrance
delivrance / ainput.py
Last active April 9, 2024 11:21
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():
@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;
# 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 / 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)))))
@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 / 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 / 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 / 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).