Skip to content

Instantly share code, notes, and snippets.

View carlwiedemann's full-sized avatar

Carl Wiedemann carlwiedemann

View GitHub Profile
@carlwiedemann
carlwiedemann / day001.rb
Created December 3, 2023 17:00
Advent of Code 2023 day001.rb
require_relative "main"
module Day001
INPUT = File.read('INPUT.txt')
lines = INPUT.to_lines
##########
# Part 1 #
##########
@carlwiedemann
carlwiedemann / day002.rb
Created December 3, 2023 17:00
Advent of Code 2023 day002.rb
require_relative "main"
module Day002
INPUT = File.read('INPUT.txt')
games = INPUT.to_lines.map do |line|
sets = line.split_strip(":").last.split_strip(";")
sets.map { |set| set.split_strip(",") }
end
@carlwiedemann
carlwiedemann / README.md
Created June 11, 2021 19:19 — forked from Potherca/README.md
Searching for a generic documentation block convention to use with BASH

Documentation block tags conventions for BASH

For most languages a single standard for documenting functions and methods in block comments (a.k.a. doc-blocks) has emerged.

For BASH, however, there does not seem to be a definitive convention. Several competing conventions exist, which made me think:

Could a list of doc-block tags be distilled from those used across all (or most) languages?

Time to find out!

There is a Taoist story of an old farmer who had worked his crops for many years. One day his horse ran away. Upon hearing the news, his neighbors came to visit. "Such bad luck," they said sympathetically. "May be," the farmer replied.
The next morning the horse returned, bringing with it three other wild horses. "How wonderful," the neighbors exclaimed. "May be," replied the old man.
The following day, his son tried to ride one of the untamed horses, was thrown, and broke his leg. The neighbors again came to offer their sympathy on his misfortune. "May be," answered the farmer.
The day after, military officials came to the village to draft young men into the army. Seeing that the son's leg was broken, they passed him by. The neighbors congratulated the farmer on how well things had turned out. "May be," said the farmer.
@carlwiedemann
carlwiedemann / pin.py
Created November 24, 2019 02:44
pin.py
import re
def does_pin_match(pin):
# FROM https://docs.python.org/3/library/re.html
# Matches the end of the string or just before the newline at the end of the
# string, and in MULTILINE mode also matches before a newline. foo matches
# both ‘foo’ and ‘foobar’, while the regular expression foo$ matches only
# ‘foo’. More interestingly, searching for foo.$ in 'foo1\nfoo2\n' matches
# ‘foo2’ normally, but ‘foo1’ in MULTILINE mode; searching for a single $ in
@carlwiedemann
carlwiedemann / netrw quick reference.md
Created February 18, 2019 22:51 — forked from t-mart/netrw quick reference.md
A quick reference for Vim's built-in netrw file selector.
Map Action
<F1> Causes Netrw to issue help
<cr> Netrw will enter the directory or read the file
<del> Netrw will attempt to remove the file/directory
- Makes Netrw go up one directory
a Toggles between normal display, hiding (suppress display of files matching g:netrw_list_hide) showing (display only files which match g:netrw_list_hide)
c Make browsing directory the current directory
C Setting the editing window
d Make a directory
<?php
print "<pre>";
$urls = [
[
'url' => 'https://badssl.com/',
'expected_http' => 200,
'expected_curl_errno' => 0,
'expected_curl_error' => '',
// See https://stackoverflow.com/questions/13104494/does-javascript-pass-by-reference
(function(){
var foo = [
'hello'
];
var replace_the_argument = function (some_array) {
some_array = ['hola'];
return some_array;
<?php
class A {
public $bar;
public function foo() {
static $cache = [];
if (!array_key_exists($this->bar, $cache)) {
$cache[$this->bar] = mt_rand();
}
<?php
/**
* # EXPECTED
* $ php -f ./switch-is-broken.php
* the word alpha
* the word beta
* the default
* the default
* the number one