Skip to content

Commit

Permalink
Merge pull request #5 from RiwEZ/dev
Browse files Browse the repository at this point in the history
feat: add backup script, add plausible, change how we load fonts
  • Loading branch information
RiwEZ authored Jun 12, 2024
2 parents 97c0c4f + 99cd79f commit 63e2605
Show file tree
Hide file tree
Showing 6 changed files with 180 additions and 16 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ pnpm-debug.log*

# macOS-specific files
.DS_Store

# backup medias
scripts/backup/*medias
3 changes: 3 additions & 0 deletions scripts/backup/go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/RiwEz/TanatBlog/backup

go 1.22.1
148 changes: 148 additions & 0 deletions scripts/backup/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
package main

import (
"errors"
"fmt"
"io"
"net/http"
"os"
"regexp"
"strings"
"time"
)

type Pair[T, U any] struct {
Fst T
Snd U
}

type Media = Pair[string, []byte]

func GetFileName(url string) (string, error) {
for i := len(url) - 1; i >= 0; i-- {
if url[i] == '/' {
return url[i+1:], nil
}
}

return "", errors.New("The URL is not valid")
}

func FindUrls(content []byte, pattern string) []string {
urls := []string{}

r, err := regexp.Compile(pattern)
if err != nil {
panic(err)
}
for _, match := range r.FindAllSubmatch(content, -1) {
// we have only one capture group, get it at index 1
urls = append(urls, string(match[1]))
}

return urls
}

func GetMediasUrl(content []byte) []string {
urls := []string{}

urls = append(urls, FindUrls(content, `<img\s+[^>]*src="([^"]+)"`)...)
urls = append(urls, FindUrls(content, `<source\s+[^>]*src="([^"]+)"`)...)
urls = append(urls, FindUrls(content, `!\[.*?\]\(([^\)]+)`)...)

return urls
}

func DownloadMedias(urls []string) ([]Media, error) {
results := []Pair[string, []byte]{}
client := &http.Client{}

for _, url := range urls {
filename, err := GetFileName(url)
if err != nil {
return nil, err
}

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, err
}
req.Header.Set("Connection", "keep-alive")
req.Header.Set("User-Agent", "TanatBlog/0.0.1")

resp, err := client.Do(req)
if err != nil {
return nil, err
}

bytes, err := io.ReadAll(resp.Body)
if err != nil {
return nil, err
}
results = append(results, Media{filename, bytes})

// sleep for 100 ms, if we recently used imgur
if strings.Contains(url, "imgur") {
time.Sleep(100 * time.Millisecond)
}
}

return results, nil
}

func WriteMedias(dir string, medias []Media) error {
if _, err := os.Stat(dir); err != nil {
if os.IsNotExist(err) {
err := os.MkdirAll(dir, 0777)
if err != nil {
return err
}
} else {
return err
}
}

for _, v := range medias {
err := os.WriteFile(dir+v.Fst, v.Snd, 0666)
if err != nil {
return err
}
}
return nil
}

func main() {
blogsPath := "../../src/content/blog/"

dir, err := os.Open(blogsPath)
if err != nil {
panic(err)
}
files, err := dir.Readdirnames(-1)
if err != nil {
panic(err)
}

currTime := time.Now().Format("2006-01-02T15:04:05")
backupsPath := currTime + "-medias/"
for _, file := range files {
fmt.Printf("backuping for" + file + ": ")

content, err := os.ReadFile(blogsPath + file)
if err != nil {
fmt.Println(err)
}

urls := GetMediasUrl(content)
medias, err := DownloadMedias(urls)
if err != nil {
fmt.Println(err)
}
err = WriteMedias(backupsPath+file+"/", medias)
if err != nil {
fmt.Println(err)
}

fmt.Printf("success\n")
}
}
28 changes: 14 additions & 14 deletions src/content/blog/fuzzy.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ are vauge and lack certainty.

We think that Fuzzy Logic can help improving technical indicator usage.
<figure>
<img src="https://imgur.com/XeQJjYB.png" loading="lazy" />
<img src="https://i.imgur.com/XeQJjYB.png" loading="lazy" />
<figcaption>
<center>
Simple example of Fuzzy Logic used with RSI
Expand Down Expand Up @@ -77,7 +77,7 @@ from my friend (yes, it's in Thai). Right now, I'm currently not hosting the web
not visit it.

<figure>
<img src="https://imgur.com/puSZftM.png" loading="lazy" />
<img src="https://i.imgur.com/puSZftM.png" loading="lazy" />
<figcaption>
<center>
Architecture Overview
Expand Down Expand Up @@ -172,7 +172,7 @@ We can think of linguistic variable as a collection of fuzzy sets with the same
to describe fuzzy system inputs and outputs.

<figure>
<img src="https://imgur.com/XgIAwAN.png" loading="lazy" />
<img src="https://i.imgur.com/XgIAwAN.png" loading="lazy" />
<figcaption>
<center>
Linguistic Variable Example
Expand Down Expand Up @@ -283,7 +283,7 @@ The idea is TradingView already has a good API interface for creating varios tec
PineScript, we can actually just copy the API interface and implemented its logic ourself.

<figure>
<img src="https://imgur.com/c253FWe.png" loading="lazy" />
<img src="https://i.imgur.com/c253FWe.png" loading="lazy" />
<figcaption>
<center>
Technical Indicator Example (RSI)
Expand Down Expand Up @@ -344,7 +344,7 @@ happen in so many more places in our code.

#### Web Server
<figure>
<img src="https://imgur.com/WNpAb5R.png" loading="lazy" />
<img src="https://i.imgur.com/WNpAb5R.png" loading="lazy" />
<figcaption>
<center>
Overview of how each thread work together.
Expand Down Expand Up @@ -602,7 +602,7 @@ gain more profit while having low drawdown. Actually, we could change the object
it better in other aspects but this idea should be in further development.

<figure>
<img src="https://imgur.com/dOmQy57.png" loading="lazy" />
<img src="https://i.imgur.com/dOmQy57.png" loading="lazy" />
<figcaption>
<center>Parameters of the linguistic variable that we will tune via PSO (a, b, c)</center>
</figcaption>
Expand Down Expand Up @@ -652,7 +652,7 @@ I didn't talk about. If you want to, you can checkout the code at

### Frontend
<figure>
<img src="https://imgur.com/6aukWw6.png" loading="lazy" />
<img src="https://i.imgur.com/6aukWw6.png" loading="lazy" />
<figcaption>
<center>One page of our website with candlestick graph of the market and our fuzzy technical indicator.</center>
</figcaption>
Expand Down Expand Up @@ -710,7 +710,7 @@ UI/UX thing. If you are interested, you can check out our [frontend repoitory](h

## Experiments & Results
<figure>
<img src="https://imgur.com/0HBlxHW.png" loading="lazy" />
<img src="https://i.imgur.com/0HBlxHW.png" loading="lazy" />
<figcaption>
<center>Variations of indicators we used.</center>
</figcaption>
Expand Down Expand Up @@ -751,21 +751,21 @@ I'll omit the details about the linguistic variables and fuzzy rules of fuzzy va
idea is simple, it's very similar to classical one but we are using fuzzy sets instead.

<figure>
<img src="https://imgur.com/5oml3PT.png" loading="lazy" />
<img src="https://i.imgur.com/5oml3PT.png" loading="lazy" />
<figcaption>
<center>AROON-MACD backtesting result on BTC, ETH, BNB while market is in uptrend.</center>
</figcaption>
</figure>

<figure>
<img src="https://imgur.com/K0Utm1u.png" loading="lazy" />
<img src="https://i.imgur.com/K0Utm1u.png" loading="lazy" />
<figcaption>
<center>AROON-MACD backtest result on ETH while market is in downtrend.</center>
</figcaption>
</figure>

<figure>
<img src="https://imgur.com/JTHhxbE.png" loading="lazy" />
<img src="https://i.imgur.com/JTHhxbE.png" loading="lazy" />
<figcaption>
<center>AROON-MACD backtest result on ETH while market is in sideway.</center>
</figcaption>
Expand All @@ -786,21 +786,21 @@ I'll omit the details about the linguistic variables and fuzzy rules of fuzzy va
the same reason on AROON-MACD too.

<figure>
<img src="https://imgur.com/yu9KwuL.png" loading="lazy" />
<img src="https://i.imgur.com/yu9KwuL.png" loading="lazy" />
<figcaption>
<center>RSI-BB backtesting result on BTC, ETH, BNB while market is in uptrend.</center>
</figcaption>
</figure>

<figure>
<img src="https://imgur.com/JKAmbae.png" loading="lazy" />
<img src="https://i.imgur.com/JKAmbae.png" loading="lazy" />
<figcaption>
<center>RSI-BB backtest result on ETH while market is in downtrend.</center>
</figcaption>
</figure>

<figure>
<img src="https://imgur.com/S0My2yz.png" loading="lazy" />
<img src="https://i.imgur.com/S0My2yz.png" loading="lazy" />
<figcaption>
<center>RSI-BB backtest result on ETH while market is in sideway.</center>
</figcaption>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ And the works I do are mainly

### The new technology that I learned

![tech](https://imgur.com/CeBkIAn.png)
![tech](https://i.imgur.com/CeBkIAn.png)

I have little experience writing a backend in JS/TS (express 🤣) and I still
don't think it's a good choice to write backend in JS/TS because we don't have
Expand Down
12 changes: 11 additions & 1 deletion src/layouts/MainLayout.astro
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,18 @@ const { title, description } = Astro.props;
<meta name="title" content={title} />
<meta name="description" content={description} />

<script
defer
data-domain="riwez.github.io"
src="http://tanatriw.totddns.com:57201/js/script.js"></script>

<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:slnt,wght@-10..0,100..900&display=swap"
rel="stylesheet"
/>
<style>
@import url("https://rsms.me/inter/inter.css");
html,
body {
background-color: #151719;
Expand Down

0 comments on commit 63e2605

Please sign in to comment.