\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{Haskell} \pdfinfo{ /Title (csc-3600.pdf) /Creator (Cheatography) /Author (Haskell) /Subject (CSC 3600 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}{076FA3} \definecolor{LightBackground}{HTML}{EFF6F9} \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{CSC 3600 Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{Haskell} via \textcolor{DarkBackground}{\uline{cheatography.com/57281/cs/15140/}}} \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}Haskell \\ \uline{cheatography.com/haskell} \\ \end{tabulary} \vfill \columnbreak \begin{tabulary}{5.8cm}{L} \SetRowColor{FootBackground} \mymulticolumn{1}{p{5.377cm}}{\bf\textcolor{white}{Cheat Sheet}} \\ \vspace{-2pt}Not Yet Published.\\ Updated 16th March, 2018.\\ 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{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Useful Functions}} \tn % Row 0 \SetRowColor{LightBackground} int socket(int domain, int type, int protocol); & Creates a socket and returns a file descriptor \tn % Row Count 3 (+ 3) % Row 1 \SetRowColor{white} struct hostent {\emph{gethostbyname(const char }}name); & Checks if the host exists and then translates its address into something useable by other functions. Note: The data you probably want from this is contained in the h\_addr field of the struct \tn % Row Count 13 (+ 10) % Row 2 \SetRowColor{LightBackground} int connect(int sockfd, const struct sockaddr *addr, socklen\_t addrlen); & Attempts to connect \tn % Row Count 18 (+ 5) % Row 3 \SetRowColor{white} ssize\_t send(int sockfd, const void *buf, size\_t len, int flags); & Sends the specified data over the network. Note: This is only for Connections, so no UDP data transmission with this one. \tn % Row Count 25 (+ 7) % Row 4 \SetRowColor{LightBackground} ssize\_t recv(int sockfd, void *buf, size\_t len, int flags); & Receives data. Opposite of send, this call blocks until it reads the number of bytes specified. \tn % Row Count 30 (+ 5) \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Useful Functions (cont)}} \tn % Row 5 \SetRowColor{LightBackground} int close(int fd); & Closes a file descriptor. Since this closes a file descriptor, it works on other things too! (Like text files) \tn % Row Count 6 (+ 6) % Row 6 \SetRowColor{white} int bind(int sockfd, const struct sockaddr *addr, socklen\_t addrlen); & Makes the specified port belong to you. The server is the only one to bind. \tn % Row Count 11 (+ 5) % Row 7 \SetRowColor{LightBackground} int listen(int sockfd, int backlog); & Waits for an incoming connection request. Blocking. \tn % Row Count 14 (+ 3) % Row 8 \SetRowColor{white} int accept(int sockfd, struct sockaddr {\emph{addr, socklen\_t }}addrlen); & Accepts a connection request. Important to note that this returns a new file descriptor to a new socket. \tn % Row Count 20 (+ 6) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Read the man pages for more information. Google is your friend.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{8.635 cm} x{8.635 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Useful Memory Management Functions}} \tn % Row 0 \SetRowColor{LightBackground} void* malloc( size\_t size ); & This is just like new only a little bit more complex. You will need to cast the data that malloc returns to the type you need. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} void free(void *ptr); & Same as delete. \tn % Row Count 9 (+ 2) % Row 2 \SetRowColor{LightBackground} void {\emph{memset(void }}str, int c, size\_t n); & Sets the value of the memory you give it to the value specified. Typically used to set a chunk of memory to 0. \tn % Row Count 15 (+ 6) % Row 3 \SetRowColor{white} void {\emph{memcpy(void }}str1, const void *str2, size\_t n); & Self explanatory. \tn % Row Count 18 (+ 3) % Row 4 \SetRowColor{LightBackground} void {\emph{memmove(void }}str1, const void *str2, size\_t n); & Self explanatory. \tn % Row Count 21 (+ 3) % Row 5 \SetRowColor{white} sizeof(thing) & sizeof will correctly get you the size of any type of data you give it. sizeof DOES NOT give you the size of an array as it only works with types. Fun Fact: sizeof isnt a function, its an operator! \tn % Row Count 31 (+ 10) \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Bit Bashing}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{Definitions \newline % Row Count 1 (+ 1) \& – Bitwise AND \newline % Row Count 2 (+ 1) | – Bitwise OR \newline % Row Count 3 (+ 1) \textasciitilde{} – Bitwise NOT \newline % Row Count 4 (+ 1) \textasciicircum{} – XOR \newline % Row Count 5 (+ 1) \textless{}\textless{} – Left Shift \newline % Row Count 6 (+ 1) \textgreater{}\textgreater{} – Right Shift \newline % Row Count 7 (+ 1) Logic Tables: \newline % Row Count 8 (+ 1) \& AND \newline % Row Count 9 (+ 1) -{}-{}-{}-0 1 \newline % Row Count 10 (+ 1) 0 | 0 0 \newline % Row Count 11 (+ 1) 1 | 0 1 \newline % Row Count 12 (+ 1) | OR \newline % Row Count 13 (+ 1) -{}-{}-{}-0 1 \newline % Row Count 14 (+ 1) 0 | 0 1 \newline % Row Count 15 (+ 1) 1 | 1 1 \newline % Row Count 16 (+ 1) \textasciicircum{} XOR \newline % Row Count 17 (+ 1) -{}-{}-{}-0 1 \newline % Row Count 18 (+ 1) 0 | 0 1 \newline % Row Count 19 (+ 1) 1 | 1 0 \newline % Row Count 20 (+ 1) \textasciitilde{} NOT \newline % Row Count 21 (+ 1) 0 becomes 1 \newline % Row Count 22 (+ 1) 1 becomes 0 \newline % Row Count 23 (+ 1) \textless{}\textless{} Shift Left \newline % Row Count 24 (+ 1) Moves ALL bits left n spaces \newline % Row Count 25 (+ 1) 0001 \textless{}\textless{} 2 = 0100 \newline % Row Count 26 (+ 1) Shift Right \newline % Row Count 27 (+ 1) 0101 \textgreater{}\textgreater{} 2 = 0001 \newline % Row Count 28 (+ 1) NOTE: Bits that are shifted too far (Like the example above) are gone so if you did \newline % Row Count 30 (+ 2) } \tn \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{17.67cm}}{\bf\textcolor{white}{Bit Bashing (cont)}} \tn \SetRowColor{white} \mymulticolumn{1}{x{17.67cm}}{x = 0101 \textgreater{}\textgreater{} 2 \newline % Row Count 1 (+ 1) x = x \textless{}\textless{} 2 \newline % Row Count 2 (+ 1) the answer would be 0100 \newline % Row Count 3 (+ 1) So for: \newline % Row Count 4 (+ 1) ~ x = 00101000 (40) \newline % Row Count 5 (+ 1) ~ y = 01010000 (80) \newline % Row Count 6 (+ 1) x\&y = 00000000= 0 (decimal) \newline % Row Count 7 (+ 1) x|y = 01111000 = 120 (decimal) \newline % Row Count 8 (+ 1) \textasciitilde{}x = 11010111 = -41 (decimal) \newline % Row Count 9 (+ 1) x\textasciicircum{}y = 01111000= 120 (decimal) \newline % Row Count 10 (+ 1) x \textless{}\textless{} 1 = 01010000 = 80 (decimal) \newline % Row Count 11 (+ 1) x \textgreater{}\textgreater{} 1 = 00010100 = 20 (decimal)% Row Count 12 (+ 1) } \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \SetRowColor{LightBackground} \mymulticolumn{1}{x{17.67cm}}{More information found here \newline https://en.wikipedia.org/wiki/Bitwise\_operations\_in\_C} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{17.67cm}{x{2.9359 cm} x{14.3341 cm} } \SetRowColor{DarkBackground} \mymulticolumn{2}{x{17.67cm}}{\bf\textcolor{white}{Useful Linux Commands/Programs}} \tn % Row 0 \SetRowColor{LightBackground} grep & This is a REALLY useful one to search anything. \seqsplit{https://www.gnu.org/savannah-checkouts/gnu/grep/manual/grep.html} Important to note that you can pipe something into grep to search the output of another program. \tn % Row Count 7 (+ 7) % Row 1 \SetRowColor{white} \seqsplit{valgrind} & The queen of memory leak detection. If you get a segfault then this is your best friend. http://valgrind.org \tn % Row Count 11 (+ 4) % Row 2 \SetRowColor{LightBackground} gdb & Your debugger, this is a pretty big topic. \seqsplit{https://www.gnu.org/software/gdb/} \tn % Row Count 14 (+ 3) % Row 3 \SetRowColor{white} make & Run a makefile. A useful makefile tutorial can be found here: \seqsplit{http://www.cs.colby.edu/maxwell/courses/tutorials/maketutor/} \tn % Row Count 18 (+ 4) \hhline{>{\arrayrulecolor{DarkBackground}}--} \SetRowColor{LightBackground} \mymulticolumn{2}{x{17.67cm}}{Basic commands like ls, pwd, and clear are not included here.} \tn \hhline{>{\arrayrulecolor{DarkBackground}}--} \end{tabularx} \par\addvspace{1.3em} \end{document}