\documentclass[10pt,a4paper]{article} % Packages \usepackage{fancyhdr} % For header and footer \usepackage{multicol} % Allows multicols in tables \usepackage{tabularx} % Intelligent column widths \usepackage{tabulary} % Used in header and footer \usepackage{hhline} % Border under tables \usepackage{graphicx} % For images \usepackage{xcolor} % For hex colours %\usepackage[utf8x]{inputenc} % For unicode character support \usepackage[T1]{fontenc} % Without this we get weird character replacements \usepackage{colortbl} % For coloured tables \usepackage{setspace} % For line height \usepackage{lastpage} % Needed for total page number \usepackage{seqsplit} % Splits long words. %\usepackage{opensans} % Can't make this work so far. Shame. Would be lovely. \usepackage[normalem]{ulem} % For underlining links % Most of the following are not required for the majority % of cheat sheets but are needed for some symbol support. \usepackage{amsmath} % Symbols \usepackage{MnSymbol} % Symbols \usepackage{wasysym} % Symbols %\usepackage[english,german,french,spanish,italian]{babel} % Languages % Document Info \author{Dockson} \pdfinfo{ /Title (dugga2.pdf) /Creator (Cheatography) /Author (Dockson) /Subject (dugga2 Cheat Sheet) } % Lengths and widths \addtolength{\textwidth}{6cm} \addtolength{\textheight}{-1cm} \addtolength{\hoffset}{-3cm} \addtolength{\voffset}{-2cm} \setlength{\tabcolsep}{0.2cm} % Space between columns \setlength{\headsep}{-12pt} % Reduce space between header and content \setlength{\headheight}{85pt} % If less, LaTeX automatically increases it \renewcommand{\footrulewidth}{0pt} % Remove footer line \renewcommand{\headrulewidth}{0pt} % Remove header line \renewcommand{\seqinsert}{\ifmmode\allowbreak\else\-\fi} % Hyphens in seqsplit % This two commands together give roughly % the right line height in the tables \renewcommand{\arraystretch}{1.3} \onehalfspacing % Commands \newcommand{\SetRowColor}[1]{\noalign{\gdef\RowColorName{#1}}\rowcolor{\RowColorName}} % Shortcut for row colour \newcommand{\mymulticolumn}[3]{\multicolumn{#1}{>{\columncolor{\RowColorName}}#2}{#3}} % For coloured multi-cols \newcolumntype{x}[1]{>{\raggedright}p{#1}} % New column types for ragged-right paragraph columns \newcommand{\tn}{\tabularnewline} % Required as custom column type in use % Font and Colours \definecolor{HeadBackground}{HTML}{333333} \definecolor{FootBackground}{HTML}{666666} \definecolor{TextColor}{HTML}{333333} \definecolor{DarkBackground}{HTML}{A3A3A3} \definecolor{LightBackground}{HTML}{F3F3F3} \renewcommand{\familydefault}{\sfdefault} \color{TextColor} % Header and Footer \pagestyle{fancy} \fancyhead{} % Set header to blank \fancyfoot{} % Set footer to blank \fancyhead[L]{ \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{C} \SetRowColor{DarkBackground} \vspace{-7pt} {\parbox{\dimexpr\textwidth-2\fboxsep\relax}{\noindent \hspace*{-6pt}\includegraphics[width=5.8cm]{/web/www.cheatography.com/public/images/cheatography_logo.pdf}} } \end{tabulary} \columnbreak \begin{tabulary}{11cm}{L} \vspace{-2pt}\large{\bf{\textcolor{DarkBackground}{\textrm{dugga2 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Dockson} via \textcolor{DarkBackground}{\uline{cheatography.com/24842/cs/7454/}}} \end{tabulary} \end{multicols}} \fancyfoot[L]{ \footnotesize \noindent \begin{multicols}{3} \begin{tabulary}{5.8cm}{LL} \SetRowColor{FootBackground} \mymulticolumn{2}{p{5.377cm}}{\bf\textcolor{white}{Cheatographer}} \\ \vspace{-2pt}Dockson \\ \uline{cheatography.com/dockson} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Published 9th March, 2016.\\ Updated 13th May, 2016.\\ Page {\thepage} of \pageref{LastPage}. \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Sponsor}} \\ \SetRowColor{white} \vspace{-5pt} %\includegraphics[width=48px,height=48px]{dave.jpeg} Measure your website readability!\\ www.readability-score.com \end{tabulary} \end{multicols}} \begin{document} \raggedright \raggedcolumns % Set font size to small. Switch to any value % from this page to resize cheat sheet text: % www.emerson.emory.edu/services/latex/latex_169.html \footnotesize % Small font. \begin{multicols*}{3} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{rdparse}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{require './rdparse' \newline \newline MONTHS = \{'januari' =\textgreater{} 1, 'februari' =\textgreater{} 2, 'mars' =\textgreater{} 3, 'april' =\textgreater{} 4, \newline 'maj' =\textgreater{} 5, 'juni' =\textgreater{} 6, 'juli' =\textgreater{} 7, 'augusti' =\textgreater{} 8, 'september' =\textgreater{} 9, \newline 'oktober' =\textgreater{} 10, 'november' =\textgreater{} 11, 'december' =\textgreater{} 12\} \newline \newline class Calendar \newline \newline def initialize \newline @calendarParser = Parser.new("calendar parser") do \newline @c = Time.now \newline logger.level = Logger::WARN \newline \newline token(/'.*?'/) \{ |m| m{[}1..-2{]} \} \# quoted strings \newline token(/\textbackslash{}s+/) \# whitespaces (ignored) \newline token(/\textbackslash{}d+/) \{ |m| m.to\_i \} \# integers \newline token(/\textbackslash{}w+/) \{ |m| m \} \# alphanumerical strings \newline token(/./) \{ |m| m \} \# other characters, individually \newline \newline start :expr do \newline match(:date) \{ {[}{]} \} \newline match(:meeting) \newline end \newline \newline rule :date do \newline match('-', Integer, String, Integer, '-') do |\_, d, m, y, \_| \newline @c = Time.local(y, MONTHS{[}m.downcase{]}, d) \newline end \newline end \newline \newline rule :meeting do \newline match(:time, '-', :time, String) do | start, \_, stop, text | \newline {[}text, start, stop{]} \newline end \newline end \newline \newline rule :time do \newline match(Integer, '.', Integer) do |h, \_, m| \newline Time.local(@c.year, @c.month, @c.day, h, m) \newline end \newline end \newline \newline end \newline end \newline \newline def read\_meetings(filename) \newline result = {[}{]} \newline content = IO.readlines(filename) \newline content.each do |line| \newline line.strip! \newline if line.length \textgreater{} 0 then \newline r = \seqsplit{@calendarParser.parse(line)} \newline if r != {[}{]} then \newline result \textless{}\textless{} r \newline end \newline end \newline end \newline result \newline end \newline end} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{DSL}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{class TripleStore \newline \newline def initialize \newline @db = \{\} \newline end \newline \newline def \seqsplit{TripleStore.load(filename)} \newline r = new \newline \seqsplit{r.instance\_eval(File.read(filename))} \newline r \newline end \newline \newline def method\_missing(property,arg1,arg2) \newline table = @db{[}property.to\_s{]} \newline if table then \newline table \textless{}\textless{} {[}arg1,arg2{]} \newline else \newline @db{[}property.to\_s{]} = {[}{[}arg1,arg2{]}{]} \newline end \newline end \newline \newline def find(property,arg1,arg2) \newline table = @db{[}property{]} \newline result = {[}{]} \newline table.each do |pair| \newline if arg1 != '{\emph{' and arg2 != '}}' then \newline result \textless{}\textless{} pair if (pair{[}0{]}==arg1) and (pair{[}1{]}==arg2) \newline elsif arg1 != '{\emph{' then \newline result \textless{}\textless{} pair if pair{[}0{]}==arg1 \newline elsif arg2 != '}}' then \newline result \textless{}\textless{} pair if pair{[}1{]}==arg2 \newline end \newline end \newline result \newline end \newline end} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{5.377cm}}{\bf\textcolor{white}{Constraint network}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{5.377cm}}{require "./constraint\_networks" \newline \newline class Squarer \newline include PrettyPrint \newline \newline attr\_accessor :a, :sq\_a \newline attr\_reader :logger \newline \newline def initialize(a,sq\_a) \newline \seqsplit{@logger=Logger.new(STDOUT)} \newline @a,@sq\_a={[}a,sq\_a{]} \newline {[}a,sq\_a{]}.each \{|x| x.add\_constraint(self)\} \newline end \newline \newline def to\_s \newline "\#\{a\}\textasciicircum{}2 == \#\{sq\_a\}" \newline end \newline \newline def new\_value(connector) \newline if a==connector and a.has\_value? and (not sq\_a.has\_value?) then \newline logger.debug("\#\{self\} : \#\{sq\_a\} updated") \newline \seqsplit{sq\_a.assign(a.value*a.value},self) \newline elsif sq\_a==connector and sq\_a.has\_value? and (not a.has\_value?) then \newline logger.debug("\#\{self\} : \#\{a\} updated") \newline \seqsplit{a.assign(Math::sqrt(sq\_a.value)},self) \newline end \newline self \newline end \newline \newline \# A connector lost its value, so propagate this information to all \newline \# others \newline def lost\_value(connector) \newline ({[}a,sq\_a{]}-{[}connector{]}).each \{ |connector| \seqsplit{connector.forget\_value(self)} \} \newline end \newline \newline end \newline \newline def circle\_area\_network \newline \newline \seqsplit{radius=Connector.new('radius')} \newline \seqsplit{radius\_sq=Connector.new('radius\_sq')} \newline \seqsplit{area=Connector.new('area')} \newline \seqsplit{pi=ConstantConnector.new('pi'},Math::PI) \newline \newline Squarer.new(radius,radius\_sq) \newline Multiplier.new(pi,radius\_sq,area) \newline \newline {[}radius,area{]} \newline end \newline \newline \$radius,\$area=circle\_area\_network \newline \newline def circle\_area(radius) \newline \$radius.forget\_value "user" if \$radius.has\_value? \newline \$radius.user\_assign radius \newline \$area.value \newline end} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Teori}} \tn % Row 0 \SetRowColor{LightBackground} PARSER: Parsern fungerar på så s{\"a}tt att den f{\"o}rst extraherar tokens ur teckenstr{\"o}mmen med hj{\"a}lp av regex f{\"o}r att sedan arbetas på med hj{\"a}lp av reglerna som {\"a}r specificerade under initialize. De tokens som extraheras matchas enligt reglerna och ett uttryck byggs på så s{\"a}tt upp från grunden. F{\"o}r varje regel som matchas så k{\"o}rs kodblocket bredvid det f{\"o}r att t.ex. spara bort koden i en variabel eller f{\"o}r att k{\"o}ra någon funktion med koden som inparameter. & DSL vs GPL: Ett DSL {\"a}r ett skr{\"a}ddarsytt språk designat f{\"o}r att l{\"o}sa specifika problem. Anv{\"a}ndning f{\"o}r ett GPL {\"a}r v{\"a}ldigt brett och det anv{\"a}nds f{\"o}r att l{\"o}sa otroligt många men orelaterade uppgifter. En anledning till att man kanske skulle vilja skriva ett DSL {\"a}r f{\"o}r att simplifiera anv{\"a}ndarinmatning, m{\"o}jligtvis f{\"o}r anv{\"a}ndare som inte {\"a}r familj{\"a}ra med kodning. Det kan också anv{\"a}ndas f{\"o}r att simplifera datainput, t.ex konfiguration f{\"o}r ett program. \tn % Row Count 24 (+ 24) % Row 1 \SetRowColor{white} CONTINUATION: En continuation {\"a}r lite av en glorifierad GOTO. Den anv{\"a}nds f{\"o}r att kunna hoppa till en specifik plats någonstans i koden. Continuations sparar {\"a}ven 'omgivningen' som den ser ut vid just det tillf{\"a}llet vilket g{\"o}r att man kan arbeta på variabler som de såg ut då och inte nu. En anledning till att anv{\"a}nda continuations ist{\"a}llet f{\"o}r ett antal for-loopar {\"a}r hur enkelt det {\"a}r att ta sig tillbaka till b{\"o}rjan continuation satsen oavsett var man {\"a}r i koden f{\"o}r tillf{\"a}llet, ist{\"a}llet f{\"o}r att beh{\"o}va breaka en massa for-satser. & LEX vs SYNT: Lexikalisk analys {\"a}r n{\"a}r en str{\"o}m tecken tolkas inte bara som enskilda tecken men de transformeras ist{\"a}llet till tokens. t.ex. 'int 5' blir uppdelad till både 'int' och siffran 5. Syntaktisk analys {\"a}r n{\"a}r dessa tokens anv{\"a}nds f{\"o}r att verifiera att de anv{\"a}nds enligt den specificerade grammatiken. t.ex att 'if' {\"a}r f{\"o}ljt av en j{\"a}mf{\"o}relse och sedan en sats. \tn % Row Count 52 (+ 28) \end{tabularx} \par\addvspace{1.3em} \vfill \columnbreak \begin{tabularx}{5.377cm}{x{2.4885 cm} x{2.4885 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{5.377cm}}{\bf\textcolor{white}{Teori (cont)}} \tn % Row 2 \SetRowColor{LightBackground} \mymulticolumn{2}{x{5.377cm}}{RUBY FÖR DSL: Ruby {\"a}r v{\"a}ldigt bra n{\"a}r det kommer till s.k metaprogrammering och DSL {\"a}r en del av just det. En anledning till att Ruby passar f{\"o}r ett DSL {\"a}r method\_missing, alltså metoden d{\"a}r man man kan dynamiskt skapa en metod utan att beh{\"o}va definera den tidigare. Detta leder till en v{\"a}ldig frihet n{\"a}r det kommer till syntax. instance\_eval {\"a}r en annan v{\"a}ldigt anv{\"a}ndbar del av Ruby n{\"a}r det kommer till DSL'er. Med instance\_eval kan man skicka in ett block kod f{\"o}r att k{\"o}ras inuti en klass. En tredje f{\"o}rdel {\"a}r metoden send d{\"a}r namnet på en metod skickas in som en symbol och då k{\"o}rs denna metod i klassen i fråga.} \tn % Row Count 13 (+ 13) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}