Skip to content

Instantly share code, notes, and snippets.

View mostafabahri's full-sized avatar
👨‍💻

Mostafa Bahri mostafabahri

👨‍💻
  • Germany
View GitHub Profile
@mostafabahri
mostafabahri / decrypt.py
Last active March 17, 2025 13:26
Fernet encryption example with password
#!/usr/bin/env python3
from cryptography.fernet import Fernet
from kdf import derive_key
passphrase = b"hunter2"
f = Fernet(derive_key(passphrase))
with open('encrypted.txt', 'rb') as file:
encrypted = file.read() # binary read
@mostafabahri
mostafabahri / tsa.md
Last active January 25, 2018 22:34
TSA guide

Trusted Timestamping Workflow

Send and verify a rfc3161 standard timestamp request

  1. Create a timestamp request (tsq)
    openssl ts -query -data file.txt -no_nonce -out request.tsq

    Got the hash already?
    `openssl ts -query -digest b7e5d3f9319...

@mostafabahri
mostafabahri / nvidia.md
Created December 27, 2017 11:16
Install Nvidia Driver on Ubuntu

How to install latest Nvidia driver on Ubuntu

 sudo apt-get update
 sudo ubuntu-drivers autoinstall

that's it!

@mostafabahri
mostafabahri / GitNotes.sh
Last active December 16, 2017 08:07
Git tips and tricks
# display all commits that are in develop but not in master
git log master..develop
# remove file from git tracking
git rm --cached main.py
pragma solidity ^0.4.11;
contract Purchase {
uint public value;
address public seller;
address public buyer;
enum State { Created, Locked, Refund, Inactive }
// state init??
State public state = State.Created;
@mostafabahri
mostafabahri / countries-flag.py
Last active December 16, 2017 08:42
Django trickery
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/flag-icon-css/2.8.0/css/flag-icon.min.css">
{% for agency in agencies %}
<div class="section">
<span class="flag-icon flag-icon-{{ agency.country|lower }}"></span> # here
<div class="info rtl">
<h5>{{ agency.country.name }}</h5>
<h5>{{ agency.agent_name }}</h5>
<h5>{{ agency.email }}</h5>
</div>
@mostafabahri
mostafabahri / img_src.regex
Created March 29, 2017 20:20
Regex tips and tricks
"\.\.\/(.+?)"
"{% static '$1' %}"
@mostafabahri
mostafabahri / container.sh
Last active December 16, 2017 08:09
Docker Tips
# remove all stopped containers!
docker container prune
@mostafabahri
mostafabahri / python-fabric-deps.sh
Last active December 16, 2017 08:11
Required dependencies for Python Cryptography and/or Fabric.
apt-get install build-essential python3-dev python-dev libssl-dev libffi-dev
@mostafabahri
mostafabahri / RTL_text_on_image.py
Last active December 16, 2017 08:23
Snippet for writing Persian or other RTL langs on image with Python PIL
# -*- coding: utf-8 -*-
#!/usr/bin/env python3
import PIL
from PIL import ImageFont, Image, ImageDraw
from bidi.algorithm import get_display
import arabic_reshaper
def rtl_fix(text):