Skip to content

Instantly share code, notes, and snippets.

View svandragt's full-sized avatar
🤞

Sander van Dragt svandragt

🤞
View GitHub Profile
@svandragt
svandragt / switch-or-start.sh
Created May 25, 2023 15:28
Switch to the window associated by the command, or start it.
#!/usr/bin/env bash
# Switch to the window associated by the command, or start it
#{{{ Bash settings
# abort on nonzero exitstatus
set -o errexit
# abort on unbound variable
set -o nounset
# don't hide errors within pipes
These gists are in the process of being moved to https://brain.vandragt.com/books/code-snippets
@svandragt
svandragt / folderactions.sh
Last active February 23, 2023 17:00
Proof of concept to setup folder actions. Requires inoticoming.
#!/usr/bin/env bash
#{{{ Bash settings
# abort on nonzero exitstatus
set -o errexit
# abort on unbound variable
set -o nounset
# don't hide errors within pipes
set -o pipefail
#}}}
@svandragt
svandragt / composer-require-git.sh
Last active January 31, 2023 11:16
./composer-require-git myorg/mypackage:dev-main
#!/usr/bin/env bash
#{{{ Bash settings
# abort on nonzero exitstatus
set -o errexit
# abort on unbound variable
set -o nounset
# don't hide errors within pipes
set -o pipefail
#}}}
#!/usr/bin/env bash
#{{{ Bash settings
# abort on nonzero exitstatus
set -o errexit
# abort on unbound variable
set -o nounset
# don't hide errors within pipes
set -o pipefail
#}}}
@svandragt
svandragt / hideothers.sh
Created October 26, 2022 15:35
Hide others for elementary / ubuntu.
#!/bin/bash
# hideothers.sh
active_window_id=$(xdotool getactivewindow)
for window_id in $(xdotool search --onlyvisible ".*")
do
if [ $window_id != $active_window_id ]
then
wname=$(xdotool getwindowname $window_id)
if [ "$wname" != "" ] && [ "$wname" != "plank" ] && [ "$wname" != "io.elementary.wingpanel" ]
@svandragt
svandragt / backup.py
Created September 27, 2022 13:45
Python3 script that: Replaces a file with a symlink, pointing to the path-preserving backup, unique per hostname.
#!/usr/bin/env python3
"""
Replaces a file with a symlink, pointing to the path-preserving backup, unique per hostname.
version 2022-09-27
"""
import os
import sys
import shutil
import socket
@svandragt
svandragt / foreach-object-list.php
Last active February 7, 2022 09:10
Gotcha: Iterated lists of objects pass by reference in PHP!
<?php
// won't be incremented
$a = [
0,
0,
];
// !! will be incremented !!
$b = [
(object)['count' => 0],
@svandragt
svandragt / Gemfile
Created January 25, 2022 16:05
Combine items from multiple feeds
gem "byebug", "~> 11.1", :groups => [:development, :test]
gem "rss", "~> 0.2.9"
@svandragt
svandragt / fts.rb
Last active December 24, 2021 18:11
Full text search a single text file
#!/usr/bin/env ruby
# v2021-12-24.1
require 'sqlite3'
dbf = '/tmp/plan.db'
File.delete(dbf) if File.exists? dbf
db = SQLite3::Database.open dbf
db.results_as_hash = true
db.execute "CREATE VIRTUAL TABLE IF NOT EXISTS plan USING FTS5(contents,tokenize = porter)"
db.execute "INSERT INTO plan (contents) VALUES(?)", File.open(ARGV[0]).read