Finished blogs

This commit is contained in:
Nicholas Orlowsky 2022-07-06 01:05:31 -05:00
parent 42c4281276
commit af69ba98ba
No known key found for this signature in database
GPG key ID: 3845F78A73B14100
18 changed files with 311 additions and 19 deletions

32
src/static/data/Blogs.ts Normal file
View file

@ -0,0 +1,32 @@
import VrboImage from "../images/vrbo-logo-min.png";
import Blog from "../../types/Blog";
import CSMD from "./blogs/c-sharp-c-assignment.md";
import TAB from "./blogs/there-is-a-blog.md";
const CSharpBlog: Blog = {
title: "Doing C assignments in C#",
date: new Date(2022, 2, 18, 14, 15, 0),
image: VrboImage,
mdfile: CSMD,
private: false
}
const TestBlog: Blog = {
title: "There's a Blog!",
date: new Date(),
image: VrboImage,
mdfile: TAB,
private: false
}
const PrivateBlog: Blog = {
title: "This blog can only be accessed via the direct URI",
date: new Date(),
image: VrboImage,
mdfile: TAB,
private: true
}
export const AllBlogs: Blog[] = [CSharpBlog, PrivateBlog, TestBlog];

View file

@ -4,7 +4,7 @@ const RunningHobby: InfoCardProps = {
title: "Running",
description: "I started running cross country in 7th grade after wanting to beat my friend in the mile. I kept running all the way through to my senior year of high school. I made varsity my sophomore year. Today, I just run with friends casually along with other physical activity like lifting, biking, and kayaking.",
listTitle: "Personal Records",
list:["1600 - 4:34", "3200 - 10:11", "5K XC - 16:42"],
list:["1600 - 4:34", "3200 - 10:11", "5K XC - 16:43"],
link: "https://tx.milesplit.com/athletes/7325388-nicholas-orlowsky/stats",
linkTitle: "Milesplit Profile",
listClassName: "col-12"
@ -14,7 +14,7 @@ const Lifting: InfoCardProps = {
title: "Lifting",
description: "Once I was done with cross country, I was so used to working out everyday, I just couldn't stop. I started lifting as a break from my 6 years and 10,000 miles of running and really really liked it.",
listTitle: "Personal Records",
list:["Bench - 235lbs", "Squat - 345lbs", "Deadlift - 345lbs (I think)"],
list:["Bench - 255lbs (Done at the Home Depot's HQ in Atlanta, GA)", "Squat - 345lbs", "Deadlift - 345lbs"],
listClassName: "col-12"
}

View file

@ -1,4 +1,3 @@
# Doing C assignments in C#
Thanks to Arpan Dhatt for doing most of the work on this (his blog here: [https://arpan.one/posts/messing-with-gradescope/](https://arpan.one/posts/messing-with-gradescope/))
@ -11,25 +10,18 @@ This makes running assignments in a docker container where the runtime is not al
The better solution is to use .NET's (experimental) AOT compilation feature (formerly called CoreRT). C# has had a number of attempts at an AOT compiler such as :
- List
- LLD2CPP built by Unity
- [AOT](https://www.mono-project.com/docs/advanced/aot/) by Mono
- LLD2CPP built by Unity
- [Ready2Run](https://docs.microsoft.com/en-us/dotnet/core/deploying/ready-to-run) by Microsoft
We'll be using the official AOT compilation built by Microsoft. In order to use it, all you have to do is add the following to your `nuget.config`:
```xaml
We'll be using the official Ready2Run AOT compilation built by Microsoft. In order to use it, all you have to do is add the following to your `nuget.config`:
```xml
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
```
and then install the package: `Microsoft.DotNet.ILCompiler`. After doing that if you run the command: `dotnet publish -r [Runtime] -c [Config]` and after waiting a considerable amount of time, you'll have a full-fledged C# application compiled directly to your target runtime's bytecode!
Compiling my simple Hello, Wold test to linux-x64 (`dotnet publish -r linux-x64 -c Release`) and adding it to my project files should let me run it using the same method Arpan used in his blog.
But running that command gives this beautiful error:
`Cross-OS native compilation is not supported. https://github.com/dotnet/corert/issues/5458 [.../CSharpAOTCompilation/CSharpAOTCompilation/CSharpAOTCompilation.csproj]`
This (unfortunately) means that I need to either find a Linux machine to run this on or spin up a docker container to compile it for me. Luckily, I'm pretty good with docker and was able to spin this Dockerfile up relatively quickly that allows for this compilation:
```dockerfile
```
After doing that, we can follow the instructions followed by Arpan and viola! C# runs on Gradescope!
I don't recommend this but it was fun to do and I needed stuff to write in a blog.
@ -39,7 +31,7 @@ I don't recommend this but it was fun to do and I needed stuff to write in a blo
C# actually has many lower level features people don't expect it to have. Some of these include pointers and direct memory management. Pointers can be enabled by encasing your code in an unsafe code block.
Example (Written by [Microsoft](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/unsafe-code))
```c#
```csharp
// Normal pointer to an object.
int[] a = new int[5] { 10, 20, 30, 40, 50 };
@ -68,4 +60,4 @@ unsafe
}
```
In .NET 6, the `NativeMemory` class was introduced which you can read about here: [](). It allows for malloc-like memory allocation and freeing which can be important for performance (and is also generally just better than letting a garbage garbage collector do your
In .NET 6, the `NativeMemory` class was introduced which you can read about [here](https://docs.microsoft.com/en-us/dotnet/api/system.runtime.interopservices.nativememory.alloc?view=net-6.0). It allows for malloc-like memory allocation and freeing which can be important for high-performance workloads.

View file

@ -0,0 +1,80 @@
My Website now has a blog! I've always wanted to write a blog and I've been keeping a collection of writings in Google Docs that I'll eventually move over here.
In this blog, I'm going to discuss how I built this blog and the differences it has with the other blogs I've built. As a point of comparison to this blog, I'm going
to be using the [CavCash Newsroom](https://cavcash.com/newsroom) which I also built.
## How I built this blog
This blog has no real backend. Blogs are written in Markdown files that are hosted with this website, which itself is a React webapp. I then have a file that adds metadata
to the blogs such as a title and a date. The metadata file looks like this:
```typescript
import BlogImage from "../images/blog-img-min.png";
import Blog from "../../types/Blog";
import CSMD from "./blogs/c-sharp-c-assignment.md";
import TAB from "./blogs/there-is-a-blog.md";
const CSharpBlog: Blog = {
title: "Doing C assignments in C#",
date: new Date(2022, 2, 18, 14, 15, 0),
image: BlogImage,
mdfile: CSMD,
private: false
}
const TestBlog: Blog = {
title: "There's a Blog!",
date: new Date(2022, 7, 6, 12, 0, 0),
image: BlogImage,
mdfile: TAB,
private: false
}
const PrivateBlog: Blog = {
title: "This blog can only be accessed via the direct URI",
date: new Date(2022, 7, 6, 12, 0, 0),
image: BlogImage,
mdfile: TAB,
private: true
}
export const AllBlogs: Blog[] = [CSharpBlog, PrivateBlog, TestBlog];
```
This metadata then gets converted into a list and whenever you view a blog, it fetches the associated markdown file and parses it to show you here.
I decided to add an option to hide some blogs from the 'All blogs' page (Notice how you don't see [This Blog](http://localhost:3000/blog?id=1) there?)
It's intended to be used so I can host things like Privacy Policies and Terms of Services for apps I write without cluttering up my blog.
You may have noticed that there's an unused Image option. This option would provide a thumbnail, but I decided to remove them for now in favor of a cleaner look.
## How I built the CavCash Newsroom
The CavCash Newsroom does have a backend. The backend is a part of the larger CavCashAPI which also manages the rest of the backend code for CavCash.
It simply stores blog details in a MongoDB collection and returns them to the React frontend. It also supports 'private' blogs, however, it filters
out the private blogs in the backend which makes it harder to find a private blog. An entry for a CavCash Newsroom entry looks like this:
```json
{
"_id" : ObjectId("60ecc0b23eae899e4e46616f"),
"BlogID" : NumberInt(3),
"Title" : "CavCash acquires Apple Inc",
"Author" : "nickorlow",
"CreatedDate" : ISODate("2021-07-12T22:22:41.000+0000"),
"HideBlog": false,
"Content" : "*AUSTIN, TX* - CavCash Inc has finalized a deal to buy Apple Inc (NASDAQ: AAPL) for 3.3 trillion dollars. This marks the 3rd 'FAANG' company CavCash has acquired, with the others being Google and Amazon. CavCash CEO Nicholas Orlowsky has been quoted as saying: \"We are pleased to welcome Apple to the CavCash family.\"\n\nApple CEO Tim Cook was enthused about the deal, expressing excitement for Apple's integration into the overall CavCash ecosystem. Tim will remain CEO of Apple for at least the next two years. \n\nSome have expressed antitrust concerns about CavCash becoming a monopoly.\"\n",
"CoverImage" : "data:image/jpeg;base64,/9j/4AAQS...GMvWWXtB1/9k="
}
```
This blog looks like the following:
![cavcash-newsroom](/blog-images/example-blog-list.png)
![cavcash-newsroom](/blog-images/example-blog-content.png)
_Screenshot of CavCash Newsroom_
## Comparison of CavCash Newsroom and this Blog
CavCash Newsroom needed to be able to be published to without pushing new code to the frontend. We also already had an API written for other things that I could just add
blog functionality to, so I chose to write it with a C# backend and a React frontend. The CavCash Newsroom also has some features not present in this blog such as author information and cover images. These features were left out because I am the only author on this blog, and I decided that cover images wouldn't be necessary.
This blog does not have a backend api associated with it and using a blog API seemed like more trouble than building the feature myself. In order to ship blogs quickly and not create unnecessary complexities in my codebase, I decided to just have markdown files that were included in the frontend as my blogs. As I write more blogs this may prove to be a poor idea for performance but that's a bridge I can cross when I get there (Maybe build my own [NWS](https://nws.nickorlow.com) Blogging service?).