Skip to content

Instantly share code, notes, and snippets.

@jmrnilsson
jmrnilsson / day03.js
Created December 3, 2022 10:35
Advent-of-Code 2022-02
function intersect(left, right){
return new Set([...left].filter(x => right.has(x)));
}
function* chunked(arr, n) {
for (let i = 0; i < arr.length; i += n) {
yield arr.slice(i, i + n);
}
}
@jmrnilsson
jmrnilsson / lxml.markdown
Last active November 16, 2022 13:01
Installing lxml in 2022 on MacOS 12.6 Monterrey
  1. Upgrade pip globally and in virtualenv and build deps
pip install --upgrade pip
source ./.venv/bin/activate
pip install --upgrade pip
pip install setuptools
deactivate
brew install libxml2
brew install libxslt
import itertools
import re
import sys
from collections import Counter, defaultdict
from functools import reduce
import numpy as np
from aoc.helpers import timing, loc, Printer, loc_input
#include "ArduinoMotorShieldR3.h"
// https://store.arduino.cc/arduino-motor-shield-rev3
// https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
// https://github.com/gallingern/arduino-motor-shield-r3
ArduinoMotorShieldR3 md;
int trigPin = 5; // Trigger
int echoPin = 4; // Echo
int ledPin = 7;
@jmrnilsson
jmrnilsson / console.js
Last active March 2, 2020 14:54
Get all failed tests from Azure DevOps
// Paste in to console when Azure DevOps view is open with some failing tests
var a = document.querySelectorAll(".ms-DetailsRow-cell .clickable-text")
for(var i = 1; i < a.length; i++) { console.log(a[i].innerHTML) }
@jmrnilsson
jmrnilsson / Dockerfile
Created November 20, 2019 23:34
Convert Canon CR2 to PNG
FROM ubuntu:xenial
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update
RUN apt-get install -y --no-install-recommends ufraw-batch
WORKDIR /app
VOLUME ["/app/data"]
COPY *.CR2 /app/data/
ENTRYPOINT [ "bash" ]
@jmrnilsson
jmrnilsson / EmptyPushCiBuild.ps1
Last active October 7, 2019 08:18
Push empty commits to git for some branches
#!/usr/bin/env pwsh
git fetch --all
$branches = ('branch0',
'branch1',
'branch2',
);
foreach ($branch in $branches) {
@jmrnilsson
jmrnilsson / robot.ino
Last active June 30, 2019 23:49
Arduino Motor R3 Obstacle Avoidance 2WD Robot
#include "ArduinoMotorShieldR3.h"
// https://store.arduino.cc/arduino-motor-shield-rev3
// https://randomnerdtutorials.com/complete-guide-for-ultrasonic-sensor-hc-sr04/
// https://github.com/gallingern/arduino-motor-shield-r3
ArduinoMotorShieldR3 md;
int trigPin = 5; // Trigger
int echoPin = 4; // Echo
int ledPin = 7;
@jmrnilsson
jmrnilsson / Program.cs
Created June 7, 2019 16:11
LinefeedPurger - Detects all invalid LF files in C# (.cs) files from git top-level - .NETCore
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
namespace LinefeedPurger
{
class Program
@jmrnilsson
jmrnilsson / gist:73b02af88162af09d5718d83a75234c6
Created June 7, 2019 10:59
Example: Outer join and group join examples in C# FLWR and "method chaining "
var q =
from iu in Items
join u in OtherItems on iu.Id equals u.Id into ug
from u in ug.DefaultIfEmpty()
where u == null
orderby iu.Id
select iu;
var q1 =