Skip to content

Instantly share code, notes, and snippets.

View themadsens's full-sized avatar

Flemming Madsen themadsens

View GitHub Profile
@themadsens
themadsens / difflines
Last active December 1, 2023 09:59
Line by line diff that highlights changes from one line to the next. Prototype kindly authored by ChatGPT :)
#!/usr/bin/env python3
import difflib
import fileinput
def display_diff(diff):
for item in diff:
action, data = item[0], item[2:]
if action == ' ':
print(data, end='')
elif action == '-':
@themadsens
themadsens / nvs-iter-example.c
Last active July 20, 2020 11:19
NVS Iterator
// Example use of the iterator. Intended for the ESP32 console
// Caveat emptor: No express or implied warranty, functionality
// or fitness for any particular purpose
....
static int nvsdump_cmd(int argc, char** argv)
{
bool all = argc == 2 && *argv[1] == '*';
@themadsens
themadsens / avrdude2udev
Last active November 25, 2018 18:52
Create udev rule file from avrdude.conf
#!/bin/bash
for candidate in /usr/local/Cellar/avrdude/*/etc/avrdude.conf /etc/avrdude.conf /usr/local/etc/avrdude.conf ;do
if [[ -f $candidate ]] ;then
AVRCONF=$candidate
fi
done
[[ -f $AVRCONF ]] || exit
gawk '
@themadsens
themadsens / showfunc.wiki
Last active January 18, 2018 12:14
Original VimTip #79. Origin of ShowFunc.vim (VimScript #397) From http://vim.wikia.com/wiki/Use_grep_to_get_a_clickable_list_of_function_names
{{review}}
{{TipImported
|id=79
|previous=78
|next=80
|created=June 14, 2001
|complexity=basic
|author=Flemming Madsen
|version=6.0
|rating=130/40
@themadsens
themadsens / MonacoB for Powerline.ttf
Last active October 10, 2017 07:56
Monaco for Powerline
@themadsens
themadsens / Node.js 8.6.0 pdf.markdown
Last active October 4, 2017 19:31
How to create a PDF of the node documentation

Created as follows

  1. Open in Chrome as "One big page"
  2. Save as "Webpage - complete"
  3. Open .htm file in editor and delete sidebar (The "column2" div)
  4. Then replace all "https://#" with "#" globally (just the unqualified anchors).
  5. Open ..._files/style.css and change to "font-size: 50%;" in body class
  6. Open result in Chrome and do "Select all" + "Copy"
  7. Start "OpenOffice Writer". Edit page style to taste (margins etc.) and do a "Paste"
  8. Export the result as PDF
  9. Voila! Bob is your uncle.
@themadsens
themadsens / rawgit-bookmarklet.js
Last active February 15, 2017 17:07
Install: Copy from 'javascript:' onwards, and paste into a bookmark. Usage: Triple click filename in github and click bookmark
// javascript:
(function() {
function getSelectionHtml() {
var html = "";
if (typeof window.getSelection != "undefined") {
var sel = window.getSelection();
if (sel.rangeCount) {
var container = document.createElement("div");
for (var i = 0, len = sel.rangeCount; i < len; ++i) {
container.appendChild(sel.getRangeAt(i).cloneContents());
@themadsens
themadsens / gauge.js
Created September 27, 2016 20:09 — forked from tomerd/gauge.js
google style gauges using javascript d3.js
function Gauge(placeholderName, configuration)
{
this.placeholderName = placeholderName;
var self = this; // for internal d3 functions
this.configure = function(configuration)
{
this.config = configuration;
/**
* A function for converting hex <-> dec w/o loss of precision.
*
* The problem is that parseInt("0x12345...") isn't precise enough to convert
* 64-bit integers correctly.
*
* Internally, this uses arrays to encode decimal digits starting with the least
* significant:
* 8 = [8]
* 16 = [6, 1]
@themadsens
themadsens / JumpBuffers.vim
Last active July 22, 2016 11:59
In vim, show a list of recent buffers to jump to. List is created from the jumplist
function! JumpBuffers()
let jumptxt = ""
redir! => jumptxt
silent jumps
redir END
let byName = {}
let byIndex = []
for line in reverse(split(jumptxt, '\n'))
let name = strpart(line, 16)
let bufno = bufnr(name)