Skip to content

Instantly share code, notes, and snippets.

View mrwilson's full-sized avatar

Alex Wilson mrwilson

View GitHub Profile
@mrwilson
mrwilson / scratch.ua
Last active April 16, 2024 12:26
uiua-scratch
⊏⊙"FDCBAA"⌊÷10↥0-50
@mrwilson
mrwilson / quack.sql
Last active December 27, 2020 14:18
quack.sql
with test(round) as (
select 0
union all
select round+1 from test where round <= 20
)
select round
from
-- delete the subselect line and it gives the expected error
-- "Error: near line 1: Catalog Error: Table with name handshake does not exist!"
@mrwilson
mrwilson / finalise_for_part_2.sql
Last active December 21, 2020 16:18
aoc_latest.sql
select
group_concat(ingredient, ',')
from (
select
ingredient,
allergen
from
named_allergens
order by allergen
);
-- Preprocessing the input into a csv e.g. 1,3,a,abcde
-- Creating table:
CREATE TABLE aoc_2(lower int4, upper int4, letter char, password varchar);
--Part 1:
SELECT
count(*)
FROM
aoc_2
@mrwilson
mrwilson / TinyInjector.java
Created November 2, 2020 16:30
Build Your Own Di Library (Part 1)
class TinyInjector {
public <T> T get(Class<T> klass) {
try {
return klass.newInstance();
} catch (InstantiationException | IllegalAccessException e) {
throw new RuntimeException(e);
}
}
}
import java.util.function.Function;
// https://en.wikipedia.org/wiki/Result_type
public sealed interface Result<LEFT, RIGHT> permits Result.Success, Result.Failure {
// Both functions have a common result supertype
// e.g. `T` can be a `Result<X,Y>` or a resolved type like a `String` / `Request`
<T, L2 extends T, R2 extends T> T either(Function<LEFT, L2> left, Function<RIGHT, R2> right);
default <T> T then(Function<Result<LEFT, RIGHT>, T> function) {
@mrwilson
mrwilson / Main.rs
Created May 25, 2015 20:42
Rust extern functions.
#[link(name = "sqlite3", kind="static")]
extern {
fn sqlite3_libversion_number() -> i8;
}
fn main() {
let x = unsafe { sqlite3_libversion_number() };
println!("Sqlite3 lib version number is {}!", x); // 2!
}
@mrwilson
mrwilson / example.yml
Last active August 29, 2015 14:07
Executable ansible manifests
#!/usr/bin/env ansible-playbook
- hosts: blog
sudo: yes
gather_facts: false
tasks:
- name: Copy blog across
synchronize: src=./blog dest=/var/www/blog
notify:
@mrwilson
mrwilson / do_codes_20140729.yml
Last active August 29, 2015 14:04
get_digital_ocean_codes.sh
# regions
do_regions_sfo1: 3
do_regions_nyc2: 4
do_regions_ams2: 5
do_regions_sgp1: 6
do_regions_lon1: 7
# sizes
do_sizes_32gb: 60
do_sizes_16gb: 61