mirror of
https://github.com/Stone-Red-Code/website.git
synced 2026-09-08 23:44:09 +02:00
Merge pull request #181 from the-programmers-hangout/content-archives-format
content(archives): format codeblocks
This commit is contained in:
@@ -16,13 +16,13 @@ The advantage to this approach is that it's very lightweight since it doesn't re
|
|||||||
**Examples**
|
**Examples**
|
||||||
You can get a fully functional ubuntu machine by just running
|
You can get a fully functional ubuntu machine by just running
|
||||||
|
|
||||||
```
|
```sh
|
||||||
docker run -it ubuntu bash
|
docker run -it ubuntu bash
|
||||||
```
|
```
|
||||||
|
|
||||||
Running an nginx web server can be done easily using docker-compose:
|
Running an nginx web server can be done easily using docker-compose:
|
||||||
|
|
||||||
docker-compose.yml:
|
Create: `docker-compose.yml`
|
||||||
|
|
||||||
```yml
|
```yml
|
||||||
web:
|
web:
|
||||||
@@ -37,17 +37,21 @@ web:
|
|||||||
command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
|
command: /bin/bash -c "envsubst < /etc/nginx/conf.d/mysite.template > /etc/nginx/conf.d/default.conf && nginx -g 'daemon off;'"
|
||||||
```
|
```
|
||||||
|
|
||||||
`docker-compose up -d`
|
And run:
|
||||||
|
|
||||||
|
```sh
|
||||||
|
docker-compose up -d
|
||||||
|
```
|
||||||
|
|
||||||
You can start a Redis instance like this:
|
You can start a Redis instance like this:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
docker run --name my-redis -d redis
|
docker run --name my-redis -d redis
|
||||||
```
|
```
|
||||||
|
|
||||||
Then you can inspect the running containers with:
|
Then you can inspect the running containers with:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ docker ps
|
$ docker ps
|
||||||
|
|
||||||
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
|
||||||
@@ -56,7 +60,7 @@ d295137f5965 redis "docker-entrypoint.s…" 6 seconds ago
|
|||||||
|
|
||||||
and attach to the running redis container to run commands with redis-cli:
|
and attach to the running redis container to run commands with redis-cli:
|
||||||
|
|
||||||
```
|
```sh
|
||||||
$ docker exec -it my-redis redis-cli
|
$ docker exec -it my-redis redis-cli
|
||||||
127.0.0.1:6379> set example-key 1234
|
127.0.0.1:6379> set example-key 1234
|
||||||
OK
|
OK
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ GraphQL was created internally by Facebook in 2012, mainly to optimize the netwo
|
|||||||
|
|
||||||
Meanwhile, a GraphQL query would look like :
|
Meanwhile, a GraphQL query would look like :
|
||||||
|
|
||||||
```
|
```graphql
|
||||||
query user(id: "5") {
|
query user(id: "5") {
|
||||||
id
|
id
|
||||||
name
|
name
|
||||||
@@ -61,7 +61,7 @@ query user(id: "5") {
|
|||||||
|
|
||||||
2. GraphQL helps building features faster. Because of the way the front-end can explicitly query the data it needs, it's not rare to not need to update the backend API. Again, using the example from earlier, if we wanted to also fetch the user friends, we could simply add it to our query:
|
2. GraphQL helps building features faster. Because of the way the front-end can explicitly query the data it needs, it's not rare to not need to update the backend API. Again, using the example from earlier, if we wanted to also fetch the user friends, we could simply add it to our query:
|
||||||
|
|
||||||
```
|
```graphql
|
||||||
query user(id: "5") {
|
query user(id: "5") {
|
||||||
name
|
name
|
||||||
posts {
|
posts {
|
||||||
@@ -85,7 +85,7 @@ GraphQL has three types of operations:
|
|||||||
|
|
||||||
Basic query:
|
Basic query:
|
||||||
|
|
||||||
```
|
```graphql
|
||||||
query User($id: ID) {
|
query User($id: ID) {
|
||||||
user {
|
user {
|
||||||
id
|
id
|
||||||
@@ -99,7 +99,7 @@ query User($id: ID) {
|
|||||||
|
|
||||||
Basic mutation:
|
Basic mutation:
|
||||||
|
|
||||||
```
|
```graphql
|
||||||
mutation CreatePost($title: String!, $content: String!, $draft: Boolean!) {
|
mutation CreatePost($title: String!, $content: String!, $draft: Boolean!) {
|
||||||
createPost(title: $title, content: $content, draft: $draft) {
|
createPost(title: $title, content: $content, draft: $draft) {
|
||||||
title
|
title
|
||||||
@@ -111,9 +111,9 @@ mutation CreatePost($title: String!, $content: String!, $draft: Boolean!) {
|
|||||||
|
|
||||||
Basic subscription:
|
Basic subscription:
|
||||||
|
|
||||||
```
|
```graphql
|
||||||
subscription OnMessageReceived($conversationId: ID!){
|
subscription OnMessageReceived($conversationId: ID!) {
|
||||||
messageReceived(conversationId: $conversationId){
|
messageReceived(conversationId: $conversationId) {
|
||||||
id
|
id
|
||||||
content
|
content
|
||||||
}
|
}
|
||||||
@@ -124,7 +124,7 @@ At its core, GraphQL consists of two parts: client, and server.
|
|||||||
|
|
||||||
A server contains a single endpoint, accepting GET and POST requests, which are translated like so:
|
A server contains a single endpoint, accepting GET and POST requests, which are translated like so:
|
||||||
|
|
||||||
```
|
```graphql
|
||||||
{
|
{
|
||||||
me {
|
me {
|
||||||
name
|
name
|
||||||
|
|||||||
@@ -123,19 +123,19 @@ If you know python, this document may be of particular interest to you: http://n
|
|||||||
|
|
||||||
Common Lisp:
|
Common Lisp:
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(print "Hello, World!")
|
(print "Hello, World!")
|
||||||
```
|
```
|
||||||
|
|
||||||
Scheme:
|
Scheme:
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(print "Hello, World!")
|
(print "Hello, World!")
|
||||||
```
|
```
|
||||||
|
|
||||||
Clojure (as a JVM program entry point):
|
Clojure (as a JVM program entry point):
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(defn -main
|
(defn -main
|
||||||
"A documentation string for my hello world function"
|
"A documentation string for my hello world function"
|
||||||
[& args]
|
[& args]
|
||||||
@@ -144,7 +144,7 @@ Clojure (as a JVM program entry point):
|
|||||||
|
|
||||||
Racket:
|
Racket:
|
||||||
|
|
||||||
```lisp
|
```clojure
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
(println "Hello, World!")
|
(println "Hello, World!")
|
||||||
@@ -152,7 +152,7 @@ Racket:
|
|||||||
|
|
||||||
ALGOL60, as implemented in Racket (to demonstrate the flexibility offered by Racket):
|
ALGOL60, as implemented in Racket (to demonstrate the flexibility offered by Racket):
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
#lang algol60
|
#lang algol60
|
||||||
|
|
||||||
begin
|
begin
|
||||||
@@ -164,7 +164,7 @@ end
|
|||||||
|
|
||||||
Common Lisp:
|
Common Lisp:
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(let ((first (block a (write-line "first number:") (read)))
|
(let ((first (block a (write-line "first number:") (read)))
|
||||||
(second (block b (write-line "second number: ") (read))))
|
(second (block b (write-line "second number: ") (read))))
|
||||||
(format t "The sum of ~A and ~A is ~D" first second (+ first second)))
|
(format t "The sum of ~A and ~A is ~D" first second (+ first second)))
|
||||||
@@ -172,7 +172,7 @@ Common Lisp:
|
|||||||
|
|
||||||
Scheme:
|
Scheme:
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(let ((first (begin (display "first number:") (read)))
|
(let ((first (begin (display "first number:") (read)))
|
||||||
(second (begin (display "second number: ") (read))))
|
(second (begin (display "second number: ") (read))))
|
||||||
(format #t "The sum of ~s and ~s is ~s" first second (+ first second)))
|
(format #t "The sum of ~s and ~s is ~s" first second (+ first second)))
|
||||||
@@ -180,7 +180,7 @@ Scheme:
|
|||||||
|
|
||||||
Clojure:
|
Clojure:
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(let [first (do (println "first number: ") (Integer/parseInt (read-line)))
|
(let [first (do (println "first number: ") (Integer/parseInt (read-line)))
|
||||||
second (do (println "second number: ") (Integer/parseInt (read-line)))]
|
second (do (println "second number: ") (Integer/parseInt (read-line)))]
|
||||||
(printf "The sum of %d and %d is %d" first second (+ first second)))
|
(printf "The sum of %d and %d is %d" first second (+ first second)))
|
||||||
@@ -188,7 +188,7 @@ Clojure:
|
|||||||
|
|
||||||
Racket:
|
Racket:
|
||||||
|
|
||||||
```lisp
|
```clojure
|
||||||
#lang racket
|
#lang racket
|
||||||
|
|
||||||
(let ((first (begin (print "first number:")(read)))
|
(let ((first (begin (print "first number:")(read)))
|
||||||
@@ -198,7 +198,7 @@ Racket:
|
|||||||
|
|
||||||
- A very basic macro in Clojure
|
- A very basic macro in Clojure
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
;; definition - we'll take an expression, evaluate it once, print the formatted string, and then return the result
|
;; definition - we'll take an expression, evaluate it once, print the formatted string, and then return the result
|
||||||
|
|
||||||
(defmacro log-call [form]
|
(defmacro log-call [form]
|
||||||
@@ -215,7 +215,7 @@ Racket:
|
|||||||
|
|
||||||
- A really simple Clojure web site using the ring and compojure libraries
|
- A really simple Clojure web site using the ring and compojure libraries
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
;; define a namespace for our functions, and import routing and default request handling functions
|
;; define a namespace for our functions, and import routing and default request handling functions
|
||||||
(ns hello-web.handler
|
(ns hello-web.handler
|
||||||
(:require [compojure.core :refer :all]
|
(:require [compojure.core :refer :all]
|
||||||
@@ -234,7 +234,7 @@ Racket:
|
|||||||
|
|
||||||
- Memoizing pure functions in Clojure
|
- Memoizing pure functions in Clojure
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(defn expensive
|
(defn expensive
|
||||||
[number]
|
[number]
|
||||||
(Thread/sleep 1000)
|
(Thread/sleep 1000)
|
||||||
@@ -257,7 +257,7 @@ Racket:
|
|||||||
|
|
||||||
- Lazy sequences in Clojure
|
- Lazy sequences in Clojure
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(defn fib-seq
|
(defn fib-seq
|
||||||
"Returns a lazy sequence of Fibonacci numbers. Copied from http://clojure-doc.org/articles/language/laziness.html"
|
"Returns a lazy sequence of Fibonacci numbers. Copied from http://clojure-doc.org/articles/language/laziness.html"
|
||||||
([]
|
([]
|
||||||
@@ -273,7 +273,7 @@ Racket:
|
|||||||
|
|
||||||
- Collatz sequence in Scheme
|
- Collatz sequence in Scheme
|
||||||
|
|
||||||
```
|
```clojure
|
||||||
(define (collatz n)
|
(define (collatz n)
|
||||||
(cond
|
(cond
|
||||||
[(equal? n 1)(format #t "1")]
|
[(equal? n 1)(format #t "1")]
|
||||||
@@ -284,7 +284,7 @@ Racket:
|
|||||||
|
|
||||||
- FizzBuzz from 1 to n using lazy evaluation in Racket
|
- FizzBuzz from 1 to n using lazy evaluation in Racket
|
||||||
|
|
||||||
```lisp
|
```clojure
|
||||||
#lang lazy
|
#lang lazy
|
||||||
|
|
||||||
(define fizzes (cycle "" "" "Fizz"))
|
(define fizzes (cycle "" "" "Fizz"))
|
||||||
|
|||||||
Reference in New Issue
Block a user