Skip to content

Instantly share code, notes, and snippets.

@stefansundin
stefansundin / requests_api.py
Last active Oct 16, 2020
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 / make-chrome-app.sh
Last active Oct 6, 2020
Create Chrome apps in Mac OS.
View make-chrome-app.sh
#!/bin/sh
# wget https://gist.githubusercontent.com/stefansundin/c89fd15bae5a58831790/raw/make-chrome-app.sh
# chmod +x make-chrome-app.sh
# ./make-chrome-app.sh
echo "Note that the app will run with a separate data dir and thus not have your regular extensions and settings."
echo
echo "What should the app be called?"
read name
echo
View moved.txt
Moved to https://github.com/stefansundin/open-with-vlc
@stefansundin
stefansundin / download-slack-emoji.sh
Last active Sep 18, 2020
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 / ffmpeg.rb
Last active Sep 11, 2020
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 / install-pre-commit.sh
Last active Sep 10, 2020
Git pre-commit check to stop accidental commits to master and develop branches. There is also a variant with a core.whitespace check.
View install-pre-commit.sh
#!/bin/sh
# This gist contains pre-commit hooks to prevent you from commiting bad code or to the wrong branch.
# There are four variants that I have built:
# - pre-commit: stops commits to "master" and "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 desired version like this before installing:
@stefansundin
stefansundin / git-bundle-hook.md
Last active Aug 8, 2020 — 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
@stefansundin
stefansundin / install-pre-push.sh
Last active Jul 22, 2020
Git pre-push hook to prevent force pushing the master branch.
View install-pre-push.sh
#!/bin/sh
# This script will install a Git pre-push hook that prevents force pushing the master branch.
# Global installation instructions:
# mkdir $HOME/.githooks
# git config --global core.hooksPath $HOME/.githooks
# curl -fL -o $HOME/.githooks/pre-push https://gist.githubusercontent.com/stefansundin/d465f1e331fc5c632088/raw/pre-push
# chmod +x $HOME/.githooks/pre-push
# Uninstall:
# rm $HOME/.githooks/pre-push
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/
You can’t perform that action at this time.