Skip to content

Instantly share code, notes, and snippets.

@digitalist
digitalist / dotenv.sh
Created March 24, 2019 19:40
dotenv script ffs
#!/usr/bin/env bash
echo "starting .dotenv.sh"
dotenv_machine_uname="$(uname -s)"
case "${unameOut}" in
Linux*) dotenv_machine=Linux;;
FreeBSD*) dotenv_machine=FreeBSD;;
Darwin*) dotenv_machine=Mac;;
CYGWIN*) dotenv_machine=Cygwin;;
MINGW*) dotenv_machine=MinGw;;
*) dotenv_machine="${dotenv_machine_uname}"
@digitalist
digitalist / imagick3.4.3-PHP7.1-forge.sh
Last active March 6, 2019 10:24
Install Imagick 3.4.3 on PHP 7.1 server (Laravel Forge)
#!/bin/bash
if [ "$EUID" -ne 0 ]
then echo "Please run as root"
exit
fi
PHP_BUILD_BIN_PATH=/opt/php-7.1/bin
PHP_BUILD_PATH=/opt/php-7.1
apt install -y autoconf
apt-get install pkg-config libmagickwand-dev -y
@digitalist
digitalist / enumerate_users_by_shell.yml
Last active March 2, 2019 20:31
ansible: enumerate_users_by_shell.yml with list append example
---
#notes: enumerate user accounts
- hosts: "{{ rhosts | default('everyhost') }}"
tasks:
- set_fact:
nologin_shells:
- '/bin/false'
- '/usr/sbin/nologin'
- '/sbin/nologin'
@digitalist
digitalist / subscript_operator_overloading.cpp
Created February 20, 2019 17:42
for stupids like me: overloading brackets [] (subscript) operator in C+
/*
# for stupids like me: overloading brackets [] (subscript) operator in C++
# run:
# g++ subscript_operator_overloading.cpp && ./a.out
this example works because
map (or, i.e. array) supports [] as an assignment operator, so
it works transparently, implicitly -
you don't need translate and implement assignment
*/
@digitalist
digitalist / git-cleanup.sh
Created January 24, 2019 11:15
Git local branches cleanup script
#!/bin/bash
SAVE_BRANCHES="master|production|testing"
#RU: этот скрипт удалит все локальные ветки КРОМЕ указанных в переменной SAVE_BRANCHES
#RU: если запустить его БЕЗ аргументов (./git-cleanup.sh) - он спросит разрешения и выведет
#RU: список удаляемых веток. C любым аргументом (./git-cleanup.sh 1) - удалит лишние ветки
#EN: This script will delete all local branches EXCEPT those in SAVE_BRANCHES_VAR
#EN: Running it without args will display deletion candidates and prompt you to action.
#EN: Running it with any arg (./git-cleanup.sh 1) will just delete those branches
@digitalist
digitalist / mitmproxy_dumb_injector_example.py
Last active August 3, 2020 08:12
Little quick and dirty mitmproxy response rewrite example
# (this script works best with --anticache)
# run it like this: mitmdump -q -s ~/b/mitm/replace.py
from mitmproxy import ctx, http
import re
DPREFIX = '[DEBUG]> ' # stupid
"""
Dict of url regexps with content-type matching and replacement pairs
I would add regexp flags as a third element of replacement list
@digitalist
digitalist / graphicsmagick.sh
Last active November 16, 2018 09:00
graphicsmagick examples
#overwrite with crop
gm mogrify -crop 1356x694+0+0 some.png
#preserver original, place output to mogrified/ dir
gm mogrify -output-directory mogrified/ -crop 1356x694+0+0 some.png
@digitalist
digitalist / site.nginx.conf
Created November 6, 2018 13:02
faking proxy_pass for POST logging with NGINX
# pin postdata as a fake upstream log format name
log_format postdata '$request_body';
server {
listen 80 default_server;
listen [::]:80 default_server;
root /var/www/html;
# Add index.php to the list if you are using PHP
@digitalist
digitalist / cli-boilerplate.py
Created November 1, 2018 18:48
Python 3 argparse boilerplate
import os
import sys
import argparse
import logging
APPNAME_LOCK_FILE_NAME = "PY-BOILERPLATE"
def argparse_str2bool(v):
"""
allows handy parsing of bool args for argparse
@digitalist
digitalist / CMakeLists.txt
Created October 8, 2018 10:40
CMakeLists.txt for Haproxy [draft]
cmake_minimum_required(VERSION 3.2.0)
project(Haproxy)
set(CMAKE_C_STANDARD 11)
find_package(OpenSSL)
if(OPENSSL_FOUND)
include_directories("${OPENSSL_INCLUDE_DIR}")
endif(OPENSSL_FOUND)