Skip to content

Instantly share code, notes, and snippets.

@madprops
madprops / toucher.py
Created Sep 13, 2021
Update the modification date of files in a directory in sorted order
View toucher.py
#!/usr/bin/python3
import pathlib
for p in sorted(pathlib.Path('.').iterdir()):
if p.is_file():
print(p)
p.touch()
View randword.sh
#!/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
View closer.sh
#!/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 Mar 10, 2020
Script to easily make naughty notifications ( awesome wm) when using bash scripts
View notify.sh
#!/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 Nov 25, 2019
Used for a video tutorial on Nim
View nimtut.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 Nov 3, 2019
This maps some buttons of generic usb snes controllers to F keys
View setup_snes_controller.sh
#!/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
View madcros.rs
#[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 Aug 5, 2019
Quick Rust algorithm to find prime factors of a number
View fac.rs
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 Jun 14, 2019
Bash script to upload to different sources
View upload.sh
#! /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 Apr 14, 2019
Word list with helper functions
View wordz.js
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",