Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

update #342

Open
wants to merge 6 commits into
base: python
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ out/
.classpath
.factorypath
*newman/
.vscode/
15 changes: 9 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<p align="center">
<img src="http://nano.sahaj.ai/logo.png" width="320" height="162" altText="Logo" title="NaN(O) logo">
<p align="center">
<img src="http://nano.sahaj.ai/27ad2091b1714f583886.png" width="320" height="162" alt="Logo" title="NaN(O) logo">
</p>

## What is NaN(O)

At Sahaj, tech consultants operate at the intersection between engineering and art. Simply put, they are artisans who take on complex engineering problems in the software industry across a wide spectrum of domains. Their work is deeply rooted in first principles thinking - asking fundamental questions to dissect and understand a problem which eventually leads to one-of-a-kind solutions, each as distinct as a fingerprint.

Through NaN(O), a hackathon driven by Sahaj across multiple colleges in India, they want to instill a culture of applying first principles thinking to a problem statement.
Through NaN(O), a coding event driven by Sahaj across multiple colleges in India, they want to instil a culture of applying first principles thinking to a problem statement.

------

Expand Down Expand Up @@ -71,14 +71,17 @@ Content-Type: application/json
In order to submit a solution, follow these steps.

- Fork the **nano-demo-calculator-app** repository ([How to fork a repository github](https://docs.github.com/en/get-started/quickstart/fork-a-repo))
- Deselect the "Copy the main branch only" to copy other language demos as well
- Clone the forked repository ([How to clone a repository github](https://docs.github.com/en/repositories/creating-and-managing-repositories/cloning-a-repository))
- Change the branch according to the language of your choice (This demo is available in (language-> branch) "kotlin"-> main, "node" -> "node", "python" -> "python", "cpp" -> "cpp" ) ([How to change branches git ](https://www.freecodecamp.org/news/git-switch-branch/))
- Enable workflows in your github fork (Under the actions tab -> Select "I understand my workflows, go ahead and enable them" to enable the test workflow)
- Use your favourite editor to make changes
- Create a commit after testing it locally ([How to commit git](https://github.com/git-guides/git-commit))
- Push the commit to the remote (github repo) ([How to push git](https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository))
- If all your changes work well, you will see a green tick on the actions section on your repo ([How to see last run action](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/viewing-workflow-run-history))
- Push the commit to the remote **to the same branch** (github repo) ([How to push git](https://docs.github.com/en/get-started/using-git/pushing-commits-to-a-remote-repository))
- If all your changes work well, you will see a green tick on the actions section on your repo under the selected branch ([How to see last run action](https://docs.github.com/en/actions/monitoring-and-troubleshooting-workflows/viewing-workflow-run-history))
- If it's a cross mark, the logs will tell you what you did wrong.
- Fix the issue, and repeat steps 4+ to resubmit
- Congratulations, you have successfully solved the dummy problem and are ready for the actual hackathon.
- Congratulations, you have successfully solved the dummy problem and are ready for the actual event.


###### Hint
Expand Down
7 changes: 7 additions & 0 deletions bin/main/application.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
micronaut:
application:
name: nanoDemoCalculatorApp
netty:
default:
allocator:
max-order: 3
7 changes: 7 additions & 0 deletions bin/main/com/nano/Application.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.nano

import io.micronaut.runtime.Micronaut.run
fun main(args: Array<String>) {
run(*args)
}

28 changes: 28 additions & 0 deletions bin/main/com/nano/MathController.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.nano

import io.micronaut.http.HttpResponse
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.annotation.Post
import io.micronaut.validation.Validated

@Controller("/calculator")
@Validated
class MathController {

@Get("/greeting")
fun greeting(): HttpResponse<String> {
return HttpResponse.ok("")
}

@Post("/add", produces = [MediaType.APPLICATION_JSON])
fun add(): HttpResponse<String> {
return HttpResponse.ok("")
}

@Post("/subtract", produces = [MediaType.APPLICATION_JSON])
fun subtract(): HttpResponse<String> {
return HttpResponse.ok("")
}
}
8 changes: 8 additions & 0 deletions bin/main/com/nano/Numbers.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.nano

import javax.validation.constraints.NotNull

data class Numbers(
@field:NotNull val first: Int,
@field:NotNull val second: Int
)
15 changes: 15 additions & 0 deletions bin/main/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<configuration>

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%cyan(%d{HH:mm:ss.SSS}) %gray([%thread]) %highlight(%-5level) %magenta(%logger{36}) - %msg%n</pattern>
</encoder>
</appender>

<root level="info">
<appender-ref ref="STDOUT" />
</root>
</configuration>
19 changes: 19 additions & 0 deletions bin/test/com/nano/DemoCalculatorAppTest.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.nano
import io.micronaut.runtime.EmbeddedApplication
import io.micronaut.test.extensions.junit5.annotation.MicronautTest
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import jakarta.inject.Inject

@MicronautTest
class DemoCalculatorAppTest {

@Inject
lateinit var application: EmbeddedApplication<*>

@Test
fun testItWorks() {
Assertions.assertTrue(application.isRunning)
}

}
27 changes: 27 additions & 0 deletions server.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from flask import Flask,request,jsonify

app = Flask(__name__)


@app.route("/calculator/greeting", methods=['GET'])
def greeting():
return 'Hello world!'

@app.route("/calculator/add", methods=['POST'])
def add():
data = request.json
first = data['first']
second = data['second']
result = first + second
return jsonify({'result': result})

@app.route("/calculator/subtract", methods=['POST'])
def subtract():
data = request.json
first = data['first']
second = data['second']
result = first - second
return jsonify({'result': result})

if _name_ == '__main__':
app.run(port=8080,host='0.0.0.0')