Skip to content

Instantly share code, notes, and snippets.

#!/bin/bash
# Note: this works with openbsd-netcat
echo "Serving powerstatusforever..."
while true; do
echo -ne "HTTP/1.0 200 OK\r\n\r\n$(cat /host-sys/class/power_supply/ACAD/online)" | nc -N -l -p 5555;
test $? -gt 0 && break;
done
@candale
candale / pushbullet_notif.sh
Last active November 2, 2021 18:47
Pushbullet Simple Notificaion
#!/usr/bin/env bash
# get the API token by going here: https://www.pushbullet.com/#settings/account
API_TOKEN=''
# to create a new channel, go to https://www.pushbullet.com/my-channel
# use the chosen tag for the var below
# for existing channel, you can get the tag from here: https://www.pushbullet.com/#settings/channels
CHANNEL_TAG=''
@candale
candale / octopi.conf
Created April 9, 2020 18:30
Octopi Nginx Proxy
server {
listen 0.0.0.0:80;
server_name my-domain;
return 301 https://$host$request_uri;
}
server {
listen 0.0.0.0:443 ssl;
server_name my-domain;
ssl_certificate /etc/letsencrypt/live/printer-see.acandale.com/fullchain.pem;
@candale
candale / bokeh_real_time.py
Created March 25, 2020 18:36
Bokeh Real Time Graph
# stolen from https://rehn.me/posts/python-real-time-plotting.html
# in case that disappears
import random
from bokeh.driving import count
from bokeh.models import ColumnDataSource
from bokeh.plotting import curdoc, figure
UPDATE_INTERVAL = 100
ROLLOVER = 100 # Number of displayed data points

We had this situation where we had to move around 53 million files (HTMLs) from a bunch of folder to some other folders. The files were located in no more than 100 files, having folders with 2.5 million files. One thing worth mentioning is that the disk where the files are is with spinning disks and is also a NFS, both of whch make the access really slow.

The reason we want to move all of these files is because we no longer want to keep them in a flat structure but rather in a nested structure, using the date when the item was created; the dir structure would look something like this: %Y/%m/%d/. So we basically want to run mv $BASE_DIR/item_name.html.gz $BASE_DIR/%Y/%m/%d/item_name.html.gz for each of those 53 million files.

@candale
candale / ffmpeg_cut_portion.sh
Last active October 16, 2019 08:18
Cut portion of .mkv file with ffmpeg
file_name=$1
from=$2
to=$3
finish=$4
ext=$5
# to copy everything: -vcodec copy -acodec copy -scodec copy
copy='-acodec copy -scodec copy'
# when you get some out of sync stuff when you use -vcoded copy it's because
@candale
candale / py_problems.md
Last active May 15, 2020 08:01
FileIntegerListProblem

Docker

To start playing with docker, we are going to have to build a toy problem. The toy problem is going to be a very simple ToDo app that we're going to take to a final conclusion, having a bunch of containers doing the work with volumes, networking an the lot.

ToDo in a container

@candale
candale / Wide Fetch Cassandra
Created June 13, 2019 07:37
fetch_cassandra_wide.py
def fetch_car_hist_items(limit=None, start=None, end=None):
class StopFetch(Exception):
pass
ses = get_or_create_session()
state = {
'last_token': -9223372036854775808,
'stop_token': 9223372036854775807,
@candale
candale / check_sub.py
Last active October 16, 2019 07:32
check_sub.py
"""
Run: python3 check_sub.py path_to.srt
Give the following:
- error if the first line in file is a number with no spaces around it
- error if there are two blank lines between two subtitle chunks
- error if sync info matches the standard format, with no spaces at the
beginning or end
- error if a subtitle chunk has more than three subtitles lines
- warning if a subtitle chunk has no subtitle lines
@candale
candale / run_tests_parallel.py
Last active May 20, 2019 11:50
django_test_parallel.py
# coding: utf-8
"""
This module provides
"""
from __future__ import unicode_literals
import os
import sys
from multiprocessing import Process, Queue