Skip to content

Instantly share code, notes, and snippets.

@dminuoso

dminuoso/c.rb Secret

Created January 2, 2018 16:01
Show Gist options
  • Save dminuoso/f6e244772ed4776f8e83acf67a367250 to your computer and use it in GitHub Desktop.
Save dminuoso/f6e244772ed4776f8e83acf67a367250 to your computer and use it in GitHub Desktop.
require 'active_support/core_ext/hash/deep_merge'
mappings = {
# Enhanced Haskell
"AA" => "∀",
"EE" => "∃",
"!EE" => "∄",
"in" => "∈",
"!in" => "∉",
"*{}" => "∅",
"not" => "¬",
"sum" => "Σ",
"*." => "◦",
"**" => "★",
"prod" => "Π",
"coprod" => "∐",
"_|_" => "⟂",
"->" => "→",
">->" => "↣",
"|->" => "↦",
"<-" => "←",
"<-<" => "↢",
"<-|" => "↤",
"=>" => "⇒",
"::" => "∷",
"==" => "≡",
">>>" => "⋙",
"<<<" => "⋘",
"_[" => "⊑",
"_]" => "⊒",
"[" => "⊏",
"]" => "⊐",
# Useful sets
"|Z" => "ℤ",
"|Q" => "ℚ",
"|N" => "ℕ",
"|C" => "ℂ",
"|H" => "ℍ",
"|P" => "ℙ",
"|B" => "𝔹",
"|{" => "⦃",
"|}" => "⦄",
# Greek alphabet
"ga" => "α",
"gA" => "Α",
"gb" => "β",
"gB" => "Β",
"gg" => "γ",
"gG" => "Γ",
"gd" => "δ",
"gD" => "Δ",
"gep" => "ε",
"gEP" => "Ε",
"gz" => "ζ",
"gZ" => "Ζ",
"get" => "η",
"gET" => "Η",
"gth" => "θ",
"gTH" => "Θ",
"gi" => "ι",
"gI" => "Ι",
"gk" => "κ",
"gK" => "Κ",
"gl" => "λ",
"gL" => "Λ",
"gm" => "μ",
"gM" => "Μ",
"gn" => "ν",
"gN" => "Ν",
"gx" => "ξ",
"gX" => "Ξ",
"go" => "ο",
"gO" => "Ο",
"gpi" => "π",
"gPI" => "Π",
"gr" => "ρ",
"gR" => "Ρ",
"gs" => "σ",
"g's" => "ς",
"gS" => "Σ",
"gta" => "τ",
"gTA" => "Τ",
"gu" => "υ",
"gU" => "Υ",
"gph" => "φ",
"gPH" => "Φ",
"gc" => "χ",
"gC" => "Χ",
"gps" => "ψ",
"gPS" => "Ψ",
"gv" => "ω",
"gV" => "Ω",
}
toHash = -> (chars, value) {
x, *xs = chars
case
when x.nil? then value
else { x => toHash.(xs, value) }
end
}
hashToDict = -> (hash, counter) {
indent = " " * (counter * 2)
hash.map { |k, v|
case
when v.is_a?(Hash) then
<<~DICT.chomp
#{indent}"#{k}" = {
#{hashToDict.(v, counter + 1)}
#{indent}};
DICT
else
indent + %Q<"#{k}" = ("insertText:", "#{v}");>
end
}.join("\n")
}
if mappings.keys.length != mappings.keys.uniq.length
puts "Duplicate entries"
exit
end
dict = mappings.to_a
.map { |key, text| toHash.(key.chars, text) }
.reduce { |l, r| l.deep_merge(r) }
bindings = {
"§" => dict,
"~ " => " ", # nbsp
}
puts "{"
puts hashToDict.(bindings, 1)
puts "}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment