Skip to content

Instantly share code, notes, and snippets.

@Ayehavgunne
Ayehavgunne / rofi_keybinds.py
Created October 12, 2024 06:41
Hyprland keybinds cheatsheet using Rofi (dmenu)
#!/usr/bin/env python3.12
import json
from dataclasses import dataclass
from subprocess import PIPE, Popen
SUPER = 64
ALT = 8
CTRL = 4
SHIFT = 1
@mvanga
mvanga / ecs-annotated.py
Last active October 5, 2023 15:32
A Python3 implementation of an entity-component-system in under 50 lines code.
import uuid
import json
# Returns a python dictionary given a file containing a JSON-based
# component definition. Every definition *must* contain a 'type'
# and 'schema' field inside a top-level dictionary. Here is an
# example of a simple schema file that defines a 'meta' component
# containing a 'name' field.
#
@Ayehavgunne
Ayehavgunne / click_outside_close.js
Last active July 29, 2017 10:37
Quick setup for clicking outside a menu to close it
//with JQuery
function clickOutsideClose(element, callback) {
$(document).mouseup(function(e) {
let container = $(element)
if (!container.is(e.target) && container.has(e.target).length === 0) {
container.hide()
if (typeof callback === 'function') {
callback()
}
}
@Ayehavgunne
Ayehavgunne / generate_html.js
Last active July 30, 2017 19:35
Programmatically create html tags
function _create_html(inner_html, attributes = {}, data_attr = {}, self_closing = false, tag = null) {
let html = '<' + tag
if (!is_array(inner_html) && is_object(inner_html)) {
attributes = inner_html
inner_html = null
}
for (let key in attributes) {
html = html + ' ' + key + '="' + attributes[key] + '"'
}
for (let key in data_attr) {
@Ayehavgunne
Ayehavgunne / parse.py
Last active November 29, 2020 11:13
Parse a string into a timedelta object in Python
from decimal import Decimal
from datetime import timedelta
def duration(duration_string): #example: '5d3h2m1s'
duration_string = duration_string.lower()
total_seconds = Decimal('0')
prev_num = []
for character in duration_string:
if character.isalpha():
@Jaza
Jaza / Private-pypi-howto
Last active July 2, 2023 16:24
Guide for how to create a (minimal) private PyPI repo, just using Apache with directory autoindex, and pip with an extra index URL.
*
@jlnwlf
jlnwlf / pre-commit
Created March 20, 2014 09:04
git pre-commit hook for Python Unittest + autopep8 check
#!/bin/bash
autopep=$(autopep8 -dr .)
if [[ -z $autopep ]]
then
echo "> PEP8 passed !"
else
echo "> PEP8 DID NOT pass !"
echo "$autopep" | colordiff
@jeremytregunna
jeremytregunna / linked-list.ll
Created August 14, 2011 00:18
Linked List in LLVM IR
;; Linked list implementation
;; I compile it like this on Mac OS X:
;
; llvm-as linked-list.ll
; llc linked-list.bc
; as linked-list.s -o linked-list.o
; ld /usr/lib/crt1.o linked-list.o -o linked-list -lSystem -macosx_version_min 10.6
;; Type aliases
%free_func = type void (i8*)*