Skip to content

Instantly share code, notes, and snippets.

View born2discover's full-sized avatar
🏠
Working from home

born2discover

🏠
Working from home
  • Switzerland
  • 01:58 (UTC +02:00)
View GitHub Profile
@born2discover
born2discover / 55-bytes-of-css.md
Created September 25, 2022 17:18 — forked from JoeyBurzynski/55-bytes-of-css.md
58 bytes of css to look great nearly everywhere

58 bytes of CSS to look great nearly everywhere

When making this website, i wanted a simple, reasonable way to make it look good on most displays. Not counting any minimization techniques, the following 58 bytes worked well for me:

main {
  max-width: 38rem;
  padding: 2rem;
  margin: auto;
}
@born2discover
born2discover / gist:5bc7a8e97b07dde273a7489d871c37ab
Created May 17, 2022 23:50 — forked from mick-t/gist:85fc40d1acaf5e98cad9
Python-LDAP: find the groups a user is a member of.
LDAP_SERVER = "ldaps://my-ldap-server.com/"
LDAP_BASE = "dc=my-ldap-server,dc=com"
def users_ldap_groups(uid):
""" Returns a list of the groups that the uid is a member of.
Returns False if it can't find the uid or throws an exception.
It's up to the caller to ensure that the UID they're using exists!
"""
logger.debug("uid: ", uid)
@born2discover
born2discover / app.py
Created August 6, 2021 20:54 — forked from makotoworld/app.py
flask-uploads-sample
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from flask import *
import os
from werkzeug import secure_filename
app = Flask(__name__)
#searchword = request.args.get('q', '')
@born2discover
born2discover / uuid_user.py
Created July 25, 2021 23:12 — forked from gmolveau/uuid_user.py
sqlalchemy uuid for sqlite
########################
# UUID for SQLite hack #
########################
from sqlalchemy.types import TypeDecorator, CHAR
from sqlalchemy.dialects.postgresql import UUID
import uuid
class GUID(TypeDecorator):
@born2discover
born2discover / gpg_git_signing.md
Created July 23, 2021 09:39 — forked from alopresto/gpg_git_signing.md
Steps to enable GPG signing of git commits.

If anyone is interested in setting up their system to automatically (or manually) sign their git commits with their GPG key, here are the steps:

  1. Generate and add your key to GitHub
  2. $ git config --global commit.gpgsign true ([OPTIONAL] every commit will now be signed)
  3. $ git config --global user.signingkey ABCDEF01 (where ABCDEF01 is the fingerprint of the key to use)
  4. $ git config --global alias.logs "log --show-signature" (now available as $ git logs)
  5. $ git config --global alias.cis "commit -S" (optional if global signing is false)
  6. $ echo "Some content" >> example.txt
  7. $ git add example.txt
  8. $ git cis -m "This commit is signed by a GPG key." (regular commit will work if global signing is enabled)
@born2discover
born2discover / git-auto-sign-commits.sh
Created July 8, 2021 14:58 — forked from mort3za/git-auto-sign-commits.sh
Auto sign your git commits
# Generate a new pgp key: (better to use gpg2 instead of gpg in all below commands)
gpg --gen-key
# maybe you need some random work in your OS to generate a key. so run this command: `find ./* /home/username -type d | xargs grep some_random_string > /dev/null`
# check current keys:
gpg --list-secret-keys --keyid-format LONG
# See your gpg public key:
gpg --armor --export YOUR_KEY_ID
# YOUR_KEY_ID is the hash in front of `sec` in previous command. (for example sec 4096R/234FAA343232333 => key id is: 234FAA343232333)
@born2discover
born2discover / authentication.py
Created May 11, 2021 23:02
Redash LDAP Authentication
def auth_ldap_user(username, password):
server = Server(settings.LDAP_HOST_URL, use_ssl=settings.LDAP_SSL)
if settings.LDAP_BIND_DN is not None:
conn = Connection(
server,
settings.LDAP_BIND_DN,
password=settings.LDAP_BIND_DN_PASSWORD,
authentication=settings.LDAP_AUTH_METHOD,
auto_bind=True,
)
@born2discover
born2discover / pwned.py
Created May 11, 2021 22:53
Check a password against pwned passwords API using k-Anonymity. https://haveibeenpwned.com/API/v3
def pwned(password):
"""
Check password against pwnedpasswords API using k-Anonymity.
https://haveibeenpwned.com/API/v3
:return: Count of password in DB (0 means hasn't been compromised)
Can raise HTTPError
.. versionadded:: 3.4.0
"""
def convert_password_tuple(value):
@born2discover
born2discover / auth.py
Last active May 11, 2021 23:00 — forked from ibeex/auth.py
Python LDAP (ActiveDirectory) authentication
import ldap
def check_credentials(username, password):
"""Verifies credentials for username and password.
Returns None on success or a string describing the error on failure
# Adapt to your needs
"""
LDAP_SERVER = 'ldap://xxx'
# fully qualified AD user name
LDAP_USERNAME = '%s@xxx.xx' % username
@born2discover
born2discover / __init__.py
Last active October 20, 2020 20:48
Celery 5.0 with Flask
from flask import Flask
from importlib import import_module
from app.extensions import celery
def create_application(config_path: str = None) -> Flask:
app = Flask(__name__)
app.config.from_pyfile("settings.cfg")
app.config.from_envvar("APP_CONFIG", silent=True)