Skip to content

Instantly share code, notes, and snippets.

@fopina
fopina / array_split.py
Created October 22, 2021 23:55
python: split list into fixed number of evenly distributed sublists
"""
Googling a solution for this seems to always end with [numpy array_split](https://numpy.org/doc/stable/reference/generated/numpy.array_split.html)
This avoids having numpy as dependency just for this
"""
def array_split(array, parts):
"""
split an array into parts arrays, evenly size
>>> list(array_split(list(range(12)), 10))
@fopina
fopina / onion_pi.md
Created September 3, 2021 01:01
onion-pi setup (reversed, WiFi as WAN)

Walkthrough to setup a raspberry pi as an onion router. Pretty much like onion-pi but WiFi as WAN instead (bonus: no hostapd required).

As a Pi0w or a Pi1 can easily be powered by the laptop USB, this setup makes a TOR-WiFi (bulky) dongle out of a Pi!!

This should (will?) be converted into an ansible playbook (or even pre-cooked image)

SDCard

  • Download latest raspios
  • Dump it on an sd card, eg:
@fopina
fopina / fusion_CE_networks.md
Created August 12, 2021 22:56
customize networking in vmware fusion 12 *community* edition

After so many years with VMWare Player being free for Windows and Linux, VMware finally released a free/community version of Fusion!

One of the main restrictions in the free version is that you cannot create/edit any networks.
But sometimes you need that little change such as using a different network range on your VMware NAT interface or the Host-only one.

It's quite easy after all. The settings are stored in /Library/Preferences/VMware Fusion/networking:

VERSION=1,0
answer VNET_1_DHCP yes
@fopina
fopina / sdtest.sh
Last active August 11, 2022 05:39
SD Card Speed Test (from Raspberry Pi Agnostics package)
#!/bin/bash
#NAME=SD Card Speed Test
#DESC=Determines whether an SD card can read and write data fast enough to provide adequate performance.\n\nShould be run on a new or newly-formatted SD card.
# Original at https://raw.githubusercontent.com/raspberrypi-ui/agnostics/1dc4a426e3a2b75276c560b612123a8551b6c0e2/data/sdtest.sh
# run with
# curl -s https://gist.githubusercontent.com/fopina/3b41fc00604d2b7ba0ce82fff6a7e211/raw/sdtest.sh | sudo bash -
# default test file location will be in /var/tmp, you can choose other directory as first parameter of the script
# curl -s https://gist.githubusercontent.com/fopina/3b41fc00604d2b7ba0ce82fff6a7e211/raw/sdtest.sh | sudo bash -s /mnt/usb
@fopina
fopina / conftest.py
Created May 28, 2020 10:01
pytest-django --debug-sql
__force_django_debug = False
def pytest_runtest_setup():
if __force_django_debug:
# required for logging SQL as pytest always sets DEBUG to False (why?)
# https://github.com/pytest-dev/pytest-django/blob/master/pytest_django/plugin.py#L473
from django.conf import settings
settings.DEBUG = True
- hosts: all
gather_facts: True
become: True
roles:
- role: fluentbit
fluentbit_inputs:
- systemd:
- Tag: docker
- Systemd_Filter: _SYSTEMD_UNIT=docker.service
- cpu:
@fopina
fopina / handlers_main.yml
Created July 9, 2019 23:18
fluentbit ansible role
---
- name: Restart Fluentbit
service:
name: td-agent-bit
enabled: true
state: restarted
@fopina
fopina / portquiz.py
Last active January 8, 2022 17:30
portquiz.net quick tester
# directly from
# https://docs.python.org/3/library/concurrent.futures.html#threadpoolexecutor-example
import concurrent.futures
import urllib.request
def check_port(port):
print('testing %d \r' % port, end='')
# smaller response text!
r = urllib.request.Request('http://portquiz.net:%d' % port, headers={'User-Agent': 'curl'})
@fopina
fopina / lenticular.py
Last active January 8, 2022 17:30
Poor Man's Lenticular
#!/usr/bin/env python
# https://www.youtube.com/watch?v=mmGB9ADKr5Y
import argparse
from PIL import Image
DEFAULT_STRIPS = 8
package main
import (
"os"
"fmt"
"math/rand"
"github.com/veandco/go-sdl2/sdl"
)
const (