Skip to content

Instantly share code, notes, and snippets.

@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 / 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 / sampleId.js
Last active April 16, 2018 19:10
GTM Sampling Variable
function(){
// Sets and gets a sample ID for bucket selection in A/B and related testing methodologies.
var ckPattern = /sampleId=(\d+)/g;
var sampleId = -1;
// TODO: adopt a different method for selecting the corp top level domain
var domain = document.location.hostname;
document.cookie.replace(ckPattern, function($0, $d){
@samba
samba / csvextract.py
Created March 9, 2018 06:10
Extract a subset of named fields from a CSV file
#!/usr/bin/env python
# Loads a CSV file, assuming it has header names, and prints only the specified columns.
# ... like selecting two columns of a 7-column table.
#
# Arguments:
# - field names, comma-separated
# - input filename
#
# Output:
# - the header row for the specified columns, and those fields for all input records.
@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 / Makefile
Last active May 5, 2017 23:18
Python requirements based on Operating System
# Example dynamic selection of Python requirements files
dependencies: $(shell python requirements.py)
for req in $^; do \
pip install --upgrade -r $$req ; \
done
test: dependencies
echo run your tests.
@samba
samba / setup.sh
Last active April 25, 2017 18:05
MAC Development Environment Setup
#!/bin/sh
# Sets up a wide array of my development environment on a Mac...
fail(){
err=$1; shift 1;
echo "$@" >&2
exit $err
}
@samba
samba / shopify.datalayer.html
Last active April 25, 2024 07:52
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 / scandupes.py
Created January 11, 2017 07:00
MD5 Index Scanner
#!/usr/bin/env python
"""
Scan an index of files, typically keyed by MD5 checksum, in the format produced by
GNU `md5sum` (not BSD-style), searching for one of many checksums listed in a pattern file.
The primary objective is to help find duplicates in a large collection of files, e.g. an
archive of music. Example:
> find ./music -type f -print0 | xargs -0 md5sum | sort > index.txt