Skip to content

Instantly share code, notes, and snippets.

@NanoDano
NanoDano / http_download.py
Created August 3, 2020 06:39
Download a file with Python requests
import requests # pip install requests
# Adapted from answer at: https://stackoverflow.com/questions/16694907/download-large-file-in-python-with-requests
def download(url, filepath):
with requests.get(url, stream=True) as response:
response.raise_for_status()
with open(filepath, 'wb') as output_file:
for chunk in response.iter_content(chunk_size=8192):
# If you have chunk encoded response, then uncomment
# the `if` statement and set chunk_size parameter to `None`.
@NanoDano
NanoDano / serve_gz_files.php
Created August 6, 2020 01:36
PHP list & serve gzipped files from dir
<?php
/**
* Given a directory full of gzipped AVI files,
* outpu a JSON array with the list of zipped video files in the dir.
*
* If a GET query param is provided for `file` then that specific
* file is returned, uncompressed, with the .gz extension removed
*/
if (isset($_GET['file'])) {
@NanoDano
NanoDano / 99_dano_grub_colors
Created March 9, 2021 04:29
My custom config file to set GRUB menu colors
#!/bin/sh
# Requires executable bit
# Move to `/etc/grub.d/99_dano_grub_colors`
# and run `sudo update-grub`
echo "set menu_color_normal=light-cyan/dark-gray"
echo "set menu_color_highlight=dark-gray/light-cyan"
echo "set color_normal=white/black"
echo "set color_highlight=black/white"
# To change image, update `/etc/default/grub` with the image path
@NanoDano
NanoDano / mount-smb.sh
Created March 22, 2021 06:58
Mount SMB Drive in Debian Linux
#!/usr/bin/bash
sudo apt install -y cifs-utils
# `uid` and `gid` is the local Linux user and group you want to mount as
# `user` and `password` are the SMB drive credentials. Wrap password with quotes if necessary.
sudo mount -t cifs -o uid=dano,gid=sudo,user=dano,password="my password" \\\\10.0.0.99\\home /mnt
@NanoDano
NanoDano / cpanel_create_email.py
Last active June 16, 2024 20:45
Create email account using cPanel API in Python
from requests import get # pip install requests
"""
Examples:
Docs:
- Create email (add_pop): https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Aadd_pop
- Delete email (delete_pop): https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Adelete_pop
- Change pass (passwd_pop): https://documentation.cpanel.net/display/DD/UAPI+Functions+-+Email%3A%3Apasswd_pop
@NanoDano
NanoDano / openfire_create_user.py
Created April 9, 2021 22:44
Use Openfire REST API to create a user
"""
Create a user on the Openfire XMPP server
Enable REST API by logging into admin portal (e.g. https://xmpp.devdungeon.com:9090) and go to `Plugins` and then `Available Plugins`. Enable the `REST API`.
Then go to `Server | Server Settings | REST API` and change it to `Enabled`.
Choose `Secret key auth` option and store that key.
(http 9090, https 9091)
POST https://example.org:9091/plugins/restapi/v1/users
@NanoDano
NanoDano / ssh-copy-id.py
Created June 9, 2021 04:12
Copy public SSH key to remote host using Paramiko
"""
Copy your SSH public key into a remote
host's `~/.ssh/authorized_keys` file.
pip install paramiko
Usage: ssh-copy-id.py <host> <username>
"""
from paramiko import SSHClient, AutoAddPolicy
import sys
@NanoDano
NanoDano / remind.sh
Last active June 23, 2021 04:09
Healthy Reminders
#!/bin/bash
# Healthy Reminders
#
# Setup a cron job to remind you to do healthy things
# Install dependency with: `sudo apt install libnotify-bin`
#
# Usage: remind.sh "Time to hydrate."
#
# Some cron examples (`crontab -e`):
# 0 * * * * /home/dano/Healthy-Reminders/remind.sh "Time to stand up."
@NanoDano
NanoDano / extract_images_from_pdf.py
Created October 14, 2021 06:57
Extract images from a PDF
#!/usr/bin/env python
"""
Extract images from a PDF
Modified from original at https://www.geeksforgeeks.org/how-to-extract-images-from-pdf-in-python/
pip install fitz frontend pymupdf
"""
import fitz
import io
from PIL import Image
@NanoDano
NanoDano / minecraft_backup.rb
Created February 1, 2022 23:23
Rotating remote SSH backup script in Ruby
#!/usr/bin/env ruby
require 'net/http'
BACKUP_DESTINATION_DIR = '/home/nanodano/mc_backup_rotate/backup_test'
DISCORD_WEBHOOK_URL = ''
DIR_TO_BACKUP = '/home/nanodano'
DB_USER = 'username'
DB_HOST = '127.0.0.1'
DB_NAME = 'dbname'
DB_PASS = 'password'