Skip to content

Instantly share code, notes, and snippets.

@mk270
mk270 / convert-heic.sh
Created March 15, 2022 20:44
convert HEIC files in place
#!/bin/bash
# Warning: converts file in place
# Usage:
# convert-heic kittens009142.heic
set -eu
if [ $# != 1 ]; then
@mk270
mk270 / ghost-add-user.py
Created August 7, 2021 20:03
A tool for adding Ghost CMS users from the command line
#!/usr/bin/env python3
# ghost-add-user, (c) Martin Keegan 2021
# Copyright licence: Apache Software Licence 2.0
# A tool for adding new users to Ghost CMS from the command line
# please excuse this pre-alpha code. I was in a massive hurry.
import logging
@mk270
mk270 / batched_generator.py
Last active March 16, 2021 14:27
batched generator for Python
import itertools
def batch_generator(size, g):
buffer = []
try:
while True:
for i in range(0, size):
buffer.append(g.next())
yield buffer
buffer = []
@mk270
mk270 / badly_formatted.adb
Created April 28, 2016 18:45
Badly formatted Ada code from science paper
with Text_IO,Ada.Numerics.Generic_Elementary_Functions;
with Ada.Numerics;
use Text_IO,Ada.Numerics;
procedure Eutecticmain is
package Real_Io is new FLOAT_IO(Float);
use Real_Io;
package Integer_IO is new Text_IO.INTEGER_IO(Integer); use Integer_IO;
use Integer_Io;
package Elem_Fct is new Ada.Numerics.Generic_Elementary_Functions (Float);
@mk270
mk270 / dynamic_allocation_experiment.adb
Last active February 17, 2016 22:38
Ada container example
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line;
with Ada.Containers.Vectors; use Ada.Containers;
package body Dynamic_Allocation_Experiment
is
type Side is (Left, Right);
package Side_Container is new Vectors (Natural, Side);
use Side_Container;
@mk270
mk270 / unchecked_deallocation_experiment.adb
Created February 16, 2016 20:49
practice returning a dynamically allocated array
with Ada.Text_IO; use Ada.Text_IO;
with Ada.Command_Line;
with Ada.Unchecked_Deallocation;
package body Dynamic_Allocation_Experiment
is
type Side is (Left, Right);
type Side_Array is array (Integer range <>) of Side;
type Side_Array_Ptr is access Side_Array;
@mk270
mk270 / gist:5408855
Last active December 16, 2015 08:49
What I had to do to get an OCaml executable working

Install OCaml from source

  • download ocaml-4.00.1.tar.gz
  • tar zxvf path/to/ocaml-4.00.1.tar.gz
  • cd ocaml-4.00.1
  • ./configure -prefix $HOME
  • make world
  • make bootstrap
  • make opt
@mk270
mk270 / gist:5213183
Created March 21, 2013 13:57
I don't understand SQLA transactions
# Leaves a transaction
p_group = models.PackageGroup.query.filter_by(name=id).first_or_404()
# Doesn't leave a transaction, if uncommented instead of above
#p_group = db.session.query(models.PackageGroup).filter_by(name=id).first()
del(p_group)
db.session.commit()
@mk270
mk270 / tags.el
Created March 17, 2013 18:45
html tag tool
(defun add-tags (tag)
"add tags"
(interactive)
(save-excursion
(goto-char (region-end))
(insert (concat "</" tag ">"))
(goto-char (region-beginning))
(insert (concat "<" tag ">"))))