Skip to content

Instantly share code, notes, and snippets.

@cpbotha
cpbotha / figure.html
Last active March 4, 2025 11:18
Drop-in replacement for Hugo figure shortcode with img srcset support
{{/*
figure with auto-resizing and srcset v2024-11-24
Drop-in replacement for Hugo's figure shortcode which uses img srcset
to enable browsers to download only the resolution that they need.
The resizing and srcset magic only works for images that are part of the page
bundle. It will fall back to stock Hugo figure behaviour otherwise.
;; https://emacs.stackexchange.com/a/3843/8743 original code
;; cpbotha.net made small improvements to ergonomics
;; cpbotha changes:
;; - by default extract files WITHOUT their relative directories into DIR,
;; because that's what I expect in OFMs.
(defun archive-extract-to-file (archive-name item-name command dir keep-relpath)
"Extract ITEM-NAME from ARCHIVE-NAME using COMMAND. Save to
DIR. If KEEP-RELPATH, extract with relative path otherwise don't."
(unwind-protect
/**
* Running this sketch on the RobotDyn Arduino M0 (SAMD21) with the itead xbee shield 1.1 I see the following output:
*
* waiting for any serial data to become available from the xbee
* 2795 MODEM_STATUS_RESPONSE: 0
* waiting for any serial data to become available from the xbee
* No packet available.
* waiting for any serial data to become available from the xbee
* 7974 MODEM_STATUS_RESPONSE: 0
*
// what we would like to see: first LED then second LED lights up on the WS2812 strip
// what we see instead: first LED (indicates startup), but then first 4 LEDs go on together, meaning xbee never talked back
// with SoftwareSerial(2,3) and the SparkFun shield switched to dline (vs UART), it does work.
#include <FastLED.h>
#include <XBee.h>
#include <Printers.h>
#define DATA_PIN 9
;; cpbotha's not so nice elpy init
(use-package elpy
:commands (elpy-enable) ;; this will ensure lazy loading
:config
(progn
(message "LAZY loading elpy")
(elpy-enable)
;; elpy is mightily confused by ipython 5.2 so we disable it
;; (elpy-use-ipython)

Keybase proof

I hereby claim:

  • I am cpbotha on github.
  • I am cpbotha (https://keybase.io/cpbotha) on keybase.
  • I have a public key ASDREmSD8t6oJihr4EnEG1-26vjV9QtcKZ8EFy0H5bsffAo

To claim this, I am signing this object:

@cpbotha
cpbotha / pyside_dynamic.py
Last active October 24, 2024 15:24
pyside_dynamic.py with minor improvements - also see http://stackoverflow.com/a/14894550/532513
#!/usr/bin/python2
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Sebastian Wiesner <[email protected]>
# Modifications by Charl Botha <[email protected]>
# * customWidgets support (registerCustomWidget() causes segfault in
# pyside 1.1.2 on Ubuntu 12.04 x86_64)
# * workingDirectory support in loadUi
# found this here:
# https://github.com/lunaryorn/snippets/blob/master/qt4/designer/pyside_dynamic.py
@cpbotha
cpbotha / colorbrewer_interpolate.js
Last active September 27, 2016 04:56
ColorBrewer sequential single hue scales vs. d3 interpolators.
// comparison of different d3 colour interpolators with
// colorbrewer sequential single-hue scales
//
// -- http://twitter.com/cpbotha
var numC = 9;
var data = d3.range(numC);
var showColourInterpolations = function(name, cbMap) {
var rectHeight = 50,
@cpbotha
cpbotha / horizontal_stacked_bar_chart.ipynb
Last active December 18, 2015 22:09
horizontal stacked bar chart
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cpbotha
cpbotha / README.md
Last active January 10, 2017 00:49
d3.js breathing drop shadows

Look ma, those drop shadows are breathing!

Your eyes want you to believe that the blocks are hovering up and down, when in fact only the drop shadow is being translated out and in again.

Follow me on https://twitter.com/cpbotha for even more fun, or see my other d3 blocks: http://bl.ocks.org/cpbotha