Skip to content

Instantly share code, notes, and snippets.

@lfaoro
lfaoro / pow.sh
Created February 13, 2025 15:42
Bitcoin's PoW in bash
#!/usr/bin/env bash
set -euo pipefail
usage() {
echo "Usage: $0 <data> <difficulty>"
echo "Example: $0 \"$(date -u +%N)\" 3"
echo
echo "Parameters:"
echo " data - Input data to hash (typically a timestamp)"
echo " difficulty - Number of leading zeros required in hash"
@lfaoro
lfaoro / main.go
Created December 3, 2024 08:10
advent of code day1 (go)
package main
import (
"bufio"
"log"
"os"
"sort"
"strconv"
"strings"
)

Source Available with Commercial Use Restrictions License (SA/CUR)

Copyright (c) 2024 Leonardo Faoro

Preamble

This license permits the use, modification, and distribution of the software for non-commercial purposes, safeguarding commercial use and ensuring attribution.

@lfaoro
lfaoro / EmacsKeyBinding.dict
Created December 9, 2018 13:58 — forked from jwreagor/EmacsKeyBinding.dict
Global Emacs Key Bindings for OS X
{
/* Keybindings for emacs emulation. Compiled by Jacob Rus.
*
* This is a pretty good set, especially considering that many emacs bindings
* such as C-o, C-a, C-e, C-k, C-y, C-v, C-f, C-b, C-p, C-n, C-t, and
* perhaps a few more, are already built into the system.
*
* BEWARE:
* This file uses the Option key as a meta key. This has the side-effect
* of overriding Mac OS keybindings for the option key, which generally
// CreditCardRegex is the pattern used to identify a credit card PAN.
var CreditCardRegex = "^(?:4[0-9]{12}(?:[0-9]{3})?|5[1-5][0-9]{14}|6(?:011|5[0-9][0-9])[0-9]{12}|3[47][0-9]{13}|3(?:0[0-5]|[68][0-9])[0-9]{11}|(?:2131|1800|35\\d{3})\\d{11})$"
var rxCreditCard = regexp.MustCompile(CreditCardRegex)
var rxNotNumber = regexp.MustCompile("[^0-9]+")
// IsCreditCard checks if the string is a credit card.
func IsCreditCard(s string) bool {
sanitized := rxNotNumber.ReplaceAllString(s, "")
if !rxCreditCard.MatchString(sanitized) {
return false
@lfaoro
lfaoro / batch-sql-backup.yaml
Last active June 25, 2018 10:32
batch-sql-backup.yaml
apiVersion: batch/v1beta1
kind: CronJob
metadata:
name: batch-sql-backup
spec:
schedule: "* */60 * * *"
concurrencyPolicy: Forbid
jobTemplate:
spec:
template:
#!/usr/bin/env bash
BASE=(`cat VERSION | tr '.' ' '`)
MAJOR=${BASE[0]}
MINOR=${BASE[1]}
PATCH=${BASE[2]}
case $1 in
"major")
let "MAJOR++"
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildMachineOSBuild</key>
<string>15E55</string>
<key>CFBundleDevelopmentRegion</key>
<string>English</string>
<key>CFBundleExecutable</key>
<string>AppleIntelHD5000Graphics</string>
141.101.98.117 - - [11/Jan/2016:21:39:57 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:58 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:58 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:58 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:58 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:58 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:58 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:59 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:59 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
141.101.98.117 - - [11/Jan/2016:21:39:59 +0100] "GET / HTTP/1.1" 303 317 "-" "curl/7.35.0"
@lfaoro
lfaoro / git-php-webhook.php
Created December 10, 2015 20:00 — forked from marcelosomers/git-php-webhook.php
A basic webhook for deploying updates to repos on Github to your local server
<?php
/**
* This script is for easily deploying updates to Github repos to your local server. It will automatically git clone or
* git pull in your repo directory every time an update is pushed to your $BRANCH (configured below).
*
* Read more about how to use this script at http://behindcompanies.com/2014/01/a-simple-script-for-deploying-code-with-githubs-webhooks/
*
* INSTRUCTIONS:
* 1. Edit the variables below
* 2. Upload this script to your server somewhere it can be publicly accessed