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

1```go | clojure-example.go

2package main

3

4import "fmt"

5

6func intSeq() func() int {

7/*!*/ i := 0

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

9/*!*/ i++

10/*!*/ return i

11/*!*/ }

12}

13

14func main() {

15 nextInt := intSeq()

16 fmt.Println(nextInt())

17 fmt.Println(nextInt())

18 fmt.Println(nextInt())

19

20 newInts := intSeq()

21 fmt.Println(newInts())

22}

23```

clojure-example.go
1package main

2

3import "fmt"

4

5func intSeq() func() int {

6 i := 0

7 return func() int {

8 i++

9 return i

10 }

11}

12

13func main() {

14 nextInt := intSeq()

15 fmt.Println(nextInt())

16 fmt.Println(nextInt())

17 fmt.Println(nextInt())

18

19 newInts := intSeq()

20 fmt.Println(newInts())

21}


Learn More

linkHints

1```python | google.py

2import urllib2

3import urllib

4import json

5

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

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

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

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

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

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

12

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

14 title = result['title']

15 url = result['url']

16 print (title + '; ' + url)

17```

google.py
1import urllib2

2import urllib

3import json

4

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

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

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

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

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

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

11

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

13 title = result['title']

14 url = result['url']

15 print (title + '; ' + url)


Learn More

linkReferences

1```rust | conversion.rs

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

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

4

5#[derive(Debug, PartialEq)]

6struct EvenNumber(i32);

7

8impl TryFrom for EvenNumber {

9 type Error = ();

10

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

12 if value % 2 == 0 {

13 Ok(EvenNumber(value))

14 } else {

15 Err(())

16 }

17 }

18}

19

20fn main() {

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

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

23

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

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

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

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

28}

29```

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

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

3

4#[derive(Debug, PartialEq)]

5struct EvenNumber(i32);

6

7impl TryFrom<i32> for EvenNumber {

8 type Error = ();

9

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

11 if value % 2 == 0 {

12 Ok(EvenNumber(value))

13 } else {

14 Err(())

15 }

16 }

17}

18

19fn main() {

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

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

22

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

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

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

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

27}


Learn More

linkTop-Bar

1```docker | project/Dockerfile

2# our base image

3FROM alpine:3.5

4

5# Install python and pip

6RUN apk add --update py2-pip

7

8# upgrade pip

9RUN pip install --upgrade pip

10

11# install Python modules needed by the Python app

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

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

14

15# copy files required for the app to run

16COPY app.py /usr/src/app/

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

18

19# tell the port number the container should expose

20EXPOSE 5000

21

22# run the application

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

24```

project/Dockerfile
1# our base image

2FROM alpine:3.5

3

4# Install python and pip

5RUN apk add --update py2-pip

6

7# upgrade pip

8RUN pip install --upgrade pip

9

10# install Python modules needed by the Python app

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

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

13

14# copy files required for the app to run

15COPY app.py /usr/src/app/

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

17

18# tell the port number the container should expose

19EXPOSE 5000

20

21# run the application

22CMD ["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:

1```

2Ok some unknown syntax

3```

1Ok some unknown syntax


1``` | whatever.xyz

2Ok some unknown syntax

3Ok some unknown syntax

4Ok some unknown syntax

5```

whatever.xyz
1Ok some unknown syntax

2Ok some unknown syntax

3Ok some unknown syntax


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

2Ok some unknown syntax

3Ok some unknown syntax

4Ok some unknown syntax

5```

whatever.xyz
1Ok some unknown syntax

2Ok some unknown syntax

3Ok some unknown syntax

Code SnippetsHighlightsHintsReferencesTop-BarUnsupported Languages

Home Overview CLI Theme

Markdownchevron_right
Code Featureschevron_right

Images & Assets

Configurationchevron_right
Customizationchevron_right