Skip to content

Instantly share code, notes, and snippets.

@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():
@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 / 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 / crosstab.py
Created June 18, 2019 20:21 — forked from gregpinero/crosstab.py
Create a cross tab / pivot table in Python
import itertools
def crosstab(rows, columns, col_idx_for_columns, lst_col_idx_for_rows, value_col_idx, fill_val, format_func=None):
"""Take col_idx_to_cross_tab and make its unique values be new columns at the end filled with
value_col_idx values. col idx arguments are 0 based.
This is basically a simplified pivot table creator with the limitations that you can only have one field in the columns
and there is no aggregation.
@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
@Ayehavgunne
Ayehavgunne / random_wallpaper.py
Created October 12, 2024 06:57
Hyprpaper random wallpaper script with portrait support
#!/usr/bin/env python3.12
import random
from dataclasses import dataclass
from subprocess import PIPE, Popen
WALLPAPERS_PATH = "~/nas/Wallpapers"
@dataclass
class Response: