Skip to content

Instantly share code, notes, and snippets.

View juandesant's full-sized avatar

Juande Santander-Vela juandesant

View GitHub Profile
#!/usr/bin/env python
import datetime as dt
def riddle_for_date(date, solutions=False):
"""
Determines the number for the Saturday Mac Riddle associated with
a given date, considering whether it is the date for the riddle
or the solutions.
@juandesant
juandesant / acronym_index.tex
Created February 26, 2024 18:04
Create glossary and index entries in LaTeX
\documentclass{article}
\usepackage{hyperref}
\usepackage{makeidx}
\usepackage{glossaries}
\makeindex
\makeglossaries
% Define your acronym
@juandesant
juandesant / export_access_tables.py
Created November 7, 2023 20:35
Export tables from an Access database
# This script assumes that [mdbtools][1] are installed, for instance with
# `brew install mdbtools`
# [1]: https://github.com/mdbtools/mdbtools
# It also assumes that [pandas][2] and [pandas_access][3] are installed,
# [2]: https://pandas.pydata.org/
# [3]: https://pypi.org/project/pandas_access/
# which you can do with
# `pip install pandas pandas_access`
# or
# `pip install pandas_access`
digraph pictionary_play {
node [fontname = "Handlee"];
edge [fontname = "Handlee"];
splines=false;
randir=LR;
draw [
label = "Draw a picture";
@juandesant
juandesant / add_labels_to_page_children.py
Created July 28, 2023 13:51
Use their Atlassian Python API to set labels for the children of a given page. The script asks for the URL, and the list of tags. It then finds all children for that page, regardless of URL form, and sets the proper tags.
import sys
import os
from atlassian import Confluence
def obtain_confluence_pat(path='~/.ConfluencePAT'):
confluence_PAT_filename = os.path.expanduser(path)
confluence_PAT = None
if os.path.exists(confluence_PAT_filename):
with open(confluence_PAT_filename, "r") as pat_file:
confluence_PAT = pat_file.readline()
@juandesant
juandesant / Quake-based Inverse Square Root.swift
Last active January 23, 2023 12:03
"Fast" Inverse Square Root based on Quake's algorithm implemented in Swift
//Quick inverse square root using bit patterns
//Might be slower nowadays than using specific functions
// The following is the abridged version of the Quake function
// See more at https://en.wikipedia.org/wiki/Fast_inverse_square_root
//float Q_rsqrt( float number )
//{
// long i;
// float x2, y;
@juandesant
juandesant / ADS_citation_count_evolution.py
Last active January 5, 2023 20:52
This Python scripts creates four graphs for the evolution of author counts in astronomy papers from 1980 to 2022. It requires an [ADS Config Token][1] in order to work. [1]: https://ui.adsabs.harvard.edu/user/settings/token
import ads
import pandas as pd
ads.config.token='putYourOwnAdsConfigTokenHere'
bibgroups = [
"ALMA",
"CfA",
"CFHT",
"Chandra",
@juandesant
juandesant / Einstein's Riddle.pl
Created December 10, 2022 21:20
Solving Einstein's Riddle with Prolog
right_of(X, Y) :- X =:= Y+1.
left_of(X, Y) :- right_of(Y, X).
next_to(X, Y) :- right_of(X, Y).
next_to(X, Y) :- left_of(X, Y).
solution(Street) :-
/* There are 5 houses in the street, all of different colours;
and their owners all have different nationalities, smoke different brands,
have different pets, and have different drinks */
@juandesant
juandesant / einstein.pl
Created December 10, 2022 20:33 — forked from jgilchrist/einstein.pl
A Prolog solution to Einstein's Riddle
right_of(X, Y) :- X is Y+1.
left_of(X, Y) :- right_of(Y, X).
next_to(X, Y) :- right_of(X, Y).
next_to(X, Y) :- left_of(X, Y).
solution(Street, FishOwner) :-
Street = [
house(1, Nationality1, Color1, Pet1, Drinks1, Smokes1),
house(2, Nationality2, Color2, Pet2, Drinks2, Smokes2),
@juandesant
juandesant / Enumerate keys using Foundation.applescript
Last active November 24, 2022 14:10
Enumerate keys in an AppleScript dictionary/record using the Foundation framework
-- Based on an answer in StackOverflow
-- Q: https://stackoverflow.com/questions/18062494/how-to-enumerate-the-keys-and-values-of-a-record-in-applescript
-- A: https://stackoverflow.com/a/29545930/919692
use framework "Foundation"
set testRecord to {b:"bbb", c:"ccc", |0|:"zero", a:"aaa", |null|:"null"}
set objCDictionary to current application's NSDictionary's dictionaryWithDictionary:testRecord
set allKeys to objCDictionary's allKeys()