Skip to content

Instantly share code, notes, and snippets.

View nicka101's full-sized avatar

Nick Anstee nicka101

  • Anstee Development
  • Norway
View GitHub Profile
@nicka101
nicka101 / patch-log4shell.yml
Last active December 18, 2021 09:03
Simple ansible playbook to patch log4j and remove JNDI lookup from discovered JARs, mitigating CVE-2021-44228. The playbook is intended for use against Debian targets (due to the use of apt and debian package names), but with minor modifications should work against other OSes.
---
- name: Patch log4shell
hosts: all
remote_user: root
tasks:
- name: Ensure find, lsof, kill, zip, unzip, coreutils and gawk are installed
apt:
name: "{{ packages }}"
state: present
vars:
@nicka101
nicka101 / check_spare_cpu.sh
Last active February 8, 2024 12:57
Xmrig (with idle mining) via systemd and screen
#!/bin/bash
# Check the amount of CPU being consumed by processes other than xmrig
# Takes a single (optional) argument, the name of the screen to target. Defaults to "xmrig" if unspecified
set -e
#12.5% or 2 full cores (with our 16 total)
IDLE_THRESHOLD=12.5
TARGET_SCREEN="${1:-xmrig}"
NUM_CORES=$(cat /proc/cpuinfo | grep "core id" | wc -l)
@nicka101
nicka101 / 2160pto1440p.py
Last active September 23, 2017 19:47
A lot of sites provide videos in 2160p and 1080p, and I like high quality, so I go for 2160p, but my monitor is only 1440p, so this script re-encodes videos down to 1440p from 2160p to save space
#!/usr/bin/env python3
# Convert 2160p to 1440p
import sys
import os
from os.path import join, getsize, dirname, basename
from subprocess import run, PIPE, STDOUT
from time import sleep
from collections import namedtuple
FFPROBE_BIN = os.getenv('FFPROBE_BINARY', 'ffprobe')
@nicka101
nicka101 / build_nginx.sh
Last active July 14, 2017 11:24 — forked from Belphemur/build_nginx.sh
Compiling Nginx with LibreSSL (and http2)
#!/usr/bin/env bash
# names of latest versions of each package
export NGINX_VERSION=1.13.1
export VERSION_PCRE=pcre-8.40
export VERSION_LIBRESSL=libressl-2.5.4
export VERSION_NGINX=nginx-$NGINX_VERSION
#export NPS_VERSION=1.9.32.10
#export VERSION_PAGESPEED=v${NPS_VERSION}-beta
@nicka101
nicka101 / mytop.sh
Created December 20, 2016 03:13
A simple bash script top-like program for mysql based on mysqladmin and dialog (well stty too, but its part of coreutils)
#!/bin/bash
# Top-like script for MySQL
DELAY=2
TTY_WIDTH=$(($(stty size | awk '{print $2}')-6)) # determine terminal width
TTY_HEIGHT=$(($(stty size | awk '{print $1}')-6)) # determine terminal height
while true; do
content="Status:\n"
@nicka101
nicka101 / Instructions.txt
Last active August 28, 2020 02:40
Notes on Building the Linux kernel for Orange Pi PC2 (Allwinner H5)
Get a copy of the linux kernel source you intend to build
Install u-boot-tools, gcc-aarch64-linux-gnu, g++-aarch64-linux-gnu device-tree-compiler libncurses-dev (packages names on debian-based systems)
You also need native compiler tools available, such as build-essential
Add the following to arch/arm64/boot/dts/allwinner/Makefile:
dtb-$(CONFIG_ARCH_SUNXI) += sun50i-h5-orangepi-pc2.dtb
If they allwinner folder doesn't exist, get the patches necessary to create it (and its friends) from mainline kernel, linux-sunxi, etc, etc
Add the attached dts, dtsi and defconfig files to the locations specified below:
dts & dtsi --> arch/arm64/boot/dts/allwinner/
defconfig --> arch/arm64/config/
Run the following (from the root of the kernel tree):
@nicka101
nicka101 / magento-backup.sh
Created August 23, 2016 09:18
Simple Backup script for Magento, with offsite uploading to Azure (requires bash, docker, mysqldump, xz, sha256sum and tar)
#!/bin/bash
# Simple Magento backup script by Nicka101 <nicka101@cloudbro.net>
# Some configuration constants
DB_NAME="<YOUR DB NAME>"
AZURE_USERNAME="<YOUR AZURE USERNAME>"
AZURE_KEY="<YOUR AZURE KEY>"
AZURE_CONTAINER="<YOUR (EXISTING) AZURE CONTAINER>"
WEBDIR=/var/www/whatever-folder
@nicka101
nicka101 / prg.php
Created April 7, 2016 13:30
Fix pricerules groups not appearing properly as a customer attribute
<?php
require_once('app/Mage.php');
Mage::app();
$attrib = Mage::getSingleton('eav/config')->getAttribute('customer', 'sinch_pricerules_group');
$attrib->setData('used_in_forms', array('adminhtml_customer'));
$attrib->save();
@nicka101
nicka101 / importPriceRules.php
Created July 14, 2015 10:29
import pricerules manual
<?php
require('app/Mage.php');
Mage::app();
$ftpCred = Mage::getStoreConfig('sinchimport_root/sinch_ftp');
Mage::dispatchEvent('sinch_pricerules_import_ftp', array(
'ftp_host' => $ftpCred["ftp_server"],
'ftp_username' => $ftpCred["login"],
'ftp_password' => $ftpCred["password"]
));
@nicka101
nicka101 / socket-constant-rebind.cpp
Last active August 29, 2015 14:23
Test ephemeral port allocation for routed connections
#include <string>
#include <iostream>
#ifdef _WIN32
#include <WS2tcpip.h>
#define LAST_ERR WSAGetLastError()
#define SOCK_INVALID(s) s == INVALID_SOCKET
#else
#define LAST_ERR errno
#define SOCK_INVALID(s) s < 0
#include <sys/socket.h>