Skip to content

Instantly share code, notes, and snippets.

@setzer22
setzer22 / find_transitive_ns_deps.clj
Created April 17, 2020 09:54
Clojure: Find out the namespaces that are not transitive dependencies of a namespace in your project
;; Meant to be run on a REPL, this small script will find all the namespaces that are not transitively required
;; by a parent ns. This may be useful if you need to extract a small application from a huge monolithic project.
;; This code has been adapted from https://github.com/hilverd/lein-ns-dep-graph and distributed under the same license.
;; Note that this only looks at the ns declarations, but has no way to detect dependencies that are dynamically built
;; (e.g. by requiring a symbol created from a string using a plain `require`).
(do
(import [java.io PushbackReader])
@setzer22
setzer22 / random_merge.clj
Created May 9, 2019 07:35
Randomly merging two listst uniformly at random in clojure
;; Most implementations of a random merge between two lists don't give equal chance to
;; each of the possible interleavings. The following approach is able to produce such
;; a result by adapting the (almost correct) algoritm shown at [1]. An important part
;; of the algorithm was generating a sorted list of size `N` uniformly at random. An
;; efficient algorithm for this is presented at [2].
;; [1]: https://stackoverflow.com/questions/4577882/how-to-merge-2-sorted-listed-into-one-shuffled-list-while-keeping-internal-order
;; [2]: https://math.stackexchange.com/questions/3218854/randomly-generate-a-sorted-set-with-uniform-distribution
(defn rand-subset
"Returns a u.a.r k-subset of {1,..,n}"
@setzer22
setzer22 / simple-screenshot
Created August 26, 2017 17:58
A small bash script to take a screenshot and save it to your Pictures folder. Requires maim
#!/bin/bash
if [ "$1" != "retry" ]; then
maim -s > /tmp/screenshot-tmp.png
fi
OUTFILE=$(zenity --file-selection --save --filename=/home/josep/Pictures/screenshot.png)
if [ $? -eq 0 ] && [ -f $OUTFILE ]; then
zenity --question --text "Image $OUTFILE exists. Do you want to overwrite?"
@setzer22
setzer22 / README.md
Last active December 2, 2023 14:03
Linux command to hibernate and then reboot into a different OS

Linux command to hibernate and then reboot into a different OS

In this document I describe my setup about how to add a menu shortcut that will hibernate and reboot the system into a different OS (in my case, Windows), and then restore linux on the next reboot.

For this, I'll be using Arch Linux with systemd-boot as my boot manager, but in practice any bootloader that handles the LoaderEntryOneShot (a.k.a. BootNext) efivar should work.

NOTE It is advisable to not do this with window's fast boot feature active, since alternating the hibernation of two systems can cause shared partitions to get corrupted. However, if additional steps are taken in order to ensure the shared partition are unmounted before reboot, or no partitions are shared between the two OSs, this can be made to work with fastboot enabled which should give quite a boost in Windows' startup time.

Set the LoaderEntryOneShot/BootNext EFI variable

@setzer22
setzer22 / pygtkeyval
Last active December 27, 2015 15:30
A simple script that displays a GTK window asking for values to the provided list of keys. Usage: pygtkeyvals Title [Keys]
#!/usr/bin/python2
#The MIT License (MIT)
#Copyright (c) 2015 setzer22
#Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
#associated documentation files (the "Software"), to deal in the Software without restriction, including
#without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the
#following conditions:
#!/bin/bash
# usage: li-results-parallel.sh instances_path > out.txt
# Number of threads to use
N_THREADS=8
INSTANCES_PATH=$1
ls $INSTANCES_PATH/*.cnf | xargs -n 1 -P $N_THREADS sh li-results-single.sh