Skip to content

Instantly share code, notes, and snippets.

#!/bin/sh
version="$1"
bootdir=/boot
[ -x /usr/bin/dracut ] || exit 0
# passing the kernel version is required
[ -z "${version}" ] && exit 0
@mrschyte
mrschyte / selsort.py
Created September 16, 2018 18:07
Selection sort with early termination
def selsort(xs):
for k in range(len(xs) - 1, -1, -1):
print(k)
done = True
imax = 0
for i in range(1, k + 1):
if xs[i] > xs[imax]:
imax = i
else:
@mrschyte
mrschyte / wait-online.py
Last active August 27, 2018 08:28
Replacement wait-online script
#!/usr/bin/python
from subprocess import check_output
from time import sleep
import click, sys
def is_interface_up(iface):
try:
return b'state DOWN' not in check_output(["/usr/bin/ip", "link", "show", "dev", iface]) and \
b'inet' in check_output(["/usr/bin/ip", "addr", "show", "dev", iface])
@mrschyte
mrschyte / controller.py
Created June 13, 2018 21:58
Impossibru Curves
from pykeyboard import PyKeyboard
from inputs import get_gamepad
import time, math
import threading
kbd = PyKeyboard()
tmax = 0.1
tmin = 0.02
curr = 0
@mrschyte
mrschyte / nth.tex
Last active February 24, 2024 15:12
LaTeX get nth element.
\documentclass{standalone}
\usepackage{pgf,pgffor}
\newcommand{\nth}[2]{
\foreach \x [count=\k] in #1 {
\ifnum\k=#2
\x
\fi
}
}
@mrschyte
mrschyte / fwf.py
Created June 5, 2018 11:37
Fixed-width parser
import subprocess
import functools
import itertools
import pprint
def transpose(table, fillvalue=None):
return itertools.zip_longest(*table, fillvalue=fillvalue)
def fwf_format(table):
widths = [max([len(row) for row in col])
@mrschyte
mrschyte / FisherYates.java
Last active March 31, 2022 12:39
Fisher-Yates Shuffle (Java)
import java.util.Random;
import java.util.Arrays;
class FisherYates {
public static <T> void shuffle(Random random, T[] array) {
shufflePartial(random, array, 1.0f);
}
public static <T> void shufflePartial(Random random, T[] array, double fudge) {
assert(fudge >= 0.0f && fudge <= 1.0f);
@mrschyte
mrschyte / fixperm.py
Created November 12, 2017 08:29
Fix python permissions
import sys
import os, stat
import fileinput
def fixperm(path):
mode = os.stat(path)[stat.ST_MODE]
perm = mode & stat.S_IRWXU & (~stat.S_IWUSR)
mode |= mode & (~stat.S_IRWXG) | (perm >> 3)
mode |= mode & (~stat.S_IRWXO) | (perm >> 6)
print(oct(mode), path)
<!doctype html>
<html lang="en">
<head>
<title>cyberlympics</title>
<meta name="generator" content="Etherpad">
<meta name="author" content="Etherpad">
<meta name="changedby" content="Etherpad">
<meta charset="utf-8">
<style>
* {
@mrschyte
mrschyte / censys.py
Created October 3, 2017 15:06
Grab censys.io data
import requests
import pprint
API_BASE = 'https://www.censys.io/api/v1/{}'
API_AUTH = ('API_ID', 'SECRET')
def call(base, query):
results = []
page_id = 1