Skip to content

Instantly share code, notes, and snippets.

@trans
trans / email-parser.rb
Created December 10, 2017 01:51
Parse Email Crude
class Email
attr :headers
attr :body
def initialize
@headers = Multimap.new
@body = ""
end
def parse(io)
@trans
trans / clik2.cr
Created September 21, 2015 03:23
$argv = [] of String
def cli(argv=ARGV)
# Convert single dash flags into multiple flags.
a = [] of String
argv.each do |v|
if v[0,1] == "-" && v[1,1] != "-"
a.concat(v[1..-1].chars.map{|c| "-#{c}"})
else
a << v
@trans
trans / clik.cr
Created August 10, 2015 03:36
Crystal port of Clik
def cli(opts : Hash(String,Proc))
cli(ARGV.dup, opts)
end
def cli(argv : Array(String), opts : Hash(String,Proc))
args = [] of String
# Split option aliases.
h = {} of String => ->
opts.each do |k,v|
# This is a build script made for ruby-install, though it may be out of date by now.
# Still the same basic approach applies.
# @see http://www.tkdocs.com/tutorial/install.html
# TODO: Add support for MacOS.
if [ -z $installdir ]; then
installdir="/opt/ActiveTcl-8.5"
fi
@trans
trans / trans1-jl.md
Last active August 29, 2015 14:05
Two proposals for a better Julia Module System

This is one of two proposals for a better module system for Julia. The goal is to promote good modular design. This proposal, as opposed to my other proposal, supports multiple modules per file.

The main concept is that files are loaded into a program always at the toplevel. Once loaded any module within those files are available for use, either through their absolute paths or by way of importing.

I will use the function load in the examples, but obviously another term can be used. When a file is loaded, it's modules are made available as are it's exported functions via absolute paths. e.g.

# Bar.jl
module Bar
  function f()

...

@trans
trans / indexfilter.jl
Created August 14, 2014 15:55
Index filter for Pandoc
#!/usr/bin/env runhaskell
import Text.Pandoc
import Text.Pandoc.Shared
import Text.Pandoc.JSON
import Text.Parsec
import Text.Regex
import Control.Applicative
import Data.Monoid
import Data.List
@trans
trans / AltGtk.jl
Last active August 29, 2015 14:05
Another Look at Julia's Import/Module Syatem
# Notes: Notice there is no `module Gtk` at the top. b/c not the file _is_ the module.
#
# The term `use` was chosen just to differentiate from the others. It would
# probably be called `import` in the end.
#
# The complex imports for GLib are gone. Why does there need to be a separate
# and specific import just b/c a function is going to be extended. The same is
# true for Base.
#
# The arguments are just file names and could also be written, e.g. `("GLib/Glib")`.
--- !!yaml
- !!version "2.0"
- !!tags
"!!": "tag:example.com,2000:app/"
---
!!int 1 - 3 # Interval, not integer
@trans
trans / superini.md
Last active August 29, 2015 14:03
Indention or Double Brackets for Super INI
[section]

  [subsection1]
  key1=value1
  key2=value2

  [subsection2]
  key1=value1
 key2=value2
@trans
trans / postponed-arguments
Created June 2, 2014 16:47
Postponed Evaluation of Arguments
# Postponed Evaluation of Arguments
Today in Ruby, there are a few special `methods' in that they do not seem to evaluate their arguments. An example is alias, which contrary to Module#alias_method does not take symbols as arguments, but instead takes the method names directly. This cannot be done by pure Ruby code as the method name would be evaluated by calling the method and taking the return value as the actual value of the parameter. The idea would be to give a method control over this. There are lots of unanswered questions though:
Languages like Lisp can do this in their macros because code is data and can easily be manipulated. In Ruby, code is not data (yet). It would be nice if it could be data. This requires the representation of a parse tree (although that may change with the advent of YARV) that can be inspected or even manipulated. This would be a powerful tool by itself, but at least inspection is required to make full use of the idea of postponed evaluation of arguments.
How is it indicated