Skip to content

Instantly share code, notes, and snippets.

stefansundin /
Last active Jun 11, 2021
Reusable class for Python requests library.
import requests
class RequestsApi:
def __init__(self, base_url, **kwargs):
self.base_url = base_url
self.session = requests.Session()
for arg in kwargs:
if isinstance(kwargs[arg], dict):
kwargs[arg] = self.__deep_merge(getattr(self.session, arg), kwargs[arg])
stefansundin /
Last active Jun 9, 2021
Download all of your Team's custom Slack emojis.
#!/bin/bash -eo pipefail
# Log in to Slack in a web browser and open the network tools to inspect the traffic.
# Filter the requests with "/api/" and pick one to inspect. Click on the Headers tab and scroll down to see the request details.
# You need the xoxc token from the request body, and a copy of the cookies. It is the "d" cookie that is important, but you can copy all of them.
# Paste the values below.
# You need to have curl and jq installed.
stefansundin /
Last active May 27, 2021
Git pre-commit check to stop accidental commits to master/main/develop branches.
# This gist contains pre-commit hooks to prevent you from commiting bad code or to the wrong branch.
# There are six variants that I have built:
# - pre-commit: stops commits to master/main/develop branches.
# - pre-commit-2: also includes a core.whitespace check.
# - pre-commit-3: the core.whitespace check and an EOF-newline-check.
# - pre-commit-4: only the core.whitespace check.
# - pre-commit-5: elixir formatting check.
# - pre-commit-6: prettier formatting check.
# Set the desired version like this before proceeding:
stefansundin / youtube-global-shortcuts.user.js
Last active May 20, 2021
Makes the YouTube shortcuts work even if the player is not focused. Install Greasemonkey/Tampermonkey first, then click [Raw] to install.
View youtube-global-shortcuts.user.js
// ==UserScript==
// @name YouTube global shortcuts
// @namespace
// @homepage
// @downloadURL
// @version 1.1
// @author Stefan Sundin
// @description Makes the YouTube shortcuts work even if the player is not focused.
// @icon
// @match*
stefansundin /
Last active Apr 26, 2021 — forked from 8bitDesigner/
Git post-checkout and post-merge hooks to simplify bundling and other tasks.

Make bundleing and npm installing easy

These git hooks runs bundle or npm install automatically whenever you:

  • git checkout a new branch with a different Gemfile or package.json.
  • git pull a change to Gemfile or package.json.

How to install

  1. cd awesome_git_repo
View twitch-extension.lua
--[[ extension v0.0.2 by Stefan Sundin
The only thing that this extension does is to act as a helper to seek to the
correct time when you open a url that contains a timestamp.
You must have the playlist parser installed as well!
1. Install the playlist parser:
stefansundin /
Last active Apr 16, 2021
Git pre-push hook to prevent force pushing the master/main branch.
# This script will install a Git pre-push hook that prevents force pushing the master/main branch.
# There are three variants that I have built:
# - pre-push: prevents force-pushing to master/main.
# - pre-push-2: prevents force-pushing to master/main depending on the remote (you need to edit the file!).
# - pre-push-3: prevents any type of pushing to master/main.
# Set the desired version like this before proceeding:
# FILE=pre-push
# Single repo installation:
stefansundin /
Last active Feb 19, 2021
Extract attachments from emails that Gmail doesn't allow you to download. This is dumb. Please use Python >= 3.4.
#!/usr/bin/env python3
# Get your files that Gmail block. Warning message:
# "Anti-virus warning - 1 attachment contains a virus or blocked file. Downloading this attachment is disabled."
# Based on:
# Instructions:
# Go to your emails, click the arrow button in the top right, "Show original", then "Download Original".
# Move the files to the same directory as this program, then run it.
import email
stefansundin / ffmpeg.rb
Last active Feb 16, 2021
Download Twitch video that has muted sound.
View ffmpeg.rb
#!/usr/bin/env ruby
files = Dir["*.ts"].sort_by { |fn| fn.split(".")[0].to_i }
puts "ffmpeg -i 'concat:#{files.join("|")}' -codec copy output.mkv"
puts "run this first:"
puts "ulimit -n 4096"
stefansundin /
Last active Feb 5, 2021
Analyze long audio files with
#!/bin/bash -ex
mkdir -p audd
if (( $# < 2 )); then
echo "Please supply two arguments, the input file and the timestamp (HH:MM:SS)."
exit 1
pos=$(date -d "1970-01-01 $2" -u +%s)