Skip to content

Instantly share code, notes, and snippets.

View Reine0017's full-sized avatar
❤️

Fang Ran Reine0017

❤️
View GitHub Profile
@Reine0017
Reine0017 / app.js
Created June 28, 2023 13:06
How to call callOpenAI function
app.post("/plan", function(req, res) {
let occasion = req.body.occasion;
let pax = req.body.pax;
let budget = req.body.budget;
let theme = req.body.theme;
let country = req.body.theme
const prompt = `Teach me how to plan for ${occasion}, for ${pax} people. I have a budget of ${budget} dollars. My theme is ${theme}. I am in ${country}.`
callOpenAI(prompt).then(response => {
console.log("Response", response)
@Reine0017
Reine0017 / app.js
Created June 28, 2023 13:02
callOpenAI function
async function callOpenAI(prompt) {
const url = 'https://api.openai.com/v1/chat/completions';
const headers = {
'Authorization': `Bearer ${process.env.OpenAIToken}`,
'Content-Type': 'application/json'
};
const data = {
'model': 'gpt-3.5-turbo',
'messages': [
{"role": "system", "content": "You are a helpful assistant."},
@Reine0017
Reine0017 / app.js
Created June 25, 2023 11:10
NodeJS set up - step 1
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
const port = process.env.PORT || 3000;
app.use(bodyParser.json()); // for parsing application/json
app.use(bodyParser.urlencoded({ extended: true })); // for parsing application/x-www-form-urlencoded
app.get('/', (req, res) => {
res.send('Hello, World!');
@Reine0017
Reine0017 / complexChannel.go
Created August 9, 2022 10:54
complex channel
package main
import (
"fmt"
"strings"
)
type FullName struct {
firstName string
lastName string
@Reine0017
Reine0017 / simpleChannel.go
Created August 9, 2022 10:41
simple channel
package main
import (
"fmt"
)
func NameFunc(nameChannel chan string, name string) {
finalName := "Name: " + name
nameChannel <- finalName
}
@Reine0017
Reine0017 / workingGoRoutine.go
Created August 9, 2022 10:33
Working Go Routine
package main
import (
"fmt"
"time"
)
func myFunc() {
fmt.Println("Reine")
}
@Reine0017
Reine0017 / unworkingGoRoutine.go
Last active August 9, 2022 10:14
Unworking Go Routine Example
package main
import "fmt"
func myFunc() {
fmt.Println("Reine")
}
func main() {
fmt.Println("Hello")
@Reine0017
Reine0017 / sketch.js
Last active July 13, 2022 04:37
Simple Drawing app - sketch.js (1)
window.addEventListener("load", () => {
const canvas = document.querySelector("#canvas");
const ctx = canvas.getContext('2d');
const img = new Image();
img.src = "assets/images/reinePic.jpg";
img.onload = () => {
const [img_scaled_width, img_scaled_height] = drawImageToScale(img, ctx);
canvas.width = img_scaled_width;
@Reine0017
Reine0017 / app.py
Created January 15, 2021 07:19
Your Flask Application
from flask import Flask, send_from_directory
from flask_restful import Api, Resource, reqparse
from flask_cors import CORS #comment this on deployment
from api.HelloApiHandler import HelloApiHandler
app = Flask(__name__, static_url_path='', static_folder='frontend/build')
CORS(app) #comment this on deployment
api = Api(app)
@app.route("/", defaults={'path':''})
@Reine0017
Reine0017 / styles.css
Created April 9, 2022 05:45
css of confetti-button
html {
font-family: sans-serif;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.confettiButton {