Skip to content

Instantly share code, notes, and snippets.

@stefansundin
stefansundin / requests_api.py
Last active Jun 11, 2021
Reusable class for Python requests library.
View requests_api.py
# http://docs.python-requests.org/en/master/api/
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
stefansundin / download-slack-emoji.sh
Last active Jun 9, 2021
Download all of your Team's custom Slack emojis.
View download-slack-emoji.sh
#!/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.
SLACK_TOKEN="xoxc-...."
COOKIES="d=...."
@stefansundin
stefansundin / install-pre-commit.sh
Last active May 27, 2021
Git pre-commit check to stop accidental commits to master/main/develop branches.
View install-pre-commit.sh
#!/bin/bash
# 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
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 https://gist.github.com/stefansundin/
// @homepage https://gist.github.com/stefansundin/65e3d6db697636d8e7f1
// @downloadURL https://gist.github.com/stefansundin/65e3d6db697636d8e7f1/raw/youtube-global-shortcuts.user.js
// @version 1.1
// @author Stefan Sundin
// @description Makes the YouTube shortcuts work even if the player is not focused.
// @icon https://www.youtube.com/favicon.ico
// @match https://www.youtube.com/*
@stefansundin
stefansundin / git-bundle-hook.md
Last active Apr 26, 2021 — forked from 8bitDesigner/1.md
Git post-checkout and post-merge hooks to simplify bundling and other tasks.
View git-bundle-hook.md

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
--[[
Twitch.tv extension v0.0.2 by Stefan Sundin
https://gist.github.com/stefansundin/c200324149bb00001fef5a252a120fc2
The only thing that this extension does is to act as a helper to seek to the
correct time when you open a twitch.tv url that contains a timestamp.
You must have the playlist parser installed as well!
Usage:
1. Install the playlist parser: https://addons.videolan.org/p/1167220/
@stefansundin
stefansundin / install-pre-push.sh
Last active Apr 16, 2021
Git pre-push hook to prevent force pushing the master/main branch.
View install-pre-push.sh
#!/bin/bash
# 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
stefansundin / extract-attachments.py
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.
View extract-attachments.py
#!/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: https://spapas.github.io/2014/10/23/retrieve-gmail-blocked-attachments/
# 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
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
puts "run this first:"
puts "ulimit -n 4096"
@stefansundin
stefansundin / audd-analyze.sh
Last active Feb 5, 2021
Analyze long audio files with audd.io.
View audd-analyze.sh
#!/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
fi
fn=$1
pos=$(date -d "1970-01-01 $2" -u +%s)