Skip to content

Instantly share code, notes, and snippets.

@felipevolpatto
felipevolpatto / find_runner.py
Created February 11, 2022 16:41
Script that kills any Github Actions Runner worker that has been running longer than 5 minutes
#!/usr/bin/env python3
import psutil
import docker
from datetime import timedelta, datetime
import time
client = docker.from_env()
while True:
time.sleep(10)
@felipevolpatto
felipevolpatto / Blockchain.js
Created November 25, 2021 18:35
Blockchain in JS
import Block from "./Block";
import { blockFromJSON } from "./Block";
import { transactionFromJSON } from "./Transaction";
import { rerender } from "../store";
import { publish, subscribeTo } from "../network";
import { maxBy, reduce, unfold, reverse, values, prop } from "ramda";
class Blockchain {
constructor(name) {
this.name = name;
@felipevolpatto
felipevolpatto / pad.go
Created June 15, 2021 22:37
Pad in Go
package strutil
// PadLeft left pads a string str with "pad". The string is padded to
// the size of width.
func PadLeft(str string, width int, pad string) string {
return Tile(pad, width-Len(str)) + str
}
// PadRight right pads a string str with "pad". The string is padded to
// the size of width.
@felipevolpatto
felipevolpatto / Connection.php
Last active October 18, 2019 12:59
Design patterns: Builder pattern
<?php
namespace Builder\Objets;
class Connection {
public $host;
public $port;
public $user;
public $pass;
public $db;
@felipevolpatto
felipevolpatto / Product.php
Created October 17, 2019 12:30
Design patterns: Decorator pattern
<?php
namespace Decorator;
use Decorator\ValidationInterface;
class Product implements ValidationInterface {
public function validate(): bool {
echo 'Validação do produto em si.';
@felipevolpatto
felipevolpatto / ApikeyStrategy.php
Last active October 22, 2019 18:39
Design patterns: Strategy pattern
<?php
namespace Strategy\Auth;
use Strategy\AuthInterface;
use Bling\Controller\UserController;
class ApiKeyStrategy implements AuthInterface {
public function authenticate(...$params): bool {
$userController = new UserController();
@felipevolpatto
felipevolpatto / pdf.py
Created December 20, 2018 18:27
Script to craft MD5 collisions of 2 PDFs via mutool and UniColl
import os
import sys
import hashlib
def EnclosedString(d, starts, ends):
off = d.find(starts) + len(starts)
return d[off:d.find(ends, off)]
def getCount(d):
s = EnclosedString(d, "/Count ", "/")
@felipevolpatto
felipevolpatto / install-ripgrep-on-ubuntu.sh
Created September 27, 2018 17:59
Install ripgrep on Ubuntu
#!/bin/bash
[[ $UID == 0 ]] || { echo "run as sudo to install"; exit 1; }
REPO="https://github.com/BurntSushi/ripgrep/releases/download/"
RG_LATEST=$(curl -sSL "https://api.github.com/repos/BurntSushi/ripgrep/releases/latest" | jq --raw-output .tag_name)
RELEASE="${RG_LATEST}/ripgrep-${RG_LATEST}-x86_64-unknown-linux-musl.tar.gz"
TMPDIR=$(mktemp -d)
cd $TMPDIR
wget -O - ${REPO}${RELEASE} | tar zxf - --strip-component=1
@felipevolpatto
felipevolpatto / portVarKeywords.php
Created December 12, 2017 16:14
Tool for changing "var" keywords to "public" in PHP.
<?php
/*
* Note: This script will directly modify the .php files in the given directory.
* It is assumed that the code is under version control, so you can easily review
* the changes using `git diff` or similar.
*/
function usageError() {
die("Usage: php portVarKeywords.php dir/\n");
@felipevolpatto
felipevolpatto / SelectoresCSS.md
Created February 12, 2016 19:19
Selectores CSS