Skip to content

Instantly share code, notes, and snippets.

View bakkdoor's full-sized avatar

Christopher Bertels bakkdoor

View GitHub Profile
(defun easter-date-for-year (year)
(let ((golden-year (+ 1 (mod year 19)))
(century (+ (/ year 100) 1)))
(let ((skipped-leap-years (- (/ (* 3 century) 4) 12))
(correction-factor (- (/ (+ (* 8 century) 5) 25) 5)))
(let ((d (- (/ (* 5 year) 4) skipped-leap-years 10))
(epac (mod (- (+ (* 11 golden-year) 20 correction-factor) skipped-leap-years) 30)))
(if (or (and (= epac 25) (> golden-year 11)) (= epac 24))
(incf epac))
(setq mac-command-modifier 'meta)
(setq x-select-enable-clipboard t)
(setq mac-option-modifier nil)
(defun fullscreen ()
"full screen mode aktivieren"
(interactive)
(when (featurep 'aquamacs)
(aquamacs-toggle-full-frame))) ; switch to fullscreen mode
%%
%% simple portscanner written in simple erlang :)
%%
-module(portscanner).
-export([start/0]).
-author({"Christopher Bertels", "bakkdoor@flasht.de"}).
%% start portscanner process.
start() ->
-module(wordsort_sequential).
-export([start/1, start_file/1]).
-import(dict, [store/3, find/2]).
-author({"Christopher Bertels", "bakkdoor@flasht.de"}).
start(String) ->
process(words(String)).
start_file(Filename) ->
# find all words in file and sort them by appearance count
def print_file(filename = "test.rb")
File.open(filename, "r") do |f|
word_hash = {} # same as Hash.new
while(not f.eof)
line = f.readline
line.split(/\s+/).each do |word|
if(word_hash[word])
word_hash[word] += 1
# this method requires a block
# if called without passing one, a compiler error / warning could be shown
def my_method_with_required_block(param1, param2, *params) [block]
# do stuff here with block, like calling it:
block.call("calling block")
# or call it with yield:
yield("calling block")
end
#!/usr/bin/env ruby
filename = ARGV.size > 0 ? ARGV[0] : nil
unless filename
puts "usage: one_word_per_line.rb <filename>"
exit 0
end
File.open filename do |f|
$ rbx loader.rb
An exception occurred running loader.rb
Coercion error: nil.to_str => String failed (TypeError)
Backtrace:
Type.coerce_to at kernel/common/type.rb:22
Kernel(Rubinius::CodeLoader)#StringValue at kernel/common/kernel.rb:112
Rubinius::CodeLoader#initialize at kernel/common/codeloader.rb:22
main.__script__ at loader.rb:3
Rubinius::CodeLoader#load_script at kernel/delta/codeloader.rb:67
# Nested classes in Fancy
def class Foo {
def class Bar {
def foobar {
"foobar!" println
}
}
};
# Mixins in Fancy:
def class AClass {
self include: AnotherClass; # mixes in AnotherClass defined somewhere else
# alternatively you could also write:
AClass include: AnotherClass
}