Skip to content

Instantly share code, notes, and snippets.

View madprops's full-sized avatar

madprops madprops

View GitHub Profile
@madprops
madprops / toucher.py
Created September 13, 2021 18:52
Update the modification date of files in a directory in sorted order
#!/usr/bin/python3
import pathlib
for p in sorted(pathlib.Path('.').iterdir()):
if p.is_file():
print(p)
p.touch()
#!/bin/bash
n=$((1 + RANDOM % 2))
if [[ "$n" == "1" ]]; then
str=$(shuf -n1 /usr/share/dict/american-english | cut -d$'\t' -f1 | tr '\n' ' ' | sed "s/'s//g")
else
str=$(cat /dev/urandom | tr -dc 'a-zA-Z0-9' | fold -w 4 | head -n 1)
fi
#!/bin/bash
date=$(($(date +%s%N)/1000000))
odate=$([ -r /tmp/closer_click_date ] && cat /tmp/closer_click_date)
oid=$([ -r /tmp/closer_click_id ] && cat /tmp/closer_click_id)
sedGetValue='s/.*=\(.*\)/\1/'
id=$(xdotool getmouselocation --shell 2>/dev/null | grep WINDOW | sed "$sedGetValue")
class=$(xprop -id "$id" | grep WM_CLASS)
type="normal"
if [[ "$class" == *"Firefox"* ]]; then
@madprops
madprops / notify.sh
Created March 10, 2020 10:52
Script to easily make naughty notifications ( awesome wm) when using bash scripts
#!/bin/bash
# Arguments: title message icon timeout mode
# If mode is 'update' it will update an existing notification with the same title
# Example usage: ~/scripts/notify.sh 'Audio Volume' ${vol} ~/scripts/music.jpg 2 update
awesome-client 'naughty = require("naughty")
local title = "'"$1"'"
local message = "'"$2"'"
@madprops
madprops / nimtut.nim
Created November 25, 2019 18:14
Used for a video tutorial on Nim
# Mutable variable
var a = "hello"
# Immutable variable
let a = "hello"
# Specify a type
var age: int
var name: string
@madprops
madprops / setup_snes_controller.sh
Last active November 3, 2019 17:23
This maps some buttons of generic usb snes controllers to F keys
#!/bin/bash
# Run with root privileges
product_id="D015"
product_id_o="d015"
vendor_id="12BD"
vendor_id_o="12bd"
cat - <<UDEV_RULESET > /etc/udev/rules.d/10-usb-snes.rules
#[macro_export]
macro_rules! hashmap
{
($( $key: expr => $val: expr ),*) => {{
let mut map = ::std::collections::HashMap::new();
$( map.insert($key, $val); )*
map
}}
}
@madprops
madprops / fac.rs
Created August 5, 2019 02:34
Quick Rust algorithm to find prime factors of a number
fn fac(n: u64) -> Vec<u64>
{
let step = |x| (1 + ((x << 2) as i32) - (((x >> 1) as i32) << 1)) as u64;
let maxq: u64 = (n as f64).sqrt().floor() as u64;
let mut d = 1;
let mut q = if n % 2 == 0 {2} else {3};
while q <= maxq && n % q != 0
{
q = step(d);
@madprops
madprops / upload.sh
Last active June 14, 2019 07:15
Bash script to upload to different sources
#! /bin/bash
# This requires dropbox_uploader.sh for dropbox support
# You can create context menu entries in your DE or keyboard shortcuts for this
# Add your Imgur client ID
function upload_image
{
client_id="yourImgurClientID"
link=$(curl -s --request POST --url https://api.imgur.com/3/image --header \
@madprops
madprops / wordz.js
Created April 14, 2019 16:50
Word list with helper functions
const Wordz = function()
{
const wordz = {}
wordz.words =
[
"aardvark", "abacus", "abbey", "abdomen", "ability", "abolishment", "abroad", "abuse",
"accelerant", "accelerator", "access", "accident", "accommodation", "accompanist", "accordion", "account",
"accountant", "achiever", "acid", "acknowledgment", "acoustic", "acoustics", "acrylic", "act",
"action", "activity", "actor", "actress", "acupuncture", "ad", "adapter", "addiction",