GithubHelp home page GithubHelp logo

ramsayleung / blog Goto Github PK

View Code? Open in Web Editor NEW
148.0 6.0 15.0 35.19 MB

A clean, elegant blog built on Rust

Home Page: https://web.archive.org/web/20220818011125/http://0x709394.me/

Rust 21.55% CSS 25.31% JavaScript 46.97% Dockerfile 0.24% PLpgSQL 0.62% Less 5.31%

blog's Introduction

*Attention*: Because Rocket is sensitive with compiler and it highly depends on lately nightly compiler, so it’s so easy to fail when compiling this project.

Update(2021-06-10): Since Rocket can compile on stable Rust with v0.5, this project leveraging on Rocket's features can also compile on stable Rust now. Cheers!

About

This is my personal blog, and its also my first Rust project.

Why Rust

Well, I know there are a lot of alternatives to writing a blog, but I find other languages such as Java, Python, Javascript,Php, are not fancy enough ;-) Kidding, the truth is that I have learned Rust for more that a half years, but I still could not build real some stuff on Rust. Yes, I lack of idea or I not am skillful enough to fulfill my thought. Finally, I decided to rewrite my blog which was built on Github Page and Org-mode.

Getting Started

Requirement

Rust

Install Rust via shell script

curl https://sh.rustup.rs -sSf | sh

After installing, you might need to

source $HOME/.cargo/env

Because this project is built on Rocket, and Rocket depends on Rust nightly, so you need change Rust environment to nightly

rustup default stable

Diesel Cli

This project use Diesel as Orm framework, so you need to install its command line tool via Rust package manager(eg, Cargo)

cargo install diesel_cli --no-default-features --features postgres

Postgresql

you need to install Postgresql database, and then configure postgresql by following document’s guide

Init database

After everything is done, it is time to create table in database for this project, just run

diesel migration run

Set up envirnment variables

In the last step, you need to create a file named .env in the root of your repository, set up the following envirnment variables, for examples:

DATABASE_URL=postgres://postgres:postgres@localhost/blog
STACKOVERFLOW_URL=https://stackoverflow.com/users/5738112/samray
GITHUB_URL=https://github.com/ramsayleung/
ERROR_LOG_PATH=/tmp/common-error.log
APP_LOG_PATH=/tmp/app-default.log
[email protected]
SLOGAN="Ramsay's Utopia"
SUB_SLOGAN="fn<T:time+joy>(resource: T)-> Ramsay's Blog"
DB_NAME=blog
DB_USER=username
DB_PASSWORD=passwd

Launch Rocket

Everything is ok, now, launch Rocket:

cargo run

And open your favourite browser, enter localhost:1337

If you want to login admin page, you could enter localhost:1337/admin/login Email: admin Password: 123456

Todo List

  • refactor admin page, it is unacceptedly ugly.

Screenshot

About Page

./images/about.png

Index Page

./images/index.png

blog's People

Contributors

dependabot-preview[bot] avatar dependabot[bot] avatar ramsayleung avatar xwjdsh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

blog's Issues

关于《一条经典面试题引发的思考》的一个问题

您好,我阅读了您的文章《一条经典面试题引发的思考》之后对一些地方有异议,由于没在博客中找到评论的地方,所以冒昧将问题写在了这里,打扰之处,还请谅解。

问题描述

请问 第23行,在 continue 之前是否需要先执行 Unlock 操作。否则可能出现锁资源未释放的情况。

具体分析如下,我们将i的上限从30改成3,这样相当于希望每个线程只执行一次有效操作。

假设有这样的情况,线程 B 执行一次后,线程 C 正在上锁,此时i的值还没改变,线程 B判断i < 3继续循环。线程 C 执行成功后,线程 B加锁成功。此时i变成了3,线程 B 判断i >= 3,结束循环,线程 B 就有了一个加锁的锁资源未释放。

     1  public void Test(){
     2      private static Integer index = 0;
     3      Lock lock = new ReentrantLock(true);
     4      @Test
     5      public void testLock(){
     6              Thread threadA = work(() -> System.out.println("A"));
     7              Thread threadB = work(() -> System.out.println("B"));
     8              Thread threadC = work(() -> System.out.println("C"));
     9              threadA.setName("threadA");
    10              threadA.start();
    11              threadB.setName("threadB");
    12              threadB.start();
    13              threadC.setName("threadC");
    14              threadC.start();
    15              System.out.println();
    16      }
    17
    18      private Thread work(Runnable function) {
    19              return new Thread(() -> {
    20                  while (index.intValue() < 3) {
    21                  lock.lock();
    22                  if (index >= 3) {
    23                      // lock.unlock();
    24                      continue;
    25                  }
    26                  if (condition.test(index.intValue())) {
    27                      function.run();
    28                      index++;
    29                  }
    30                  lock.unlock();
    31                  }
    32              });
    33      }
    34  }

Readme initial login username and password

Hi Ramsay,
The initial login username and password seems not working at the moment. May I ask where can I find the correct one?
BTW, I guess the server port has been changed to 1337.
Thank you.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.