Skip to content

Instantly share code, notes, and snippets.

@cmcaine
cmcaine / x.md
Last active June 1, 2024 10:46
"The Center Party wants to shoot all wolves in Norway"

Google translation of https://web.archive.org/web/20130211040508/http://www.nationen.no/2012/09/06/rovdyr/ulv/jakt/rovdyrforlik/fellingtillatelse/7637759/

The Center Party wants to shoot all wolves in Norway

When wolves are released from zoos in Sweden to save the wolf tribe, something is wrong, says Deputy Director of Sp and head of the program committee, Trygve Slagsvold Vedum.


The wolf has been protected in Norway since 1973, but Sp wants to put an end to that. In a submission to the Storting program for the Center Party, the government party advocates free hunting of wolves in Norway.

@cmcaine
cmcaine / diff-example.sql
Last active September 8, 2023 03:13
Diff SQL Select statements
/*
Show row differences between SELECT statements `new` and `old`.
The first column ("diff") will contain a '+' for rows that are in new and not in old
and a '-' for rows that are in old and not in new. The rest of the columns are whatever
new and old return.
If the rows in new and old share ids, then you may want to add an "ORDER BY" at the end
of the outer SELECT to make the two versions of the rows appear next to each other.
@cmcaine
cmcaine / alphametics.jl
Last active November 15, 2021 10:57
Brute force solver for alphametics
# See also https://github.com/exercism/julia/blob/3e57ea81abbff1882b263eb414fb0e453b07a17e/exercises/practice/alphametics/.meta/example.jl
using Combinatorics: permutations
using Test
function sum_expr(exprs)
if length(exprs) == 1
return only(exprs)
else
using Combinatorics
using Random
couples = 1:8
possible_groups = combinations(couples, 3)
function doit(couples, possible_groups)
has_not_met = [couple => setdiff(couples, couple) for couple in couples]
selected_groups = []
@cmcaine
cmcaine / MultipleLinearRegressionDemo.jl
Last active January 18, 2020 19:52
Simpler Flux demos
"""
Learn a linear model for a linear relationship of three variables
"""
module MultipleLinearRegressionDemo
using Flux: gradient, params
using Statistics: mean
function linreg(X, Y)
using Base64: base64encode
# From Base64 but copied here for readability
const BASE64_ENCODE = [UInt8(x) for x in ['A':'Z'; 'a':'z'; '0':'9'; '+'; '/']]
encode(x::UInt8) = @inbounds return BASE64_ENCODE[(x & 0x3f) + 1]
encodepadding() = UInt8('=')
"""
Spec:
@cmcaine
cmcaine / cruftless-webext-messaging.ts
Last active May 16, 2018 13:05
Is this as little cruft as possible?
/**
* Class C is loaded in two contexts: content and background. The decorators
* @content and @background replace the decorated function with a call to a
* messaging library if the current context is not the desired context for the
* function.
*
* The intention is that a developer can write code that is split between the
* content and background without having to think too much about where it is:
* calls that pass through messaging just look like regular async function
* calls.
@cmcaine
cmcaine / einsum-efficiency-problem.ipynb
Last active June 5, 2017 17:01
einsum-efficiency-problem.ipynb
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@cmcaine
cmcaine / justify-and-hyphenate.css
Last active March 23, 2017 22:38
Justify and hyphenate the web
p,ul,ol,dl,
div.thumbcaption /* wikipedia */ {
text-align: justify !important;
hyphens: auto !important;
}
@cmcaine
cmcaine / defaultlang.js
Created March 23, 2017 21:59
Set default language to "en"
// ==UserScript==
// @name Default language = en
// @namespace cmcaine
// @version 1
// @grant none
// ==/UserScript==
// So hyphens work better.
if (window.document.documentElement.lang == "") {