Star

MIT License
Copyright © 2020
CONNECT-platform

linkCode Snippets

Code snippets and examples are perhaps the most important tools at your disposal when trying to teach other people how to work with your software project (which is the purpose of CODEDOC to begin with). As a result, codedoc comes with a host of features on code snippets to enhance learning experience by them.


linkHighlights

1link```go | clojure-example.go

2linkpackage main

3link

4linkimport "fmt"

5link

6linkfunc intSeq() func() int {

7link/*!*/ i := 0

8link/*!*/ return func() int {

9link/*!*/ i++

10link/*!*/ return i

11link/*!*/ }

12link}

13link

14linkfunc main() {

15link/*-*/ nextInt := intSeq()

16link/*-*/ fmt.Println(nextInt())

17link /*~*/fmt.Println(nextInt())/*~*/

18link /*~warn~*/fmt.Println(nextInt())/*~warn~*/

19link

20link/*+*/ newInts := intSeq()

21link/*+*/ fmt.Println(newInts())

22link}

23link```

clojure-example.go
1linkpackage main

2link

3linkimport "fmt"

4link

5linkfunc intSeq() func() int {

6link i := 0

7link return func() int {

8link i++

9link return i

10link }

11link}

12link

13linkfunc main() {

14link nextInt := intSeq()

15link fmt.Println(nextInt())

16link fmt~~~.~Println~~~~~~~(~nextInt~~~~~~~(~)~)~

17link fmt~~~.~Println~~~~~~~(~nextInt~~~~~~~(~)~)~

18link

19link newInts := intSeq()

20link fmt.Println(newInts())

21link}


Learn More

linkHints

1link```python | google.py

2linkimport urllib2

3linkimport urllib

4linkimport json

5link

6linkurl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&" # --> url to google API

7linkquery = raw_input("What do you want to search for ? >> ") # --> get the search query from user

8linkquery = urllib.urlencode({'q' : query }) # --> url-encode it

9linkresponse = urllib2.urlopen (url + query).read() # --> ask google

10linkdata = json.loads (response) # --> parse the response

11linkresults = data ['responseData'] ['results'] # --> open the response array

12link

13linkfor result in results: # --> nicely print the results

14link title = result['title']

15link url = result['url']

16link print (title + '; ' + url)

17link```

google.py
1linkimport urllib2

2linkimport urllib

3linkimport json

4link

5linkurl = "http://ajax.googleapis.com/ajax/services/search/web?v=1.0&" # --> url to google API

6linkquery = raw_input("What do you want to search for ? >> ") # --> get the search query from user

7linkquery = urllib.urlencode({'q' : query }) # --> url-encode it

8linkresponse = urllib2.urlopen (url + query).read() # --> ask google

9linkdata = json.loads (response) # --> parse the response

10linkresults = data ['responseData'] ['results'] # --> open the response array

11link

12linkfor result in results: # --> nicely print the results

13link title = result['title']

14link url = result['url']

15link print (title + '; ' + url)


Learn More

linkReferences

1link```rust | conversion.rs

2link/*!*/use std::convert::TryFrom; // @see [official docs](https://doc.rust-lang.org/rust-by-example/conversion/try_from_try_into.html)

3link/*!*/use std::convert::TryInto; // @see [official docs](https://doc.rust-lang.org/rust-by-example/conversion/try_from_try_into.html)

4link

5link#[derive(Debug, PartialEq)]

6linkstruct EvenNumber(i32);

7link

8linkimpl TryFrom for EvenNumber {

9link type Error = ();

10link

11link fn try_from(value: i32) -> Result {

12link if value % 2 == 0 {

13link Ok(EvenNumber(value))

14link } else {

15link Err(())

16link }

17link }

18link}

19link

20linkfn main() {

21link assert_eq!(EvenNumber::try_from(8), Ok(EvenNumber(8))); // --> Try From

22link assert_eq!(EvenNumber::try_from(5), Err(())); // --> Try From

23link

24link let result: Result = 8i32.try_into(); // --> Try To

25link assert_eq!(result, Ok(EvenNumber(8))); // --> Try To

26link let result: Result = 5i32.try_into(); // --> Try To

27link assert_eq!(result, Err(())); // --> Try To

28link}

29link```

conversion.rs
1linkuse std::convert::TryFrom; // @see [official docs](https://doc.rust-lang.org/rust-by-example/conversion/try_from_try_into.html)

2linkuse std::convert::TryInto; // @see [official docs](https://doc.rust-lang.org/rust-by-example/conversion/try_from_try_into.html)

3link

4link#[derive(Debug, PartialEq)]

5linkstruct EvenNumber(i32);

6link

7linkimpl TryFrom<i32> for EvenNumber {

8link type Error = ();

9link

10link fn try_from(value: i32) -> Result<Self, Self::Error> {

11link if value % 2 == 0 {

12link Ok(EvenNumber(value))

13link } else {

14link Err(())

15link }

16link }

17link}

18link

19linkfn main() {

20link assert_eq!(EvenNumber::try_from(8), Ok(EvenNumber(8))); // --> Try From

21link assert_eq!(EvenNumber::try_from(5), Err(())); // --> Try From

22link

23link let result: Result<EvenNumber, ()> = 8i32.try_into(); // --> Try To

24link assert_eq!(result, Ok(EvenNumber(8))); // --> Try To

25link let result: Result<EvenNumber, ()> = 5i32.try_into(); // --> Try To

26link assert_eq!(result, Err(())); // --> Try To

27link}


Learn More

linkLinking Code-Snippets

1link> :Buttons

2link> > :Button url=#code7-l2:l2, label=First Button Code

3link>

4link> > :Button url=#code7-l4:l4, label=Second Button Code

First Button CodeSecond Button Code

Learn More

linkTerminal Snippets

1link```bash

2linkcodedoc u

3link> # Updating CLI ...

4link> # Updating local codedoc installation ...

5link>

6link> + @codedoc/core@0.2.18

7link> updated 1 package and audited 585 packages in 23.75s

8link> found 0 vulnerabilities

9linkcodedoc s

10link> {greenBright #} Serving ...

11link> {greenBright #} Fetching project configuration ...

12link> ts-node-dev ver. 1.0.0-pre.63 (using ts-node ver. 8.10.2, typescript ver. 3.9.7)

13link>

14link> {greenBright #} Serving docs on {cyan http://localhost:3000}

15link> {gray # building ........ docs/md/404.md}

16link> {green # built:: ......... dist/404.html}

17link> ...

18link```

1link$codedoc u

# Updating CLI ... # Updating local codedoc installation ... + @codedoc/core@0.2.18 updated 1 package and audited 585 packages in 23.75s found 0 vulnerabilities
2link$codedoc s

# Serving ... # Fetching project configuration ... ts-node-dev ver. 1.0.0-pre.63 (using ts-node ver. 8.10.2, typescript ver. 3.9.7) # Serving docs on http://localhost:3000 # building ........ docs/md/404.md # built:: ......... dist/404.html ...

Learn More

linkTop-Bar

1link```docker | project/Dockerfile

2link# our base image

3linkFROM alpine:3.5

4link

5link# Install python and pip

6linkRUN apk add --update py2-pip

7link

8link# upgrade pip

9linkRUN pip install --upgrade pip

10link

11link# install Python modules needed by the Python app

12linkCOPY requirements.txt /usr/src/app/

13linkRUN pip install --no-cache-dir -r /usr/src/app/requirements.txt

14link

15link# copy files required for the app to run

16linkCOPY app.py /usr/src/app/

17linkCOPY templates/index.html /usr/src/app/templates/

18link

19link# tell the port number the container should expose

20linkEXPOSE 5000

21link

22link# run the application

23linkCMD ["python", "/usr/src/app/app.py"]

24link```

project/Dockerfile
1link# our base image

2linkFROM alpine:3.5

3link

4link# Install python and pip

5linkRUN apk add --update py2-pip

6link

7link# upgrade pip

8linkRUN pip install --upgrade pip

9link

10link# install Python modules needed by the Python app

11linkCOPY requirements.txt /usr/src/app/

12linkRUN pip install --no-cache-dir -r /usr/src/app/requirements.txt

13link

14link# copy files required for the app to run

15linkCOPY app.py /usr/src/app/

16linkCOPY templates/index.html /usr/src/app/templates/

17link

18link# tell the port number the container should expose

19linkEXPOSE 5000

20link

21link# run the application

22linkCMD ["python", "/usr/src/app/app.py"]


Learn More

linkUnsupported Languages

CODEDOC uses Prism for syntax highlighting. In case a language is not supported by Prism, you will get an error indicating that the language for the snippet is not recognized.

Languages Supported by Prism

In most cases, this is actually a typo in the markdown, and the error helps you track it down and fix it. However, in rare cases you are actually writing a snippet in a new language which is not yet supported by Prism. In such a case, you can overcome the error in two ways:

1link```

2linkOk some unknown syntax

3link```

1linkOk some unknown syntax


1link``` | whatever.xyz

2linkOk some unknown syntax

3linkOk some unknown syntax

4linkOk some unknown syntax

5link```

whatever.xyz
1linkOk some unknown syntax

2linkOk some unknown syntax

3linkOk some unknown syntax


1link``` xyz | whatever.xyz | --safe-highlight

2linkOk some unknown syntax

3linkOk some unknown syntax

4linkOk some unknown syntax

5link```

whatever.xyz
1linkOk some unknown syntax

2linkOk some unknown syntax

3linkOk some unknown syntax

Code SnippetsHighlightsHintsReferencesLinking Code-SnippetsTerminal SnippetsTop-BarUnsupported Languages

Home Overview CLI Theme

Markdownchevron_right
Code Featureschevron_right

Images & Assets

Configurationchevron_right
Customizationchevron_right