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 / 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 {
@Reine0017
Reine0017 / confetti-button.js
Created April 9, 2022 05:06
confetti-button.js
const createConfetti = () => {
const confettiBtn = document.querySelector(".confettiButton")
const words = document.querySelector("p")
if(words){
confettiBtn.textContent = "Click me for confetti!"
confettiBtn.style.backgroundColor = "aquamarine"
words.remove()
return
}
const para = document.createElement('p');
@Reine0017
Reine0017 / confetti-button.html
Created April 9, 2022 04:54
HTML of the confetti-button
<!DOCTYPE html>
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>JavaScript Confetti Example</title>
<link rel="stylesheet" href="styles.css">
<script src="confetti-button.js" defer></script> <!--Executes last because of the defer-->
<script src="https://cdn.jsdelivr.net/npm/js-confetti@latest/dist/js-confetti.browser.js"></script> <!--Executes first-->
</head>