Skip to content

Instantly share code, notes, and snippets.

View MrYakobo's full-sized avatar
Not AI

Jakob Lindskog MrYakobo

Not AI
View GitHub Profile
@MrYakobo
MrYakobo / pyclip.py
Created December 8, 2022 09:46
xclip and xsel alternative, for non-epel rpm distros for example
#!/usr/bin/env python3
# takes text on stdin and stores it in the clipboard
# depends on gtk (i.e. a gnome desktop or something alike)
import gi
gi.require_version('Gtk', '3.0')
from gi.repository import Gtk, Gdk
import fileinput
@MrYakobo
MrYakobo / jwt-decode.py
Created December 8, 2022 08:31
Decode a jwt from stdin, without using jwt.io or external libraries
#!/usr/bin/env python3
import base64
import json
import fileinput
for jwt in fileinput.input():
parts = jwt.split(".")
# '==' is padding
@MrYakobo
MrYakobo / mmd.py
Created February 10, 2021 09:37
Maximum mean discrepancy for tensorflow
# based on https://github.com/wzell/mann/blob/master/models/maximum_mean_discrepancy.py
# that didn't work for me on tensorflow
import tensorflow as tf
def gaussian_kernel(x1, x2, beta = 1.0):
r = tf.transpose(x1)
r = tf.expand_dims(r, 2)
return tf.reduce_sum(K.exp( -beta * K.square(r - x2)), axis=-1)
@MrYakobo
MrYakobo / info.md
Created August 24, 2020 17:40
List of all shortcodes in Visual Composer

these are from js_composer

Anyhow, this comphrenhensive list was ungooglable for me. Googling "List of Visual Composer Shortcodes" gives nothing at all. I guess that's how it goes with most of Wordpress things; references are sparse and examples are numerous. Reminds me of Classic ASP, where W3Schools literally is your best reference. Because Microsoft don't document shit.

Anyhow, hope this is useful to someone

@MrYakobo
MrYakobo / paging.py
Last active July 7, 2020 16:22
Google-like pagination algorithm
#!/usr/bin/env python3
# heavily inspired by https://jasonwatmore.com/post/2016/01/31/angularjs-pagination-example-with-logic-like-google
import math
def paginate(curr, itemsPerPage, numItems, numPagesToShowAtOnce):
# ceil here to make sure we don't miss anything
half = math.ceil(numPagesToShowAtOnce / 2)
numPages = math.ceil(numItems / itemsPerPage)
@MrYakobo
MrYakobo / bspwmrc
Created September 3, 2018 18:50
Unixporn configs
#! /bin/sh
bspc config border_width 0
bspc config window_gap 12
bspc config split_ratio 0.60
bspc config borderless_monocle true
bspc config gapless_monocle true
bspc config single_monocle true
bspc config focus_by_distance true
bspc config adaptive_raise true
@MrYakobo
MrYakobo / dl.sh
Last active August 30, 2018 15:24
Automated download and extract process from https://wiiu.hacks.guide/get-started
#!/usr/bin/env bash
echo "This script follows the guide from https://wiiu.hacks.guide/get-started as of 2018-08-30."
mkdir -p SDCARD
cd SDCARD
declare -a files=(
https://wiiu.hacks.guide/assets/files/config.txt \
https://wiiu.hacks.guide/assets/files/config.ini \
https://github.com/vgmoose/hbas/releases/download/1.5/appstore15.zip \
@MrYakobo
MrYakobo / update-code
Created February 23, 2018 13:11
If your distro doesn't pack VSCode and you want to update it.
#!/bin/bash
curl -L https://vscode-update.azurewebsites.net/latest/linux-x64/stable | tar xz -C ~/Downloads/vscode/
# symlink ~/bin/code to ~/Downloads/vscode
ln -s ~/Downloads/vscode ~/bin/code
var a = $("a>img").map((i,t)=>$(t).attr('data-src'));
var arr = [];
for(var i = 0; i < a.length; i++)
arr.push(a[i]);
var c = arr.map(t=>{
var b = `-o ${/[^\/]+?\.png|[^\/]+?\.jpg/.exec(t)}`
if(b != null){
@MrYakobo
MrYakobo / example.png
Last active November 29, 2017 20:09
DNS setup for custom domain on Github
example.png