Skip to content

Instantly share code, notes, and snippets.

@kugland
kugland / shell_escape.c
Last active June 18, 2018 01:44
Escapes a string for use with bash shell, formatted as $'...'.
#include <stdio.h>
#include <stdlib.h>
#include <assert.h>
/**
* Escapes a string for use with bash shell, formatted as $'...'.
*
* @param input the input string you want to escape.
*
* @return the escaped string (which must be free'd after use).
@kugland
kugland / reboot-powerbox.py
Created July 24, 2018 22:02
Script para reiniciar o GVT PowerBox — SAGECOM FAST2764
#!/usr/bin/env python3
import requests
import urllib3
from html.parser import HTMLParser
ip = '192.168.25.1'
credentials = ('admin', 'gvt12345')
class SessionIdFinder(HTMLParser):
#include <cstdint>
template<bool Fits8Bit, bool Fits16Bit, bool Fits32Bit>
struct intopt_helper {
using signed_type = std::int64_t;
using unsigned_type = std::uint64_t;
};
template<>
struct intopt_helper<false, false, true> {
@kugland
kugland / micro_rc4.c
Last active July 28, 2019 18:41
RC4 algorithm for microcontrollers
#include "micro_rc4.h"
static char rc4_state[256];
static unsigned char rc4_i, rc4_j;
__attribute__((always_inline)) inline
static void rc4_swap(void)
{
unsigned char rc4_tmp = rc4_state[rc4_i];
rc4_state[rc4_i] = rc4_state[rc4_j];
@kugland
kugland / crc32.cpp
Last active September 3, 2019 05:07
Primitives for a header-only CRC-32 implementation for MCUs.
#include <stdint.h>
#include <stdio.h>
#include "helper.hpp"
#include "reflect.hpp"
using crc32::impl::bit_sizeof;
using crc32::impl::and_mask;
using crc32::impl::shift;
using crc32::impl::reflect_u8;
@kugland
kugland / download-youtube-subtitles.js
Last active February 9, 2024 05:20
Download YouTube subtitles (GreaseMonkey/TamperMonkey script)
// ==UserScript==
// @name Download YouTube subtitles
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Now you can download YouTube subtitles
// @author André Kugland
// @match http*://*.youtube.com/*
// @grant none
// @require https://cdn.jsdelivr.net/npm/file-saver@2.0.2/dist/FileSaver.min.js#sha256=bbf27552b76b9379c260579fa68793320239be2535ba3083bb67d75e84898e18
// ==/UserScript==
@kugland
kugland / naked-instagram.js
Last active December 31, 2019 19:31
Remove overlay above Instagram images and select the highest res img. - GreaseMonkey / TamperMonkey userscript.
// ==UserScript==
// @name Naked Instagram
// @namespace http://www.instagram.com/
// @version 0.1
// @description Remove overlay above Instagram images and select the highest res img.
// @author André Kugland
// @match http*://*.instagram.com/*
// @grant none
// ==/UserScript==
// ==UserScript==
// @name Dicionário Analógico Aulete (correções)
// @namespace http://tampermonkey.net/
// @version 0.1
// @description Corrige alguns problemas na página do dicionário analógico Aulete.
// @author You
// @match http://*.aulete.com.br/analogico/*
// @match https://*.aulete.com.br/analogico/*
// @grant none
// ==/UserScript==
@kugland
kugland / remove-baloo.hook
Created December 3, 2020 07:58
Pacman Hook: Make sure baloo executables are links to /bin/true
# /usr/share/libalpm/hooks/remove-baloo.hook
[Trigger]
Operation = Install
Operation = Upgrade
Operation = Remove
Type = Package
Target = *
[Action]
@kugland
kugland / avr_reflect_u64.c
Last active March 21, 2021 10:01
Bit reflect for uint64_t hand-optimized for size for AVR processors. https://godbolt.org/z/qjn8rb
#include <inttypes.h>
typedef union {
uint64_t u64;
uint8_t u8[8];
} uint64_union;
__attribute__((optimize("Os"))) // Avoid loop unrolling.
void reflect_u64(uint64_t* value)
{