Skip to content

Instantly share code, notes, and snippets.

View retrography's full-sized avatar

Mahmood S. Zargar retrography

  • VU Amsterdam
  • Amsterdam, Netherlands
  • X @mszargar
View GitHub Profile
@retrography
retrography / bluetooth_sleep.lua
Created August 31, 2020 08:31 — forked from ysimonson/bluetooth_sleep.lua
Hammerspoon script to disable bluetooth when the computer is put to sleep. Requires `blueutil` to be installed (`brew install blueutil`).
require "string"
function checkBluetoothResult(rc, stderr, stderr)
if rc ~= 0 then
print(string.format("Unexpected result executing `blueutil`: rc=%d stderr=%s stdout=%s", rc, stderr, stdout))
end
end
function bluetooth(power)
print("Setting bluetooth to " .. power)
@retrography
retrography / corona_nl.R
Last active March 12, 2020 14:17
Plotting COVID-19 spread in The Netherlands
require(tidyverse)
# Set timezone to Central European Time
Sys.setenv(TZ='CET')
# The prefix to load the data from the web
stub <- "https://www.volksgezondheidenzorg.info/sites/default/files/map/detail_data/klik_corona"
# Day statistics are normally published before 4:30
upTime <-
@retrography
retrography / forked-daapd.log
Created November 10, 2019 18:06
Forked DAAPD / HomePod Log
[2019-04-29 22:10:04] [DEBUG] web: JSON api request: '/api/player'
[2019-04-29 22:10:04] [DEBUG] httpd: Checking web interface authentication
[2019-04-29 22:10:04] [DEBUG] httpd: Authentication successful
[2019-04-29 22:10:04] [DEBUG] player: Player status: playing
[2019-04-29 22:10:06] [DEBUG] raop: Got retransmit request from 'myPod', seq_start 16757 len 1
[2019-04-29 22:10:06] [DEBUG] raop: Got retransmit request from 'myPod', seq_start 16816 len 1
[2019-04-29 22:10:10] [DEBUG] raop: Got retransmit request from 'myPod', seq_start 17336 len 1
.
.
.
@retrography
retrography / forked-daapd.log
Created November 10, 2019 18:05
Forked-DAAPD / HomePod Log
[2019-11-10 17:59:29] [DEBUG] player: Start playback of '/media/music/Mark Knopfler/Down the Road Wherever (2018) [CD]/14 Every Heart in the Room.m4a' (id=29562, item-id=1667)
[2019-11-10 17:59:29] [DEBUG] db: Running query 'SELECT f.* FROM files f WHERE f.id = 29562;'
[2019-11-10 17:59:29] [DEBUG] player: (Re)opening track: '/media/music/Mark Knopfler/Down the Road Wherever (2018) [CD]/14 Every Heart in the Room.m4a' (id=1667, seek=0)
[2019-11-10 17:59:29] [DEBUG] db: Running query 'BEGIN TRANSACTION;'
[2019-11-10 17:59:29] [DEBUG] db: Starting enum 'SELECT * FROM queue f WHERE id = 1667 ORDER BY pos;'
[2019-11-10 17:59:29] [DEBUG] db: Running query 'END TRANSACTION;'
[2019-11-10 17:59:29] [DEBUG] player: Setting up input item '/media/music/Mark Knopfler/Down the Road Wherever (2018) [CD]/14 Every Heart in the Room.m4a' (item id 1667)
[2019-11-10 17:59:30] [DEBUG] ffmpeg: Unhandled or malformed custom metadata of size 64
[2019-11-10 17:59:30] [DEBUG] ffmpeg: Unhandled or mal
@retrography
retrography / command.md
Created September 9, 2019 22:10
How to save a readonly file opened in Vim
:w !sudo tee %
@retrography
retrography / killring.plugin.zsh
Created May 17, 2019 14:56
OH-MY-ZSH Custom Plugin -- Redefines the most used kill ring bindings to sync with the system clipboard (requires clipcopy plugin)
kill-line() { zle .kill-line ; echo -n $CUTBUFFER | clipcopy }
zle -N kill-line
bindkey "^K" kill-line
kill-whole-line() { zle .kill-whole-line ; echo -n $CUTBUFFER | clipcopy }
zle -N kill-whole-line
bindkey "^U" kill-whole-line
yank() { LBUFFER=$LBUFFER$(clippaste) }
zle -N yank
@retrography
retrography / FormatReference.rb
Created September 25, 2017 01:55
Parses the reference from the clipboard using AnyStyle parser and returns the corresponding bibtex record back into the clipboard
Encoding.default_external='utf-8'
Encoding.default_internal='utf-8'
require 'anystyle/parser'
require 'clipboard'
text = Clipboard.paste.tr("\n\r", " ").gsub(/\s+/,' ').gsub(/([a-zA-Z])- ([a-zA-Z])/, '\1\2')
ref = Anystyle.parse(text, :bibtex).to_s
Clipboard.copy(ref)
@retrography
retrography / pdf.rb
Created September 20, 2017 11:07
Transforms jbig2-encoded images into PDF - A Ruby port of https://github.com/agl/jbig2enc/blob/master/pdf.py
#!/usr/bin/env ruby
# Copyright 2017 Mahmood S. Zargar
# Author: mahmood@gmail.com (Mahmood S. Zargar)
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
@retrography
retrography / canvas.group_members.js
Created September 15, 2017 21:06
A bookmarklet that downloads group names and group members in a groupset on Canvas in csv format
var groups = [];
document.querySelectorAll("li.group").forEach(
function(group) {
name = group.querySelector("span.group-name").textContent;
members = [];
group.querySelectorAll("div.group-user-name").forEach(
function(member) {
members.push(member.textContent.trim() + "\t" + name);
}
);
@retrography
retrography / parallelRDS.R
Last active May 20, 2022 12:45 — forked from russellpierce/parallelRDS.R
Parallelize RDS compression/decompression to improve serialization performance in R
# The functions below use parallelized versions of gzip, xz, and bzip2 to
# improve compression/decompression performance of RDS serialization in R.
# Each function searches for the appropriate program (based on the required
# compression format) and if found, offloads the compression handling to the
# external program and therefore leaves R free to do the data import/export.
# The two main functions (saveRDS and readRDS) mask R's native read and write
# functions. The functions have been only tested on macOS, but they must work
# on any Linux/Unix.
#
# Requires the following packages: pxz, pbzip2, and pigz.