\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{bigocb} \pdfinfo{ /Title (coding-general.pdf) /Creator (Cheatography) /Author (bigocb) /Subject (Coding (General) 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}{3944A3} \definecolor{LightBackground}{HTML}{F2F3F9} \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{Coding (General) Cheat Sheet}}}} \\ \normalsize{by \textcolor{DarkBackground}{bigocb} via \textcolor{DarkBackground}{\uline{cheatography.com/97523/cs/20904/}}} \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}bigocb \\ \uline{cheatography.com/bigocb} \\ \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 25th October, 2019.\\ 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*}{2} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Making API Call}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{public int getNews() \{ \newline \newline @Value( "\$\{api.url\}" ) \newline private String uri; \newline \newline @Value( "\$\{api.key\}" ) \newline private String key; \newline \newline ObjectMapper mapper = new ObjectMapper(); \newline RestTemplate restTemplate = new RestTemplate(); \newline \newline List\textless{}Articles\textgreater{} result = \seqsplit{restTemplate.getForObject(uri} + key, \newline \seqsplit{InboundNewsResponse.class).getArticles();} \newline \newline return 1 \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Rest Template}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{@Bean \newline public int \seqsplit{getRest(RestTemplateBuilder} restTemplateBuilder) \{ \newline String baseUrl = \textless{}URL\textgreater{} \newline RestTemplate restTemplate = restTemplateBuilder \newline \seqsplit{.setConnectTimeout(ncoaConnectTimeout)} \newline \seqsplit{.setReadTimeout(ncoaReadTimeout)} \newline .build(); \newline \newline return new NCOAClient(baseUrl, restTemplate); \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Misc.}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Random Number}} \newline public static double getRandomNumber()\{ \newline double x = Math.random(); \newline return x; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Recieving API Call}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Basic Get}} \newline @GetMapping(path = "/enp" \newline protected boolean get() \{ \newline return true; \newline \} \newline \newline {\bf{Info From Request Body}} \newline (@RequestBody String blah) \newline \newline {\bf{Info From Request Header}} \newline (@RequestHeader ("dp-token") String dpToken) \newline \newline {\bf{Receive File}} \newline @RequestMapping(value = "/upload", method = RequestMethod.POST, \newline consumes = \seqsplit{MediaType.MULTIPART\_FORM\_DATA\_VALUE)} \newline \newline public String \seqsplit{fileUpload(@RequestParam("file")} MultipartFile file) throws IOException \{ \newline File convertFile = new \seqsplit{File("/var/tmp/"+file.getOriginalFilename());} \newline \seqsplit{convertFile.createNewFile();} \newline FileOutputStream fout = new \seqsplit{FileOutputStream(convertFile);} \newline \seqsplit{fout.write(file.getBytes());} \newline fout.close(); \newline return "File is upload successfully"; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{General}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{toString}} \newline @Override \newline public String toString() \{ \newline return "MailFwdRequest\{" + \newline "cfpsid='" + cfpsId + \newline ", btid=" + btId + \newline '\}'; \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Read file}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{import java.io.*; \newline public class ReadingFromFile \newline \{ \newline public static void main(String{[}{]} args) throws Exception \newline \{ \newline // pass the path to the file as a parameter \newline FileReader fr = \newline new FileReader("C:\textbackslash{}\textbackslash{}Users\textbackslash{}\textbackslash{}pankaj\textbackslash{}\textbackslash{}Desktop\textbackslash{}\textbackslash{}test.txt"); \newline \newline int i; \newline while ((i=fr.read()) != -1) \newline System.out.print((char) i); \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Run Method on Start}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{@PostConstruct \newline private void init() \{ \newline \seqsplit{log.info("InitDemoApplication} initialization logic ..."); \newline // ... \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Lists, Maps, Trees}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{{\bf{Trees}} \newline \{\{link="https://www.baeldung.com/java-binary-tree"\}\}Trees Article\{\{/link\}\} \newline \newline {\bf{Maps}} \newline HashMap\textless{}String, Integer\textgreater{} map = new HashMap\textless{}\textgreater{}(); \newline map.put("vishal", 10); \newline map.get("vishal"); \newline \newline {\bf{Lists}} \newline List a = new ArrayList(); \newline List b = new LinkedList(); \newline List c = new Vector(); \newline List d = new Stack(); \newline List\textless{}Integer\textgreater{} l1 = new ArrayList\textless{}Integer\textgreater{}(); \newline l1.add(0, 1); // adds 1 at 0 index \newline l1.add(1, 2); // adds 2 at 1 index} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{Jooq}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{private final DSLContext jooq; \newline \newline @Transactional \newline public boolean selectExists(Long \textless{}var) \{ \newline return jooq.fetchExists( \newline select() \newline \seqsplit{.from(COA\_INFORMED\_DELIVERY)} \newline .where(\textless{}table\textgreater{}.\textless{}column\textgreater{}.eq(\textless{}var\textgreater{})) \newline ); \newline \} \newline \newline @Transactional(readOnly = true) \newline public List\textless{}MailFwdExtension\textgreater{} select(String cfpsId) \{ \newline List\textless{}MailFwdExtensionsRecord\textgreater{} records = jooq \newline \seqsplit{.selectFrom(MAIL\_FWD\_EXTENSIONS)} \newline \seqsplit{.where(MAIL\_FWD\_EXTENSIONS.CFPSID.eq(cfpsId))} \newline \seqsplit{.fetchInto(MailFwdExtensionsRecord.class);} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{OAuth / Auth}} \tn % Row 0 \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{} \tn % Row Count 0 (+ 0) \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} \begin{tabularx}{8.4cm}{X} \SetRowColor{DarkBackground} \mymulticolumn{1}{x{8.4cm}}{\bf\textcolor{white}{h2}} \tn \SetRowColor{LightBackground} \mymulticolumn{1}{x{8.4cm}}{\seqsplit{spring.datasource.url=jdbc:h2:mem:testdb} \newline spring.datasource.driverClassName=org.h2.Driver \newline spring.datasource.username=sa \newline spring.datasource.password= \newline spring.h2.console.enabled=false \newline \newline spring.h2.console.enabled=true \newline http://localhost:8080/h2-console \newline \newline @Entity \newline public class Person \{ \newline \newline @Id \newline @GeneratedValue \newline private int id; \newline private String name; \newline private int age; \newline private String emailId; \newline \newline //getters and setters \newline \} \newline \newline public interface PersonRepository extends CrudRepository\textless{}Person, Integer\textgreater{} \{\} \newline \newline @Service \newline public class PersonService \{ \newline \newline @Autowired \newline PersonRepository personRepository; \newline \newline public List\textless{}Person\textgreater{} getAllPersons() \{ \newline List\textless{}Person\textgreater{} persons = new ArrayList\textless{}Person\textgreater{}(); \newline \seqsplit{personRepository.findAll().forEach(person} -\textgreater{} persons.add(person)); \newline return persons; \newline \} \newline \newline public Person getPersonById(int id) \{ \newline return \seqsplit{personRepository.findById(id).get();} \newline \} \newline \newline public void saveOrUpdate(Person person) \{ \newline \seqsplit{personRepository.save(person);} \newline \} \newline \newline public void delete(int id) \{ \newline \seqsplit{personRepository.deleteById(id);} \newline \} \newline \}} \tn \hhline{>{\arrayrulecolor{DarkBackground}}-} \end{tabularx} \par\addvspace{1.3em} % That's all folks \end{multicols*} \end{document}