Skip to content

Instantly share code, notes, and snippets.

Avatar
🐫

Omar Ryhan omarryhan

🐫
View GitHub Profile
@omarryhan
omarryhan / Sanic-Gino-Alembic migrations Setup
Last active May 30, 2020
Sanic/Gino/Alembic migrations
View Sanic-Gino-Alembic migrations Setup
# Do the first 6 steps only once.
1. pip install --user alembic
2. bash: ``cd {{my_project}} && alembic init alembic``
3. bash: ``text_editor {{my_project}}/alembic.ini``
4. Change: "sqlalchemy.url = postgres://{{username}}:{{password}}@{{address}}/{{db_name}}"
5. bash: ``text_editor {{my_project}}/alembic/env.py``
6. Now, import your metadata/db object from your app.:
# {{my_project}}/{{my_project_dir}}/app.py
@omarryhan
omarryhan / coinbase_commerce.py
Created Jan 3, 2019
Coinbase Commerce Python Validation
View coinbase_commerce.py
@coinbase_bp.route('/service/coinbase/hook', methods=['GET', 'POST', 'UPDATE', 'DELETE'], name='coinbase_hook', version=1)
async def webhook(request):
secret = request.app.config.COINBASE_WEBHOOK_SHARED_SECRET
payload = request.json
if not payload.get('event'):
return response.json(dict(
code=200, # We need coinbase to stop sending this message wether its valid or not
message='Invalid Event'
))
View keybase.md

Keybase proof

I hereby claim:

  • I am omarryhan on github.
  • I am omarryhan (https://keybase.io/omarryhan) on keybase.
  • I have a public key ASCs7tEYxwWyNtBjbc9hbgiq4pGFK5U9zpsBEWPJhTxwcgo

To claim this, I am signing this object:

View convert-from-png-to-webp-and-resize-png-and-webp
# sudo apt install webp imagemagick parallel
# I ran this on 59 very high quality PNGs and my processor was maxing out for about a minute or so. I have an Intel Core-i7-8750H.
cd folder-with-huge-ass-png-files
# convert to webp in the same folder
parallel -eta cwebp {} -o {.}.webp ::: *.png
# Run resize commands in parallel (on many processes/threads). Adjust numbers to taste.
View roman numerals to dec
def roman_numerals_to_decimal(strParam):
# code goes here
roman_numerals_order = ['I', 'V', 'X', 'L', 'C', 'D', 'M']
roman_numerals_mapping = {
roman_numerals_order[0]: 1,
roman_numerals_order[1]: 5,
roman_numerals_order[2]: 10,
roman_numerals_order[3]: 50,
roman_numerals_order[4]: 100,