This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use axum::{routing::get, Json, Router}; | |
| use serde::{Deserialize, Serialize}; | |
| #[derive(Deserialize, Serialize, Debug)] | |
| struct Todo { | |
| userId: u32, | |
| id: u32, | |
| title: String, | |
| completed: bool, | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from fastapi import FastAPI, HTTPException | |
| from pydantic import BaseModel | |
| import httpx | |
| import uvicorn | |
| app = FastAPI() | |
| class Todo(BaseModel): | |
| userId: int | |
| id: int |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const express = require('express'); | |
| const app = express(); | |
| app.get('/fetch-todo', async (req, res) => { | |
| const url = 'https://jsonplaceholder.typicode.com/todos/1'; | |
| try { | |
| const response = await fetch(url); | |
| if (!response.ok) { | |
| throw new Error(`HTTP error! status: ${response.status}`); | |
| } | |
| const todo = await response.json(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //usr/bin/env jbang "$0" "$@" ; exit $? | |
| //JAVA 25 | |
| //DEPS org.springframework.boot:spring-boot-starter-web:4.1.0 | |
| //DEPS org.springframework.boot:spring-boot-starter-restclient:4.1.0 | |
| //DEPS https://github.com/scratches/spring-script | |
| import static org.springframework.web.servlet.function.RouterFunctions.route; | |
| import static org.springframework.web.servlet.function.ServerResponse.*; | |
| import org.springframework.context.annotation.Bean; | |
| import org.springframework.web.client.RestClient; | |
| import org.springframework.web.servlet.function.*; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // save to ss.java and run with: java ss.java | |
| sealed interface Loan permits SecuredLoan, UnsecuredLoan {} | |
| final class SecuredLoan implements Loan {} | |
| record UnsecuredLoan(float interest) implements Loan {} | |
| String admonition(Loan loan) { | |
| return switch (loan) { | |
| case SecuredLoan sl -> "good job. nice loan."; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package com.example.lifecycle; | |
| import org.springframework.beans.BeansException; | |
| import org.springframework.beans.factory.config.BeanFactoryPostProcessor; | |
| import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; | |
| import org.springframework.beans.factory.support.DefaultListableBeanFactory; | |
| import org.springframework.boot.ApplicationArguments; | |
| import org.springframework.boot.ApplicationRunner; | |
| import org.springframework.boot.SpringApplication; | |
| import org.springframework.boot.autoconfigure.SpringBootApplication; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data class Point(val x: Int, val y: Int) | |
| data class Rectangle(val width: Int, val height: Int) | |
| data class Circle(val radius: Int) | |
| fun describePoint(point: Point) = when (point) { | |
| Point(0, 0) -> "Origin" | |
| Point(1, 2) -> "1,2" | |
| else -> throw IllegalStateException("Unexpected value: $point") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // sdk install java 23.0.1-librca && sdk use java 23.0.1-librca | |
| // java --enable-preview Main.java | |
| record Point(int x, int y) {} | |
| sealed interface Shape permits Rectangle, Circle {} | |
| record Rectangle(int width, int height) implements Shape {} | |
| record Circle(int radius) implements Shape {} | |
| void main() { | |
| var point = new Point(1, 2); | |
| println(describePoint(point)); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package org.springframework.http.client; | |
| import org.springframework.core.task.SimpleAsyncTaskExecutor; | |
| import org.springframework.http.HttpMethod; | |
| import org.springframework.util.Assert; | |
| import java.io.IOException; | |
| import java.net.URI; | |
| import java.net.http.HttpClient; | |
| import java.time.Duration; |
NewerOlder