Skip to content

Instantly share code, notes, and snippets.

@samba
samba / htpasswd-ssl.sh
Created June 13, 2014 16:21
htpasswd replacement with openssl
#!/bin/sh
# Writes an APR1-format password hash to the provided <htpasswd-file> for a provided <username>
# This is useful where an alternative web server (e.g. nginx) supports APR1 but no `htpasswd` is installed.
# The APR1 format provides signifcantly stronger password validation, and is described here:
# http://httpd.apache.org/docs/current/misc/password_encryptions.html
help (){
cat <<EOF
Usage: $0 <htpasswd-file> <username>
@samba
samba / lightamd.js
Last active February 11, 2024 22:20
Simplified AMD-style module framework
/* A lightweight module framework intended to provide (simplified)
* AMD-style module support.
*
* Currently its minified form yields 987 bytes, 577 after gzip compression.
*
* It DOES NOT parse module identifiers as paths (e.g. "/a/b" or "../a").
* It assumes that all module IDs are simple strings, and seeks an exact
* match, without attempting to navigate any hierarchy.
*
* It DOES NOT parse incoming modules as string for require() statements.
@samba
samba / Principles.md
Last active January 25, 2024 04:20
API Design Principles

Principles of API Design

Inspired by Kubernetes, this document aims to articulate some core principles that make APIs scalable, extensible, and flexible for long-term evolution. Hopefully these concepts will be useful to you in designing your next application.

This is a living document. Please feel free to comment with ideas/feedback.

@samba
samba / ubuntu-vnc-activate-remote.sh
Last active January 24, 2024 00:56
Activate VNC support in Ubuntu, from command-line (for active sessions)
#!/bin/sh
# This assumes you have access to the system via SSH already, and need
# remote VNC access as the same user, and you want only the primary display.
export DISPLAY=:0
# Encoded password with http://www.motobit.com/util/base64-decoder-encoder.asp
export VNC_PASSWORD="dm5jX3Bhc3N3b3JkNzE=" # vnc_password71
export VNC_PASSWORD="dm5jX3Bhc3M=" # vnc_password (a character limit is enforced?)
# Sadly many common VNC clients don't support encryption.
@samba
samba / download_batocera.sh
Created November 11, 2023 23:18
Batocera x86_64 download script
#!/bin/bash
ARCH="x86_64"
DOWNLOAD_URL_PAGE="https://batocera.org/download"
get_downloader () {
which -a curl wget | head -n 1
}
read_url_cmd () {
@samba
samba / shopify.datalayer.html
Last active October 25, 2023 23:57
Shopify DataLayer Checkout
{% if first_time_accessed %}
<script>
(function(dataLayer){
var customer_type = ({{customer.orders_count}} > 1) ? 'repeatcustomer' : 'newcustomer';
var discounts = "{{ order.discounts | map: 'code' | join: ',' | upcase}}";
function strip(text){
return text.replace(/\s+/, ' ').replace(/^\s+/, '').replace(/\s+$/, '');
}
@samba
samba / README.md
Last active October 11, 2021 11:29
Google Tag Manager Utility Scripts

Utility Scripts for Google Tag Manager

Each script should include some outline of its usage. In general, the scripts will require installation as a Custom HTML tag in GTM, and should be triggered to run on every page.

Custom HTML scripts in GTM require wrapping Javascript in <script> tags, like so:

@samba
samba / md5unicode.js
Last active August 19, 2019 06:14
MD5 in Javascript with Full Unicode support
/* MD5 implementation with Unicode support
* Javascript's standard "charCodeAt" method returns 32-bit big-endian integers,
* which breaks most (JS) MD5 implementations for any input that isn't strictly
* 7-bit ASCII (i.e. within 8 bits). This implementation converts Javascript's
* character ordinals (including UCS-2) to UTF-8 equivalents, and buffers the
* code-points in 8-bit units, so it behaves more like other MD5 implementations
* on Unicode input.
*
* I've put this kit through only a handful test cases, so there maybe issues yet
* unknown. Contributions by way of testing, bug filing/fixing, and optimization
@samba
samba / kubescan.sh
Last active May 22, 2019 21:52
Dump cluster state to YAML
#!/usr/bin/env bash
# USAGE
# bash kubescan.sh kubeconfig.yaml > state.yaml
# Goal:
# - Provide a quick way to dump the state of a cluster for analysis
# - Simplify verification of live state of the cluster
@samba
samba / pythonrc.py
Last active June 21, 2018 19:09
Python RC with Color Prompt :)
# ~/.pythonrc
import sys
# enable syntax completion via tab
try:
import readline
except ImportError:
print "Module readline not available."
else: