Skip to content

Instantly share code, notes, and snippets.

View hazcod's full-sized avatar

Niels Hofmans hazcod

View GitHub Profile
@hazcod
hazcod / sluggify.php
Last active November 22, 2017 16:13
PHP slugify snippet
public function sluggify($string, $separator = '-', $maxLength = 96)
{
$title = iconv('UTF-8', 'ASCII//TRANSLIT', $string);
$title = preg_replace("%[^-/+|\w ]%", '', $title);
$title = strtolower(trim(substr($title, 0, $maxLength), '-'));
$title = preg_replace("/[\/_|+ -]+/", $separator, $title);
return $title;
}
@hazcod
hazcod / urlencode
Last active January 24, 2020 19:16
UrlEncode function in Bash
# put this in your .bashrc or .bash_profile
function urlencode(){
[ -z "$1" ] || echo -n "$@" | hexdump -v -e '/1 "%02x"' | sed 's/\(..\)/%\1/g'
}

Keybase proof

I hereby claim:

  • I am HazCod on github.
  • I am nhofmans (https://keybase.io/nhofmans) on keybase.
  • I have a public key whose fingerprint is 11C8 F0F3 F757 9049 316F 322B 4A06 75C4 7CBE D349

To claim this, I am signing this object:

@hazcod
hazcod / fix-weechat-macos-ca.sh
Last active January 10, 2017 15:23
Fixes the ca bundle when using freenode/.. SSL with weechat on macos.
#!/usr/bin/env bash
# exit script when something fails
set -e
# get curl source
git clone https://github.com/curl/curl /tmp/curl
# create weechat cert directory
mkdir -p ~/.weechat/certs
@hazcod
hazcod / notify-tm-backup
Last active December 23, 2019 09:25
Show a notification when Time Machine backup completes
# Raw command
BACKUP=$(tmutil latestbackup) ; if [ "$(cat ~/.lastbackup 2>/dev/null)" != "$BACKUP" ]; then echo $BACKUP > ~/.lastbackup ; osascript -e "display notification \"$(echo $BACKUP | xargs basename)\" with title \"Backup finished\""; fi
# As cron entry
*/5 * * * * BACKUP=$(tmutil latestbackup 2>/dev/null) ; if [ "$(cat ~/.lastbackup 2>/dev/null)" != "$BACKUP" ]; then echo $BACKUP > ~/.lastbackup ; osascript -e "display notification \"$(echo $BACKUP | xargs basename)\" with title \"Backup finished\""; fi 2>&1 >/dev/null
@hazcod
hazcod / expose-docker-sock
Last active April 6, 2022 03:06
Expose docker.sock on a TCP socket.
FROM alpine
# the group id of the docker group on the host
ENV HOST_DOCKER_GID 101
# SECURITY CONSIDERATIONS:
# Only expose this via a dedicated internal, encrypted net to your webserver/..
# Mount /var/run/docker.sock READONLY, make this container readonly too
RUN addgroup -g $HOST_DOCKER_GID docker \
@hazcod
hazcod / git-bare-pull.sh
Created October 13, 2016 08:04
Pull changes from remote to a bare git repo.
#!/usr/bin/env bash
#set -e
#set -x
# directory where your git repos reside
repo_dir="/home/hazcod/repos/"
# the repos in repo_dir that should be pulled from remote (origin)
repos=(myproject)
@hazcod
hazcod / ssh-over-tls
Created January 15, 2016 12:59
Setup for enabling SSH over TLS
-- Apache vhost config
```
<VirtualHost *:443>
ServerName ssh.website.com
SSLEngine On
SSLCertificateFile /etc/ssl/cert.pem
SSLCertificateKeyFile /etc/ssl/privkey.pem
SSLCertificateChainFile /etc/ssl/fullchain.pem
@hazcod
hazcod / apache-plex-reverse-proxy.vhost
Last active December 12, 2024 05:45
Apache2 reverse proxy vhost configuration for Plex. Rerquires modules ssl, proxy, wstunnel
This current configuration is based of at least Server Version 1.16.5.1488 and Web Version: 3.108.2.
This updated config file allows the playing of trailers and TV Show theme music where as the previous one did not.
## Requirements
1. Apache version > 2.4
2. A bunch of mod's enabled (proxy, ssl, proxy_wstunnel, http, dir, env, headers, proxy_balancer, proxy_http, rewrite)
3. Protocols h2 http/1.1 needs apachectl -V 2.4.17 and higher...
## Apache .conf file
@hazcod
hazcod / __init__.py
Last active November 16, 2015 18:15
Post-process file for CouchPotato (custom_plugins/__init__.py)
from os import system, path, makedirs
import sys
def autoload():
move_to="/home/media/data/uploadme/movies/"
arr=sys.argv[2].split('/')
moviename=arr[6]
if not path.exists(move_to + moviename):
makedirs(move_to + moviename)