new domain
2018.11.30
migrated permanently to a new domain: https://airen-no-jikken.icu
- 「哀憐」 as in like “sympathy”, like “for someone or something less-fortunate”
- 「実験」 like “actually putting it into practice”, or else conducting a formal experiment (basically the same thing, suppose)
to go along with the switch, been planning out how to rewrite this whole thing as a simple elixir+plug+cowboy site (really a mess underneath right now x-x), and as a first step to that, working out how to properly handle markdown stuff.
the most immediate solution seems to be pandoc, because it can handle commonmark-gfm and also does syntax highlighting by parsing in-line and assigning class tags.
here are example outputs for zsh:
fizzbuzz() {
# this is used to determine if a divisible number was seen
typeset -i local seen=0
# ensure there is exactly one argument
[[ $#@ -ne 1 ]] && printf 'Usage: %s <pos_int>\n' $0 && return 0
# error if arg is not a positive integer
[[ ! $1 =~ '^[1-9][0-9]*$' ]] \
&& 1>&2 printf 'err: `%s` is not a positive integer\n' $1 \
&& return 1
# check for divisibility and print if necessary
[[ $(($1 % 3)) -eq 0 ]] && printf 'Fizz' && seen=1
[[ $(($1 % 5)) -eq 0 ]] && printf 'Buzz' && seen=1
# if something was printed above, add a newline. else, print $1
[[ $seen -eq 1 ]] && printf '\n' || printf '%s\n' $1
}
for elixir:
defmodule Raindrops do
@fac2str [{3, "Pling"}, {5, "Plang"}, {7, "Plong"}]
@doc """
Returns a string based on raindrop factors.
- If the number contains 3 as a prime factor, output 'Pling'.
- If the number contains 5 as a prime factor, output 'Plang'.
- If the number contains 7 as a prime factor, output 'Plong'.
- If the number does not contain 3, 5, or 7 as a prime factor,
just pass the number's digits straight through.
"""
@spec convert(integer) :: String.t
def convert(number) do
Enum.reduce(@fac2str, {number, ""}, &check_rem/2)
|> (fn {i,s} -> if s == "", do: Integer.to_string(i), else: s end).()
end
defp check_rem({k, v}, {n, s}) do
cond do
rem(n, k) == 0 -> {n, s <> v }
true -> {n, s}
end
end
end
and for c:
#include "pangram.h"
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
/*
* determine if a given string is a "pangram"
* (that is, if it contains every letter of the alphabet)
*/
bool is_pangram(const char *s)
{
unsigned acc = 0;
unsigned char c;
if (s == NULL)
return false;
for (;s[0] != '\0'; s++) {
c = toupper(s[0]);
if (isalpha(c))
acc |= 1 << (c - 'A');
}
/* one bit for every letter of the alphabet */
return acc == 0x3ffffff;
}
p’neat, right?…except that pandoc pulls in like 4 gigs of dependencies, so no way can run it on-server. should be some way to get this same effect using just cmark-gfm and skylighting, so that could have a single command elixir server could use to auto-update things on fs-change, but that would take some work, something html-aware to patch stuff together in the middle
dunno, this s’enough for now
song of the day: