This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s/\x1b\[0m/\x0f/g | |
s/\x1b\[1m/\x02/g | |
s/\x1b\[30m/\x031/g | |
s/\x1b\[31m/\x035/g | |
s/\x1b\[32m/\x033/g | |
s/\x1b\[33m/\x037/g | |
s/\x1b\[34m/\x032/g | |
s/\x1b\[35m/\x036/g | |
s/\x1b\[36m/\x0310/g | |
s/\x1b\[37m/\x0315/g |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
pub inline fn out(port: u16, value: var) void { | |
const TypeId = @import("builtin").TypeId; | |
const maxInt = @import("std").math.maxInt; | |
const value_ = switch (@typeId(@typeOf(value))) { | |
TypeId.ComptimeInt => switch (value) { | |
0...maxInt(u8) => @intCast(u8, value), | |
maxInt(u8) + 1...maxInt(u16) => @intCast(u16, value), | |
maxInt(u16) + 1...maxInt(u32) => @intCast(u32, value), | |
else => @compileError("port out of range"), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
triangles = [(a,b,c) | a<-[1..], b<-[1..a-1], c<-[a..a+b], a^2+b^2==c^2] | |
main = putStr $ unlines $ map show triangles |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Data.Complex | |
import Data.List | |
import Control.Parallel.Strategies | |
mandelbrot c = c : [z^2 + c | z <- mandelbrot c] | |
color (a,b,c,d) x y | |
| len < a = ' ' | |
| len < b = '.' | |
| len < c = ':' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import qualified Data.HashMap.Strict as M | |
import qualified Data.ByteString.Char8 as B | |
import Data.List (sortOn) | |
import Data.List.Split (chunksOf) | |
import Control.Parallel.Strategies (parMap, rdeepseq) | |
main = do | |
words <- B.words <$> B.getContents | |
let result = sortOn snd $ M.toList $ foldl (M.unionWith (+)) M.empty $ parMap rdeepseq (foldl (\acc x -> M.insertWith (+) x (1 :: Integer) acc) M.empty) (chunksOf 50000 words) | |
B.putStr . B.concat $ result >>= (\(a,b) -> [B.pack $ show b, B.singleton '\t', a, B.singleton '\n']) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/etc/localtime: | |
ln -sf /usr/share/zoneinfo/Europe/Berlin /etc/localtime | |
/etc/rc.conf: | |
inetd=NO | |
postfix=NO | |
named=YES | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
* { | |
animation-name: colors; | |
animation-duration: 4s; | |
animation-iteration-count: infinite; | |
} | |
@keyframes colors { | |
0% { text-shadow: 0 0 1pt hsl(0, 100%, 50%); } | |
17% { text-shadow: 0 0 1pt hsl(60, 100%, 50%); } | |
33% { text-shadow: 0 0 1pt hsl(120, 100%, 50%); } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import System.Environment (getArgs) | |
import System.IO (hPutStrLn, stderr) | |
import Data.List (genericTake) | |
import Text.Read (readMaybe) | |
-- sqrt possibly inaccurate for large primes. | |
primes = 2 : [ n | n<-[3,5..], all (\x -> n `mod` x /= 0) $ takeWhile (<= (floor $ sqrt $ fromIntegral n)) primes] | |
-- guaranteed to be correct for all primes, but much slower: | |
-- primes = 2 : [ n | n<-[3,5..], all (\x -> n `mod` x /= 0) $ takeWhile (<= (quot n 2)) primes] | |
-- for all n out of [1..] there's a prime p so that n < p < 2*n (Bertrand's postulate) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <assert.h> | |
#include <malloc.h> | |
#include <stdbool.h> | |
#include <stdlib.h> | |
#define FN void __attribute__((noreturn)) | |
#define LAMBDA(c_) ({ FN _ c_ _;}) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <inttypes.h> | |
#include <signal.h> | |
#include <stdio.h> | |
#include <string.h> | |
#include <unistd.h> | |
char *name; | |
void term(int signum) | |
{ |