Skip to content

Instantly share code, notes, and snippets.

View citizen428's full-sized avatar

Michael Kohl citizen428

View GitHub Profile
@citizen428
citizen428 / day1.p6
Last active December 7, 2020 15:48
AOC 2020 Raku
my @l = 'aoc-expenses.txt'.IO.lines;
# part 1
say [*] @l.combinations(2).first: *.sum == 2020;
# part 2
say [*] @l.combinations(3).first: *.sum == 2020;
### Keybase proof
I hereby claim:
* I am citizen428 on github.
* I am citizen428 (https://keybase.io/citizen428) on keybase.
* I have a public key whose fingerprint is E183 E826 AAA2 71D9 A25E B8E9 EF16 E5E6 87B2 A218
To claim this, I am signing this object:
@citizen428
citizen428 / even_numbers_sequence.swift
Last active January 13, 2016 07:34
Swift sequences, generators etc
class EvenNumbers: CollectionType {
let startIndex : Int
let endIndex : Int
init(start: Int, end: Int) {
self.startIndex = start
self.endIndex = end
}
convenience init() {
@citizen428
citizen428 / array_extension.swift
Last active January 26, 2016 17:22
Turning Swift into Ruby
import Foundation
extension Array {
func each(task: (Element) -> ()) {
for element in self {
task(element)
}
}
func eachWithIndex(start: Int? = nil, task: (Int, Element) -> ()) {
#
# A colorful, friendly, multiline theme with some handy features.
# Based on the 'giddie' theme by Paul Gideon Dann.
#
# Authors:
# Michael Kohl <citizen428@gmail.com>
# Paul Gideon Dann <pd@gmail.com>
# Sorin Ionescu <sorin.ionescu@gmail.com>
#
# Features:
@citizen428
citizen428 / fizzbuzz.ex
Last active August 29, 2015 14:10
Elixir FizzBuzz server
defmodule FizzBuzz do
def compute do
receive do
n -> IO.puts compute(n)
end
compute
end
defp compute(n) do
case {rem(n, 3), rem(n, 5)} do
loop { print ">> " ; puts("=> %s" % eval(gets.chomp!)) }
@citizen428
citizen428 / userContent.css
Created January 16, 2014 20:42
Get rid of the "Inland" section of http://derstandard.at. Place contents of this file in `chrome/userContent.css` inside your Firefox profile directory.
@-moz-document url(http://derstandard.at/) {
div.section.inland { display: none }
}
@citizen428
citizen428 / with.rb
Created March 21, 2012 12:30
ActionScript-like "with" for Ruby, result of SO discussion
module Kernel
def with(obj, &block)
obj.instance_eval &block
obj
end
end
@citizen428
citizen428 / forth.rb
Last active September 29, 2015 23:58
NotReallyFORTH
class Proc
def prim_call(stack)
forth_arity = self.arity - 1
if stack.size < forth_arity
puts "Buffer underrun"
return stack.clear
end
forth_arity > 0 ? self.call(stack, *stack.pop(forth_arity)) : call(stack)
end
end