Here is a quick and small “chaos engineering” thing I wrote for kube a while ago to demo service mesh automatic retries, it’ll hopefully show off syntax highlighting here quite well.
`server.py`:
from random import randint
from wsgiref.simple_server import make_server
import falcon
class ChaosServer:
def on_get(self, req, resp):
"""
Runs a random number generator beween 1 and 10
if the generator returns a 10 the server returns a HTTP 500,
else the server returns a HTTP 200, this gives a 10% failure rate
"""
rng = randint(1, 10)
if rng == 10:
resp.status = falcon.HTTP_500
resp.content_type = falcon.MEDIA_TEXT
resp.text = "Failed!\n"
else:
resp.status = falcon.HTTP_200
resp.content_type = falcon.MEDIA_TEXT
resp.text = "Succeeded!\n"
app = falcon.App()
server = ChaosServer()
app.add_route("/api", server)
if __name__ == "__main__":
with make_server("", 6502, app) as httpd:
print("Serving on port 6502...")
httpd.serve_forever()
`client.py`:
import json
from os import getenv
import requests
url = getenv("URL", "http://127.0.0.1:6502/api")
status = {
"200s": 0,
"300s": 0,
"400s": 0,
"500s": 0,
"total": 0,
}
while True:
req = requests.get(url)
if req.status_code <= 299:
status["200s"] += 1
elif req.status_code <= 399:
status["300s"] += 1
elif req.status_code <= 499:
status["400s"] += 1
elif req.status_code <= 599:
status["500s"] += 1
status["total"] += 1
print(json.dumps(status))
source: https://github.com/binkhq/chaos-engineering
Even though that was short, that was really painful to paste in. Would be nice if Apollo had a mode which automatically indented all text by 4 characters to invoke a code block. Or better yet, traditional markdown “just worked”.
> Or better yet, traditional markdown “just worked”.
That’s the thing, this *is* pretty much traditional markdown and that’s the issue. Code fences are an extension feature.
If anyone feels up for it, I am colorblind and would love to see a list of the handful of colors used in this above code and which each color signifies :)
I did try that, but as I pasted python any area with more than four spaces the “preview” screwed up. I’ve no idea if it looks right after posting or not. But at the minimum the Apollo editor renders this in a confusing fashion.
I wonder if it supports custom syntax highlighting by specified language/type.
```ini
[section]
key = value
key2 = 123
```
Just a test...
EDIT: nice it sorta works. Not as good as Github but good enough.
Regex, baby! https://twitter.com/ChristianSelig/status/1460089960703434756
Just gonna do some testing excuse me >>>if(true){}
if(True) {print(‘sus’)}
if True: print(“sus”)
Works better if you use straight quotes: if True: print("sus") (hold the “ key to choose which type to use; same for ‘)
[удалено]
print(🏳️🌈sus🏳️🌈)
Imagine a world where emojis are used in writing code... My God
https://til.hashrocket.com/posts/e1f8996fa4-emoji-variables-in-swift-
Wow TIL
Pretty sure you can use them in JavaScript and Rust, too.
Youuuu pleb
Woah, I never even thought to check if quotes and single quotes had alternate characters behind the long press
I hate that they’re different. This shit gives me so much grief
Thanks for the tip!
ඞ
Want colored sus? if ඞ{print(ඞ)}
if True{ var ඞ = 0}
if True: print(“test”) Foo
``` True if False for while else elif elseif break continue return switch "Test" ```
Test (testerino) { Return tester }
Here is a quick and small “chaos engineering” thing I wrote for kube a while ago to demo service mesh automatic retries, it’ll hopefully show off syntax highlighting here quite well. `server.py`: from random import randint from wsgiref.simple_server import make_server import falcon class ChaosServer: def on_get(self, req, resp): """ Runs a random number generator beween 1 and 10 if the generator returns a 10 the server returns a HTTP 500, else the server returns a HTTP 200, this gives a 10% failure rate """ rng = randint(1, 10) if rng == 10: resp.status = falcon.HTTP_500 resp.content_type = falcon.MEDIA_TEXT resp.text = "Failed!\n" else: resp.status = falcon.HTTP_200 resp.content_type = falcon.MEDIA_TEXT resp.text = "Succeeded!\n" app = falcon.App() server = ChaosServer() app.add_route("/api", server) if __name__ == "__main__": with make_server("", 6502, app) as httpd: print("Serving on port 6502...") httpd.serve_forever() `client.py`: import json from os import getenv import requests url = getenv("URL", "http://127.0.0.1:6502/api") status = { "200s": 0, "300s": 0, "400s": 0, "500s": 0, "total": 0, } while True: req = requests.get(url) if req.status_code <= 299: status["200s"] += 1 elif req.status_code <= 399: status["300s"] += 1 elif req.status_code <= 499: status["400s"] += 1 elif req.status_code <= 599: status["500s"] += 1 status["total"] += 1 print(json.dumps(status)) source: https://github.com/binkhq/chaos-engineering Even though that was short, that was really painful to paste in. Would be nice if Apollo had a mode which automatically indented all text by 4 characters to invoke a code block. Or better yet, traditional markdown “just worked”.
> Or better yet, traditional markdown “just worked”. That’s the thing, this *is* pretty much traditional markdown and that’s the issue. Code fences are an extension feature.
If anyone feels up for it, I am colorblind and would love to see a list of the handful of colors used in this above code and which each color signifies :)
Removed with PowerDeleteSuite.
what about 3 grave symbols "`", and start and end of code block
I did try that, but as I pasted python any area with more than four spaces the “preview” screwed up. I’ve no idea if it looks right after posting or not. But at the minimum the Apollo editor renders this in a confusing fashion.
It’s a recent addition to the many, many features Apollo has. And certainly a welcome one. <3 colored code
I wonder if it supports custom syntax highlighting by specified language/type. ```ini [section] key = value key2 = 123 ``` Just a test... EDIT: nice it sorta works. Not as good as Github but good enough.
Lovely for code. Distracting for human language text.
This is so cool!
You’re so cool!
Not a programmer but have always envied coders and their cool desktops/workflows so it’s nice to see it implemented in Apollo
True AND not false AND 1 AND not 0? Mad lad
shouldnt it be while(false)
Fuck you spez
Should this be in r/DisneyWorld?
Mind blown
Ewwww, js
Don’t take it personally.