Skip to content

Instantly share code, notes, and snippets.

View narenaryan's full-sized avatar
🏠
Dreaming Big

N3N narenaryan

🏠
Dreaming Big
View GitHub Profile
package main
import (
"bytes"
"fmt"
)
func main() {
// Empty buffer (implements io.Writer)
var b bytes.Buffer
package main
import (
"fmt"
"os"
)
func main() {
fmt.Fprintln(os.Stdout, "Hello Medium")
}
package main
import "fmt"
func main() {
fmt.Println("Hello Medium")
}
# Example to use Docker instead of containerd & nerdctl
# $ limactl start ./docker.yaml
# $ limactl shell docker docker run -it -v $HOME:$HOME --rm alpine
# To run `docker` on the host (assumes docker-cli is installed):
# $ export DOCKER_HOST=$(limactl list docker --format 'unix://{{.Dir}}/sock/docker.sock')
# $ docker ...
# This example requires Lima v0.8.0 or later
images:
import asyncio
import random
# A co-routine
async def add(x: int, y: int):
# function can do work between 1 second to 5 seconds
await asyncio.sleep(random.randrange(1, 5))
return x + y
# Create a function to schedule co-routines on the event loop
import asyncio
# A co-routine
async def add(x: int, y: int):
return x + y
# Create a function to schedule co-routines on the event loop
# then print results
async def get_results():
inputs = [(2,3), (4,5), (5,5), (7,2)]
import asyncio
# A co-routine
async def add(x: int, y: int):
return x + y
# Create a function to schedule tasks on the event loop
# then print results
async def get_results():
inputs = [(2,3), (4,5), (5,5), (7,2)]
import asyncio
# A co-routine
async def add(x: int, y: int):
return x + y
# Create a function to schedule co-routines on the event loop
# then print results
async def get_results():
inputs = [(2,3), (4,5), (5,5), (7,2)]
import asyncio
# A fast co-routine
async def add_fast(x, y):
print("starting fast add")
await asyncio.sleep(3) # Mimic some network delay
print("result ready for fast add")
return x + y
# A slow co-routine
import asyncio
# A co-routine
async def add(x: int, y: int):
return x + y
# Create a function to schedule co-routines on the event loop
# then print results and stop the loop
async def get_results():
result1 = await add(3, 4)