Skip to content

Instantly share code, notes, and snippets.

View naxty's full-sized avatar

naxty

  • oxolo
  • Karlsruhe, Germany
View GitHub Profile
@naxty
naxty / fastapi_async_httpx_blog.py
Last active October 9, 2023 18:00
This code showcases integration with popular public APIs like JSONPlaceholder and REST Countries, demonstrating efficient data fetching using asynchronous HTTP requests by using the httpx framework in combination with fastapi.
# pip install fastapi uvicorn httpx
import asyncio
import httpx
from fastapi import FastAPI
app = FastAPI()
async def fetch_data(url: str):
@naxty
naxty / xss-alert.js
Last active November 6, 2022 20:07
xss-alert.js
<script>
const message = function() {
console.log("This message is shown after 3 seconds");
alert(1);
}
setTimeout(message, 3000);
</script>
type Category = {
name: string
tags: string[]
}
type Product = {
name: string
description: string
}
let products: Array<Product> =[
@naxty
naxty / sort.ts
Created August 8, 2020 19:47
Generic function to sort array with objects in TypeScript alphabetically.
const sort = <Element extends {name: string}>(array: Array<Element>) => {
return array.sort((a: Element, b: Element) => {
if (a.name < b.name){
return -1;
}
if (a.name > b.name){
return 1;
}
return 0;
})
@naxty
naxty / sortCategories.ts
Created August 8, 2020 19:45
Sort array of objects alphabetically in TypeScript
type Category = {
name: string
}
const categories:Array<Category> = [
{
name: "Travel"
},
{
name: "Electronics"
@naxty
naxty / cortex.yaml
Last active October 7, 2019 15:33
Cortex YAML for boston housing model
- kind: deployment
name: boston-housing
- kind: api
name: linear-regression
model: s3://cortex-07af1aa182/boston_housing/linear_regression.onnx
request_handler: boston_handler.py
@naxty
naxty / boston_handler.py
Created October 4, 2019 10:13
Boston features handler for cortex
from pydantic import BaseModel
import numpy as np
class HousingFeatures(BaseModel):
CRIM: float
ZN: float
INDUS: float
CHAS: float
@naxty
naxty / cortex_install.sh
Created October 4, 2019 10:03
Shell script to install cortex 0.8
# Download
curl -O https://raw.githubusercontent.com/cortexlabs/cortex/0.8/cortex.sh
# Change permissions
chmod +x cortex.sh
# Install the Cortex CLI on your machine
./cortex.sh install cli
# Set AWS credentials
export AWS_ACCESS_KEY_ID=***
export AWS_SECRET_ACCESS_KEY=***
# Configure AWS instance settings (at least 4GB memory)
@naxty
naxty / emotion_service_deployment.json
Created September 9, 2019 06:08
K8 template seldon core
{
"apiVersion": "machinelearning.seldon.io/v1alpha2",
"kind": "SeldonDeployment",
"metadata": {
"labels": {
"app": "seldon"
},
"name": "seldon-emotion"
},
"spec": {
@naxty
naxty / rest_client.py
Created September 9, 2019 06:06
REST Client for local seldon core docker container
from PIL import Image
import numpy as np
import requests
path_to_image = "images/smile.jpg"
image = Image.open(path_to_image).convert('L')
resized = image.resize((64, 64))
values = np.array(resized).reshape(1, 1, 64, 64)
req = requests.post("http://localhost:5000/predict", json={"data":{"ndarray": values.tolist()}})