Skip to content

Instantly share code, notes, and snippets.

View josefandersson's full-sized avatar
⛩️
Hehe

Josef Andersson josefandersson

⛩️
Hehe
View GitHub Profile
@josefandersson
josefandersson / create-timelapse.sh
Created May 16, 2021 10:31
Create a timelapse video file from many images using FFMPEG
# Create a timelapse video from many images
ffmpeg -r 60 -pattern_type glob -i "*.JPG" -s 1920x1440 -vcodec libx264 output.mp4
# -r <framerate> : output framerate
# -pattern_type glob : allow for * input
# -i <pattern> : input files pattern
# -s <size> : output size (4000x3000 -> 1920x1440 is suitable for GoPro output)
# -vcodec <codec> : output codec (see ffmpeg -codecs) (libx264 for standard mpeg-4 avc) (libx265 for hevc)
# May also be relevant to rotate the output:
@josefandersson
josefandersson / backup-tool.sh
Last active June 7, 2022 19:12
Script to backup (compress and pgp encrypt) a file or directory and send it anywhere via ssh.
#!/bin/bash
# Usage: script <source file/directory> <gpg recipient> <ssh login@server>:<target directory> [chmod]
# Example: /usr/local/bin/backup-tool.sh /home/alice/bwdata [email protected] [email protected]:backups/ 0600
# Example crontab: 0 5 * * * <see example above>
# Notes: Remember that elevated permissions is required to read some dirs/files
# Remember to add and trust the GPG recipient, otherwise the encryption will fail
[ -z "$1" ] && echo "No source file/directory" && exit 1
[ -z "$2" ] && echo "No recipient" && exit 1
@josefandersson
josefandersson / country-data.js
Last active December 27, 2020 03:13
A collection of various data points for all countries in the World.
const COUNTRY_DATA = {
"AF": {
"name": "Afghanistan",
"iso2": "AF",
"tld": "af",
"phone": "93",
"continent": "Asia",
"capital": "Kabul",
"time": "Asia/Kabul",
"langs": "Afghan Persian or Dari (official) 50%, Pashto (official) 35%, Turkic languages (primarily Uzbek and Turkmen) 11%, 30 minor languages (primarily Balochi and Pashai) 4%, much bilingualism, but Dari functions as the lingua franca",
// ==UserScript==
// @name DuckDuckGo Force Strict
// @namespace -
// @version 1.0
// @description Force 'strict' search mode on DuckDuckGo.
// @author Josef Andersson
// @include *://duckduckgo.com/?*
// @icon https://duckduckgo.com/favicon.ico
// @grant GM_addStyle
// ==/UserScript==
@josefandersson
josefandersson / bspwmhacky.c
Last active March 18, 2021 09:20
Method for bypassing bspwm 'focus' bug for chromium based apps. Build bspwmhacky.c, start it with bspwm, use xdotool to move hacky window to desktop before focusing on desktop.
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(void) {
XEvent e;
Display *d = XOpenDisplay(NULL);
@josefandersson
josefandersson / backup_bitwarden.sh
Last active September 16, 2020 11:39
Script to backup Bitwarden data folder to another server using ssh and gpg encryption
#!/bin/bash
# Usage: script <bitwarden data directory> <gpg recipient> <ssh login@server>:<target folder>
# Example: script /home/alice/bwdata [email protected] [email protected]:~/backups/
# Note: Requires elevated permissions to read all files in bitwarden data folder
[ -z "$1" ] && echo "No data directory" && exit
[ -z "$2" ] && echo "No recipient" && exit
[ -z "$3" ] && echo "No backup server" && exit
// ==UserScript==
// @name DuckDuckGo Verbatim
// @namespace https://github.com/josefandersson/userscripts/
// @version 1.1
// @description Adds a verbatim button to the duckduckgo search bar
// @author Josef Andersson
// @match https://duckduckgo.com/*
// @run-at document-end
// ==/UserScript==
@josefandersson
josefandersson / background.js
Last active June 8, 2020 14:51
A chromium extension for moving tabs with key commands
chrome.commands.onCommand.addListener(cmd => {
chrome.tabs.query({ currentWindow:true, active:true }, tabs => {
const tab = tabs[0];
if (!tab) return;
switch (cmd) {
case 'move-left': chrome.tabs.move(tab.id, { index:Math.max(0, tab.index-1) }); break;
case 'move-right': chrome.tabs.move(tab.id, { index:tab.index+1 }); break;
case 'move-to-first': chrome.tabs.move(tab.id, { index:0 }); break;
case 'move-to-last': chrome.tabs.move(tab.id, { index:-1 }); break;
case 'move-next-window': tabMoveWindow(tab, 1); break;
@josefandersson
josefandersson / dwmblockssendsignal.c
Created June 2, 2020 22:51
Send signals to dwmblock blocks
#include <signal.h>
#include <stdio.h>
static int send(int pid, int sigval);
int
main(int argc, char* argv[])
{
if (argc < 4) {
printf("Usage: command <PID> <BLOCK> <DATA>\n");
@josefandersson
josefandersson / switch-windows-monitors.ahk
Created February 1, 2020 03:14
Move open windows from one monitor to the other on dual monitor setups
WinGet, windows, List
Loop %windows%
{
id := windows%A_Index%
WinGetPos, x, y,,, ahk_id %id%
WinGetTitle, wt, ahk_id %id%
StringLen, tl, wt
If tl > 0 And WinExist("ahk_id" . id)
{
If x < -8