Skip to content

Instantly share code, notes, and snippets.

@fopina
fopina / mic_client.py
Created July 28, 2016 12:24
microphone streaming with pyAudio
#!/usr/bin/env python
import pyaudio
import socket
import sys
FORMAT = pyaudio.paInt16
CHANNELS = 1
RATE = 44100
CHUNK = 4096
@fopina
fopina / meo-ipv6-off-playbook.yml
Created May 16, 2018 13:44
Disable IPv6 in MEO Router ansible
# requires ansible 2.4
# usage:
# ansible-playbook playbook.yml -i 192.168.1.254,
- hosts: all
gather_facts: false
tasks:
# ansible 2.4 telnet plugin does not add \r
# and the router requires it so...
- name: disable ipv6 in meo router
@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
@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 / emuparadise.py
Last active January 8, 2022 17:30
Scraper script for emuparadise.me
#!/usr/bin/env python
"""
Scraper script for emuparadise.me
Usage
=====
```
fopina$ ./emuparadise.py -h
usage: emuparadise.py [-h] [--download] [--search] [--system SYSTEM] [--list]
@fopina
fopina / watchlog.sh
Last active January 8, 2022 17:30
Bash script to tail a log file and push new lines to your phone
#!/bin/bash
#
# Watch log
#
# Script that will "tail -f" a log file and push the new lines to your phone
# using a Telegram bot (@PushItBot - https://fopina.github.io/tgbot-pushitbot/)
function pushit() {
# this function receives the first parameter passed to the script
# plus the latest line of the log file
@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
@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 / 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 / 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))