Skip to content

Instantly share code, notes, and snippets.

View ddkasa's full-sized avatar
🎯
Focusing

David Kasakaitis ddkasa

🎯
Focusing
  • London, United Kingdom
  • 08:49 (UTC +01:00)
View GitHub Profile
@ispanos
ispanos / package_history.py
Created October 10, 2023 19:23
dnf 'exclusively' installed packages
import subprocess
import re
import sys
def get_pks_repoquery():
# Use repoquery to create a list of userinstalled packages
return set(subprocess.check_output(
'dnf repoquery --userinstalled --qf "%{name}"', shell=True, text=True
).splitlines())
@rochacbruno
rochacbruno / validate_dataclass.py
Created September 30, 2021 11:13
Validate Dataclass Python
from typing import Union, List
from dataclasses import dataclass
class Validations:
def __post_init__(self):
"""Run validation methods if declared.
The validation method can be a simple check
that raises ValueError or a transformation to
@daxburatto
daxburatto / Validating a Hex Value.md
Last active February 2, 2025 10:02
Validating a Hex Value with Regex

Validating a Hex Value

/^#?([a-f0-9]{6}|[a-f0-9]{3})$/

Summary

A Regular expression, or Regex, is a method of validating a specific piece of text by use of a sequence of characters each including their own fundimental principles. Regex can be used to validate emails, hex values, URLs, and HTML. In this case we will be focusing on Hex values which are typically a # with 6 numbers or letters following it.

Table of Contents

@mikeboiko
mikeboiko / git-credential-rbw
Last active December 21, 2024 22:11
Use bitwarden rbw as git-credential helper
#!/usr/bin/env bash
# rbw git-credential helper
# Based on https://github.com/lastpass/lastpass-cli/blob/master/contrib/examples/git-credential-lastpass
# A credential helper for git to retrieve usernames and passwords from rbw.
# For general usage, see https://git-scm.com/docs/gitcredentials.
# Here's a quick version:
# 1. Put this somewhere in your path.
# 2. git config --global credential.helper rbw
@andrebrait
andrebrait / keychron_linux.md
Last active May 13, 2025 04:22
Keychron keyboards on Linux + Bluetooth fixes

Here is the best setup (I think so :D) for K-series Keychron keyboards on Linux.

Note: many newer Keychron keyboards use QMK as firmware and most tips here do not apply to them. Maybe the ones related to Bluetooth can be useful, but everything related to Apple's keyboard module (hid_apple) on Linux, won't work. As far as I know, all QMK-based boards use the hid_generic module instead. Examples of QMK-based boards are: Q, Q-Pro, V, K-Pro, etc.

Most of these commands have been tested on Ubuntu 20.04 and should also work on most Debian-based distributions. If a command happens not to work for you, take a look in the comment section.

Make Fn + F-keys work (NOT FOR QMK-BASED BOARDS)

Older Keychron keyboards (those not based on QMK) use the hid_apple driver on Linux, even in the Windows/Android mode, both in Bluetooth and Wired modes.

@ckrybus
ckrybus / 1integrate-django-filter-django-tables2-django-crispy-forms.md
Last active March 30, 2025 05:44
How to integrate django-crispy-forms, django-tables2 and django-filter in order to display a paginated table with filter functionality.
@m3nu
m3nu / simpletreemodel.py
Last active October 10, 2024 01:23
QTreeView with Custom QAbstractItemModel and Lazy Loading
"""
This is an adjusted version of the official simpletreemodel[1] that adds lazy loading and uses a dict as backend.
Instead of the dict it could also use a database or similar. Items are only loaded when expanded, which allows
for speedy startup-time, even with 2.5m items.
1: https://github.com/baoboa/pyqt5/tree/master/examples/itemviews/simpletreemodel
"""
import sys
# Credit for this: Nicholas Swift
# as found at https://medium.com/@nicholas.w.swift/easy-a-star-pathfinding-7e6689c7f7b2
from warnings import warn
import heapq
class Node:
"""
A node class for A* Pathfinding
"""
@jnhmcknight
jnhmcknight / colour-inverter.py
Created June 15, 2018 14:09
Invert all colours in a CSS file.
#!/usr/bin/env python
# Concept taken from http://code.activestate.com/recipes/527747-invert-css-hex-colors/
# Modified to take the css filename as an argument and also handle rgb() and rgba() values
#
# To run:
# python ./colour-inverter.py <path/to/file.css>
import os
import re
@naushad-rahman
naushad-rahman / using_requests_with_django.py
Created January 19, 2018 09:42 — forked from hbradio/using_requests_with_django.py
An example of using Python requests to log in and post data to your Django API
import requests
LOGIN_URL = "http://mydjangosite.com/accounts/login/"
ENDPOINT_URL = 'http://mydjangosite.com/myendpoint/'
'''
Create a session.
A session will automatically store the cookies that Django
sends back to you, like the csrf token and a the session id. You
could do it without the session, but then you'd have to save off the