Skip to content

Instantly share code, notes, and snippets.

View juandesant's full-sized avatar

Juande Santander-Vela juandesant

View GitHub Profile
@juandesant
juandesant / remove_tags.zsh
Created November 22, 2022 14:54
Remove ending part of filename from Twitter tags
for file in $(ls -1 [a-zA-Z0-9]*.mp4\?tag*)
do
# echo $file # optional, for visualisation purposes
file_parts=("${(@s/?/)file}") # splits $file into an array, split by ?
mv -v $file $file_parts[1] # rename file to the first part of the name (before the ?)
done
@juandesant
juandesant / make_alias.scpt
Created November 17, 2022 15:08
Creation of alias with some error management
tell application "Finder"
try
make new alias to POSIX file "/System/Applications/Automator.app" at POSIX file "/System/Applications/Automator.app" with properties {name:"Alias to Automator"}
on error errorMsg
make new alias to POSIX file "/System/Applications/Automator.app" at (path to downloads folder) with properties {name:"Alias to Automator.app"}
end try
end tell
# Requires atlassian-python-api PyPI module
from atlassian import Confluence
# You should read your secret information some other way
your_confluence_url = "https://confluence.domain.tld"
your_username = "your_username"
your_password = "your_password"
# cf becomes the Confluence instance with the user logged in
cf = Confluence(
@juandesant
juandesant / anagram.py
Last active August 18, 2022 00:00
Generates anagrams for words found in /usr/share/dict/words
from itertools import permutations
from functools import reduce
from collections import Counter
# Iterative product for factorial
def factorial(x): return reduce(lambda x,y: x*y , range(1,x+1))
words_file_path = "/usr/share/dict/words"
words_file = open(words_file_path, "r") # Valid for macOS; change for Linux, other UNIXes
words = { x.rstrip("\n").lower() for x in words_file.readlines() } # create a set for faster membership tests
@juandesant
juandesant / RevealAllFilesInHierarchy.scpt
Created March 18, 2022 21:20
Uses AppleScript to reveal all files within a hierarchy, using the frontmost folder in the Finder
tell application "Finder"
-- get the folder that corresponds to the foremost Finder Window
set theFolder to the folder of the first window
-- alternatively, you could choose a folder with the form below
-- set theFolder to (choose folder)
-- get justTheFiles by using the every item of ... whose ... construct
set justTheFiles to every item of the (entire contents of theFolder) whose kind ≠ "Folder"
-- reveal them opens up new folders of each directory and subdirectory in the hierarchy below the current folder
reveal justTheFiles
end tell
@juandesant
juandesant / git-url.sh
Created March 18, 2022 15:33
Bash/ZSH function that returns the HTTP url for a Git repository
git-url () {
# Use `git config` to get the remote URL
git_url=$(git config --get remote.origin.url)
# Check if it is an HTTP-based URL
if [[ $git_url == *"http"* ]]
then
# for HTTP-based URLs, nothing to do but report it
echo $git_url
else
# for SSH based URLs, remake git_url so that the user is removed, and the server separator changed to a slash
@juandesant
juandesant / astropy_units_volume.ipynb
Last active July 17, 2023 20:54
Astropy Units — Volume
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@juandesant
juandesant / gource-multirepo.sh
Last active August 27, 2021 14:10 — forked from derEremit/gource-multiple-repositories.sh
Generates gource video out of multiple repositories.
#!/usr/bin/env bash
# Generates gource video (h.264) out of multiple repositories.
# Pass the repositories in command line arguments.
# Example:
# <gource-multirepo.sh> /path/to/repo1 /path/to/repo2
RESOLUTION="1600x1080"
outfile="gource.mp4"
i=0
def dict_diff(dict_a, dict_b, show_value_diff=True):
result = {}
result['added'] = {k: dict_b[k] for k in set(dict_b) - set(dict_a)}
result['removed'] = {k: dict_a[k] for k in set(dict_a) - set(dict_b)}
if show_value_diff:
common_keys = set(first_dict) & set(second_dict)
result['value_diffs'] = {
k:(dict_a[k], dict_b[k])
for k in common_keys
if dict_a[k] != dict_b[k]
@juandesant
juandesant / collatz.py
Last active August 4, 2021 16:24
Python implementation of the Collatz series as a generator
def next_collatz(n):
if n%2 == 0:
return n//2
else:
return 3*n+1
def collatz(n):
yield n
result = next_collatz(n)
while result != 1 and result :