@@ -1,5 +1,6 @@
|
|||||||
## Start Server
|
## Start Server
|
||||||
```sh
|
```sh
|
||||||
|
git submodule update --init --recursive
|
||||||
hugo server --disableFastRender -D #D to include drafts
|
hugo server --disableFastRender -D #D to include drafts
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
17
config.yaml
@@ -1,6 +1,6 @@
|
|||||||
baseURL: "https://trude.dev"
|
baseURL: "https://trude.dev"
|
||||||
title: trude.dev
|
title: trude.dev
|
||||||
paginate: 5
|
pagerSize: 5
|
||||||
theme: PaperMod
|
theme: PaperMod
|
||||||
copyright: "Open-source - MIT License"
|
copyright: "Open-source - MIT License"
|
||||||
#canonifyURLs: true
|
#canonifyURLs: true
|
||||||
@@ -12,6 +12,10 @@ outputs:
|
|||||||
- RSS
|
- RSS
|
||||||
- JSON # necessary for search
|
- JSON # necessary for search
|
||||||
|
|
||||||
|
ignoreFiles:
|
||||||
|
- "notes/drafts/_Templates"
|
||||||
|
- "notes/drafts/TODO.md"
|
||||||
|
|
||||||
taxonomies:
|
taxonomies:
|
||||||
tag: tags
|
tag: tags
|
||||||
|
|
||||||
@@ -36,6 +40,7 @@ params:
|
|||||||
DateFormat: "January 2, 2006"
|
DateFormat: "January 2, 2006"
|
||||||
defaultTheme: auto # dark, light
|
defaultTheme: auto # dark, light
|
||||||
disableThemeToggle: false
|
disableThemeToggle: false
|
||||||
|
social: true
|
||||||
|
|
||||||
ShowReadingTime: true
|
ShowReadingTime: true
|
||||||
ShowShareButtons: true
|
ShowShareButtons: true
|
||||||
@@ -79,8 +84,8 @@ params:
|
|||||||
buttons:
|
buttons:
|
||||||
- name: My Portfolio
|
- name: My Portfolio
|
||||||
url: https://me.trude.dev
|
url: https://me.trude.dev
|
||||||
- name: My Knowledge Base
|
- name: My Notes
|
||||||
url: https://trude.notion.site/Trude-s-Knowledge-Base-10449cf14b4c80ff89d1f2c9541fe789?pvs=4
|
url: /notes/
|
||||||
|
|
||||||
# home-info mode
|
# home-info mode
|
||||||
homeInfoParams:
|
homeInfoParams:
|
||||||
@@ -90,8 +95,6 @@ params:
|
|||||||
socialIcons:
|
socialIcons:
|
||||||
- name: email
|
- name: email
|
||||||
url: "mailto:ehtrude@gmail.com"
|
url: "mailto:ehtrude@gmail.com"
|
||||||
- name: matrix
|
|
||||||
url: "https://matrix.to/#/@ehtrude:matrix.org"
|
|
||||||
- name: github
|
- name: github
|
||||||
url: "https://github.com/TrudeEH"
|
url: "https://github.com/TrudeEH"
|
||||||
- name: rss
|
- name: rss
|
||||||
@@ -125,6 +128,10 @@ params:
|
|||||||
|
|
||||||
menu:
|
menu:
|
||||||
main:
|
main:
|
||||||
|
- identifier: notes
|
||||||
|
name: Notes
|
||||||
|
url: /notes/
|
||||||
|
weight: 5
|
||||||
- identifier: categories
|
- identifier: categories
|
||||||
name: Posts
|
name: Posts
|
||||||
url: /posts/
|
url: /posts/
|
||||||
|
|||||||
BIN
content/notes/.obsidian/.DS_Store
vendored
Normal file
5
content/notes/.obsidian/app.json
vendored
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
{
|
||||||
|
"promptDelete": false,
|
||||||
|
"tabSize": 2,
|
||||||
|
"alwaysUpdateLinks": true
|
||||||
|
}
|
||||||
9
content/notes/.obsidian/appearance.json
vendored
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
{
|
||||||
|
"accentColor": "#f5bd5c",
|
||||||
|
"cssTheme": "Adwaita",
|
||||||
|
"interfaceFontFamily": "Adwaita Sans",
|
||||||
|
"textFontFamily": "Adwaita Sans",
|
||||||
|
"monospaceFontFamily": "Adwaita Mono",
|
||||||
|
"nativeMenus": false,
|
||||||
|
"baseFontSize": 16
|
||||||
|
}
|
||||||
7
content/notes/.obsidian/community-plugins.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
[
|
||||||
|
"obsidian-importer",
|
||||||
|
"obsidian-linter",
|
||||||
|
"table-editor-obsidian",
|
||||||
|
"obsidian-languagetool-plugin",
|
||||||
|
"obsidian-link-converter"
|
||||||
|
]
|
||||||
31
content/notes/.obsidian/core-plugins.json
vendored
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
{
|
||||||
|
"file-explorer": true,
|
||||||
|
"global-search": true,
|
||||||
|
"switcher": true,
|
||||||
|
"graph": true,
|
||||||
|
"backlink": true,
|
||||||
|
"canvas": true,
|
||||||
|
"outgoing-link": true,
|
||||||
|
"tag-pane": true,
|
||||||
|
"properties": false,
|
||||||
|
"page-preview": true,
|
||||||
|
"daily-notes": true,
|
||||||
|
"templates": true,
|
||||||
|
"note-composer": true,
|
||||||
|
"command-palette": true,
|
||||||
|
"slash-command": true,
|
||||||
|
"editor-status": true,
|
||||||
|
"bookmarks": true,
|
||||||
|
"markdown-importer": false,
|
||||||
|
"zk-prefixer": false,
|
||||||
|
"random-note": false,
|
||||||
|
"outline": true,
|
||||||
|
"word-count": true,
|
||||||
|
"slides": true,
|
||||||
|
"audio-recorder": false,
|
||||||
|
"workspaces": false,
|
||||||
|
"file-recovery": true,
|
||||||
|
"publish": false,
|
||||||
|
"sync": false,
|
||||||
|
"webviewer": false
|
||||||
|
}
|
||||||
22
content/notes/.obsidian/graph.json
vendored
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
{
|
||||||
|
"collapse-filter": false,
|
||||||
|
"search": "",
|
||||||
|
"showTags": false,
|
||||||
|
"showAttachments": false,
|
||||||
|
"hideUnresolved": false,
|
||||||
|
"showOrphans": true,
|
||||||
|
"collapse-color-groups": false,
|
||||||
|
"colorGroups": [],
|
||||||
|
"collapse-display": false,
|
||||||
|
"showArrow": false,
|
||||||
|
"textFadeMultiplier": 0,
|
||||||
|
"nodeSizeMultiplier": 1,
|
||||||
|
"lineSizeMultiplier": 1,
|
||||||
|
"collapse-forces": true,
|
||||||
|
"centerStrength": 0.518713248970312,
|
||||||
|
"repelStrength": 10,
|
||||||
|
"linkStrength": 1,
|
||||||
|
"linkDistance": 250,
|
||||||
|
"scale": 0.12668834340524918,
|
||||||
|
"close": true
|
||||||
|
}
|
||||||
BIN
content/notes/.obsidian/plugins/.DS_Store
vendored
Normal file
228
content/notes/.obsidian/plugins/obsidian-importer/main.js
vendored
Normal file
10
content/notes/.obsidian/plugins/obsidian-importer/manifest.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"id": "obsidian-importer",
|
||||||
|
"name": "Importer",
|
||||||
|
"version": "1.6.19",
|
||||||
|
"minAppVersion": "0.15.0",
|
||||||
|
"description": "Import data from Notion, Evernote, Apple Notes, Microsoft OneNote, Google Keep, Bear, Roam, and HTML files.",
|
||||||
|
"author": "Obsidian",
|
||||||
|
"authorUrl": "https://obsidian.md",
|
||||||
|
"isDesktopOnly": false
|
||||||
|
}
|
||||||
87
content/notes/.obsidian/plugins/obsidian-importer/styles.css
vendored
Normal file
@@ -0,0 +1,87 @@
|
|||||||
|
.modal.mod-importer {
|
||||||
|
max-height: var(--modal-height);
|
||||||
|
padding: var(--size-4-4) 0 0 0;
|
||||||
|
position: relative;
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
.modal.mod-importer .modal-title {
|
||||||
|
padding: 0 var(--size-4-4);
|
||||||
|
}
|
||||||
|
.modal.mod-importer .modal-content {
|
||||||
|
overflow: auto;
|
||||||
|
padding: var(--size-4-4);
|
||||||
|
margin-bottom: calc(var(--input-height) + var(--size-4-8));
|
||||||
|
border-top: var(--border-width) solid var(--background-modifier-border);
|
||||||
|
}
|
||||||
|
.modal.mod-importer .modal-button-container {
|
||||||
|
margin: 0 0 0 calc(var(--size-4-4) * -1);
|
||||||
|
padding: var(--size-4-4);
|
||||||
|
gap: var(--size-4-2);
|
||||||
|
position: absolute;
|
||||||
|
bottom: 0;
|
||||||
|
background-color: var(--background-primary);
|
||||||
|
border-top: var(--border-width) solid var(--background-modifier-border);
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-progress-bar {
|
||||||
|
width: 100%;
|
||||||
|
height: 8px;
|
||||||
|
background-color: var(--background-secondary);
|
||||||
|
overflow: hidden;
|
||||||
|
box-shadow: inset 0px 0px 0px 1px var(--background-modifier-border);
|
||||||
|
border-radius: var(--radius-s);
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-progress-bar-inner {
|
||||||
|
width: 0;
|
||||||
|
height: 100%;
|
||||||
|
background-color: var(--interactive-accent);
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-status {
|
||||||
|
white-space: nowrap;
|
||||||
|
overflow: hidden;
|
||||||
|
text-overflow: ellipsis;
|
||||||
|
padding: var(--size-4-2) 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-stats-container {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-evenly;
|
||||||
|
margin-top: var(--size-4-5);
|
||||||
|
margin-bottom: var(--size-4-5);
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-stat {
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-stat-count {
|
||||||
|
font-size: var(--font-ui-large);
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-log {
|
||||||
|
overflow: auto;
|
||||||
|
flex-grow: 1;
|
||||||
|
font-family: var(--font-monospace);
|
||||||
|
font-size: var(--font-ui-smaller);
|
||||||
|
color: var(--text-muted);
|
||||||
|
border: 1px solid var(--background-modifier-border);
|
||||||
|
padding: var(--size-4-4);
|
||||||
|
background-color: var(--background-secondary);
|
||||||
|
border-radius: var(--radius-s);
|
||||||
|
max-height: 300px;
|
||||||
|
user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-log .list-item {
|
||||||
|
display: inline-block;
|
||||||
|
line-height: var(--line-height-normal);
|
||||||
|
white-space: pre;
|
||||||
|
margin: var(--size-2-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
.importer-error {
|
||||||
|
color: var(--text-error);
|
||||||
|
}
|
||||||
9
content/notes/.obsidian/plugins/obsidian-languagetool-plugin/main.js
vendored
Normal file
10
content/notes/.obsidian/plugins/obsidian-languagetool-plugin/manifest.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"id": "obsidian-languagetool-plugin",
|
||||||
|
"name": "LanguageTool Integration",
|
||||||
|
"version": "0.3.7",
|
||||||
|
"minAppVersion": "0.15.2",
|
||||||
|
"description": "Inofficial LanguageTool plugin",
|
||||||
|
"author": "Clemens Ertle",
|
||||||
|
"authorUrl": "https://github.com/Clemens-E",
|
||||||
|
"isDesktopOnly": false
|
||||||
|
}
|
||||||
204
content/notes/.obsidian/plugins/obsidian-languagetool-plugin/styles.css
vendored
Normal file
@@ -0,0 +1,204 @@
|
|||||||
|
.lt-underline {
|
||||||
|
cursor: pointer;
|
||||||
|
transition: background-color 100ms ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-underline.lt-minor {
|
||||||
|
box-shadow: inset 0 -2px #e9b35f;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-underline.lt-major {
|
||||||
|
box-shadow: inset 0 -2px #da615c;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-underline.lt-style {
|
||||||
|
box-shadow: inset 0 -2px #8981f3;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-underline.lt-minor:hover {
|
||||||
|
background-color: #e9b35f21;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-underline.lt-major:hover {
|
||||||
|
background-color: #da615c21;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-underline.lt-style:hover {
|
||||||
|
background-color: #8981f321;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes lineInserted {
|
||||||
|
from {
|
||||||
|
opacity: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
opacity: 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-predictions-container-glass.cm-tooltip,
|
||||||
|
.lt-predictions-container.cm-tooltip,
|
||||||
|
.lt-predictions-container-glass,
|
||||||
|
.lt-predictions-container {
|
||||||
|
position: absolute;
|
||||||
|
animation-duration: 150ms;
|
||||||
|
animation-name: lineInserted;
|
||||||
|
font-family: var(--default-font);
|
||||||
|
font-size: 0.93rem;
|
||||||
|
padding: 12px 0 0;
|
||||||
|
background-color: var(--background-primary);
|
||||||
|
border: 1px solid var(--background-modifier-border);
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 6px;
|
||||||
|
width: 300px;
|
||||||
|
line-height: 1.5;
|
||||||
|
z-index: var(--layer-popover);
|
||||||
|
overflow: visible;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-predictions-container-glass {
|
||||||
|
background: hsla(0, 0%, 100%, 0.25);
|
||||||
|
backdrop-filter: blur(12px);
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-predictions-container > button {
|
||||||
|
transition-delay: 0.5s;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-buttoncontainer:not(:empty) {
|
||||||
|
padding-top: 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-buttoncontainer > button {
|
||||||
|
border: 1px solid var(--background-modifier-border);
|
||||||
|
font-size: 1rem;
|
||||||
|
margin-right: 4px;
|
||||||
|
margin-bottom: 4px;
|
||||||
|
padding: 4px 10px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-title {
|
||||||
|
display: block;
|
||||||
|
font-weight: 600;
|
||||||
|
margin-bottom: 6px;
|
||||||
|
padding: 0 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-message {
|
||||||
|
padding: 0 12px;
|
||||||
|
display: block;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-bottom {
|
||||||
|
min-height: 10px;
|
||||||
|
padding-left: 12px;
|
||||||
|
position: relative;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-info-container {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
bottom: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-info-button {
|
||||||
|
color: var(--text-faint);
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-info-box {
|
||||||
|
position: absolute;
|
||||||
|
right: 0;
|
||||||
|
animation-duration: 150ms;
|
||||||
|
animation-name: lineInserted;
|
||||||
|
font-family: var(--default-font);
|
||||||
|
font-size: 0.93rem;
|
||||||
|
padding: 12px 0;
|
||||||
|
background-color: var(--background-primary);
|
||||||
|
border: 1px solid var(--background-modifier-border);
|
||||||
|
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.1);
|
||||||
|
border-radius: 6px;
|
||||||
|
line-height: 1.5;
|
||||||
|
z-index: var(--layer-popover);
|
||||||
|
overflow: hidden;
|
||||||
|
}
|
||||||
|
|
||||||
|
.hidden {
|
||||||
|
display: none;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-info {
|
||||||
|
padding: 0 12px;
|
||||||
|
display: block;
|
||||||
|
font-size: 0.8rem;
|
||||||
|
color: var(--text-muted);
|
||||||
|
user-select: text;
|
||||||
|
-webkit-user-select: text;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-ignorecontainer {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-status-bar-btn {
|
||||||
|
height: 100%;
|
||||||
|
display: flex;
|
||||||
|
cursor: pointer;
|
||||||
|
line-height: 1;
|
||||||
|
align-items: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-status-bar-check-icon {
|
||||||
|
display: block;
|
||||||
|
text-decoration: underline;
|
||||||
|
text-decoration-style: dotted;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-ignore-btn {
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px;
|
||||||
|
display: flex;
|
||||||
|
width: 100%;
|
||||||
|
text-align: left;
|
||||||
|
border-radius: 0;
|
||||||
|
align-items: center;
|
||||||
|
line-height: 1;
|
||||||
|
border-top: 1px solid var(--background-modifier-border);
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-ignore-btn > span {
|
||||||
|
display: flex;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-ignore-btn > span:last-child {
|
||||||
|
margin-left: 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-minor .lt-title > span {
|
||||||
|
box-shadow: inset 0 -2px #e9b35f88;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-major .lt-title > span {
|
||||||
|
box-shadow: inset 0 -2px #da615c88;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-style .lt-title > span {
|
||||||
|
box-shadow: inset 0 -2px #8981f388;
|
||||||
|
}
|
||||||
|
|
||||||
|
.lt-loading > svg {
|
||||||
|
animation-name: spin;
|
||||||
|
animation-duration: 1s;
|
||||||
|
animation-iteration-count: infinite;
|
||||||
|
animation-timing-function: linear;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
from {
|
||||||
|
transform: rotate(0deg);
|
||||||
|
}
|
||||||
|
|
||||||
|
to {
|
||||||
|
transform: rotate(360deg);
|
||||||
|
}
|
||||||
|
}
|
||||||
6
content/notes/.obsidian/plugins/obsidian-link-converter/data.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"mySetting": "default",
|
||||||
|
"contextMenu": true,
|
||||||
|
"finalLinkFormat": "relative-path",
|
||||||
|
"keepMtime": false
|
||||||
|
}
|
||||||
4
content/notes/.obsidian/plugins/obsidian-link-converter/main.js
vendored
Normal file
10
content/notes/.obsidian/plugins/obsidian-link-converter/manifest.json
vendored
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
{
|
||||||
|
"id": "obsidian-link-converter",
|
||||||
|
"name": "Link Converter",
|
||||||
|
"version": "0.1.6",
|
||||||
|
"minAppVersion": "0.9.12",
|
||||||
|
"description": "Scan all your links in the vault and convert them to your desired format.",
|
||||||
|
"author": "Ozan Tellioglu",
|
||||||
|
"authorUrl": "https://ozan.pl",
|
||||||
|
"isDesktopOnly": false
|
||||||
|
}
|
||||||
4
content/notes/.obsidian/plugins/obsidian-link-converter/styles.css
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
.oz-coffee-div {
|
||||||
|
text-align: center;
|
||||||
|
margin-top: 20px;
|
||||||
|
}
|
||||||
293
content/notes/.obsidian/plugins/obsidian-linter/data.json
vendored
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
{
|
||||||
|
"ruleConfigs": {
|
||||||
|
"add-blank-line-after-yaml": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"dedupe-yaml-array-values": {
|
||||||
|
"enabled": false,
|
||||||
|
"dedupe-alias-key": true,
|
||||||
|
"dedupe-tag-key": true,
|
||||||
|
"dedupe-array-keys": true,
|
||||||
|
"ignore-keys": ""
|
||||||
|
},
|
||||||
|
"escape-yaml-special-characters": {
|
||||||
|
"enabled": false,
|
||||||
|
"try-to-escape-single-line-arrays": false
|
||||||
|
},
|
||||||
|
"force-yaml-escape": {
|
||||||
|
"enabled": false,
|
||||||
|
"force-yaml-escape-keys": ""
|
||||||
|
},
|
||||||
|
"format-tags-in-yaml": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"format-yaml-array": {
|
||||||
|
"enabled": false,
|
||||||
|
"alias-key": true,
|
||||||
|
"tag-key": true,
|
||||||
|
"default-array-style": "single-line",
|
||||||
|
"default-array-keys": true,
|
||||||
|
"force-single-line-array-style": "",
|
||||||
|
"force-multi-line-array-style": ""
|
||||||
|
},
|
||||||
|
"insert-yaml-attributes": {
|
||||||
|
"enabled": false,
|
||||||
|
"text-to-insert": "aliases: \ntags: "
|
||||||
|
},
|
||||||
|
"move-tags-to-yaml": {
|
||||||
|
"enabled": false,
|
||||||
|
"how-to-handle-existing-tags": "Nothing",
|
||||||
|
"tags-to-ignore": ""
|
||||||
|
},
|
||||||
|
"remove-yaml-keys": {
|
||||||
|
"enabled": false,
|
||||||
|
"yaml-keys-to-remove": ""
|
||||||
|
},
|
||||||
|
"sort-yaml-array-values": {
|
||||||
|
"enabled": false,
|
||||||
|
"sort-alias-key": true,
|
||||||
|
"sort-tag-key": true,
|
||||||
|
"sort-array-keys": true,
|
||||||
|
"ignore-keys": "",
|
||||||
|
"sort-order": "Ascending Alphabetical"
|
||||||
|
},
|
||||||
|
"yaml-key-sort": {
|
||||||
|
"enabled": false,
|
||||||
|
"yaml-key-priority-sort-order": "",
|
||||||
|
"priority-keys-at-start-of-yaml": true,
|
||||||
|
"yaml-sort-order-for-other-keys": "None"
|
||||||
|
},
|
||||||
|
"yaml-timestamp": {
|
||||||
|
"enabled": false,
|
||||||
|
"date-created": true,
|
||||||
|
"date-created-key": "date created",
|
||||||
|
"date-created-source-of-truth": "file system",
|
||||||
|
"date-modified": true,
|
||||||
|
"date-modified-key": "date modified",
|
||||||
|
"date-modified-source-of-truth": "file system",
|
||||||
|
"format": "dddd, MMMM Do YYYY, h:mm:ss a",
|
||||||
|
"convert-to-utc": false,
|
||||||
|
"update-on-file-contents-updated": "never"
|
||||||
|
},
|
||||||
|
"yaml-title": {
|
||||||
|
"enabled": false,
|
||||||
|
"title-key": "title",
|
||||||
|
"mode": "first-h1-or-filename-if-h1-missing"
|
||||||
|
},
|
||||||
|
"yaml-title-alias": {
|
||||||
|
"enabled": false,
|
||||||
|
"preserve-existing-alias-section-style": true,
|
||||||
|
"keep-alias-that-matches-the-filename": false,
|
||||||
|
"use-yaml-key-to-keep-track-of-old-filename-or-heading": true,
|
||||||
|
"alias-helper-key": "linter-yaml-title-alias"
|
||||||
|
},
|
||||||
|
"capitalize-headings": {
|
||||||
|
"enabled": true,
|
||||||
|
"style": "Title Case",
|
||||||
|
"ignore-case-words": true,
|
||||||
|
"ignore-words": "macOS, iOS, iPhone, iPad, JavaScript, TypeScript, AppleScript, I",
|
||||||
|
"lowercase-words": "a, an, the, aboard, about, abt., above, abreast, absent, across, after, against, along, aloft, alongside, amid, amidst, mid, midst, among, amongst, anti, apropos, around, round, as, aslant, astride, at, atop, ontop, bar, barring, before, B4, behind, below, beneath, neath, beside, besides, between, 'tween, beyond, but, by, chez, circa, c., ca., come, concerning, contra, counting, cum, despite, spite, down, during, effective, ere, except, excepting, excluding, failing, following, for, from, in, including, inside, into, less, like, minus, modulo, mod, near, nearer, nearest, next, notwithstanding, of, o', off, offshore, on, onto, opposite, out, outside, over, o'er, pace, past, pending, per, plus, post, pre, pro, qua, re, regarding, respecting, sans, save, saving, short, since, sub, than, through, thru, throughout, thruout, till, times, to, t', touching, toward, towards, under, underneath, unlike, until, unto, up, upon, versus, vs., v., via, vice, vis-à-vis, wanting, with, w/, w., c̄, within, w/i, without, 'thout, w/o, abroad, adrift, aft, afterward, afterwards, ahead, apart, ashore, aside, away, back, backward, backwards, beforehand, downhill, downstage, downstairs, downstream, downward, downwards, downwind, east, eastward, eastwards, forth, forward, forwards, heavenward, heavenwards, hence, henceforth, here, hereby, herein, hereof, hereto, herewith, home, homeward, homewards, indoors, inward, inwards, leftward, leftwards, north, northeast, northward, northwards, northwest, now, onward, onwards, outdoors, outward, outwards, overboard, overhead, overland, overseas, rightward, rightwards, seaward, seawards, skywards, skyward, south, southeast, southwards, southward, southwest, then, thence, thenceforth, there, thereby, therein, thereof, thereto, therewith, together, underfoot, underground, uphill, upstage, upstairs, upstream, upward, upwards, upwind, west, westward, westwards, when, whence, where, whereby, wherein, whereto, wherewith, although, because, considering, given, granted, if, lest, once, provided, providing, seeing, so, supposing, though, unless, whenever, whereas, wherever, while, whilst, ago, according to, as regards, counter to, instead of, owing to, pertaining to, at the behest of, at the expense of, at the hands of, at risk of, at the risk of, at variance with, by dint of, by means of, by virtue of, by way of, for the sake of, for sake of, for lack of, for want of, from want of, in accordance with, in addition to, in case of, in charge of, in compliance with, in conformity with, in contact with, in exchange for, in favor of, in front of, in lieu of, in light of, in the light of, in line with, in place of, in point of, in quest of, in relation to, in regard to, with regard to, in respect to, with respect to, in return for, in search of, in step with, in touch with, in terms of, in the name of, in view of, on account of, on behalf of, on grounds of, on the grounds of, on the part of, on top of, with a view to, with the exception of, à la, a la, as soon as, as well as, close to, due to, far from, in case, other than, prior to, pursuant to, regardless of, subsequent to, as long as, as much as, as far as, by the time, in as much as, inasmuch, in order to, in order that, even, provide that, if only, whether, whose, whoever, why, how, or not, whatever, what, both, and, or, not only, but also, either, neither, nor, just, rather, no sooner, such, that, yet, is, it"
|
||||||
|
},
|
||||||
|
"file-name-heading": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"header-increment": {
|
||||||
|
"enabled": true,
|
||||||
|
"start-at-h2": true
|
||||||
|
},
|
||||||
|
"headings-start-line": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"remove-trailing-punctuation-in-heading": {
|
||||||
|
"enabled": false,
|
||||||
|
"punctuation-to-remove": ".,;:!。,;:!"
|
||||||
|
},
|
||||||
|
"footnote-after-punctuation": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"move-footnotes-to-the-bottom": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"re-index-footnotes": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"auto-correct-common-misspellings": {
|
||||||
|
"enabled": false,
|
||||||
|
"ignore-words": "",
|
||||||
|
"skip-words-with-multiple-capitals": false,
|
||||||
|
"extra-auto-correct-files": []
|
||||||
|
},
|
||||||
|
"blockquote-style": {
|
||||||
|
"enabled": true,
|
||||||
|
"style": "space"
|
||||||
|
},
|
||||||
|
"convert-bullet-list-markers": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"default-language-for-code-fences": {
|
||||||
|
"enabled": false,
|
||||||
|
"default-language": ""
|
||||||
|
},
|
||||||
|
"emphasis-style": {
|
||||||
|
"enabled": true,
|
||||||
|
"style": "asterisk"
|
||||||
|
},
|
||||||
|
"no-bare-urls": {
|
||||||
|
"enabled": false,
|
||||||
|
"no-bare-uris": false
|
||||||
|
},
|
||||||
|
"ordered-list-style": {
|
||||||
|
"enabled": true,
|
||||||
|
"number-style": "ascending",
|
||||||
|
"list-end-style": ".",
|
||||||
|
"preserve-start": true
|
||||||
|
},
|
||||||
|
"proper-ellipsis": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"quote-style": {
|
||||||
|
"enabled": true,
|
||||||
|
"single-quote-enabled": true,
|
||||||
|
"single-quote-style": "''",
|
||||||
|
"double-quote-enabled": true,
|
||||||
|
"double-quote-style": "\"\""
|
||||||
|
},
|
||||||
|
"remove-consecutive-list-markers": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"remove-empty-list-markers": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"remove-hyphenated-line-breaks": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"remove-multiple-spaces": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"strong-style": {
|
||||||
|
"enabled": true,
|
||||||
|
"style": "asterisk"
|
||||||
|
},
|
||||||
|
"two-spaces-between-lines-with-content": {
|
||||||
|
"enabled": true,
|
||||||
|
"line-break-indicator": " "
|
||||||
|
},
|
||||||
|
"unordered-list-style": {
|
||||||
|
"enabled": true,
|
||||||
|
"list-style": "-"
|
||||||
|
},
|
||||||
|
"compact-yaml": {
|
||||||
|
"enabled": false,
|
||||||
|
"inner-new-lines": false
|
||||||
|
},
|
||||||
|
"consecutive-blank-lines": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"convert-spaces-to-tabs": {
|
||||||
|
"enabled": false,
|
||||||
|
"tabsize": 4
|
||||||
|
},
|
||||||
|
"empty-line-around-blockquotes": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"empty-line-around-code-fences": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"empty-line-around-horizontal-rules": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"empty-line-around-math-blocks": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"empty-line-around-tables": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"heading-blank-lines": {
|
||||||
|
"enabled": true,
|
||||||
|
"bottom": true,
|
||||||
|
"empty-line-after-yaml": true
|
||||||
|
},
|
||||||
|
"line-break-at-document-end": {
|
||||||
|
"enabled": true
|
||||||
|
},
|
||||||
|
"move-math-block-indicators-to-their-own-line": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"paragraph-blank-lines": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-empty-lines-between-list-markers-and-checklists": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-link-spacing": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-space-around-characters": {
|
||||||
|
"enabled": false,
|
||||||
|
"include-fullwidth-forms": true,
|
||||||
|
"include-cjk-symbols-and-punctuation": true,
|
||||||
|
"include-dashes": true,
|
||||||
|
"other-symbols": ""
|
||||||
|
},
|
||||||
|
"remove-space-before-or-after-characters": {
|
||||||
|
"enabled": false,
|
||||||
|
"characters-to-remove-space-before": ",!?;:).’”]",
|
||||||
|
"characters-to-remove-space-after": "¿¡‘“(["
|
||||||
|
},
|
||||||
|
"space-after-list-markers": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"space-between-chinese-japanese-or-korean-and-english-or-numbers": {
|
||||||
|
"enabled": false,
|
||||||
|
"english-symbols-punctuation-before": "-+;:'\"°%$)]",
|
||||||
|
"english-symbols-punctuation-after": "-+'\"([¥$"
|
||||||
|
},
|
||||||
|
"trailing-spaces": {
|
||||||
|
"enabled": false,
|
||||||
|
"twp-space-line-break": false
|
||||||
|
},
|
||||||
|
"add-blockquote-indentation-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"prevent-double-checklist-indicator-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"prevent-double-list-item-indicator-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"proper-ellipsis-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-hyphens-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-leading-or-trailing-whitespace-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-leftover-footnotes-from-quote-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
},
|
||||||
|
"remove-multiple-blank-lines-on-paste": {
|
||||||
|
"enabled": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"lintOnSave": true,
|
||||||
|
"recordLintOnSaveLogs": false,
|
||||||
|
"displayChanged": true,
|
||||||
|
"lintOnFileChange": false,
|
||||||
|
"displayLintOnFileChangeNotice": false,
|
||||||
|
"settingsConvertedToConfigKeyValues": true,
|
||||||
|
"foldersToIgnore": [],
|
||||||
|
"filesToIgnore": [],
|
||||||
|
"linterLocale": "system-default",
|
||||||
|
"logLevel": "ERROR",
|
||||||
|
"lintCommands": [],
|
||||||
|
"customRegexes": [],
|
||||||
|
"commonStyles": {
|
||||||
|
"aliasArrayStyle": "single-line",
|
||||||
|
"tagArrayStyle": "single-line",
|
||||||
|
"minimumNumberOfDollarSignsToBeAMathBlock": 2,
|
||||||
|
"escapeCharacter": "\"",
|
||||||
|
"removeUnnecessaryEscapeCharsForMultiLineArrays": false
|
||||||
|
}
|
||||||
|
}
|
||||||
325
content/notes/.obsidian/plugins/obsidian-linter/main.js
vendored
Normal file
11
content/notes/.obsidian/plugins/obsidian-linter/manifest.json
vendored
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
{
|
||||||
|
"id": "obsidian-linter",
|
||||||
|
"name": "Linter",
|
||||||
|
"version": "1.28.0",
|
||||||
|
"minAppVersion": "1.5.7",
|
||||||
|
"description": "Formats and styles your notes. It can be used to format YAML tags, aliases, arrays, and metadata; footnotes; headings; spacing; math blocks; regular markdown contents like list, italics, and bold styles; and more with the use of custom rule options as well.",
|
||||||
|
"author": "Victor Tao",
|
||||||
|
"authorUrl": "https://github.com/platers",
|
||||||
|
"helpUrl": "https://platers.github.io/obsidian-linter/",
|
||||||
|
"isDesktopOnly": false
|
||||||
|
}
|
||||||
1
content/notes/.obsidian/plugins/obsidian-linter/styles.css
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
.linter-navigation-item{align-items:center;background-color:var(--background-primary-secondary-alt);border:1px solid var(--background-modifier-border);border-radius:100px;border-radius:8px 8px 2px 2px;cursor:pointer;display:flex;flex-direction:row;font-size:16px;font-weight:700;gap:4px;height:32px;overflow:hidden;padding:4px 6px;transition:color .25s ease-in-out,padding .25s ease-in-out,background-color .35s cubic-bezier(.45,.25,.83,.67),max-width .35s cubic-bezier(.57,.04,.58,1);white-space:nowrap}@media screen and (max-width:1325px){.linter-navigation-item.linter-desktop{max-width:32px}}@media screen and (max-width:800px){.linter-navigation-item.linter-mobile{max-width:32px}}.linter-navigation-item-icon,.linter-warning{padding-top:5px}.linter-navigation-item:hover{border-color:var(--interactive-accent-hover);border-bottom:0}.linter-navigation-item-selected{background-color:var(--interactive-accent)!important;border:1px solid var(--background-modifier-border);border-bottom:0;border-radius:8px 8px 2px 2px;color:var(--text-on-accent);max-width:100%!important;padding:4px 9px!important;transition:color .25s ease-in-out,padding .25s ease-in-out,background-color .35s cubic-bezier(.45,.25,.83,.67),max-width .45s cubic-bezier(.57,.04,.58,1) .2s}.linter{transition:transform .4s 0s}.linter-setting-title{align-items:baseline;display:flex;gap:30px;justify-content:space-between}.linter-setting-title.linter-mobile{justify-content:space-around}.linter-setting-title h1{font-weight:900;margin-bottom:12px;margin-top:6px}.linter-setting-header{margin-bottom:24px;overflow-x:auto;overflow-y:hidden}.linter-setting-header .linter-setting-tab-group{align-items:flex-end;display:flex;flex-wrap:wrap;width:100%}.linter-setting-tab-group{border-bottom:2px solid var(--background-modifier-border);margin-top:6px;padding-left:2px;padding-right:2px}.linter-setting-header .linter-tab-settings{border-left:2px solid transparent;border-right:2px solid transparent;cursor:pointer;font-weight:600;padding:6px 12px;white-space:nowrap}.linter-setting-header .linter-tab-settings:first-child{margin-left:6px}.linter-setting-header .linter-tab-settings.linter-tab-settings-active{border:2px solid var(--background-modifier-border);border-bottom-color:var(--background-primary);border-radius:2px;transform:translateY(2px)}.linter-navigation-item:not(.linter-navigation-item-selected)>span:nth-child(2),.linter-visually-hidden{border:0;clip:rect(0 0 0 0);clip-path:rect(0 0 0 0);height:auto;margin:0;overflow:hidden;padding:0;position:absolute;white-space:nowrap;width:1px}textarea.full-width{margin-bottom:.8em;margin-top:.8em;min-height:10em;width:100%}.full-width-textbox-input-wrapper{position:relative}.settings-copy-button{margin:0 0 0 auto;padding:4px;position:absolute;right:.8em;top:.8em}.settings-copy-button svg.linter-clipboard path{fill:var(--text-faint)}.settings-copy-button svg.linter-success path{fill:var(--interactive-success)}.settings-copy-button:active,.settings-copy-button:hover{cursor:pointer}.settings-copy-button:active svg path,.settings-copy-button:hover svg path{fill:var(--text-accent-hover);transition:all .3s ease}.settings-copy-button:focus{outline:0}.linter-custom-regex-replacement-container div:last-child{border:none}.linter-custom-regex-replacement{border:none;border-bottom:var(--hr-thickness) solid;border-color:var(--hr-color);margin-bottom:15px}.linter-custom-regex-replacement-row2{flex-wrap:wrap}.linter-custom-regex-replacement-normal-input{width:40%}.linter-custom-regex-replacement-flags{width:15%}.linter-custom-regex-replacement-label{flex-direction:row-reverse}.linter-custom-regex-replacement-label-input{width:50%}.linter-files-to-ignore-container div:last-child{border:none}.linter-files-to-ignore{border:none;border-bottom:var(--hr-thickness) solid;border-color:var(--hr-color);margin-bottom:15px}.linter-files-to-ignore-normal-input{width:40%}.linter-files-to-ignore-flags{width:15%}.linter-no-border{border:none}.linter-border-bottom{border-bottom:1px solid var(--background-modifier-border);border-top:0;margin-bottom:.75em}.linter-no-padding-top{padding-top:0}.custom-row-description{margin-top:0}.modal-warn,.search-zero-state{font-weight:700}.modal-heading,.search-zero-state{text-align:center}
|
||||||
6
content/notes/.obsidian/plugins/table-editor-obsidian/data.json
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"formatType": "normal",
|
||||||
|
"showRibbonIcon": true,
|
||||||
|
"bindEnter": true,
|
||||||
|
"bindTab": true
|
||||||
|
}
|
||||||
236
content/notes/.obsidian/plugins/table-editor-obsidian/main.js
vendored
Normal file
17
content/notes/.obsidian/plugins/table-editor-obsidian/manifest.json
vendored
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"id": "table-editor-obsidian",
|
||||||
|
"name": "Advanced Tables",
|
||||||
|
"author": "Tony Grosinger",
|
||||||
|
"authorUrl": "https://grosinger.net",
|
||||||
|
"description": "Improved table navigation, formatting, manipulation, and formulas",
|
||||||
|
"isDesktopOnly": false,
|
||||||
|
"minAppVersion": "1.0.0",
|
||||||
|
"version": "0.22.1",
|
||||||
|
"js": "main.js",
|
||||||
|
"fundingUrl": {
|
||||||
|
"Github Sponsor": "https://github.com/sponsors/tgrosinger",
|
||||||
|
"Buy me a Coffee": "https://buymeacoffee.com/tgrosinger",
|
||||||
|
"Paypal": "https://paypal.me/tgrosinger"
|
||||||
|
},
|
||||||
|
"donation": "https://buymeacoffee.com/tgrosinger"
|
||||||
|
}
|
||||||
78
content/notes/.obsidian/plugins/table-editor-obsidian/styles.css
vendored
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
:root {
|
||||||
|
--advanced-tables-helper-size: 28px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.HyperMD-table-row span.cm-inline-code {
|
||||||
|
font-size: 100%;
|
||||||
|
padding: 0px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-tables-buttons>div>.title {
|
||||||
|
font-weight: var(--font-medium);
|
||||||
|
font-size: var(--nav-item-size);
|
||||||
|
color: var(--nav-item-color);
|
||||||
|
text-decoration: underline;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="advanced-tables-toolbar"] .nav-buttons-container {
|
||||||
|
column-gap: 0.2rem;
|
||||||
|
margin: 0.2rem 0 0.2rem 0;
|
||||||
|
justify-content: start;
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="advanced-tables-toolbar"] .nav-buttons-container::before {
|
||||||
|
min-width: 2.6rem;
|
||||||
|
line-height: var(--advanced-tables-helper-size);
|
||||||
|
font-size: var(--nav-item-size);
|
||||||
|
font-weight: var(--nav-item-weight);
|
||||||
|
color: var(--nav-item-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="advanced-tables-toolbar"] .nav-buttons-container>* {
|
||||||
|
height: var(--advanced-tables-helper-size);
|
||||||
|
line-height: var(--advanced-tables-helper-size);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="advanced-tables-toolbar"] .nav-buttons-container .nav-action-button {
|
||||||
|
width: var(--advanced-tables-helper-size);
|
||||||
|
height: var(--advanced-tables-helper-size);
|
||||||
|
display: flex;
|
||||||
|
justify-content: center;
|
||||||
|
align-items: center;
|
||||||
|
border-radius: var(--radius-s);
|
||||||
|
}
|
||||||
|
|
||||||
|
[data-type="advanced-tables-toolbar"] .nav-buttons-container .nav-action-button:hover {
|
||||||
|
background-color: var(--nav-item-background-hover);
|
||||||
|
color: var(--nav-item-color-hover);
|
||||||
|
font-weight: var(--nav-item-weight-hover);
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-tables-row-label {
|
||||||
|
width: 50px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-icon {
|
||||||
|
width: 20px;
|
||||||
|
height: 20px;
|
||||||
|
fill: var(--text-muted);
|
||||||
|
}
|
||||||
|
|
||||||
|
.widget-icon:hover {
|
||||||
|
fill: var(--text-normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-tables-csv-export textarea {
|
||||||
|
height: 200px;
|
||||||
|
width: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-tables-donation {
|
||||||
|
width: 70%;
|
||||||
|
margin: 0 auto;
|
||||||
|
text-align: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.advanced-tables-donate-button {
|
||||||
|
margin: 10px;
|
||||||
|
}
|
||||||
3
content/notes/.obsidian/templates.json
vendored
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"folder": "drafts/_Templates"
|
||||||
|
}
|
||||||
7
content/notes/.obsidian/themes/Adwaita/manifest.json
vendored
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"name": "Adwaita",
|
||||||
|
"version": "0.5.0",
|
||||||
|
"minAppVersion": "1.0.0",
|
||||||
|
"author": "@birneee",
|
||||||
|
"authorUrl": "https://github.com/birneee"
|
||||||
|
}
|
||||||
744
content/notes/.obsidian/themes/Adwaita/theme.css
vendored
Normal file
@@ -0,0 +1,744 @@
|
|||||||
|
/* This file is generated; DO NOT EDIT. */
|
||||||
|
/* @settings
|
||||||
|
|
||||||
|
name: Adwaita
|
||||||
|
id: com-github-birneee-obsidian-adwaita
|
||||||
|
settings:
|
||||||
|
-
|
||||||
|
title: Window Buttons
|
||||||
|
description: Style of minimize, maximize and close window buttons
|
||||||
|
type: heading
|
||||||
|
level: 2
|
||||||
|
collapsed: false
|
||||||
|
-
|
||||||
|
id: adwaita-mod
|
||||||
|
title: Enable
|
||||||
|
description: Whether to use the Adwaita style window buttons
|
||||||
|
type: class-select
|
||||||
|
default: adwaita-mod-linux-only
|
||||||
|
allowEmpty: false
|
||||||
|
options:
|
||||||
|
-
|
||||||
|
label: Always
|
||||||
|
value: adwaita-mod-always
|
||||||
|
-
|
||||||
|
label: Linux Only
|
||||||
|
value: adwaita-mod-linux-only
|
||||||
|
-
|
||||||
|
label: Never
|
||||||
|
value: adwaita-mod-never
|
||||||
|
-
|
||||||
|
id: adwaita-mod-scale
|
||||||
|
title: Scale
|
||||||
|
description:
|
||||||
|
type: variable-number
|
||||||
|
default: 1
|
||||||
|
-
|
||||||
|
id: adwaita-mod-right-margin
|
||||||
|
title: Right Margin
|
||||||
|
type: variable-number
|
||||||
|
default: 8
|
||||||
|
format: px
|
||||||
|
-
|
||||||
|
id: adwaita-window-button-minimize-hide
|
||||||
|
title: Hide minimize button
|
||||||
|
type: class-toggle
|
||||||
|
-
|
||||||
|
id: adwaita-window-button-maximize-hide
|
||||||
|
title: Hide maximize button
|
||||||
|
type: class-toggle
|
||||||
|
-
|
||||||
|
id: adwaita-window-button-close-hide
|
||||||
|
title: Hide close button
|
||||||
|
type: class-toggle
|
||||||
|
|
||||||
|
-
|
||||||
|
title: Tabs
|
||||||
|
type: heading
|
||||||
|
level: 2
|
||||||
|
collapsed: false
|
||||||
|
-
|
||||||
|
id: adwaita-tabs
|
||||||
|
title: Enable
|
||||||
|
description: Whether to use the Adwaita style tabs
|
||||||
|
type: class-select
|
||||||
|
default: adwaita-tabs-linux-only
|
||||||
|
allowEmpty: false
|
||||||
|
options:
|
||||||
|
-
|
||||||
|
label: Always
|
||||||
|
value: adwaita-tabs-always
|
||||||
|
-
|
||||||
|
label: Linux Only
|
||||||
|
value: adwaita-tabs-linux-only
|
||||||
|
-
|
||||||
|
label: Never
|
||||||
|
value: adwaita-tabs-never
|
||||||
|
-
|
||||||
|
id: adwaita-tabs-short
|
||||||
|
title: Short
|
||||||
|
type: class-toggle
|
||||||
|
|
||||||
|
-
|
||||||
|
title: Colors
|
||||||
|
type: heading
|
||||||
|
level: 2
|
||||||
|
collapsed: false
|
||||||
|
-
|
||||||
|
id: adwaita-colors
|
||||||
|
title: Enable
|
||||||
|
description: Whether to use the Adwaita colors
|
||||||
|
type: class-select
|
||||||
|
default: adwaita-colors-linux-only
|
||||||
|
allowEmpty: false
|
||||||
|
options:
|
||||||
|
-
|
||||||
|
label: Always
|
||||||
|
value: adwaita-colors-always
|
||||||
|
-
|
||||||
|
label: Linux Only
|
||||||
|
value: adwaita-colors-linux-only
|
||||||
|
-
|
||||||
|
label: Never
|
||||||
|
value: adwaita-colors-never
|
||||||
|
|
||||||
|
-
|
||||||
|
title: Font
|
||||||
|
type: heading
|
||||||
|
level: 2
|
||||||
|
collapsed: false
|
||||||
|
-
|
||||||
|
id: adwaita-font
|
||||||
|
title: Enable
|
||||||
|
description: Whether to use the Cantarell font (must be installed on system)
|
||||||
|
type: class-select
|
||||||
|
default: adwaita-font-linux-only
|
||||||
|
allowEmpty: false
|
||||||
|
options:
|
||||||
|
-
|
||||||
|
label: Always
|
||||||
|
value: adwaita-font-always
|
||||||
|
-
|
||||||
|
label: Linux Only
|
||||||
|
value: adwaita-font-linux-only
|
||||||
|
-
|
||||||
|
label: Never
|
||||||
|
value: adwaita-font-never
|
||||||
|
|
||||||
|
-
|
||||||
|
title: Icons
|
||||||
|
type: heading
|
||||||
|
level: 2
|
||||||
|
collapsed: false
|
||||||
|
-
|
||||||
|
id: adwaita-icon
|
||||||
|
title: Enable
|
||||||
|
description: Whether to use the Adwaita icons
|
||||||
|
type: class-select
|
||||||
|
default: adwaita-icons-linux-only
|
||||||
|
allowEmpty: false
|
||||||
|
options:
|
||||||
|
-
|
||||||
|
label: Always
|
||||||
|
value: adwaita-icons-always
|
||||||
|
-
|
||||||
|
label: Linux Only
|
||||||
|
value: adwaita-icons-linux-only
|
||||||
|
-
|
||||||
|
label: Never
|
||||||
|
value: adwaita-icons-never
|
||||||
|
*/
|
||||||
|
:root {
|
||||||
|
--adwaita-mod-scale: 1;
|
||||||
|
--adwaita-mod-right-margin: 8px;
|
||||||
|
/* TODO window radius */ }
|
||||||
|
|
||||||
|
:root {
|
||||||
|
--adwaita-icon-folder-saved-search-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDYuNjA1NDY5IDAuMDU4NTkzOCBjIC0zLjU3ODEyNSAwIC02LjUgMi45MjE4NzUyIC02LjUgNi41MDAwMDAyIHMgMi45MjE4NzUgNi40OTYwOTQgNi41IDYuNDk2MDk0IGMgMS40Mjk2ODcgMCAyLjc1MzkwNiAtMC40NjQ4NDQgMy44MjgxMjUgLTEuMjUzOTA3IGwgMi45NzI2NTYgMi45NzI2NTcgYyAwLjk1NzAzMSAwLjk0MTQwNiAyLjM2MzI4MSAtMC40OTYwOTQgMS40MDYyNSAtMS40Mzc1IGwgLTIuOTU3MDMxIC0yLjk1NzAzMiBjIDAuNzgxMjUgLTEuMDc0MjE4IDEuMjUgLTIuMzk0NTMxIDEuMjUgLTMuODIwMzEyIGMgMCAtMy41NzgxMjUgLTIuOTI1NzgxIC02LjUwMDAwMDIgLTYuNSAtNi41MDAwMDAyIHogbSAwIDIuMDAwMDAwMiBjIDIuNDk2MDkzIDAgNC41IDIuMDAzOTA2IDQuNSA0LjUgcyAtMi4wMDM5MDcgNC40OTYwOTQgLTQuNSA0LjQ5NjA5NCBjIC0yLjUgMCAtNC41IC0yIC00LjUgLTQuNDk2MDk0IHMgMiAtNC41IDQuNSAtNC41IHogbSAwIDAiIGZpbGw9IiMyZTM0MzYiLz4KPC9zdmc+Cg==");
|
||||||
|
--adwaita-icon-folder-visiting-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDMgMSBjIC0xLjY0NDUzMSAwIC0zIDEuMzU1NDY5IC0zIDMgdiA4IGMgMCAxLjY0NDUzMSAxLjM1NTQ2OSAzIDMgMyBoIDEwIGMgMS42NDQ1MzEgMCAzIC0xLjM1NTQ2OSAzIC0zIHYgLTYgYyAwIC0xLjY0NDUzMSAtMS4zNTU0NjkgLTMgLTMgLTMgaCAtMy41ODU5MzggbCAtMS43MDcwMzEgLTEuNzA3MDMxIGMgLTAuMTg3NSAtMC4xODc1IC0wLjQ0MTQwNiAtMC4yOTI5NjkgLTAuNzA3MDMxIC0wLjI5Mjk2OSB6IG0gMCAyIGggMy41ODU5MzggbCAxLjcwNzAzMSAxLjcwNzAzMSBjIDAuMTg3NSAwLjE4NzUgMC40NDE0MDYgMC4yOTI5NjkgMC43MDcwMzEgMC4yOTI5NjkgaCA0IGMgMC41NjI1IDAgMSAwLjQzNzUgMSAxIHYgNiBjIDAgMC41NjY0MDYgLTAuNDM3NSAxIC0xIDEgaCAtMTAgYyAtMC41NjI1IDAgLTEgLTAuNDMzNTk0IC0xIC0xIHYgLTggYyAwIC0wLjU2MjUgMC40Mzc1IC0xIDEgLTEgeiBtIDAgMCIgZmlsbD0iIzJlMzQzNiIvPgo8L3N2Zz4K");
|
||||||
|
--adwaita-icon-go-down-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDEgNSBjIDAgLTAuMjY1NjI1IDAuMTA1NDY5IC0wLjUxOTUzMSAwLjI5Mjk2OSAtMC43MDcwMzEgYyAwLjM5MDYyNSAtMC4zOTA2MjUgMS4wMjM0MzcgLTAuMzkwNjI1IDEuNDE0MDYyIDAgbCA1LjI5Mjk2OSA1LjI5Mjk2OSBsIDUuMjkyOTY5IC01LjI5Mjk2OSBjIDAuMzkwNjI1IC0wLjM5MDYyNSAxLjAyMzQzNyAtMC4zOTA2MjUgMS40MTQwNjIgMCBjIDAuMTg3NSAwLjE4NzUgMC4yOTI5NjkgMC40NDE0MDYgMC4yOTI5NjkgMC43MDcwMzEgcyAtMC4xMDU0NjkgMC41MTk1MzEgLTAuMjkyOTY5IDAuNzA3MDMxIGwgLTYgNiBjIC0wLjM5MDYyNSAwLjM5MDYyNSAtMS4wMjM0MzcgMC4zOTA2MjUgLTEuNDE0MDYyIDAgbCAtNiAtNiBjIC0wLjE4NzUgLTAuMTg3NSAtMC4yOTI5NjkgLTAuNDQxNDA2IC0wLjI5Mjk2OSAtMC43MDcwMzEgeiBtIDAgMCIgZmlsbD0iIzJlMzQzNiIvPgo8L3N2Zz4K");
|
||||||
|
--adwaita-icon-sidebar-show-right-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8ZyBmaWxsPSIjMmUzNDM2Ij4KICAgICAgICA8cGF0aCBkPSJtIDkuNSAxNCB2IC0xMiBoIDUgdiAxMiB6IG0gMCAwIiBmaWxsLW9wYWNpdHk9IjAuMzQ5MDIiLz4KICAgICAgICA8cGF0aCBkPSJtIDEzIDEgYyAxLjY0NDUzMSAwIDMgMS4zNTU0NjkgMyAzIHYgOCBjIDAgMS42NDQ1MzEgLTEuMzU1NDY5IDMgLTMgMyBoIC0xMCBjIC0xLjY0NDUzMSAwIC0zIC0xLjM1NTQ2OSAtMyAtMyB2IC04IGMgMCAtMS42NDQ1MzEgMS4zNTU0NjkgLTMgMyAtMyB6IG0gMCAyIGggLTEwIGMgLTAuNTcwMzEyIDAgLTEgMC40Mjk2ODggLTEgMSB2IDggYyAwIDAuNTcwMzEyIDAuNDI5Njg4IDEgMSAxIGggMTAgYyAwLjU3MDMxMiAwIDEgLTAuNDI5Njg4IDEgLTEgdiAtOCBjIDAgLTAuNTcwMzEyIC0wLjQyOTY4OCAtMSAtMSAtMSB6IG0gMCAwIi8+CiAgICAgICAgPHBhdGggZD0ibSAxMCAyIGggLTEgdiAxMiBoIDEgeiBtIDAgMCIvPgogICAgPC9nPgo8L3N2Zz4K");
|
||||||
|
--adwaita-icon-sidebar-show-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8ZyBmaWxsPSIjMmUzNDM2Ij4KICAgICAgICA8cGF0aCBkPSJtIDYuNSAxNCB2IC0xMiBoIC01IHYgMTIgeiBtIDAgMCIgZmlsbC1vcGFjaXR5PSIwLjM0OTAyIi8+CiAgICAgICAgPHBhdGggZD0ibSAzIDEgYyAtMS42NDQ1MzEgMCAtMyAxLjM1NTQ2OSAtMyAzIHYgOCBjIDAgMS42NDQ1MzEgMS4zNTU0NjkgMyAzIDMgaCAxMCBjIDEuNjQ0NTMxIDAgMyAtMS4zNTU0NjkgMyAtMyB2IC04IGMgMCAtMS42NDQ1MzEgLTEuMzU1NDY5IC0zIC0zIC0zIHogbSAwIDIgaCAxMCBjIDAuNTcwMzEyIDAgMSAwLjQyOTY4OCAxIDEgdiA4IGMgMCAwLjU3MDMxMiAtMC40Mjk2ODggMSAtMSAxIGggLTEwIGMgLTAuNTcwMzEyIDAgLTEgLTAuNDI5Njg4IC0xIC0xIHYgLTggYyAwIC0wLjU3MDMxMiAwLjQyOTY4OCAtMSAxIC0xIHogbSAwIDAiLz4KICAgICAgICA8cGF0aCBkPSJtIDYgMiBoIDEgdiAxMiBoIC0xIHogbSAwIDAiLz4KICAgIDwvZz4KPC9zdmc+Cg==");
|
||||||
|
--adwaita-icon-tab-new-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8ZyBmaWxsPSIjMmUzNDM2Ij4KICAgICAgICA8cGF0aCBkPSJtIDMgMCBjIC0xLjY0NDUzMSAwIC0zIDEuMzU1NDY5IC0zIDMgdiAxMCBjIDAgMS42NDQ1MzEgMS4zNTU0NjkgMyAzIDMgaCAxMCBjIDEuNjQ0NTMxIDAgMyAtMS4zNTU0NjkgMyAtMyB2IC0xMCBjIDAgLTEuNjQ0NTMxIC0xLjM1NTQ2OSAtMyAtMyAtMyB6IG0gMCAyIGggMTAgYyAwLjU3MDMxMiAwIDEgMC40Mjk2ODggMSAxIHYgMTAgYyAwIDAuNTcwMzEyIC0wLjQyOTY4OCAxIC0xIDEgaCAtMTAgYyAtMC41NzAzMTIgMCAtMSAtMC40Mjk2ODggLTEgLTEgdiAtMTAgYyAwIC0wLjU3MDMxMiAwLjQyOTY4OCAtMSAxIC0xIHogbSAwIDAiLz4KICAgICAgICA8cGF0aCBkPSJtIDQgNyBoIDggdiAyIGggLTggeiBtIDAgMCIvPgogICAgICAgIDxwYXRoIGQ9Im0gOSA0IHYgOCBoIC0yIHYgLTggeiBtIDAgMCIvPgogICAgPC9nPgo8L3N2Zz4K");
|
||||||
|
--adwaita-icon-view-more-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDcuOTk2MDk0IDAgYyAtMS4xMDU0NjkgMCAtMiAwLjg5NDUzMSAtMiAyIHMgMC44OTQ1MzEgMiAyIDIgYyAxLjEwMTU2MiAwIDIgLTAuODk0NTMxIDIgLTIgcyAtMC44OTg0MzggLTIgLTIgLTIgeiBtIDAgNiBjIC0xLjEwNTQ2OSAwIC0yIDAuODk0NTMxIC0yIDIgcyAwLjg5NDUzMSAyIDIgMiBjIDEuMTAxNTYyIDAgMiAtMC44OTQ1MzEgMiAtMiBzIC0wLjg5ODQzOCAtMiAtMiAtMiB6IG0gMCA2IGMgLTEuMTA1NDY5IDAgLTIgMC44OTQ1MzEgLTIgMiBzIDAuODk0NTMxIDIgMiAyIGMgMS4xMDE1NjIgMCAyIC0wLjg5NDUzMSAyIC0yIHMgLTAuODk4NDM4IC0yIC0yIC0yIHogbSAwIDAiIGZpbGw9IiMyZTM0MzYiLz4KPC9zdmc+Cg==");
|
||||||
|
--adwaita-icon-window-close-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDQgNCBoIDEgaCAwLjAzMTI1IGMgMC4yNTM5MDYgMC4wMTE3MTkgMC41MTE3MTkgMC4xMjg5MDYgMC42ODc1IDAuMzEyNSBsIDIuMjgxMjUgMi4yODEyNSBsIDIuMzEyNSAtMi4yODEyNSBjIDAuMjY1NjI1IC0wLjIzMDQ2OSAwLjQ0NTMxMiAtMC4zMDQ2ODggMC42ODc1IC0wLjMxMjUgaCAxIHYgMSBjIDAgMC4yODUxNTYgLTAuMDM1MTU2IDAuNTUwNzgxIC0wLjI1IDAuNzUgbCAtMi4yODEyNSAyLjI4MTI1IGwgMi4yNSAyLjI1IGMgMC4xODc1IDAuMTg3NSAwLjI4MTI1IDAuNDUzMTI1IDAuMjgxMjUgMC43MTg3NSB2IDEgaCAtMSBjIC0wLjI2NTYyNSAwIC0wLjUzMTI1IC0wLjA5Mzc1IC0wLjcxODc1IC0wLjI4MTI1IGwgLTIuMjgxMjUgLTIuMjgxMjUgbCAtMi4yODEyNSAyLjI4MTI1IGMgLTAuMTg3NSAwLjE4NzUgLTAuNDUzMTI1IDAuMjgxMjUgLTAuNzE4NzUgMC4yODEyNSBoIC0xIHYgLTEgYyAwIC0wLjI2NTYyNSAwLjA5Mzc1IC0wLjUzMTI1IDAuMjgxMjUgLTAuNzE4NzUgbCAyLjI4MTI1IC0yLjI1IGwgLTIuMjgxMjUgLTIuMjgxMjUgYyAtMC4yMTA5MzggLTAuMTk1MzEyIC0wLjMwNDY4OCAtMC40Njg3NSAtMC4yODEyNSAtMC43NSB6IG0gMCAwIiBmaWxsPSIjMmUzNDM2Ii8+Cjwvc3ZnPgo=");
|
||||||
|
--adwaita-icon-window-maximize-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDMuOTg4MjgxIDMuOTkyMTg4IHYgOC4wMTE3MTggaCA4LjAxMTcxOSB2IC04LjAxMTcxOCB6IG0gMiAyIGggNC4wMTE3MTkgdiA0LjAxMTcxOCBoIC00LjAxMTcxOSB6IG0gMCAwIiBmaWxsPSIjMmUzNDM2Ii8+Cjwvc3ZnPgo=");
|
||||||
|
--adwaita-icon-window-minimize-symbolic: url("data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0iVVRGLTgiPz4KPHN2ZyBoZWlnaHQ9IjE2cHgiIHZpZXdCb3g9IjAgMCAxNiAxNiIgd2lkdGg9IjE2cHgiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+CiAgICA8cGF0aCBkPSJtIDQgMTAuMDA3ODEyIGggOCB2IDEuOTg4MjgyIGggLTggeiBtIDAgMCIgZmlsbD0iIzJlMzQzNiIvPgo8L3N2Zz4K"); }
|
||||||
|
|
||||||
|
body {
|
||||||
|
--adwaita-blue-1: #99c1f1;
|
||||||
|
--adwaita-blue-2: #62a0ea;
|
||||||
|
--adwaita-blue-3: #3584e4;
|
||||||
|
--adwaita-blue-4: #1c71d8;
|
||||||
|
--adwaita-blue-5: #1a5fb4;
|
||||||
|
--adwaita-green-1: #8ff0a4;
|
||||||
|
--adwaita-green-2: #57e389;
|
||||||
|
--adwaita-green-3: #33d17a;
|
||||||
|
--adwaita-green-4: #2ec27e;
|
||||||
|
--adwaita-green-5: #26a269;
|
||||||
|
--adwaita-yellow-1: #f9f06b;
|
||||||
|
--adwaita-yellow-2: #f8e45c;
|
||||||
|
--adwaita-yellow-3: #f6d32d;
|
||||||
|
--adwaita-yellow-4: #f5c211;
|
||||||
|
--adwaita-yellow-5: #e5a50a;
|
||||||
|
--adwaita-orange-1: #ffbe6f;
|
||||||
|
--adwaita-orange-2: #ffa348;
|
||||||
|
--adwaita-orange-3: #ff7800;
|
||||||
|
--adwaita-orange-4: #e66100;
|
||||||
|
--adwaita-orange-5: #c64600;
|
||||||
|
--adwaita-red-1: #f66151;
|
||||||
|
--adwaita-red-2: #ed333b;
|
||||||
|
--adwaita-red-3: #e01b24;
|
||||||
|
--adwaita-red-4: #c01c28;
|
||||||
|
--adwaita-red-5: #a51d2d;
|
||||||
|
--adwaita-purple-1: #dc8add;
|
||||||
|
--adwaita-purple-2: #c061cb;
|
||||||
|
--adwaita-purple-3: #9141ac;
|
||||||
|
--adwaita-purple-4: #813d9c;
|
||||||
|
--adwaita-purple-5: #613583;
|
||||||
|
--adwaita-brown-2: #b5835a;
|
||||||
|
--adwaita-brown-1: #cdab8f;
|
||||||
|
--adwaita-brown-3: #986a44;
|
||||||
|
--adwaita-brown-4: #865e3c;
|
||||||
|
--adwaita-brown-5: #63452c;
|
||||||
|
--adwaita-light-1: #ffffff;
|
||||||
|
--adwaita-light-2: #f6f5f4;
|
||||||
|
--adwaita-light-3: #deddda;
|
||||||
|
--adwaita-light-4: #c0bfbc;
|
||||||
|
--adwaita-light-5: #9a9996;
|
||||||
|
--adwaita-dark-1: #77767b;
|
||||||
|
--adwaita-dark-2: #5e5c64;
|
||||||
|
--adwaita-dark-3: #3d3846;
|
||||||
|
--adwaita-dark-4: #241f31;
|
||||||
|
--adwaita-dark-5: #000000; }
|
||||||
|
body.theme-dark {
|
||||||
|
--adwaita-accent-color: #78aeed;
|
||||||
|
--adwaita-accent-bg-color: #3584e4;
|
||||||
|
--adwaita-accent-fg-color: #ffffff;
|
||||||
|
--adwaita-destructive-color: #ff7b63;
|
||||||
|
--adwaita-destructive-bg-color: #c01c28;
|
||||||
|
--adwaita-destructive-fg-color: #ffffff;
|
||||||
|
--adwaita-success-color: #8ff0a4;
|
||||||
|
--adwaita-success-bg-color: #26a269;
|
||||||
|
--adwaita-success-fg-color: #ffffff;
|
||||||
|
--adwaita-warning-color: #f8e45c;
|
||||||
|
--adwaita-warning-bg-color: #cd9309;
|
||||||
|
--adwaita-warning-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-error-color: #ff7b63;
|
||||||
|
--adwaita-error-bg-color: #c01c28;
|
||||||
|
--adwaita-error-fg-color: #ffffff;
|
||||||
|
--adwaita-window-bg-color: #242424;
|
||||||
|
--adwaita-window-fg-color: #ffffff;
|
||||||
|
--adwaita-view-bg-color: #1e1e1e;
|
||||||
|
--adwaita-view-fg-color: #ffffff;
|
||||||
|
--adwaita-headerbar-bg-color: #303030;
|
||||||
|
--adwaita-headerbar-fg-color: #ffffff;
|
||||||
|
--adwaita-headerbar-border-color: #ffffff;
|
||||||
|
--adwaita-headerbar-backdrop-color: #242424;
|
||||||
|
--adwaita-headerbar-shade-color: rgba(0, 0, 0, 0.36);
|
||||||
|
--adwaita-card-bg-color: rgba(255, 255, 255, 0.08);
|
||||||
|
--adwaita-card-fg-color: #ffffff;
|
||||||
|
--adwaita-card-shade-color: rgba(0, 0, 0, 0.36);
|
||||||
|
--adwaita-dialog-bg-color: #383838;
|
||||||
|
--adwaita-dialog-fg-color: #ffffff;
|
||||||
|
--adwaita-popover-bg-color: #383838;
|
||||||
|
--adwaita-popover-fg-color: #ffffff;
|
||||||
|
--adwaita-popover-shader-color: rgba(0, 0, 0, 0.36);
|
||||||
|
--adwaita-shade-color: rgba(0, 0, 0, 0.36);
|
||||||
|
--adwaita-scrollbar-outline-color: rgba(0, 0, 0, 0.5); }
|
||||||
|
body.theme-light {
|
||||||
|
--adwaita-accent-color: #1c71d8;
|
||||||
|
--adwaita-accent-bg-color: #3584e4;
|
||||||
|
--adwaita-accent-fg-color: #ffffff;
|
||||||
|
--adwaita-destructive-color: #c01c28;
|
||||||
|
--adwaita-destructive-bg-color: #e01b24;
|
||||||
|
--adwaita-destructive-fg-color: #ffffff;
|
||||||
|
--adwaita-success-color: #1b8553;
|
||||||
|
--adwaita-success-bg-color: #2ec27e;
|
||||||
|
--adwaita-success-fg-color: #ffffff;
|
||||||
|
--adwaita-warning-color: #9c6e03;
|
||||||
|
--adwaita-warning-bg-color: #e5a50a;
|
||||||
|
--adwaita-warning-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-error-color: #c01c28;
|
||||||
|
--adwaita-error-bg-color: #e01b24;
|
||||||
|
--adwaita-error-fg-color: #ffffff;
|
||||||
|
--adwaita-window-bg-color: #fafafa;
|
||||||
|
--adwaita-window-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-view-bg-color: #ffffff;
|
||||||
|
--adwaita-view-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-headerbar-bg-color: #ffffff;
|
||||||
|
--adwaita-headerbar-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-headerbar-border-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-headerbar-backdrop-color: #fafafa;
|
||||||
|
--adwaita-headerbar-shade-color: rgba(0, 0, 0, 0.12);
|
||||||
|
--adwaita-card-bg-color: #ffffff;
|
||||||
|
--adwaita-card-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-card-shade-color: rgba(0, 0, 0, 0.07);
|
||||||
|
--adwaita-dialog-bg-color: #ffffff;
|
||||||
|
--adwaita-dialog-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-popover-bg-color: #fafafa;
|
||||||
|
--adwaita-popover-fg-color: rgba(0, 0, 0, 0.8);
|
||||||
|
--adwaita-popover-shader-color: rgba(0, 0, 0, 0.07);
|
||||||
|
--adwaita-shade-color: rgba(0, 0, 0, 0.07);
|
||||||
|
--adwaita-scrollbar-outline-color: #ffffff; }
|
||||||
|
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux,
|
||||||
|
body.adwaita-colors-always,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux {
|
||||||
|
--titlebar-background: var(--adwaita-headerbar-backdrop-color);
|
||||||
|
--titlebar-background-focused: var(--adwaita-headerbar-bg-color);
|
||||||
|
--titlebar-text-color-focused: var(--adwaita-headerbar-fg-color);
|
||||||
|
--text-normal: var(--adwaita-view-fg-color); }
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.is-focused .sidebar-toggle-button,
|
||||||
|
body.adwaita-colors-always.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body.adwaita-colors-always.is-focused .sidebar-toggle-button,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.is-focused .sidebar-toggle-button {
|
||||||
|
--icon-color: var(--adwaita-headerbar-fg-color);
|
||||||
|
--icon-color-hover: var(--adwaita-headerbar-fg-color);
|
||||||
|
--icon-color-focused: var(--adwaita-headerbar-fg-color);
|
||||||
|
--tab-text-color-focused: var(--adwaita-headerbar-fg-color);
|
||||||
|
--tab-text-color-focused-active-current: var(--adwaita-headerbar-fg-color); }
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.theme-dark,
|
||||||
|
body.adwaita-colors-always.theme-dark,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.theme-dark {
|
||||||
|
--titlebar-text-color: #919191;
|
||||||
|
--icon-color: #929292;
|
||||||
|
--icon-color-hover: #929292;
|
||||||
|
--icon-color-focused: #929292;
|
||||||
|
--tab-text-color: #929292;
|
||||||
|
--tab-text-color-focused: #8a8a8a;
|
||||||
|
--tab-text-color-focused-active-current: #8a8a8a;
|
||||||
|
--background-modifier-hover: #323232; }
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.theme-dark.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.theme-dark.is-focused .sidebar-toggle-button,
|
||||||
|
body.adwaita-colors-always.theme-dark.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body.adwaita-colors-always.theme-dark.is-focused .sidebar-toggle-button,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.theme-dark.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.theme-dark.is-focused .sidebar-toggle-button {
|
||||||
|
--background-modifier-hover: #464646; }
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.theme-light,
|
||||||
|
body.adwaita-colors-always.theme-light,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.theme-light {
|
||||||
|
--titlebar-text-color: #8c8c8c;
|
||||||
|
--icon-color: #939393;
|
||||||
|
--icon-color-hover: #939393;
|
||||||
|
--icon-color-focused: #939393;
|
||||||
|
--tab-text-color: #939393;
|
||||||
|
--tab-text-color-focused: #939393;
|
||||||
|
--tab-text-color-focused-active-current: #939393;
|
||||||
|
--background-modifier-hover: #f0f0f0; }
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.theme-light.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux.theme-light.is-focused .sidebar-toggle-button,
|
||||||
|
body.adwaita-colors-always.theme-light.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body.adwaita-colors-always.theme-light.is-focused .sidebar-toggle-button,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.theme-light.is-focused .workspace-tabs.mod-top .workspace-tab-header-container,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux.theme-light.is-focused .sidebar-toggle-button {
|
||||||
|
--background-modifier-hover: #d8d8d8; }
|
||||||
|
body:not(.adwaita-colors-always, .adwaita-colors-linux-only, .adwaita-colors-never).mod-linux .titlebar-button.mod-logo:hover,
|
||||||
|
body.adwaita-colors-always .titlebar-button.mod-logo:hover,
|
||||||
|
body.adwaita-colors-linux-only.mod-linux .titlebar-button.mod-logo:hover {
|
||||||
|
background-color: inherit; }
|
||||||
|
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux,
|
||||||
|
body.adwaita-mod-always,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux {
|
||||||
|
--frame-right-space: calc(var(--adwaita-mod-scale) * 120px);
|
||||||
|
--adwaita-mod-foreground-focus: var(--adwaita-headerbar-fg-color); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.theme-dark,
|
||||||
|
body.adwaita-mod-always.theme-dark,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.theme-dark {
|
||||||
|
--adwaita-mod-background: #2e2e2e;
|
||||||
|
--adwaita-mod-background-focus: #444444;
|
||||||
|
--adwaita-mod-background-hover: #4f4f4f;
|
||||||
|
--adwaita-mod-background-active: #6e6e6e;
|
||||||
|
--adwaita-mod-foreground: #929292; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.theme-light,
|
||||||
|
body.adwaita-mod-always.theme-light,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.theme-light {
|
||||||
|
--adwaita-mod-background: #efefef;
|
||||||
|
--adwaita-mod-background-focus: #d8d8d8;
|
||||||
|
--adwaita-mod-background-hover: #cfcfcf;
|
||||||
|
--adwaita-mod-background-active: #b3b3b3;
|
||||||
|
--adwaita-mod-foreground: #949494; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-minimize-hide .titlebar-button-container.mod-right .titlebar-button.mod-minimize,
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-minimize-hide .titlebar-button-container.mod-right .titlebar-button.mod-minimize,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-minimize-hide .titlebar-button-container.mod-right .titlebar-button.mod-minimize {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-maximize-hide .titlebar-button-container.mod-right .titlebar-button.mod-maximize,
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-maximize-hide .titlebar-button-container.mod-right .titlebar-button.mod-maximize,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-maximize-hide .titlebar-button-container.mod-right .titlebar-button.mod-maximize {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-close-hide .titlebar-button-container.mod-right .titlebar-button.mod-close,
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-close-hide .titlebar-button-container.mod-right .titlebar-button.mod-close,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-close-hide .titlebar-button-container.mod-right .titlebar-button.mod-close {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide), body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide), body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide),
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide),
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide),
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide),
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide),
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide),
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide) {
|
||||||
|
--frame-right-space: calc(var(--adwaita-mod-scale) * (120px - 38px)); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide), body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide), body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide),
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide),
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide),
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide),
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide:not(.adwaita-window-button-close-hide),
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide:not(.adwaita-window-button-minimize-hide),
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-close-hide.adwaita-window-button-minimize-hide:not(.adwaita-window-button-maximize-hide) {
|
||||||
|
--frame-right-space: calc(var(--adwaita-mod-scale) * (120px - 38px - 38px)); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide,
|
||||||
|
body.adwaita-mod-always.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.adwaita-window-button-minimize-hide.adwaita-window-button-maximize-hide.adwaita-window-button-close-hide {
|
||||||
|
--frame-right-space: calc(var(--adwaita-mod-scale) * (120px - 38px - 38px - 38px)); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right {
|
||||||
|
transform: scale(var(--adwaita-mod-scale));
|
||||||
|
margin-right: var(--adwaita-mod-right-margin);
|
||||||
|
transform-origin: right; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button {
|
||||||
|
height: 24px;
|
||||||
|
width: 24px;
|
||||||
|
border-radius: 12px;
|
||||||
|
padding: 0;
|
||||||
|
margin: auto 0 auto 14px;
|
||||||
|
background: var(--adwaita-mod-background);
|
||||||
|
color: var(--adwaita-mod-foreground); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-minimize svg, body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-maximize svg, body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-close svg,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button.mod-minimize svg,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button.mod-maximize svg,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button.mod-close svg,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-minimize svg,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-maximize svg,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-close svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button::after,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button::after,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-minimize::after,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button.mod-minimize::after,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-minimize::after {
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-window-minimize-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-window-minimize-symbolic); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-maximize::after,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button.mod-maximize::after,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-maximize::after {
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-window-maximize-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-window-maximize-symbolic); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-close::after,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button.mod-close::after,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button.mod-close::after {
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-window-close-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-window-close-symbolic); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button:hover,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button:hover,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button:hover {
|
||||||
|
background: var(--adwaita-mod-background) !important; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .titlebar-button-container.mod-right .titlebar-button svg,
|
||||||
|
body.adwaita-mod-always .titlebar-button-container.mod-right .titlebar-button svg,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .titlebar-button-container.mod-right .titlebar-button svg {
|
||||||
|
width: 12px;
|
||||||
|
height: 12px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.is-focused .titlebar-button-container.mod-right .titlebar-button,
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.is-focused .modal-close-button,
|
||||||
|
body.adwaita-mod-always.is-focused .titlebar-button-container.mod-right .titlebar-button,
|
||||||
|
body.adwaita-mod-always.is-focused .modal-close-button,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.is-focused .titlebar-button-container.mod-right .titlebar-button,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.is-focused .modal-close-button {
|
||||||
|
background: var(--adwaita-mod-background-focus);
|
||||||
|
color: var(--adwaita-mod-foreground-focus); }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.is-focused .titlebar-button-container.mod-right .titlebar-button:hover,
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.is-focused .modal-close-button:hover,
|
||||||
|
body.adwaita-mod-always.is-focused .titlebar-button-container.mod-right .titlebar-button:hover,
|
||||||
|
body.adwaita-mod-always.is-focused .modal-close-button:hover,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.is-focused .titlebar-button-container.mod-right .titlebar-button:hover,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.is-focused .modal-close-button:hover {
|
||||||
|
background: var(--adwaita-mod-background-hover) !important; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.is-focused .titlebar-button-container.mod-right .titlebar-button:active,
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux.is-focused .modal-close-button:active,
|
||||||
|
body.adwaita-mod-always.is-focused .titlebar-button-container.mod-right .titlebar-button:active,
|
||||||
|
body.adwaita-mod-always.is-focused .modal-close-button:active,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.is-focused .titlebar-button-container.mod-right .titlebar-button:active,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux.is-focused .modal-close-button:active {
|
||||||
|
background: var(--adwaita-mod-background-active) !important; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .modal-close-button,
|
||||||
|
body.adwaita-mod-always .modal-close-button,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .modal-close-button {
|
||||||
|
height: 24px;
|
||||||
|
width: 24px;
|
||||||
|
border-radius: 12px;
|
||||||
|
color: var(--adwaita-mod-foreground);
|
||||||
|
background: var(--adwaita-mod-background);
|
||||||
|
transform: scale(var(--adwaita-mod-scale));
|
||||||
|
transform-origin: right; }
|
||||||
|
body:not(.adwaita-mod-always, .adwaita-mod-linux-only, .adwaita-mod-never).mod-linux .modal-close-button:before,
|
||||||
|
body.adwaita-mod-always .modal-close-button:before,
|
||||||
|
body.adwaita-mod-linux-only.mod-linux .modal-close-button:before {
|
||||||
|
content: '';
|
||||||
|
display: block;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto;
|
||||||
|
top: 50%;
|
||||||
|
position: absolute;
|
||||||
|
transform: translateY(-50%);
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-window-close-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-window-close-symbolic);
|
||||||
|
background-color: currentColor; }
|
||||||
|
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux,
|
||||||
|
body.adwaita-tabs-always,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux {
|
||||||
|
--tab-radius-active: 4px; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux:not(.adwaita-tabs-short),
|
||||||
|
body.adwaita-tabs-always:not(.adwaita-tabs-short),
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux:not(.adwaita-tabs-short) {
|
||||||
|
--tab-width: 10000px;
|
||||||
|
/* infinite width */
|
||||||
|
--tab-max-width: none; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux.theme-dark,
|
||||||
|
body.adwaita-tabs-always.theme-dark,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux.theme-dark {
|
||||||
|
--tab-background-active: #323232; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux.theme-dark.is-focused,
|
||||||
|
body.adwaita-tabs-always.theme-dark.is-focused,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux.theme-dark.is-focused {
|
||||||
|
--tab-background-active: #464646; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux.theme-light,
|
||||||
|
body.adwaita-tabs-always.theme-light,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux.theme-light {
|
||||||
|
--tab-background-active: #f0f0f0; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux.theme-light.is-focused,
|
||||||
|
body.adwaita-tabs-always.theme-light.is-focused,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux.theme-light.is-focused {
|
||||||
|
--tab-background-active: #d8d8d8; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .workspace-tab-header-container .workspace-tab-header-container-inner,
|
||||||
|
body.adwaita-tabs-always .workspace-tab-header-container .workspace-tab-header-container-inner,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .workspace-tab-header-container .workspace-tab-header-container-inner {
|
||||||
|
--tab-outline-width: 0; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .workspace-tab-header-container .workspace-tab-header-new-tab,
|
||||||
|
body.adwaita-tabs-always .workspace-tab-header-container .workspace-tab-header-new-tab,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .workspace-tab-header-container .workspace-tab-header-new-tab {
|
||||||
|
margin-right: var(--size-4-1); }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .workspace-tab-header-new-tab,
|
||||||
|
body.adwaita-tabs-always .workspace-tab-header-new-tab,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .workspace-tab-header-new-tab {
|
||||||
|
order: 1; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .workspace-tab-header-tab-list,
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .sidebar-toggle-button.mod-right,
|
||||||
|
body.adwaita-tabs-always .workspace-tab-header-tab-list,
|
||||||
|
body.adwaita-tabs-always .sidebar-toggle-button.mod-right,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .workspace-tab-header-tab-list,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .sidebar-toggle-button.mod-right {
|
||||||
|
order: 2; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header {
|
||||||
|
padding: 0;
|
||||||
|
margin: 5px 3px 5px 2px; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header.is-active,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header.is-active,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header.is-active {
|
||||||
|
color: var(--tab-text-color-focused); }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:before, body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:after,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:before,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:after,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:before,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:after {
|
||||||
|
content: none; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner::after,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner::after,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner::after {
|
||||||
|
right: -6px; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner-title,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner-title,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner-title {
|
||||||
|
padding-left: 20px;
|
||||||
|
text-align: center; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:last-child .workspace-tab-header-inner::after,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:last-child .workspace-tab-header-inner::after,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header:last-child .workspace-tab-header-inner::after {
|
||||||
|
content: none; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner-close-button,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner-close-button,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header .workspace-tab-header-inner-close-button {
|
||||||
|
opacity: 0;
|
||||||
|
display: flex; }
|
||||||
|
body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header.is-active .workspace-tab-header-inner-close-button, body:not(.adwaita-tabs-always, .adwaita-tabs-linux-only, .adwaita-tabs-never).mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header :hover .workspace-tab-header-inner-close-button,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header.is-active .workspace-tab-header-inner-close-button,
|
||||||
|
body.adwaita-tabs-always .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header :hover .workspace-tab-header-inner-close-button,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header.is-active .workspace-tab-header-inner-close-button,
|
||||||
|
body.adwaita-tabs-linux-only.mod-linux .mod-root .workspace-tabs:not(.mod-stacked) .workspace-tab-header :hover .workspace-tab-header-inner-close-button {
|
||||||
|
opacity: 1; }
|
||||||
|
|
||||||
|
body:not(.adwaita-font-always, .adwaita-font-linux-only, .adwaita-font-never).mod-linux,
|
||||||
|
body.adwaita-font-always,
|
||||||
|
body.adwaita-font-linux-only.mod-linux {
|
||||||
|
--titlebar-height: 45px;
|
||||||
|
--font-interface-theme: Cantarell;
|
||||||
|
--font-ui-small: 15px;
|
||||||
|
--h1-weight: 900; }
|
||||||
|
body:not(.adwaita-font-always, .adwaita-font-linux-only, .adwaita-font-never).mod-linux .titlebar-text,
|
||||||
|
body.adwaita-font-always .titlebar-text,
|
||||||
|
body.adwaita-font-linux-only.mod-linux .titlebar-text {
|
||||||
|
top: 10px;
|
||||||
|
height: auto; }
|
||||||
|
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux,
|
||||||
|
body.adwaita-icons-always,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux {
|
||||||
|
--titlebar-height: 45px;
|
||||||
|
--header-height: 46px; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux svg.logo-wireframe,
|
||||||
|
body.adwaita-icons-always svg.logo-wireframe,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux svg.logo-wireframe {
|
||||||
|
stroke-width: 45; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux.is-frameless:not(.is-hidden-frameless) .app-container,
|
||||||
|
body.adwaita-icons-always.is-frameless:not(.is-hidden-frameless) .app-container,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux.is-frameless:not(.is-hidden-frameless) .app-container {
|
||||||
|
margin-top: -9px;
|
||||||
|
height: calc(100% + 9px); }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .sidebar-toggle-button,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-new-tab,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-tab-list,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .mod-left-split .workspace-tabs .workspace-tab-header-container-inner,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .mod-right-split .workspace-tabs .workspace-tab-header-container-inner,
|
||||||
|
body.adwaita-icons-always .sidebar-toggle-button,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-new-tab,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-tab-list,
|
||||||
|
body.adwaita-icons-always .mod-left-split .workspace-tabs .workspace-tab-header-container-inner,
|
||||||
|
body.adwaita-icons-always .mod-right-split .workspace-tabs .workspace-tab-header-container-inner,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .sidebar-toggle-button,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-new-tab,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-tab-list,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .mod-left-split .workspace-tabs .workspace-tab-header-container-inner,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .mod-right-split .workspace-tabs .workspace-tab-header-container-inner {
|
||||||
|
margin-top: 0;
|
||||||
|
padding-top: 0;
|
||||||
|
padding-bottom: 0; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .mod-left-split .workspace-tabs .workspace-tab-header,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .mod-right-split .workspace-tabs .workspace-tab-header,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .sidebar-toggle-button .clickable-icon,
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tabs.mod-top .workspace-tab-header-container .clickable-icon,
|
||||||
|
body.adwaita-icons-always .mod-left-split .workspace-tabs .workspace-tab-header,
|
||||||
|
body.adwaita-icons-always .mod-right-split .workspace-tabs .workspace-tab-header,
|
||||||
|
body.adwaita-icons-always .sidebar-toggle-button .clickable-icon,
|
||||||
|
body.adwaita-icons-always .workspace-tabs.mod-top .workspace-tab-header-container .clickable-icon,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .mod-left-split .workspace-tabs .workspace-tab-header,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .mod-right-split .workspace-tabs .workspace-tab-header,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .sidebar-toggle-button .clickable-icon,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tabs.mod-top .workspace-tab-header-container .clickable-icon {
|
||||||
|
height: 34px;
|
||||||
|
min-width: 34px;
|
||||||
|
margin-top: auto;
|
||||||
|
margin-bottom: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .sidebar-toggle-button.mod-left .clickable-icon svg,
|
||||||
|
body.adwaita-icons-always .sidebar-toggle-button.mod-left .clickable-icon svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .sidebar-toggle-button.mod-left .clickable-icon svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .sidebar-toggle-button.mod-left .clickable-icon::after,
|
||||||
|
body.adwaita-icons-always .sidebar-toggle-button.mod-left .clickable-icon::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .sidebar-toggle-button.mod-left .clickable-icon::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-sidebar-show-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-sidebar-show-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .sidebar-toggle-button.mod-right .clickable-icon svg,
|
||||||
|
body.adwaita-icons-always .sidebar-toggle-button.mod-right .clickable-icon svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .sidebar-toggle-button.mod-right .clickable-icon svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .sidebar-toggle-button.mod-right .clickable-icon::after,
|
||||||
|
body.adwaita-icons-always .sidebar-toggle-button.mod-right .clickable-icon::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .sidebar-toggle-button.mod-right .clickable-icon::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-sidebar-show-right-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-sidebar-show-right-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-new-tab .clickable-icon svg,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-new-tab .clickable-icon svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-new-tab .clickable-icon svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-new-tab .clickable-icon::after,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-new-tab .clickable-icon::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-new-tab .clickable-icon::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-tab-new-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-tab-new-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-tab-list .clickable-icon svg,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-tab-list .clickable-icon svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-tab-list .clickable-icon svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-tab-list .clickable-icon::after,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-tab-list .clickable-icon::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-tab-list .clickable-icon::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-go-down-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-go-down-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-inner-close-button svg,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-inner-close-button svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-inner-close-button svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header-inner-close-button::after,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header-inner-close-button::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header-inner-close-button::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-window-close-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-window-close-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon svg,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon::after,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header[data-type="file-explorer"] .workspace-tab-header-inner-icon::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-folder-visiting-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-folder-visiting-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon svg,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon svg,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon svg {
|
||||||
|
display: none; }
|
||||||
|
body:not(.adwaita-icons-always, .adwaita-icons-linux-only, .adwaita-icons-never).mod-linux .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon::after,
|
||||||
|
body.adwaita-icons-always .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon::after,
|
||||||
|
body.adwaita-icons-linux-only.mod-linux .workspace-tab-header[data-type="search"] .workspace-tab-header-inner-icon::after {
|
||||||
|
content: '';
|
||||||
|
background-color: currentColor !important;
|
||||||
|
-webkit-mask-image: var(--adwaita-icon-folder-saved-search-symbolic);
|
||||||
|
mask-image: var(--adwaita-icon-folder-saved-search-symbolic);
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
margin: auto; }
|
||||||
199
content/notes/.obsidian/workspace.json
vendored
Normal file
@@ -0,0 +1,199 @@
|
|||||||
|
{
|
||||||
|
"main": {
|
||||||
|
"id": "5324373015726ba8",
|
||||||
|
"type": "split",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "da1c1c5ba8d6b94f",
|
||||||
|
"type": "tabs",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "ab03f7100c1ce0fb",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "markdown",
|
||||||
|
"state": {
|
||||||
|
"file": "drafts/hardware-tools.md",
|
||||||
|
"mode": "source",
|
||||||
|
"source": false
|
||||||
|
},
|
||||||
|
"icon": "lucide-file",
|
||||||
|
"title": "hardware-tools"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"direction": "vertical"
|
||||||
|
},
|
||||||
|
"left": {
|
||||||
|
"id": "eb9752450aad8905",
|
||||||
|
"type": "split",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "4162aa8f7241215d",
|
||||||
|
"type": "tabs",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "b73f137a8a755c19",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "file-explorer",
|
||||||
|
"state": {
|
||||||
|
"sortOrder": "alphabetical",
|
||||||
|
"autoReveal": false
|
||||||
|
},
|
||||||
|
"icon": "lucide-folder-closed",
|
||||||
|
"title": "Files"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "9326f66eb4ea3558",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "search",
|
||||||
|
"state": {
|
||||||
|
"query": "",
|
||||||
|
"matchingCase": false,
|
||||||
|
"explainSearch": false,
|
||||||
|
"collapseAll": false,
|
||||||
|
"extraContext": false,
|
||||||
|
"sortOrder": "alphabetical"
|
||||||
|
},
|
||||||
|
"icon": "lucide-search",
|
||||||
|
"title": "Search"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "22ea3aa7ebecbacb",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "bookmarks",
|
||||||
|
"state": {},
|
||||||
|
"icon": "lucide-bookmark",
|
||||||
|
"title": "Bookmarks"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"direction": "horizontal",
|
||||||
|
"width": 300
|
||||||
|
},
|
||||||
|
"right": {
|
||||||
|
"id": "f049c1d8215eafd9",
|
||||||
|
"type": "split",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "0455a82f86b09797",
|
||||||
|
"type": "tabs",
|
||||||
|
"children": [
|
||||||
|
{
|
||||||
|
"id": "3a41ad6c5fed23f5",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "backlink",
|
||||||
|
"state": {
|
||||||
|
"collapseAll": false,
|
||||||
|
"extraContext": false,
|
||||||
|
"sortOrder": "alphabetical",
|
||||||
|
"showSearch": false,
|
||||||
|
"searchQuery": "",
|
||||||
|
"backlinkCollapsed": false,
|
||||||
|
"unlinkedCollapsed": true
|
||||||
|
},
|
||||||
|
"icon": "links-coming-in",
|
||||||
|
"title": "Backlinks"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "4a36bf58b19c0cce",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "outgoing-link",
|
||||||
|
"state": {
|
||||||
|
"linksCollapsed": false,
|
||||||
|
"unlinkedCollapsed": true
|
||||||
|
},
|
||||||
|
"icon": "links-going-out",
|
||||||
|
"title": "Outgoing links"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "adbc09def111b239",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "tag",
|
||||||
|
"state": {
|
||||||
|
"sortOrder": "frequency",
|
||||||
|
"useHierarchy": true,
|
||||||
|
"showSearch": false,
|
||||||
|
"searchQuery": ""
|
||||||
|
},
|
||||||
|
"icon": "lucide-tags",
|
||||||
|
"title": "Tags"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"id": "91a2b2f8427bd50b",
|
||||||
|
"type": "leaf",
|
||||||
|
"state": {
|
||||||
|
"type": "outline",
|
||||||
|
"state": {
|
||||||
|
"followCursor": false,
|
||||||
|
"showSearch": false,
|
||||||
|
"searchQuery": ""
|
||||||
|
},
|
||||||
|
"icon": "lucide-list",
|
||||||
|
"title": "Outline"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"direction": "horizontal",
|
||||||
|
"width": 300,
|
||||||
|
"collapsed": true
|
||||||
|
},
|
||||||
|
"left-ribbon": {
|
||||||
|
"hiddenItems": {
|
||||||
|
"switcher:Open quick switcher": false,
|
||||||
|
"graph:Open graph view": false,
|
||||||
|
"canvas:Create new canvas": false,
|
||||||
|
"daily-notes:Open today's daily note": false,
|
||||||
|
"templates:Insert template": false,
|
||||||
|
"command-palette:Open command palette": false,
|
||||||
|
"obsidian-importer:Open Importer": false,
|
||||||
|
"table-editor-obsidian:Advanced Tables Toolbar": false
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"active": "ab03f7100c1ce0fb",
|
||||||
|
"lastOpenFiles": [
|
||||||
|
"drafts/nvim.md",
|
||||||
|
"drafts/rust.md",
|
||||||
|
"drafts/swift.md",
|
||||||
|
"drafts/TODO.md",
|
||||||
|
"drafts/Untitled.md",
|
||||||
|
"drafts/hardware-tools.md",
|
||||||
|
"drafts/macOS.md",
|
||||||
|
"ready/algorithms_and_data/index.md",
|
||||||
|
"ready/binary_operations/index.md",
|
||||||
|
"ready/cpu_architecture/index.md",
|
||||||
|
"ready/databases/index.md",
|
||||||
|
"ready/logic_gates/index.md",
|
||||||
|
"ready/memory/index.md",
|
||||||
|
"ready/tmux/index.md",
|
||||||
|
"ready/transistors/index.md",
|
||||||
|
"ready/c-language.md",
|
||||||
|
"ready/c-snippets.md",
|
||||||
|
"ready/compiling.md",
|
||||||
|
"ready/diodes.md",
|
||||||
|
"ready/encryption.md",
|
||||||
|
"ready/flask.md",
|
||||||
|
"ready/gdb.md",
|
||||||
|
"ready/git.md",
|
||||||
|
"ready/html.md",
|
||||||
|
"ready/http.md",
|
||||||
|
"ready/https-ssl-certs.md"
|
||||||
|
]
|
||||||
|
}
|
||||||
16
content/notes/drafts/TODO.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
---
|
||||||
|
draft: true
|
||||||
|
---
|
||||||
|
In draft folder? (checkbox)
|
||||||
|
- [x] Linux Architecture / Linux
|
||||||
|
- [x] Assembly
|
||||||
|
- [x] Rust
|
||||||
|
- [x] Swift
|
||||||
|
- [x] Lua
|
||||||
|
- [ ] JS
|
||||||
|
- [ ] CSS
|
||||||
|
- [ ] Firewall
|
||||||
|
- [x] macOS
|
||||||
|
- [ ] FreeBSD
|
||||||
|
- [x] Neovim, vim bindings, text editor
|
||||||
|
- [x] Hardware Debug/Repair Tools (maybe integrate JCionx page?)
|
||||||
8
content/notes/drafts/_Templates/base.md
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
title: "{{Title}}"
|
||||||
|
description:
|
||||||
|
draft: true
|
||||||
|
tags:
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
47
content/notes/drafts/assembly.md
Normal file
@@ -0,0 +1,47 @@
|
|||||||
|
---
|
||||||
|
tags:
|
||||||
|
- computer-science
|
||||||
|
- notes
|
||||||
|
author: TrudeEH
|
||||||
|
draft: true
|
||||||
|
showToc: true
|
||||||
|
title: Assembly
|
||||||
|
---
|
||||||
|
|
||||||
|
#todo
|
||||||
|
|
||||||
|
## Assembler/Compiler
|
||||||
|
|
||||||
|
- `gcc` GNU C Compiler (The package includes `as` (assembler) and `ld` (linker))
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
as <file.asm> -o <output.o> # Assemble
|
||||||
|
gcc -o <output_file> <output.o> -nostdlib -static # Link using gcc
|
||||||
|
ld <output.o> # Link using ld
|
||||||
|
```
|
||||||
|
|
||||||
|
## Hello World
|
||||||
|
|
||||||
|
```Assembly
|
||||||
|
.global _start
|
||||||
|
.intel_syntax noprefix
|
||||||
|
_start:
|
||||||
|
// sys_write (Print to stdout)
|
||||||
|
mov rax, 1
|
||||||
|
mov rdi, 1
|
||||||
|
lea rsi, [hello_world]
|
||||||
|
// Buffer length
|
||||||
|
mov rdx, 14
|
||||||
|
syscall
|
||||||
|
// sys_exit (safely end the program with a re turn code)
|
||||||
|
mov rax, 60
|
||||||
|
// Exit with code 0
|
||||||
|
mov rdi, 0
|
||||||
|
syscall
|
||||||
|
|
||||||
|
hello_world:
|
||||||
|
// ASCII, zero delimited
|
||||||
|
.asciz "Hello, World!\n"
|
||||||
|
```
|
||||||
|
|
||||||
|
To know which system calls we can execute and which values needed for the registers, refer to [this table](https://blog.rchapman.org/posts/Linux_System_Call_Table_for_x86_64/).
|
||||||
19
content/notes/drafts/hardware-tools.md
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
---
|
||||||
|
title: "hardware-tools"
|
||||||
|
description:
|
||||||
|
draft: true
|
||||||
|
tags:
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
Scrcpy
|
||||||
|
|
||||||
|
scrcpy —otg
|
||||||
|
|
||||||
|
scrcpy
|
||||||
|
|
||||||
|
ADB
|
||||||
|
|
||||||
|
adb kill-server
|
||||||
62
content/notes/drafts/linux/index.md
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
---
|
||||||
|
tags:
|
||||||
|
- notes
|
||||||
|
- os
|
||||||
|
author: TrudeEH
|
||||||
|
draft: true
|
||||||
|
showToc: true
|
||||||
|
title: Linux
|
||||||
|
---
|
||||||
|
#todo
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
- Read error logs from the last session
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
sudo journalctl -b -1 -r -p err
|
||||||
|
```
|
||||||
|
|
||||||
|
## Disk Encryption
|
||||||
|
|
||||||
|
### Full Disk Encryption
|
||||||
|
|
||||||
|
The exact steps to fully encrypt a disk varies depending on the distribution, and can only be done at the install time.
|
||||||
|
On Ubuntu, for example, you can enable it in the "Advanced Features" toggle, at the disk selection stage.
|
||||||
|

|
||||||
|
|
||||||
|
### Encrypt Home Directory
|
||||||
|
|
||||||
|
```Bash
|
||||||
|
sudo apt install ecryptfs-utils cryptsetup # Install dependencies
|
||||||
|
# Create temporary admin account
|
||||||
|
sudo adduser temp_user # Add new user
|
||||||
|
sudo usermod -aG sudo temp_user # Give the new user sudo perms
|
||||||
|
```
|
||||||
|
|
||||||
|
Now, log out of the current user and switch to `temp_user`.
|
||||||
|
|
||||||
|
> [!important] Do not "switch accounts", the current user cannot be active while its home directory is being encrypted.
|
||||||
|
On the `temp_user` account, run the following command, then, log out and return to your user.
|
||||||
|
|
||||||
|
```Bash
|
||||||
|
sudo ecryptfs-migrate-home -u <username>
|
||||||
|
```
|
||||||
|
|
||||||
|
After logging in, you might be greeted with a pop-up with the title "Update Information". Click on "Run this action now" and provide your password.
|
||||||
|
If you already closed the pop-up, run the command below, and provide your password.
|
||||||
|
|
||||||
|
```Bash
|
||||||
|
encryptfs-unwrap-passphrase
|
||||||
|
```
|
||||||
|
|
||||||
|
You will receive a string of text. This will be your recovery password, needed to mount the home folder from another machine.
|
||||||
|
|
||||||
|
### Encrypt Swap
|
||||||
|
|
||||||
|
```Bash
|
||||||
|
swapon -s # Check if you have a swap partition
|
||||||
|
sudo ecryptfs-setup-swap # Encrypt swap
|
||||||
|
```
|
||||||
|
|
||||||
|
You may get an error: `swapon: cannot open /dev/mapper/cryptswap1: No such file or directory`. If you do, reboot and check if the swap partition is encrypted with the `swapon -s` command.
|
||||||
BIN
content/notes/drafts/linux_architecture/EXT2.png
Normal file
|
After Width: | Height: | Size: 3.2 MiB |
BIN
content/notes/drafts/linux_architecture/EXT3.png
Normal file
|
After Width: | Height: | Size: 2.5 MiB |
BIN
content/notes/drafts/linux_architecture/image5.png
Normal file
|
After Width: | Height: | Size: 43 KiB |
BIN
content/notes/drafts/linux_architecture/image6.png
Normal file
|
After Width: | Height: | Size: 60 KiB |
BIN
content/notes/drafts/linux_architecture/image7.png
Normal file
|
After Width: | Height: | Size: 155 KiB |
197
content/notes/drafts/linux_architecture/index.md
Normal file
@@ -0,0 +1,197 @@
|
|||||||
|
---
|
||||||
|
title: Linux Architecture
|
||||||
|
description:
|
||||||
|
date: 2025-02-17T08:32:33+00:00
|
||||||
|
draft: true
|
||||||
|
tags:
|
||||||
|
- computer-science
|
||||||
|
- os
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Kernel
|
||||||
|
|
||||||
|
Linux is a kernel: the core of an operative system. OSes that use the Linux kernel are called Linux Distros (Distributions).
|
||||||
|
A Kernel does the following:
|
||||||
|
- Executes first when the computer boots up and has full access to the hardware.
|
||||||
|
- Implements drivers to control peripherals, network devices and other resources.
|
||||||
|
- Runs other programs (userland software) and allows them to communicate with each other and with the hardware.
|
||||||
|
|
||||||
|
### Syscalls
|
||||||
|
|
||||||
|
To "ask" the kernel to perform a hardware task, or to access the file system or other resources, a program executes a syscall.
|
||||||
|
For example (x64 assembly):
|
||||||
|
|
||||||
|
```Assembly
|
||||||
|
// sys_write (Print to stdout)
|
||||||
|
mov rax, 1
|
||||||
|
mov rdi, 1
|
||||||
|
lea rsi, [hello_world]
|
||||||
|
// Buffer length
|
||||||
|
mov rdx, 14
|
||||||
|
syscall
|
||||||
|
```
|
||||||
|
|
||||||
|
This snippet implements a syscall that prints text to `stdout`, usually a terminal window.
|
||||||
|
|
||||||
|
### Processes
|
||||||
|
|
||||||
|
A program is an executable containing machine code. When a computer executes a program, it is first loaded into memory.
|
||||||
|

|
||||||
|
A program loaded in memory is a process.
|
||||||
|
|
||||||
|
> Note: For interpreted languages, the interpreter creates a process that executes the code directly.
|
||||||
|
|
||||||
|
### Modules
|
||||||
|
|
||||||
|
## Devices
|
||||||
|
|
||||||
|
### Device Drivers
|
||||||
|
|
||||||
|
Once a new device is plugged in, it attempts to call the Kernel, which identifies that device. The Kernel then loads the appropriate driver. Drivers are Kernel Modules used to interact with hardware. Once the required module is loaded, the Kernel calls the `udevadm` program, that creates a device file in the `/dev` directory.
|
||||||
|
Whenever there is a read/write operation to that device, the Kernel intercepts the request and calls the driver function instead, which implements that operation, and this is why a driver must implement all possible file operations.
|
||||||
|
Not all devices control hardware. For example, `/dev/random` generates a random number.
|
||||||
|
In the Linux Kernel, there are **Character Type Devices** and **Block Type Devices.**
|
||||||
|
A Character Device provides an endless stream or characters that can be read one at a time. This includes a keyboard and sensors, for example. Block Devices provide data as blocks of a defined size. These include disks and USB drives.
|
||||||
|
The only exceptions are Network Devices. Network data cannot be manipulated with file operations, so they are handled differently in the kernel.
|
||||||
|
|
||||||
|
### Network Devices
|
||||||
|
|
||||||
|
If a network card is plugged in, like any other device, it communicates with the Kernel, and the Kernel loads the appropriate Kernel Module that contains the driver. After that, the driver adds new entries to the Kernel's `NICs`, which are data structures stored in memory. The driver then creates configuration files in the `/sys/class/net/` directory. These are not device files, just configuration files. Different network cards can have multiple network interfaces, and even multiple ports to connect to an Ethernet cable, for example. Each interface gets its own folder, as they can have different configurations. Editing these files can change device configurations, but the only way to actually use these interfaces is by calling the Kernel directly. The Kernel can, in turn, create a virtual file in memory, which is then passed as an ID to the application. The application still receives it as a regular file ID (File Descriptor), like with any other device, but it works differently from the Kernel's perspective.
|
||||||
|
A GPU works similarly, and although the Kernel exposes these devices as files, they are not real files in the filesystem, as doing so would slow them down immensely.
|
||||||
|
|
||||||
|
### GPUs
|
||||||
|
|
||||||
|
At the startup time, a device file is generated for the GPU, like any other device.
|
||||||
|
When an application attempts to use the GPU, it first searches for a **Graphics API** to use with it. Examples include Vulkan, OpenGL and DirectX.
|
||||||
|
These APIs are code functions that forward the requests to a library such as `Mesa`.
|
||||||
|
|
||||||
|
`Mesa` then calls the Kernel's DRM (Direct Rendering Engine), which then calls the GPU driver to provide GPU capabilities.
|
||||||
|
The GPU still has a device file, which is used by the Kernel's DRM and Mesa, but most commands are delivered to the GPU driver directly.
|
||||||
|
|
||||||
|
## File Systems
|
||||||
|
|
||||||
|
> This section is heavily simplified and only covers `EXT2-4`.
|
||||||
|
|
||||||
|
### Concepts
|
||||||
|
|
||||||
|
- An `inode` provides the following information:
|
||||||
|
- Pointer to the file
|
||||||
|
- Creation date / Modified times
|
||||||
|
- Permissions
|
||||||
|
- A `directory (table)` contains the data before the current directory, the directory itself, and every file inside that directory.
|
||||||
|
- A `block` is the standard data unit for data in a hard drive. (Same size as memory pages. Ex `x86` CPU would use `4 KB` as the block size.)
|
||||||
|
|
||||||
|
|
||||||
|
### EXT2
|
||||||
|
|
||||||
|
Uses linked lists to store and lookup data, to keep the implementation of the filesystem itself as simple as possible. A simple filesystem makes it easier to repair (or skip) broken sectors on the hard drive.
|
||||||
|
|
||||||
|
#### Partition Layout
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### EXT3
|
||||||
|
|
||||||
|
#### Journal
|
||||||
|
|
||||||
|
`EXT3` implements a journal to act as a buffer after a crash. If any operation in the journal fails, because it was logged, the filesystem is able to recover and finish any pending operations quickly, and not lose data. `EXT2` had another issue, where if an opened directory were deleted, its `inode` wouldn't be deleted, leaving an orphaned, empty `inode` on the filesystem. If the program holding it was to be closed, the `inode` would be deleted, but in the event of a crash, the `inode` would be left in the filesystem, with no way to be freed.
|
||||||
|
|
||||||
|
#### HTrees
|
||||||
|
|
||||||
|
`EXT3` can also use a [index](ready/algorithms_and_data/index.md) instead of a linked list to store directory entries, making lookup times much faster. To build the HTree, all filenames are hashed and ordered, making the implementation more complex. This feature is disabled by default.
|
||||||
|
|
||||||
|
#### Scalability
|
||||||
|
|
||||||
|
Before, only one core could write to the *superblock* at a time, but `EXT3` updates `inode` and `block` count at the *block group descrip_t_or* level. The superblock is only updated through a system call: `statfs()`, or if the filesystem is unmounted.
|
||||||
|
`EXT3` also removed *big kernel locks* (deprecated feature that added the ability to freeze the kernel), and `sleep_on()`, which was replaced with `wait_event()`, preventing infinite loops.
|
||||||
|
These patches improved multicore performance by over 10x.
|
||||||
|
|
||||||
|
#### Preallocation / Reservation
|
||||||
|
|
||||||
|
Writing two files simultaneously can create noncontinuous space.
|
||||||
|

|
||||||
|
Because `EXT3` was designed to be used with HDDs, and separate portions of a file would slow down read speeds, `EXT3` implemented a preallocation/reservation system.
|
||||||
|
Inside the block bitmap, a few extra blocks were preallocated, storing both files in separate locations.
|
||||||
|

|
||||||
|
Instead of `EXT2`, where errors were corrected directly in the hard drive, `EXT3` reserves space for each specific `inode` in memory. In the event of a crash, all data would be stored in memory, and thus, not corrupting the HDD itself.
|
||||||
|
|
||||||
|
#### Online Resizer
|
||||||
|
|
||||||
|
`EXT3` also implements a protocol to support `LVM`, which allows for many disks to be used as a single partition. The largest possible space `EXT3` supports without patches is 16 GB.
|
||||||
|
|
||||||
|
#### Partition Layout
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### EXT4
|
||||||
|
|
||||||
|
#### Larger FS
|
||||||
|
|
||||||
|
`EXT3` can only support up to 16 TB. This is why `EXT4` was created.
|
||||||
|
Instead of ==32 bits== capacity to count blocks, `EXT4` divides each entry in the block descriptor table in two parts: An upper, and a lower entry. This lower entry extends the upper one, and since each supports up to ==32 bits==, the total supported block count (in the block descriptor table) rises to ==64 bits== (16 TB → 1,000,000,000 TB).
|
||||||
|
|
||||||
|
#### Extents
|
||||||
|
|
||||||
|
Instead of using block mapping (the filesystem allocates blocks individually for each file), which can lead to fragmentation, `EXT4` uses **extents**, a range of contiguous blocks, allocated to each file.
|
||||||
|
This uses a 48 bit system, which limits the FS capacity to 1 EB (1,000,000 TB).
|
||||||
|
Each extent can point to 128 MB of data, or 1 block group.
|
||||||
|
|
||||||
|
#### Compatibility
|
||||||
|
|
||||||
|
The `EXT4` driver supports `EXT3` as well, and so, the Linux kernel only uses the `EXT2` and `EXT4` drivers. The `EXT3` driver was removed as the new one is more performant.
|
||||||
|
|
||||||
|
#### HTrees
|
||||||
|
|
||||||
|
HTrees are now enabled by default, allowing up to 10 million subdirectories. However, `EXT4` implements a Three Level HTree, which can be enabled using the `large_dir` flag, and extends this limit to 2 Billion subdirectories.
|
||||||
|
|
||||||
|
#### Fast FS Check
|
||||||
|
|
||||||
|
The `big_itable_unused` field was added to the block descriptor table, allowing for fast filesystem checks and error correction, as well as some other improvements.
|
||||||
|
|
||||||
|
#### Multiblock Allocation
|
||||||
|
|
||||||
|
Previously, each block needed one call to be allocated. `EXT4` added support for multi-block allocation, which means that only one call is needed to allocate multiple blocks.
|
||||||
|
|
||||||
|
#### Delayed Allocation
|
||||||
|
|
||||||
|
Every write command is delayed for as long as possible, making it so that changes can be made in memory before they affect (and possible fragment) the actual drive.
|
||||||
|
|
||||||
|
#### Persistent PreAllocaition
|
||||||
|
|
||||||
|
The FS can now be called to preallocate an empty extent, so, once that file is populated, it stays as a contiguous space.
|
||||||
|
|
||||||
|
#### Metadata Checksums
|
||||||
|
|
||||||
|
Metadata is checked often, which helps find any issues with the file system, as each data structure is now properly 'documented'.
|
||||||
|
|
||||||
|
#### Better Times
|
||||||
|
|
||||||
|
- A creation time was added;
|
||||||
|
- The time precision was increased to nanoseconds instead of only seconds;
|
||||||
|
- The maximum supported time was increased as well (the standard UNIX time can only go up to 2038).
|
||||||
|
|
||||||
|
#### Extended Attributes
|
||||||
|
|
||||||
|
The filesystem can also be customized with new entries at the end of each `inode`.
|
||||||
|
|
||||||
|
#### Quotas
|
||||||
|
|
||||||
|
`EXT4` also supports adding limits to the size of a file, or even multiple files spread across the filesystem.
|
||||||
|
|
||||||
|
#### Barriers
|
||||||
|
|
||||||
|
Some hard drives have caches, which impact the journal, sometimes causing it to be written after the cache, which would create conflicts. To fix this issue, `EXT4` creates a 'barrier', preventing the disk from writing data before the journal is written to the drive. This feature impacts performance, but is also very needed.
|
||||||
|
|
||||||
|
#### Flexible Block Groups
|
||||||
|
|
||||||
|
Groups blocks together, isolating chucks to write data on, which helps make data more contiguous.
|
||||||
|
|
||||||
|
#### Meta Block Groups
|
||||||
|
|
||||||
|
If the whole filesystem was only a single block group, it would max out at 256 TB of total data. Using meta block groups, this limit is increased to 32 bits of block group descriptor, which makes the **total capacity of the filesystem** ==**512 PB**==.
|
||||||
|
|
||||||
|
#### Partition Layout
|
||||||
|
|
||||||
|
[https://maplecircuit.dev/linux/fs/ext/ext4.html](https://maplecircuit.dev/linux/fs/ext/ext4.html)
|
||||||
191
content/notes/drafts/lua.md
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
---
|
||||||
|
Status: Planned
|
||||||
|
Created by: Trude EH
|
||||||
|
tags:
|
||||||
|
- notes
|
||||||
|
- programming
|
||||||
|
author: TrudeEH
|
||||||
|
draft: true
|
||||||
|
searchHidden: false
|
||||||
|
showToc: true
|
||||||
|
title: Lua
|
||||||
|
---
|
||||||
|
Embedded language.
|
||||||
|
#todo
|
||||||
|
|
||||||
|
## Comments
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
-- One-Line comment
|
||||||
|
--[[ Multi-line
|
||||||
|
comment
|
||||||
|
--]]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Simple Literals
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local number = 5
|
||||||
|
local string = "hello, world"
|
||||||
|
local single = 'same as using \"'
|
||||||
|
local multiline = [[ Multi
|
||||||
|
line
|
||||||
|
string ]]
|
||||||
|
local yes, no = true, false
|
||||||
|
local nothing = nil
|
||||||
|
```
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
Functions can be stored as values.
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local function hello(name)
|
||||||
|
print("Hello", name)
|
||||||
|
end
|
||||||
|
local greet = function(name)
|
||||||
|
-- .. is string concaternation
|
||||||
|
print("Hello " .. name .. "!")
|
||||||
|
end
|
||||||
|
-- Calling a function
|
||||||
|
greet("Trude")
|
||||||
|
greet "Trude"
|
||||||
|
```
|
||||||
|
|
||||||
|
Functions can also return other functions.
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local high = function(value)
|
||||||
|
return function(value2)
|
||||||
|
return value + value2
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local add_one = high(1)
|
||||||
|
print("1 + 2 -> ", add_one(2))
|
||||||
|
```
|
||||||
|
|
||||||
|
Functions can return multiple values.
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local return_four_values = function()
|
||||||
|
return 1, 2, 3, 4
|
||||||
|
end
|
||||||
|
first, second, third = return_four_values() -- "4" was discarded.
|
||||||
|
```
|
||||||
|
|
||||||
|
Variable arguments.
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local variable_arguments = function( ... )
|
||||||
|
local arguments = { ... }
|
||||||
|
for i, v in ipairs({ ... }) do print(i, v) end
|
||||||
|
end
|
||||||
|
print(variable_arguments("this", "is", "a", "test"))
|
||||||
|
```
|
||||||
|
|
||||||
|
## Tables
|
||||||
|
|
||||||
|
Lua's only data structure. (Also used for maps and lists)
|
||||||
|
|
||||||
|
### As lists…
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local list = { "first", 2, false, function() print("Fourth") end }
|
||||||
|
print("Lua is 1-indexed:", list[1])
|
||||||
|
```
|
||||||
|
|
||||||
|
### As maps…
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local t = {
|
||||||
|
literal_key = "a string",
|
||||||
|
["an expression"] = "also works",
|
||||||
|
[function() end] = true
|
||||||
|
}
|
||||||
|
print("literal_key : ", t.literal_key)
|
||||||
|
print("an expression : ", t["an expression"]
|
||||||
|
print("function() end : ", t[function() end]) -- nothing will be printed here, because each function definition points to a different memory address.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Colon Functions
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local T = {}
|
||||||
|
function T.something(self, ... ) end
|
||||||
|
function T:something( ... ) end -- Same as the previous line
|
||||||
|
```
|
||||||
|
|
||||||
|
### Metatables
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local vector_mt = {}
|
||||||
|
vector_mt.__add = function(left, right)
|
||||||
|
return setmetatable({
|
||||||
|
left[1] + right[1],
|
||||||
|
left[2] + right[2],
|
||||||
|
left[3] + right[3]
|
||||||
|
}, vector_mt)
|
||||||
|
end
|
||||||
|
local v1 = setmetatable({ 3, 1, 5 }, vector_mt)
|
||||||
|
local v2 = setmetatable({ -3, 2, 2}, vector_mt)
|
||||||
|
local v3 = v1 + v2 -- normally would produce an error, but doesn't, since the __add keyword was used.
|
||||||
|
print(v3[1], v3[2], v3[3])
|
||||||
|
```
|
||||||
|
|
||||||
|
## Control Flow
|
||||||
|
|
||||||
|
### For
|
||||||
|
|
||||||
|
#### Lists
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local favs = { "ThePrimeagen", "ctt", "NoBoilerplate" }
|
||||||
|
for index = 1, \#favs do -- # is the length operator (does not work on maps!)
|
||||||
|
print(index, favs[index])
|
||||||
|
end
|
||||||
|
for index, value in ipairs(favs) do -- ipairs return the index and values of that index
|
||||||
|
print(index, value)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Maps
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local favs = { ThePrimeagen = 9.5, NoBoilerplate = "N/A" }
|
||||||
|
for key, value in pairs(favs) do -- pairs return the index and values of that key
|
||||||
|
print(key, value)
|
||||||
|
end
|
||||||
|
```
|
||||||
|
|
||||||
|
### If
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
local function action(visit_page)
|
||||||
|
if visit_page then
|
||||||
|
print("Opening new tab...")
|
||||||
|
else
|
||||||
|
print("Skipping...")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- "falsey": nil, false
|
||||||
|
action() -- Same as: action(nil)
|
||||||
|
action(false)
|
||||||
|
-- Everything else is "truthy"
|
||||||
|
action(true)
|
||||||
|
action(0)
|
||||||
|
action({})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Modules
|
||||||
|
|
||||||
|
Modules are just files.
|
||||||
|
|
||||||
|
```Lua
|
||||||
|
-- module.lua
|
||||||
|
local M = {}
|
||||||
|
M.some_function = function() end
|
||||||
|
return M
|
||||||
|
-- main.lua
|
||||||
|
local something = require("module")
|
||||||
|
something.some_function()
|
||||||
|
```
|
||||||
63
content/notes/drafts/macOS.md
Normal file
@@ -0,0 +1,63 @@
|
|||||||
|
---
|
||||||
|
Status: In progress
|
||||||
|
Created by: Trude EH
|
||||||
|
tags:
|
||||||
|
- notes
|
||||||
|
- os
|
||||||
|
author: TrudeEH
|
||||||
|
draft: true
|
||||||
|
searchHidden: false
|
||||||
|
showToc: true
|
||||||
|
title: macOS
|
||||||
|
---
|
||||||
|
#todo
|
||||||
|
|
||||||
|
## System Data
|
||||||
|
|
||||||
|
System data is anything in the following locations:
|
||||||
|
- `/Library`
|
||||||
|
- `/System`
|
||||||
|
- `~Library`
|
||||||
|
- `/usr`
|
||||||
|
- `.hidden_files`
|
||||||
|
|
||||||
|
## Memory
|
||||||
|
|
||||||
|
- Physical Memory - Total system memory
|
||||||
|
- Memory Used
|
||||||
|
- App Memory - Memory used for apps
|
||||||
|
- Wired Memory - System memory
|
||||||
|
- Compressed - Memory used by apps, but compressed as it is not immediately needed
|
||||||
|
- Cached Files - Files saved in memory for faster launching
|
||||||
|
- Swap Used - Memory stored in the SSD
|
||||||
|
|
||||||
|
### Memory Pressure
|
||||||
|
|
||||||
|
A measurement of how well macOS is managing the available memory.
|
||||||
|
- Green/Low: Normal function; No tricks needed.
|
||||||
|
- Yellow/Medium: There is not enough memory as-is, so macOS is actively compressing and decompressing memory as needed.
|
||||||
|
- Red/High: Aside from compression, macOS is using the swap heavily.
|
||||||
|
|
||||||
|
## Troubleshooting
|
||||||
|
|
||||||
|
### System and Apps
|
||||||
|
|
||||||
|
|Description|Fix|
|
||||||
|
|---|---|
|
||||||
|
|Fix "App X is damaged and can't be opened."|`xattr -c <path/to/application.app>`|
|
||||||
|
|Disable the Dock autohide delay|Fix: <br> <br>`defaults write com.apple.dock autohide-delay -float 0; defaults write com.apple.dock autohide-time-modifier -int 0;killall Dock` <br> <br>Restore defaults: <br> <br>`defaults delete com.apple.Dock autohide-delay; killall Dock`|
|
||||||
|
|||
|
||||||
|
|||
|
||||||
|
|
||||||
|
### Gaming
|
||||||
|
|
||||||
|
|Issue / Error / Description|Fix|
|
||||||
|
|---|---|
|
||||||
|
|Improve Terraria performance (and some other games)|Add `/gldevice:Vulkan` as a launch argument (on Steam).|
|
||||||
|
|||
|
||||||
|
|
||||||
|
### Flash IMG File to Disk
|
||||||
|
|
||||||
|
1. `diskutil list` → Find the path to the device (`/dev/XXX`)
|
||||||
|
2. `diskutil unmount /dev/XXX` → Unmount the disk
|
||||||
|
3. `sudo dd if=image.img of=/dev/XXX bs=1M oflag=direct,sync status=progress`
|
||||||
14
content/notes/drafts/nvim.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
---
|
||||||
|
title: "nvim"
|
||||||
|
description:
|
||||||
|
draft: true
|
||||||
|
tags:
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## VIM Bindings
|
||||||
|
|
||||||
|
## Using Neovim
|
||||||
|
|
||||||
|
## Configuring Neovim
|
||||||
315
content/notes/drafts/rust.md
Normal file
@@ -0,0 +1,315 @@
|
|||||||
|
---
|
||||||
|
title: "rust"
|
||||||
|
description:
|
||||||
|
draft: true
|
||||||
|
tags:
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Vocabulary
|
||||||
|
|
||||||
|
|Command / Word|Action / Meaning|Example|
|
||||||
|
|---|---|---|
|
||||||
|
|Statement|Performs an action, but does not return a value.|Function definitions, code that ends with `;`.|
|
||||||
|
|Expression|Evaluate to a resultant value.|Tests, math.|
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
- Install Rust: `curl --proto '=https' --tlsv1.2 -sSf <https://sh.rustup.rs> | sh`
|
||||||
|
- `rustup`
|
||||||
|
- `rustc`
|
||||||
|
- `cargo`
|
||||||
|
|
||||||
|
## Hello World!
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main() {
|
||||||
|
println!("Hello world!");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Variables
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let x: i32; // A variable can only be used if it has been initialized (contains a value)
|
||||||
|
|
||||||
|
let y: i8 = 5; // All variables are constant by default.
|
||||||
|
let mut z = 1; // The mut keyword makes the variable mutable. (Explicit type annotation is not necessary, but recommended).
|
||||||
|
|
||||||
|
let (k, f); //Same as "let k; let f;"
|
||||||
|
|
||||||
|
let t = { // Initialize a variable as the result of an expression.
|
||||||
|
let squared = y * y;
|
||||||
|
squared
|
||||||
|
};
|
||||||
|
```
|
||||||
|
|
||||||
|
## Data Types
|
||||||
|
|
||||||
|
### Integer Types
|
||||||
|
|
||||||
|
|Length|Signed|Unsigned|Unsigned Decimal Length|
|
||||||
|
|---|---|---|---|
|
||||||
|
|8-bit|`i8`|`u8`|`0..=255`|
|
||||||
|
|16-bit|`i16`|`u16`|`0..=65535`|
|
||||||
|
|32-bit (default)|`i32`|`u32`|`0..=4294967295`|
|
||||||
|
|64-bit|`i64`|`u64`|`0..=18446744073709551615`|
|
||||||
|
|128-bit|`i128`|`u128`|`0..=340282366920938463463374607431768211455`|
|
||||||
|
|arch||||
|
||||||
|
|(Size of CPU architecture)|`isize`|`usize`|The size of a memory address.|
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let v: u16 = 32_u8 as u16; // Convert an u8 type to u16.
|
||||||
|
println!("{}", i8::MAX); // Print the largest possible value a data type can hold.
|
||||||
|
let a = 10_000; // _ is ignored, and is only used to help with readability.
|
||||||
|
let b = 1 + 0xff + 0o77 + 0b1111_1111; // Various numerical bases are supported.
|
||||||
|
|
||||||
|
println!("{}", type_of(&v));
|
||||||
|
```
|
||||||
|
|
||||||
|
### Floating Point Values
|
||||||
|
|
||||||
|
|Length|Signed|Unsigned|Unsigned Decimal Length|
|
||||||
|
|---|---|---|---|
|
||||||
|
|8-bit|`f8`|`u8`|`0..=255`|
|
||||||
|
|16-bit|`f16`|`u16`|`0..=65535`|
|
||||||
|
|32-bit (default)|`f32`|`u32`|`0..=4294967295`|
|
||||||
|
|64-bit|`f64`|`u64`|`0..=18446744073709551615`|
|
||||||
|
|128-bit|`f128`|`u128`|`0..=340282366920938463463374607431768211455`|
|
||||||
|
|
||||||
|
```rust
|
||||||
|
assert!(0.1 + 0.2 == 0.3); // False, floating point numbers are subject to imprecision.
|
||||||
|
assert!(0.1_f32 + 0.2 as f32 == 0.3_f32); // True. f32 is less precise. (Note: Remember that _ are optional and are ignored.)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Boolean Logic
|
||||||
|
|
||||||
|
|True|False|
|
||||||
|
|---|---|
|
||||||
|
|`true`|`false`|
|
||||||
|
|`1`|`0`|
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let _f: bool = false; // 1 byte
|
||||||
|
|
||||||
|
let t = false;
|
||||||
|
if !t { println!("t became true") }
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Boolean Operators
|
||||||
|
|
||||||
|
- `AND`
|
||||||
|
- `OR`
|
||||||
|
- `NOT`
|
||||||
|
|
||||||
|
#### Bitwise Operations
|
||||||
|
|
||||||
|
Each bit is considered a unit.
|
||||||
|
|
||||||
|
|AND|`&`|
|
||||||
|
|---|---|
|
||||||
|
|OR|`|
|
||||||
|
|XOR|`^`|
|
||||||
|
|LEFT SHIFT|`<<`|
|
||||||
|
|RIGHT SHIFT|`>>`|
|
||||||
|
|
||||||
|
### Characters
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let c1: char = 'a'; // 4 bytes
|
||||||
|
let c2: char = 'µ'; // Unicode is supported
|
||||||
|
```
|
||||||
|
|
||||||
|
### Unit Type
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let _v: () = (); // () is similar to null. It means nothing. Takes up 0 bytes.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Range
|
||||||
|
|
||||||
|
```rust
|
||||||
|
-3..2 // -3 to 1. 2 is excluded.
|
||||||
|
'a'..='z' // a to z. z is included.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Scope
|
||||||
|
|
||||||
|
A scope can be created anywhere in the program.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// Global Scope
|
||||||
|
let y = 2;
|
||||||
|
|
||||||
|
{
|
||||||
|
// Local Scope. x is not accessible outside this scope.
|
||||||
|
let x = 1;
|
||||||
|
println!("{} and {}", x, y);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If a variable inside the inner scope has the same name as one outside, the latter is shadowed.
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main() { // No output; Implicit "-> ()".
|
||||||
|
sum(3, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn sum(x: i32, y: i32) -> i32 { // Takes 2 numbers as input, and outputs another.
|
||||||
|
x + y;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn never_return() -> ! { // "-> !" A function that never returns to the caller. Either panics, or loops forever.
|
||||||
|
panic!() // Error.
|
||||||
|
unimplemented!() // Use if a function is not implemented yet.
|
||||||
|
todo!() // Incomplete.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Type annotation is required in function definitions.
|
||||||
|
|
||||||
|
## Ownership
|
||||||
|
|
||||||
|
- Each value has an owner.
|
||||||
|
- There can only be one owner at a time.
|
||||||
|
- When the owner goes out of scope, the value will be dropped.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
{
|
||||||
|
let s = "example";
|
||||||
|
| |
|
||||||
|
Owner Value
|
||||||
|
}
|
||||||
|
// Outside this scope, s is dropped from memory.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Borrowing
|
||||||
|
|
||||||
|
- Access data **without taking ownership** of it.
|
||||||
|
- When borrowing, you are taking a **reference** (pointer) to the data, not the value itself.
|
||||||
|
|
||||||
|
**Rules**
|
||||||
|
|
||||||
|
- At any given time, you can have either **one mutable reference** or **any number** of **immutable references**.
|
||||||
|
- References must **always be valid**.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main() {
|
||||||
|
let s1 = String::from("hello");
|
||||||
|
let len = calculate_length(&s1);
|
||||||
|
|
||||||
|
println!("The length of '{}' is {}.", s1, len);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn calculate_length(s: &String) -> usize {
|
||||||
|
s.len() // s is a pointer to s1
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Example mutable reference:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
fn main() {
|
||||||
|
let mut s = String::from("hello");
|
||||||
|
change(&mut s);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn change(some_string: &mut String) {
|
||||||
|
some_string.push_str(", world");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Get the address in memory:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let x = 5;
|
||||||
|
let p: &i32 = &x; // Reference to x, reads 5 by println!.
|
||||||
|
|
||||||
|
println!("The memory address of x is {:p}", p); // :p reads the raw reference value.
|
||||||
|
```
|
||||||
|
|
||||||
|
Dereference:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let x = 5;
|
||||||
|
let p: &i32 = &x; // Reference to x
|
||||||
|
assert_eq!(5, *p) // Go to the value p points to and read it.
|
||||||
|
```
|
||||||
|
|
||||||
|
The `ref` keyword is an alternate syntax to create a reference:
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let c = 'T';
|
||||||
|
let r1 = &c;
|
||||||
|
let ref r2 = c;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Compound Types
|
||||||
|
|
||||||
|
Data types made of other types.
|
||||||
|
|
||||||
|
### Strings
|
||||||
|
|
||||||
|
A `String` is mutable, and is stored on the *stack* with a pointer to the *heap,* where the value is stored.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let s1 = String::from("hello");
|
||||||
|
| |
|
||||||
|
Pointer Array stored on the heap
|
||||||
|
(usize)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Copy vs. Move
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// Copy a value
|
||||||
|
let x = 1;
|
||||||
|
let y = x;
|
||||||
|
|
||||||
|
// Move the pointer value.
|
||||||
|
let s1 = String::from("hello");
|
||||||
|
let s2 = s1;
|
||||||
|
```
|
||||||
|
|
||||||
|
Now `s2` also points to the same string as `s1`. This [is not allowed in rust](https://www.notion.so/Rust-14149cf14b4c80ed8f7be5c63490aac2?pvs=21), so `s1` will be dropped. (Passing a string pointer to a function makes the function the new owner of the string).
|
||||||
|
|
||||||
|
```rust
|
||||||
|
// Copy a string (Deep Copy)
|
||||||
|
let s1 = String::from("hello");
|
||||||
|
let s2 = s1.clone();
|
||||||
|
```
|
||||||
|
|
||||||
|
In this example, the value in the heap is copied, so both `s1` and `s2` have their own values, and only own their own instance of the string.
|
||||||
|
|
||||||
|
#### `String` Vs. `&str`
|
||||||
|
|
||||||
|
|Type|Mutability|Ownership|Efficiency|
|
||||||
|
|---|---|---|---|
|
||||||
|
|`String`|Mutable; heap|Owns its contents|`-`|
|
||||||
|
|`&str` (String Slice)|Immutable; stack|Does not own data|`+`|
|
||||||
|
|`"..."` (String Literal)|Immutable; static storage (Stored inside the compiled program)|Does not own data|`+`; Same as `&str`|
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let s1: String = String::from("hello");
|
||||||
|
let s2: &str = "Hello";
|
||||||
|
|
||||||
|
// Read String Slice
|
||||||
|
let read_string_slice = &s2[0..1]; // "he"
|
||||||
|
|
||||||
|
// Move str to heap to make it mutable.
|
||||||
|
let s: Box<str> = "hello, world".into(); // .into() converts to the variable type.
|
||||||
|
let str_again = &s;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Tuples
|
||||||
|
|
||||||
|
Store different data types.
|
||||||
|
|
||||||
|
```rust
|
||||||
|
let t: (String, Int) = (String::from("hello"), 14);
|
||||||
|
```
|
||||||
|
|
||||||
|
Reference: [](https://youtu.be/BpPEoZW5IiY?si=1ri40iKdXR4zwp0J&t=8461)[https://youtu.be/BpPEoZW5IiY?si=WiJX41VB55S7Tx17&t=5607](https://youtu.be/BpPEoZW5IiY?si=WiJX41VB55S7Tx17&t=5607)
|
||||||
491
content/notes/drafts/swift.md
Normal file
@@ -0,0 +1,491 @@
|
|||||||
|
---
|
||||||
|
title: "swift"
|
||||||
|
description:
|
||||||
|
draft: true
|
||||||
|
tags:
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
- Xcode & Xcode Command-line tools
|
||||||
|
|
||||||
|
## Hello World
|
||||||
|
|
||||||
|
In Swift, this line of code is a complete program.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
print("Hello, world!")
|
||||||
|
```
|
||||||
|
|
||||||
|
Unlike C, you don't need to import a separate library for functionality like outputting text or handling strings.
|
||||||
|
|
||||||
|
Code written at global scope is used as the entry point for the program, so you don't need a `main()` function.
|
||||||
|
|
||||||
|
Swift does not require a `;` at the end of every line.
|
||||||
|
|
||||||
|
## Simple Values
|
||||||
|
|
||||||
|
Use `let` to make a constant and `var` to make a variable.
|
||||||
|
|
||||||
|
The value of a constant doesn't need to be known at compile time, but you must assign it a value exactly once.
|
||||||
|
|
||||||
|
This means you can use constants to name a value that you determine once but use in many places.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
var myVariable = 42
|
||||||
|
myVariable = 50
|
||||||
|
|
||||||
|
let myConstant = 42
|
||||||
|
```
|
||||||
|
|
||||||
|
Data types don't always have to write the type explicitly. Providing a value when you create a constant or variable lets the compiler infer its type. In the example above, the compiler infers that `myVariable` is an integer because its initial value is an integer.
|
||||||
|
|
||||||
|
If the initial value doesn't provide enough information (or if there isn't an initial value), specify the type by writing it after the variable, separated by a colon.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let implicitInteger = 70
|
||||||
|
let implicitDouble = 70.0
|
||||||
|
|
||||||
|
let explicitDouble: Double = 70
|
||||||
|
```
|
||||||
|
|
||||||
|
Values are never implicitly converted to another type. If you need to convert a value to a different type, explicitly make an instance of the desired type.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let label = "The width is "
|
||||||
|
let width = 94
|
||||||
|
let widthLabel = label + String(width)
|
||||||
|
```
|
||||||
|
|
||||||
|
If the conversion to `String` from the last line is removed, the compiler throws an error:
|
||||||
|
|
||||||
|
```
|
||||||
|
Binary operator '+' cannot be applied to operands of type 'String' and 'Int'
|
||||||
|
```
|
||||||
|
|
||||||
|
There's also a simpler way to include values in strings:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let apples = 3
|
||||||
|
let oranges = 5
|
||||||
|
let appleSummary = "I have \\(apples) apples."
|
||||||
|
let fruitSummary = "I have \\(apples + oranges) pieces of fruit."
|
||||||
|
```
|
||||||
|
|
||||||
|
Use three double quotation marks (`"""`) for strings that take up multiple lines. Indentation at the start of each quoted line is removed, as long as it matches the indentation of the closing quotation marks. For example:
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let quotation = """
|
||||||
|
Even though there's whitespace to the left,
|
||||||
|
the actual lines aren't indented.
|
||||||
|
Except for this line.
|
||||||
|
Double quotes (") can appear without being escaped.
|
||||||
|
I still have \\(apples + oranges) pieces of fruit.
|
||||||
|
"""
|
||||||
|
```
|
||||||
|
|
||||||
|
Create arrays and dictionaries using brackets (`[]`), and access their elements by writing the index or key in brackets. A comma is allowed after the last element.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
var fruits = ["strawberries", "limes", "tangerines"]
|
||||||
|
fruits[1] = "grapes"
|
||||||
|
|
||||||
|
var occupations = [
|
||||||
|
"Malcolm": "Captain",
|
||||||
|
"Kaylee": "Mechanic",
|
||||||
|
]
|
||||||
|
occupations["Jayne"] = "Public Relations"
|
||||||
|
```
|
||||||
|
|
||||||
|
Arrays automatically grow as you add elements.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
fruits.append("blueberries")
|
||||||
|
print(fruits)
|
||||||
|
// Prints "["strawberries", "grapes", "tangerines", "blueberries"]"
|
||||||
|
```
|
||||||
|
|
||||||
|
You also use brackets to write an empty array or dictionary. For an array, write `[]`, and for a dictionary, write `[:]`.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
fruits = []
|
||||||
|
occupations = [:]
|
||||||
|
```
|
||||||
|
|
||||||
|
If you're assigning an empty array or dictionary to a new variable, or another place where there isn't any type information, you need to specify the type.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let emptyArray: [String] = []
|
||||||
|
let emptyDictionary: [String: Float] = [:]
|
||||||
|
```
|
||||||
|
|
||||||
|
## Control Flow
|
||||||
|
|
||||||
|
Use `if` and `switch` to make conditionals, and use `for`-`in`, `while`, and `repeat`-`while` to make loops.
|
||||||
|
|
||||||
|
Parentheses around the condition or loop variable are optional. Braces around the body are required.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let individualScores = [75, 43, 103, 87, 12]
|
||||||
|
var teamScore = 0
|
||||||
|
|
||||||
|
for score in individualScores {
|
||||||
|
if score > 50 {
|
||||||
|
teamScore += 3
|
||||||
|
} else {
|
||||||
|
teamScore += 1
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
print(teamScore)// Prints "11"
|
||||||
|
```
|
||||||
|
|
||||||
|
In an `if` statement, the conditional must be a Boolean expression — this means that code such as `if score { ... }` is an error, not an implicit comparison to zero.
|
||||||
|
|
||||||
|
You can write `if` or `switch` after the equal sign (`=`) of an assignment or after `return`, to choose a value based on the condition.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let scoreDecoration = if teamScore > 10 { "🎉" } else {""}
|
||||||
|
|
||||||
|
print("Score:", teamScore, scoreDecoration)// Prints "Score: 11 🎉"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use `if` and `let` together to work with values that might be missing. These values are represented as optionals. An optional value either contains a value or contains `nil` to indicate that a value is missing. Write a question mark (`?`) after the type of a value to mark the value as optional.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
var optionalString: String? = "Hello"
|
||||||
|
print(optionalString == nil)// Prints "false"
|
||||||
|
|
||||||
|
var optionalName: String? = "John Appleseed"
|
||||||
|
var greeting = "Hello!"
|
||||||
|
|
||||||
|
if let name = optionalName {
|
||||||
|
greeting = "Hello, \\(name)"
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
If the optional value is `nil`, the conditional is `false` and the code in braces is skipped. Otherwise, the optional value is unwrapped and assigned to the constant after `let`, which makes the unwrapped value available inside the block of code.
|
||||||
|
|
||||||
|
Another way to handle optional values is to provide a default value using the `??` operator. If the optional value is missing, the default value is used instead.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let nickname: String? = nil
|
||||||
|
let fullName: String = "John Appleseed"
|
||||||
|
|
||||||
|
let informalGreeting = "Hi \\(nickname ?? fullName)"
|
||||||
|
```
|
||||||
|
|
||||||
|
You can use a shorter spelling to unwrap a value, using the same name for that unwrapped value.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
if let nickname {
|
||||||
|
print("Hey, \\(nickname)")
|
||||||
|
}// Doesn't print anything, because nickname is nil.
|
||||||
|
```
|
||||||
|
|
||||||
|
Switches support any kind of data and a wide variety of comparison operations — they aren't limited to integers and tests for equality.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let vegetable = "red pepper"
|
||||||
|
|
||||||
|
switch vegetable {
|
||||||
|
case "celery":
|
||||||
|
print("Add some raisins and make ants on a log.")
|
||||||
|
case "cucumber", "watercress":
|
||||||
|
print("That would make a good tea sandwich.")
|
||||||
|
case let x where x.hasSuffix("pepper"):
|
||||||
|
print("Is it a spicy \\(x)?")
|
||||||
|
default:
|
||||||
|
print("Everything tastes good in soup.")
|
||||||
|
}// Prints "Is it a spicy red pepper?"
|
||||||
|
```
|
||||||
|
|
||||||
|
Notice how `let` can be used in a pattern to assign the value that matched the pattern to a constant.
|
||||||
|
|
||||||
|
After executing the code inside the switch case that matched, the program exits from the switch statement. Execution doesn't continue to the next case, so you don't need to explicitly break out of the switch at the end of each case's code.
|
||||||
|
|
||||||
|
You use `for`-`in` to iterate over items in a dictionary by providing a pair of names to use for each key-value pair. Dictionaries are an unordered collection, so their keys and values are iterated over in an arbitrary order.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
let interestingNumbers = [
|
||||||
|
"Prime": [2, 3, 5, 7, 11, 13],
|
||||||
|
"Fibonacci": [1, 1, 2, 3, 5, 8],
|
||||||
|
"Square": [1, 4, 9, 16, 25],
|
||||||
|
]
|
||||||
|
|
||||||
|
var largest = 0
|
||||||
|
for (_, numbers) in interestingNumbers {
|
||||||
|
for number in numbers {
|
||||||
|
if number > largest { largest = number }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
print(largest)// Prints "25"
|
||||||
|
```
|
||||||
|
|
||||||
|
The `_` character is a placeholder; It can be useful when it is not necessary to keep track of the loop iterations. It could be omitted in this example.
|
||||||
|
|
||||||
|
Use `while` to repeat a block of code until a condition changes. The condition of a loop can be at the end instead, ensuring that the loop is run at least once.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
var n = 2
|
||||||
|
while n < 100 {
|
||||||
|
n *= 2
|
||||||
|
}
|
||||||
|
print(n)// Prints "128"
|
||||||
|
|
||||||
|
var m = 2
|
||||||
|
repeat {
|
||||||
|
m *= 2
|
||||||
|
} while m < 100
|
||||||
|
print(m)// Prints "128"
|
||||||
|
```
|
||||||
|
|
||||||
|
If you change the condition from `m < 100` to `m < 0`, `while` and `repeat`-`while` behave differently, as `repeat`-`while` would still execute once, even if the condition was already false.
|
||||||
|
|
||||||
|
You can keep an index in a loop by using `..<` to make a range of indexes.
|
||||||
|
|
||||||
|
```swift
|
||||||
|
var total = 0
|
||||||
|
for i in 0..<4 { total += i}
|
||||||
|
print(total)// Prints "6"
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `..<` to make a range that omits its upper value, and use `...` to make a range that includes both values.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### [Functions and Closures](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Functions-and-Closures)
|
||||||
|
|
||||||
|
Use `func` to declare a function. Call a function by following its name with a list of arguments in parentheses. Use `->` to separate the parameter names and types from the function's return type.
|
||||||
|
|
||||||
|
`func greet(person: String, day: String) -> String { return "Hello \\(person), today is \\(day)."}greet(person: "Bob", day: "Tuesday")`
|
||||||
|
|
||||||
|
**Experiment** Remove the `day` parameter. Add a parameter to include today's lunch special in the greeting.
|
||||||
|
|
||||||
|
By default, functions use their parameter names as labels for their arguments. Write a custom argument label before the parameter name, or write `_` to use no argument label.
|
||||||
|
|
||||||
|
`func greet(_ person: String, on day: String) -> String { return "Hello \\(person), today is \\(day)."}greet("John", on: "Wednesday")`
|
||||||
|
|
||||||
|
Use a tuple to make a compound value — for example, to return multiple values from a function. The elements of a tuple can be referred to either by name or by number.
|
||||||
|
|
||||||
|
`func calculateStatistics(scores: [Int]) -> (min: Int, max: Int, sum: Int) { var min = scores[0] var max = scores[0] var sum = 0 for score in scores { if score > max { max = score } else if score < min { min = score } sum += score } return (min, max, sum)}let statistics = calculateStatistics(scores: [5, 3, 100, 3, 9])print(statistics.sum)// Prints "120"print(statistics.2)// Prints "120"`
|
||||||
|
|
||||||
|
Functions can be nested. Nested functions have access to variables that were declared in the outer function. You can use nested functions to organize the code in a function that's long or complex.
|
||||||
|
|
||||||
|
`func returnFifteen() -> Int { var y = 10 func add() { y += 5 } add() return y}returnFifteen()`
|
||||||
|
|
||||||
|
Functions are a first-class type. This means that a function can return another function as its value.
|
||||||
|
|
||||||
|
`func makeIncrementer() -> ((Int) -> Int) { func addOne(number: Int) -> Int { return 1 + number } return addOne}var increment = makeIncrementer()increment(7)`
|
||||||
|
|
||||||
|
A function can take another function as one of its arguments.
|
||||||
|
|
||||||
|
`func hasAnyMatches(list: [Int], condition: (Int) -> Bool) -> Bool { for item in list { if condition(item) { return true } } return false}func lessThanTen(number: Int) -> Bool { return number < 10}var numbers = [20, 19, 7, 12]hasAnyMatches(list: numbers, condition: lessThanTen)`
|
||||||
|
|
||||||
|
Functions are actually a special case of closures: blocks of code that can be called later. The code in a closure has access to things like variables and functions that were available in the scope where the closure was created, even if the closure is in a different scope when it's executed — you saw an example of this already with nested functions. You can write a closure without a name by surrounding code with braces (`{}`). Use `in` to separate the arguments and return type from the body.
|
||||||
|
|
||||||
|
`numbers.map({ (number: Int) -> Int in let result = 3 * number return result})`
|
||||||
|
|
||||||
|
**Experiment** Rewrite the closure to return zero for all odd numbers.
|
||||||
|
|
||||||
|
You have several options for writing closures more concisely. When a closure's type is already known, such as the callback for a delegate, you can omit the type of its parameters, its return type, or both. Single statement closures implicitly return the value of their only statement.
|
||||||
|
|
||||||
|
`let mappedNumbers = numbers.map({ number in 3 * number })print(mappedNumbers)// Prints "[60, 57, 21, 36]"`
|
||||||
|
|
||||||
|
You can refer to parameters by number instead of by name — this approach is especially useful in very short closures. A closure passed as the last argument to a function can appear immediately after the parentheses. When a closure is the only argument to a function, you can omit the parentheses entirely.
|
||||||
|
|
||||||
|
`let sortedNumbers = numbers.sorted { $0 > $1 }print(sortedNumbers)// Prints "[20, 19, 12, 7]"`
|
||||||
|
|
||||||
|
### [Objects and Classes](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Objects-and-Classes)
|
||||||
|
|
||||||
|
Use `class` followed by the class's name to create a class. A property declaration in a class is written the same way as a constant or variable declaration, except that it's in the context of a class. Likewise, method and function declarations are written the same way.
|
||||||
|
|
||||||
|
`class Shape { var numberOfSides = 0 func simpleDescription() -> String { return "A shape with \\(numberOfSides) sides." }}`
|
||||||
|
|
||||||
|
**Experiment** Add a constant property with `let`, and add another method that takes an argument.
|
||||||
|
|
||||||
|
Create an instance of a class by putting parentheses after the class name. Use dot syntax to access the properties and methods of the instance.
|
||||||
|
|
||||||
|
`var shape = Shape()shape.numberOfSides = 7var shapeDescription = shape.simpleDescription()`
|
||||||
|
|
||||||
|
This version of the `Shape` class is missing something important: an initializer to set up the class when an instance is created. Use `init` to create one.
|
||||||
|
|
||||||
|
`class NamedShape { var numberOfSides: Int = 0 var name: String init(name: String) { self.name = name } func simpleDescription() -> String { return "A shape with \\(numberOfSides) sides." }}`
|
||||||
|
|
||||||
|
Notice how `self` is used to distinguish the `name` property from the `name` argument to the initializer. The arguments to the initializer are passed like a function call when you create an instance of the class. Every property needs a value assigned — either in its declaration (as with `numberOfSides`) or in the initializer (as with `name`).
|
||||||
|
|
||||||
|
Use `deinit` to create a deinitializer if you need to perform some cleanup before the object is deallocated.
|
||||||
|
|
||||||
|
Subclasses include their superclass name after their class name, separated by a colon. There's no requirement for classes to subclass any standard root class, so you can include or omit a superclass as needed.
|
||||||
|
|
||||||
|
Methods on a subclass that override the superclass's implementation are marked with `override` — overriding a method by accident, without `override`, is detected by the compiler as an error. The compiler also detects methods with `override` that don't actually override any method in the superclass.
|
||||||
|
|
||||||
|
`class Square: NamedShape { var sideLength: Double init(sideLength: Double, name: String) { self.sideLength = sideLength super.init(name: name) numberOfSides = 4 } func area() -> Double { return sideLength * sideLength } override func simpleDescription() -> String { return "A square with sides of length \\(sideLength)." }}let test = Square(sideLength: 5.2, name: "my test square")test.area()test.simpleDescription()`
|
||||||
|
|
||||||
|
**Experiment** Make another subclass of `NamedShape` called `Circle` that takes a radius and a name as arguments to its initializer. Implement an `area()` and a `simpleDescription()` method on the `Circle` class.
|
||||||
|
|
||||||
|
In addition to simple properties that are stored, properties can have a getter and a setter.
|
||||||
|
|
||||||
|
`class EquilateralTriangle: NamedShape { var sideLength: Double = 0.0 init(sideLength: Double, name: String) { self.sideLength = sideLength super.init(name: name) numberOfSides = 3 } var perimeter: Double { get { return 3.0 * sideLength } set { sideLength = newValue / 3.0 } } override func simpleDescription() -> String { return "An equilateral triangle with sides of length \\(sideLength)." }}var triangle = EquilateralTriangle(sideLength: 3.1, name: "a triangle")print(triangle.perimeter)// Prints "9.3"triangle.perimeter = 9.9print(triangle.sideLength)// Prints "3.3000000000000003"`
|
||||||
|
|
||||||
|
In the setter for `perimeter`, the new value has the implicit name `newValue`. You can provide an explicit name in parentheses after `set`.
|
||||||
|
|
||||||
|
Notice that the initializer for the `EquilateralTriangle` class has three different steps:
|
||||||
|
|
||||||
|
1. Setting the value of properties that the subclass declares.
|
||||||
|
2. Calling the superclass's initializer.
|
||||||
|
3. Changing the value of properties defined by the superclass. Any additional setup work that uses methods, getters, or setters can also be done at this point.
|
||||||
|
|
||||||
|
If you don't need to compute the property but still need to provide code that's run before and after setting a new value, use `willSet` and `didSet`. The code you provide is run any time the value changes outside of an initializer. For example, the class below ensures that the side length of its triangle is always the same as the side length of its square.
|
||||||
|
|
||||||
|
`class TriangleAndSquare { var triangle: EquilateralTriangle { willSet { square.sideLength = newValue.sideLength } } var square: Square { willSet { triangle.sideLength = newValue.sideLength } } init(size: Double, name: String) { square = Square(sideLength: size, name: name) triangle = EquilateralTriangle(sideLength: size, name: name) }}var triangleAndSquare = TriangleAndSquare(size: 10, name: "another test shape")print(triangleAndSquare.square.sideLength)// Prints "10.0"print(triangleAndSquare.triangle.sideLength)// Prints "10.0"triangleAndSquare.square = Square(sideLength: 50, name: "larger square")print(triangleAndSquare.triangle.sideLength)// Prints "50.0"`
|
||||||
|
|
||||||
|
When working with optional values, you can write `?` before operations like methods, properties, and subscripting. If the value before the `?` is `nil`, everything after the `?` is ignored and the value of the whole expression is `nil`. Otherwise, the optional value is unwrapped, and everything after the `?` acts on the unwrapped value. In both cases, the value of the whole expression is an optional value.
|
||||||
|
|
||||||
|
`let optionalSquare: Square? = Square(sideLength: 2.5, name: "optional square")let sideLength = optionalSquare?.sideLength`
|
||||||
|
|
||||||
|
### [Enumerations and Structures](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Enumerations-and-Structures)
|
||||||
|
|
||||||
|
Use `enum` to create an enumeration. Like classes and all other named types, enumerations can have methods associated with them.
|
||||||
|
|
||||||
|
`enum Rank: Int { case ace = 1 case two, three, four, five, six, seven, eight, nine, ten case jack, queen, king func simpleDescription() -> String { switch self { case .ace: return "ace" case .jack: return "jack" case .queen: return "queen" case .king: return "king" default: return String(self.rawValue) } }}let ace = Rank.acelet aceRawValue = ace.rawValue`
|
||||||
|
|
||||||
|
**Experiment** Write a function that compares two `Rank` values by comparing their raw values.
|
||||||
|
|
||||||
|
By default, Swift assigns the raw values starting at zero and incrementing by one each time, but you can change this behavior by explicitly specifying values. In the example above, `Ace` is explicitly given a raw value of `1`, and the rest of the raw values are assigned in order. You can also use strings or floating-point numbers as the raw type of an enumeration. Use the `rawValue` property to access the raw value of an enumeration case.
|
||||||
|
|
||||||
|
Use the `init?(rawValue:)` initializer to make an instance of an enumeration from a raw value. It returns either the enumeration case matching the raw value or `nil` if there's no matching `Rank`.
|
||||||
|
|
||||||
|
`if let convertedRank = Rank(rawValue: 3) { let threeDescription = convertedRank.simpleDescription()}`
|
||||||
|
|
||||||
|
The case values of an enumeration are actual values, not just another way of writing their raw values. In fact, in cases where there isn't a meaningful raw value, you don't have to provide one.
|
||||||
|
|
||||||
|
`enum Suit { case spades, hearts, diamonds, clubs func simpleDescription() -> String { switch self { case .spades: return "spades" case .hearts: return "hearts" case .diamonds: return "diamonds" case .clubs: return "clubs" } }}let hearts = Suit.heartslet heartsDescription = hearts.simpleDescription()`
|
||||||
|
|
||||||
|
**Experiment** Add a `color()` method to `Suit` that returns "black" for spades and clubs, and returns "red" for hearts and diamonds.
|
||||||
|
|
||||||
|
Notice the two ways that the `hearts` case of the enumeration is referred to above: When assigning a value to the `hearts` constant, the enumeration case `Suit.hearts` is referred to by its full name because the constant doesn't have an explicit type specified. Inside the switch, the enumeration case is referred to by the abbreviated form `.hearts` because the value of `self` is already known to be a suit. You can use the abbreviated form anytime the value's type is already known.
|
||||||
|
|
||||||
|
If an enumeration has raw values, those values are determined as part of the declaration, which means every instance of a particular enumeration case always has the same raw value. Another choice for enumeration cases is to have values associated with the case — these values are determined when you make the instance, and they can be different for each instance of an enumeration case. You can think of the associated values as behaving like stored properties of the enumeration case instance. For example, consider the case of requesting the sunrise and sunset times from a server. The server either responds with the requested information, or it responds with a description of what went wrong.
|
||||||
|
|
||||||
|
`enum ServerResponse { case result(String, String) case failure(String)} let success = ServerResponse.result("6:00 am", "8:09 pm")let failure = ServerResponse.failure("Out of cheese.") switch success {case let .result(sunrise, sunset): print("Sunrise is at \\(sunrise) and sunset is at \\(sunset).")case let .failure(message): print("Failure... \\(message)")}// Prints "Sunrise is at 6:00 am and sunset is at 8:09 pm."`
|
||||||
|
|
||||||
|
**Experiment** Add a third case to `ServerResponse` and to the switch.
|
||||||
|
|
||||||
|
Notice how the sunrise and sunset times are extracted from the `ServerResponse` value as part of matching the value against the switch cases.
|
||||||
|
|
||||||
|
Use `struct` to create a structure. Structures support many of the same behaviors as classes, including methods and initializers. One of the most important differences between structures and classes is that structures are always copied when they're passed around in your code, but classes are passed by reference.
|
||||||
|
|
||||||
|
`struct Card { var rank: Rank var suit: Suit func simpleDescription() -> String { return "The \\(rank.simpleDescription()) of \\(suit.simpleDescription())" }}let threeOfSpades = Card(rank: .three, suit: .spades)let threeOfSpadesDescription = threeOfSpades.simpleDescription()`
|
||||||
|
|
||||||
|
**Experiment** Write a function that returns an array containing a full deck of cards, with one card of each combination of rank and suit.
|
||||||
|
|
||||||
|
### [Concurrency](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Concurrency)
|
||||||
|
|
||||||
|
Use `async` to mark a function that runs asynchronously.
|
||||||
|
|
||||||
|
`func fetchUserID(from server: String) async -> Int { if server == "primary" { return 97 } return 501}`
|
||||||
|
|
||||||
|
You mark a call to an asynchronous function by writing `await` in front of it.
|
||||||
|
|
||||||
|
`func fetchUsername(from server: String) async -> String { let userID = await fetchUserID(from: server) if userID == 501 { return "John Appleseed" } return "Guest"}`
|
||||||
|
|
||||||
|
Use `async let` to call an asynchronous function, letting it run in parallel with other asynchronous code. When you use the value it returns, write `await`.
|
||||||
|
|
||||||
|
`func connectUser(to server: String) async { async let userID = fetchUserID(from: server) async let username = fetchUsername(from: server) let greeting = await "Hello \\(username), user ID \\(userID)" print(greeting)}`
|
||||||
|
|
||||||
|
Use `Task` to call asynchronous functions from synchronous code, without waiting for them to return.
|
||||||
|
|
||||||
|
`Task { await connectUser(to: "primary")}// Prints "Hello Guest, user ID 97"`
|
||||||
|
|
||||||
|
Use task groups to structure concurrent code.
|
||||||
|
|
||||||
|
`let userIDs = await withTaskGroup(of: Int.self) { group in for server in ["primary", "secondary", "development"] { group.addTask { return await fetchUserID(from: server) } } var results: [Int] = [] for await result in group { results.append(result) } return results}`
|
||||||
|
|
||||||
|
Actors are similar to classes, except they ensure that different asynchronous functions can safely interact with an instance of the same actor at the same time.
|
||||||
|
|
||||||
|
`actor ServerConnection { var server: String = "primary" private var activeUsers: [Int] = [] func connect() async -> Int { let userID = await fetchUserID(from: server) // ... communicate with server ... activeUsers.append(userID) return userID }}`
|
||||||
|
|
||||||
|
When you call a method on an actor or access one of its properties, you mark that code with `await` to indicate that it might have to wait for other code that's already running on the actor to finish.
|
||||||
|
|
||||||
|
`let server = ServerConnection()let userID = await server.connect()`
|
||||||
|
|
||||||
|
### [Protocols and Extensions](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Protocols-and-Extensions)
|
||||||
|
|
||||||
|
Use `protocol` to declare a protocol.
|
||||||
|
|
||||||
|
`protocol ExampleProtocol { var simpleDescription: String { get } mutating func adjust()}`
|
||||||
|
|
||||||
|
Classes, enumerations, and structures can all adopt protocols.
|
||||||
|
|
||||||
|
`class SimpleClass: ExampleProtocol { var simpleDescription: String = "A very simple class." var anotherProperty: Int = 69105 func adjust() { simpleDescription += " Now 100% adjusted." }}var a = SimpleClass()a.adjust()let aDescription = a.simpleDescription struct SimpleStructure: ExampleProtocol { var simpleDescription: String = "A simple structure" mutating func adjust() { simpleDescription += " (adjusted)" }}var b = SimpleStructure()b.adjust()let bDescription = b.simpleDescription`
|
||||||
|
|
||||||
|
**Experiment** Add another requirement to `ExampleProtocol`. What changes do you need to make to `SimpleClass` and `SimpleStructure` so that they still conform to the protocol?
|
||||||
|
|
||||||
|
Notice the use of the `mutating` keyword in the declaration of `SimpleStructure` to mark a method that modifies the structure. The declaration of `SimpleClass` doesn't need any of its methods marked as mutating because methods on a class can always modify the class.
|
||||||
|
|
||||||
|
Use `extension` to add functionality to an existing type, such as new methods and computed properties. You can use an extension to add protocol conformance to a type that's declared elsewhere, or even to a type that you imported from a library or framework.
|
||||||
|
|
||||||
|
`extension Int: ExampleProtocol { var simpleDescription: String { return "The number \\(self)" } mutating func adjust() { self += 42 } }print(7.simpleDescription)// Prints "The number 7"`
|
||||||
|
|
||||||
|
**Experiment** Write an extension for the `Double` type that adds an `absoluteValue` property.
|
||||||
|
|
||||||
|
You can use a protocol name just like any other named type — for example, to create a collection of objects that have different types but that all conform to a single protocol. When you work with values whose type is a boxed protocol type, methods outside the protocol definition aren't available.
|
||||||
|
|
||||||
|
`let protocolValue: any ExampleProtocol = aprint(protocolValue.simpleDescription)// Prints "A very simple class. Now 100% adjusted."// print(protocolValue.anotherProperty) // Uncomment to see the error`
|
||||||
|
|
||||||
|
Even though the variable `protocolValue` has a runtime type of `SimpleClass`, the compiler treats it as the given type of `ExampleProtocol`. This means that you can't accidentally access methods or properties that the class implements in addition to its protocol conformance.
|
||||||
|
|
||||||
|
### [Error Handling](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Error-Handling)
|
||||||
|
|
||||||
|
You represent errors using any type that adopts the `Error` protocol.
|
||||||
|
|
||||||
|
`enum PrinterError: Error { case outOfPaper case noToner case onFire}`
|
||||||
|
|
||||||
|
Use `throw` to throw an error and `throws` to mark a function that can throw an error. If you throw an error in a function, the function returns immediately and the code that called the function handles the error.
|
||||||
|
|
||||||
|
`func send(job: Int, toPrinter printerName: String) throws -> String { if printerName == "Never Has Toner" { throw PrinterError.noToner } return "Job sent"}`
|
||||||
|
|
||||||
|
There are several ways to handle errors. One way is to use `do`-`catch`. Inside the `do` block, you mark code that can throw an error by writing `try` in front of it. Inside the `catch` block, the error is automatically given the name `error` unless you give it a different name.
|
||||||
|
|
||||||
|
`do { let printerResponse = try send(job: 1040, toPrinter: "Bi Sheng") print(printerResponse)} catch { print(error)}// Prints "Job sent"`
|
||||||
|
|
||||||
|
**Experiment** Change the printer name to `"Never Has Toner"`, so that the `send(job:toPrinter:)` function throws an error.
|
||||||
|
|
||||||
|
You can provide multiple `catch` blocks that handle specific errors. You write a pattern after `catch` just as you do after `case` in a switch.
|
||||||
|
|
||||||
|
`do { let printerResponse = try send(job: 1440, toPrinter: "Gutenberg") print(printerResponse)} catch PrinterError.onFire { print("I'll just put this over here, with the rest of the fire.")} catch let printerError as PrinterError { print("Printer error: \\(printerError).")} catch { print(error)}// Prints "Job sent"`
|
||||||
|
|
||||||
|
**Experiment** Add code to throw an error inside the `do` block. What kind of error do you need to throw so that the error is handled by the first `catch` block? What about the second and third blocks?
|
||||||
|
|
||||||
|
Another way to handle errors is to use `try?` to convert the result to an optional. If the function throws an error, the specific error is discarded and the result is `nil`. Otherwise, the result is an optional containing the value that the function returned.
|
||||||
|
|
||||||
|
`let printerSuccess = try? send(job: 1884, toPrinter: "Mergenthaler")let printerFailure = try? send(job: 1885, toPrinter: "Never Has Toner")`
|
||||||
|
|
||||||
|
Use `defer` to write a block of code that's executed after all other code in the function, just before the function returns. The code is executed regardless of whether the function throws an error. You can use `defer` to write setup and cleanup code next to each other, even though they need to be executed at different times.
|
||||||
|
|
||||||
|
`var fridgeIsOpen = falselet fridgeContent = ["milk", "eggs", "leftovers"] func fridgeContains(_ food: String) -> Bool { fridgeIsOpen = true defer { fridgeIsOpen = false } let result = fridgeContent.contains(food) return result}if fridgeContains("banana") { print("Found a banana")}print(fridgeIsOpen)// Prints "false"`
|
||||||
|
|
||||||
|
### [Generics](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/#Generics)
|
||||||
|
|
||||||
|
Write a name inside angle brackets to make a generic function or type.
|
||||||
|
|
||||||
|
`func makeArray<Item>(repeating item: Item, numberOfTimes: Int) -> [Item] { var result: [Item] = [] for _ in 0..<numberOfTimes { result.append(item) } return result}makeArray(repeating: "knock", numberOfTimes: 4)`
|
||||||
|
|
||||||
|
You can make generic forms of functions and methods, as well as classes, enumerations, and structures.
|
||||||
|
|
||||||
|
`// Reimplement the Swift standard library's optional typeenum OptionalValue<Wrapped> { case none case some(Wrapped)}var possibleInteger: OptionalValue<Int> = .nonepossibleInteger = .some(100)`
|
||||||
|
|
||||||
|
Use `where` right before the body to specify a list of requirements — for example, to require the type to implement a protocol, to require two types to be the same, or to require a class to have a particular superclass.
|
||||||
|
|
||||||
|
`func anyCommonElements<T: Sequence, U: Sequence>(_ lhs: T, _ rhs: U) -> Bool where T.Element: Equatable, T.Element == U.Element{ for lhsItem in lhs { for rhsItem in rhs { if lhsItem == rhsItem { return true } } } return false}anyCommonElements([1, 2, 3], [3])`
|
||||||
|
|
||||||
|
**Experiment** Modify the `anyCommonElements(_:_:)` function to make a function that returns an array of the elements that any two sequences have in common.
|
||||||
|
|
||||||
|
Writing `<T: Equatable>` is the same as writing `<T> ... where T: Equatable`.
|
||||||
|
|
||||||
|
## Sources
|
||||||
|
|
||||||
|
- [A Swift Tour | Documentation](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/guidedtour/)
|
||||||
BIN
content/notes/ready/algorithms_and_data/bigO.png
Normal file
|
After Width: | Height: | Size: 243 KiB |
498
content/notes/ready/algorithms_and_data/index.md
Normal file
@@ -0,0 +1,498 @@
|
|||||||
|
---
|
||||||
|
title: Algorithms & Data Structures
|
||||||
|
description:
|
||||||
|
draft: false
|
||||||
|
tags:
|
||||||
|
- c
|
||||||
|
- programming
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Time Complexity
|
||||||
|
|
||||||
|
The amount of steps required for an algorithm to execute.
|
||||||
|
|
||||||
|
### Big O Notation
|
||||||
|
|
||||||
|
Maximum time for `n` input size. (Upper bound - worst case)
|
||||||
|

|
||||||
|
|
||||||
|
### Omega Notation
|
||||||
|
|
||||||
|
Minimum time for `n` input size. (Lower bound)
|
||||||
|
- `Ω(n²)`
|
||||||
|
- `Ω(n log n)`
|
||||||
|
- `Ω(n)`
|
||||||
|
- `Ω(log n)`
|
||||||
|
- `Ω(1)`
|
||||||
|
|
||||||
|
> If both are the same, use `θ`
|
||||||
|
|
||||||
|
## Searching Algorithms
|
||||||
|
|
||||||
|
|Algorithm|Average Time Complexity|RAM|
|
||||||
|
|---|---|---|
|
||||||
|
|Linear Search|O(n) \| Ω(1)|0|
|
||||||
|
|Binary Search|O(log n) \| Ω(1)|0|
|
||||||
|
|
||||||
|
### Linear Search
|
||||||
|
|
||||||
|
Check every element until `n` is found.
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(void) {
|
||||||
|
int n = 1; // number to find
|
||||||
|
int numbers[] = {20, 500, 10, 5, 100, 1, 50};
|
||||||
|
const int numbersLength = 7;
|
||||||
|
for (int i = 0; i < numbersLength; i++) {
|
||||||
|
if (numbers[i] == n) {
|
||||||
|
printf("Found n\n");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("Not found\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Binary Search
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
int c;
|
||||||
|
int n = 10 // Number of elements in array
|
||||||
|
int array[] = {0, 1, 2, 3, 4, 5, 6, 7, 8 ,9}
|
||||||
|
int search = 2; // Number to find
|
||||||
|
int first = 0;
|
||||||
|
int last = n - 1;
|
||||||
|
int middle = (first+last)/2; // Average
|
||||||
|
while (first <= last) {
|
||||||
|
if (array[middle] < search)
|
||||||
|
first = middle + 1;
|
||||||
|
else if (array[middle] == search) {
|
||||||
|
printf("%d found at location %d.\n", search, middle+1);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
last = middle - 1;
|
||||||
|
middle = (first + last)/2;
|
||||||
|
}
|
||||||
|
if (first > last)
|
||||||
|
printf("Not found! %d isn't present in the list.\n", search);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Sorting Algorithms
|
||||||
|
|
||||||
|
|Algorithm|Average Time Complexity|RAM|Use If|
|
||||||
|
|---|---|---|---|
|
||||||
|
|Selection Sort|O(n²) \| Ω(n²)|1 var|Never|
|
||||||
|
|Bubble Sort|O(n²) \| Ω(n)|0||
|
||||||
|
|Insertion Sort|O(n²) (Faster if the data is kind of sorted)|0||
|
||||||
|
|Merge Sort|O(n log n) \| Ω(n log n)|More RAM|Large Arrays|
|
||||||
|
|Quick Sort|O(n log n)|Less RAM|Small arrays|
|
||||||
|
|
||||||
|
## Data Structures
|
||||||
|
|
||||||
|
### Queue (Concept)
|
||||||
|
|
||||||
|
First In, First Out
|
||||||
|
- enqueue - Add an item to the end of the line.
|
||||||
|
- dequeue - Remove an item from the beginning of the line.
|
||||||
|
|
||||||
|
### Stack (Concept)
|
||||||
|
|
||||||
|
Last In, First Out
|
||||||
|
The last item added will be used first, so the first ones added might never be used.
|
||||||
|
- push - Add an item to the top of the stack
|
||||||
|
- pop - Remove an item from the top of the stack
|
||||||
|
|
||||||
|
### Arrays
|
||||||
|
|
||||||
|
|Search|O(log n)|
|
||||||
|
|---|---|
|
||||||
|
|Multiple data types|No|
|
||||||
|
|Resizable|No|
|
||||||
|
|RAM Usage|Low|
|
||||||
|
|
||||||
|
```C
|
||||||
|
double prices[] = {5.0, 3.2, 13.0};
|
||||||
|
double values[5]; //Initialize an empty array, that can hold 5 items.
|
||||||
|
printf("%lf€", prices[0]);
|
||||||
|
printf("%d", sizeof(prices)); //3
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2D Arrays
|
||||||
|
|
||||||
|
```C
|
||||||
|
int numbers[2][3] = {
|
||||||
|
{1, 2, 3},
|
||||||
|
{4, 5, 6}
|
||||||
|
};
|
||||||
|
numbers[0][1]; //2
|
||||||
|
numbers[1][2]; //6
|
||||||
|
numbers[0][1] = 10; //Set [0][1] to 10.
|
||||||
|
// Note: Calculate the rows and columns automatically.
|
||||||
|
int rows = sizeof(numbers)/sizeof(numbers[0]);
|
||||||
|
int columns = sizeof(numbers[0])/sizeof(numbers[0][0]);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Array of Strings
|
||||||
|
|
||||||
|
```C
|
||||||
|
char cars[][10] = {"Mustang", "Corvette", "Camaro"};
|
||||||
|
//cars[0] = "Tesla"; ERROR! String arrays don't support item assignment.
|
||||||
|
strcpy(cars[0], "Tesla"); //Does the same, but <string.h> must be included.
|
||||||
|
```
|
||||||
|
|
||||||
|
### Resize Array
|
||||||
|
|
||||||
|
#### Manually
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdlib.h>
|
||||||
|
int *list = malloc(3 * sizeof(int));
|
||||||
|
// Works like an array
|
||||||
|
list[0] = 1;
|
||||||
|
list[1] = 2;
|
||||||
|
list[2] = 3;
|
||||||
|
//Same as
|
||||||
|
*list = 1;
|
||||||
|
*(list + 1) = 2;
|
||||||
|
*(list + 2) = 3;
|
||||||
|
// ...
|
||||||
|
// Add 1 extra byte to the array
|
||||||
|
int *tmp = malloc(4 * sizeof(int));
|
||||||
|
if (tmp == NULL) {
|
||||||
|
free(list);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < 3; i++){
|
||||||
|
tmp[i] = list[i];
|
||||||
|
}
|
||||||
|
tmp[3] = 4;
|
||||||
|
free(list);
|
||||||
|
list = tmp;
|
||||||
|
// ...
|
||||||
|
free(list);
|
||||||
|
return 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Realloc
|
||||||
|
|
||||||
|
```C
|
||||||
|
int *list = malloc(3 * sizeof(int));
|
||||||
|
list[0] = 1;
|
||||||
|
list[1] = 2;
|
||||||
|
list[2] = 3;
|
||||||
|
// ...
|
||||||
|
int *tmp = realloc(list, 4 * sizeof(int)); //tmp is only needed to verify if realloc was successful, if realloc was assigned to int and failed, the 3 bytes from the list would be lost as list = NULL.
|
||||||
|
if (tmp == NULL) {
|
||||||
|
free(list);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
list = tmp;
|
||||||
|
list[3] = 4;
|
||||||
|
// ...
|
||||||
|
free(list);
|
||||||
|
return 0;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Linked Lists
|
||||||
|
|
||||||
|
| Linked List | TC |
|
||||||
|
| --------------------- | ------ |
|
||||||
|
| Add element unordered | O(1) |
|
||||||
|
| Add element ordered | O(n) |
|
||||||
|
| Search | O(n) |
|
||||||
|
| Insert | O(n) |
|
||||||
|
| Multiple data types | Yes |
|
||||||
|
| Resizable | Yes |
|
||||||
|
| RAM Usage | Medium |
|
||||||
|
|
||||||
|
Each element has its value, and a pointer to the next element. The last element's pointer is `NULL`. (NULL == 0x0)
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
[N] -> [N] -> [N] -> [N] ...
|
||||||
|
```
|
||||||
|
|
||||||
|
```C
|
||||||
|
typedef struct node {
|
||||||
|
int number; // Value
|
||||||
|
struct node *next; // Pointer to the next node
|
||||||
|
} node;
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Unordered Linked List Example
|
||||||
|
|
||||||
|
Both code blocks are unsafe (if there's no memory, the program won't free)
|
||||||
|
|
||||||
|
```C
|
||||||
|
typedef struct node {
|
||||||
|
int number;
|
||||||
|
struct node *next;
|
||||||
|
} node;
|
||||||
|
int main(void) {
|
||||||
|
node *list = NULL;
|
||||||
|
node *n = malloc(sizeof(node)); // n points at the first node of the linked list.
|
||||||
|
(*n).number = 1; // First element = 1.
|
||||||
|
//Or
|
||||||
|
n->number = 1; // Same.
|
||||||
|
n->next = NULL; // Point to NULL so it won't point to a garbage value.
|
||||||
|
list = n;
|
||||||
|
node *n = malloc(sizeof(node)); // n points at the first node of the linked list.
|
||||||
|
n->number = 2;
|
||||||
|
n->next = list;
|
||||||
|
list = n;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
typedef struct node {
|
||||||
|
int number;
|
||||||
|
struct node *next;
|
||||||
|
} node;
|
||||||
|
int main(void) {
|
||||||
|
node *list = NULL;
|
||||||
|
int numbers[] = {1, 2, 3};
|
||||||
|
// Create linked list with the elements in the array.
|
||||||
|
for (int i = 0; i < 3; i++) {
|
||||||
|
node *n = malloc(sizeof(node));
|
||||||
|
if (n == NULL) return 1;
|
||||||
|
n->number = number;
|
||||||
|
n->next = NULL;
|
||||||
|
n->next = list;
|
||||||
|
list = n;
|
||||||
|
}
|
||||||
|
// Print all elements from linked list.
|
||||||
|
node *ptr = list;
|
||||||
|
while (ptr != NULL) {
|
||||||
|
printf("%i\\n", ptr->number);
|
||||||
|
ptr = ptr->next; // Borrow the value in the list->n, which has the next node address.
|
||||||
|
}
|
||||||
|
// Free the list's memory.
|
||||||
|
ptr = list;
|
||||||
|
while (ptr != NULL) {
|
||||||
|
node *next = ptr->next;
|
||||||
|
free(ptr);
|
||||||
|
ptr = next;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Trees
|
||||||
|
|
||||||
|
| Balanced | Unbalanced | TC |
|
||||||
|
| ------------------- | ---------- | ---- |
|
||||||
|
| Add element | O(n) | O(n) |
|
||||||
|
| Search | O(log n) | O(n) |
|
||||||
|
| Insert | O(log n) | O(n) |
|
||||||
|
| Multiple data types | Yes | Yes |
|
||||||
|
| Resizable | Yes | Yes |
|
||||||
|
| RAM Usage | High | High |
|
||||||
|
|
||||||
|
If organized correctly, allows for binary search.
|
||||||
|
Each node has 2 pointers.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
[N] - root / parent
|
||||||
|
/ \\
|
||||||
|
[N] [N] - parent and children
|
||||||
|
/ \\ / \\
|
||||||
|
[N] [N] [N] [N] - leaf / child
|
||||||
|
```
|
||||||
|
|
||||||
|
```C
|
||||||
|
typedef struct treenode {
|
||||||
|
int value;
|
||||||
|
struct treenode *left;
|
||||||
|
struct treenode *right;
|
||||||
|
} treenode;
|
||||||
|
treenode *createnode(int value) {
|
||||||
|
treenode* result = malloc(sizeof(treenode));
|
||||||
|
if (result != NULL) {
|
||||||
|
result->left = NULL;
|
||||||
|
result->right = NULL;
|
||||||
|
result->value = value;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
void printtabs(int numtabs){
|
||||||
|
for (int i=0; i < numtabs; i++){
|
||||||
|
printf("\\t");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
void printtree_rec(treenode *root, int level){
|
||||||
|
if (root == NULL) {
|
||||||
|
printtabs(level);
|
||||||
|
printf("----<empty>-----\\n");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Preordered
|
||||||
|
printtabs(level);
|
||||||
|
printf("value = %d\\n", root->value);
|
||||||
|
printtabs(level);
|
||||||
|
printf("left\\n");
|
||||||
|
printtree_rec(root->left, level + 1);
|
||||||
|
printtabs(level);
|
||||||
|
printf("right\\n");
|
||||||
|
printtree_rec(root->right, level + 1);
|
||||||
|
printtabs(level);
|
||||||
|
printf("done\\n");
|
||||||
|
}
|
||||||
|
void printtree(treenode *root) {
|
||||||
|
printtree_rec(root, 0);
|
||||||
|
}
|
||||||
|
int main(void){
|
||||||
|
treenode *n1 = createnode(10);
|
||||||
|
treenode *n2 = createnode(11);
|
||||||
|
treenode *n3 = createnode(12);
|
||||||
|
treenode *n4 = createnode(13);
|
||||||
|
treenode *n5 = createnode(14);
|
||||||
|
// n1 will be the root
|
||||||
|
n1->left = n2;
|
||||||
|
n1->right = n3;
|
||||||
|
n3->left = n4;
|
||||||
|
n4->right = n5;
|
||||||
|
printtree(n1);
|
||||||
|
free(n1);
|
||||||
|
free(n2);
|
||||||
|
free(n3);
|
||||||
|
free(n4);
|
||||||
|
free(n5);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Hash Tables
|
||||||
|
|
||||||
|
| Average | Worst | Best |
|
||||||
|
| ------------------- | --------- | --------- |
|
||||||
|
| Add element | O(1) | O(n) |
|
||||||
|
| Search | O(1) | O(n) |
|
||||||
|
| Insert | O(1) | O(n) |
|
||||||
|
| Multiple data types | Yes | Yes |
|
||||||
|
| Resizable | Yes | Yes |
|
||||||
|
| RAM Usage | Very High | Very High |
|
||||||
|
|
||||||
|
An array, in which every element is a linked list.
|
||||||
|
The array is used to 'choose' a linked list, and the linked list stores a dynamic number of elements.
|
||||||
|
|
||||||
|
```C
|
||||||
|
[0] -> [N] -> [N] -> [N]
|
||||||
|
[1] -> [N] -> [N]
|
||||||
|
[2] -> [N]
|
||||||
|
[3] -> [N] -> [N]
|
||||||
|
[4] -> [N] -> [N] -> [N]
|
||||||
|
[5] -> [N] -> [N]
|
||||||
|
0-5 - Array element
|
||||||
|
N - Linked list node
|
||||||
|
```
|
||||||
|
|
||||||
|
### Trie
|
||||||
|
|
||||||
|
| Trie | Average | Worst |
|
||||||
|
| ------------------- | -------------- | -------------- |
|
||||||
|
| Add element | O(1) | O(1) |
|
||||||
|
| Search | O(1) | O(1) |
|
||||||
|
| Insert | O(1) | O(1) |
|
||||||
|
| Multiple data types | Yes | Yes |
|
||||||
|
| Resizable | Yes | Yes |
|
||||||
|
| RAM Usage | Extremely High | Extremely High |
|
||||||
|
|
||||||
|
Tree, but every node is an array.
|
||||||
|
Useful to store words. Every element in an array is linked to the next letter.
|
||||||
|

|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <string.h>
|
||||||
|
#define ALPHABET_SIZE 26
|
||||||
|
struct TrieNode {
|
||||||
|
struct TrieNode *children[ALPHABET_SIZE];
|
||||||
|
bool isendofword;
|
||||||
|
};
|
||||||
|
typedef struct TrieNode TrieNode;
|
||||||
|
TrieNode *createNode() {
|
||||||
|
TrieNode *node = (TrieNode *)malloc(sizeof(TrieNode));
|
||||||
|
node->isendofword = false;
|
||||||
|
for (int i = 0; i < ALPHABET_SIZE; i++) {
|
||||||
|
node->children[i] = NULL;
|
||||||
|
}
|
||||||
|
return node;
|
||||||
|
}
|
||||||
|
void insert(TrieNode *root, const char *key) {
|
||||||
|
TrieNode *current = root;
|
||||||
|
for (int i = 0; i < strlen(key); i++) {
|
||||||
|
int index = key[i] - 'a';
|
||||||
|
if (current->children[index] == NULL) {
|
||||||
|
current->children[index] = createNode();
|
||||||
|
}
|
||||||
|
current = current->children[index];
|
||||||
|
}
|
||||||
|
current->isendofword = true;
|
||||||
|
}
|
||||||
|
bool search(TrieNode *root, const char *key) {
|
||||||
|
TrieNode *current = root;
|
||||||
|
for (int i = 0; i < strlen(key); i++) {
|
||||||
|
int index = key[i] - 'a';
|
||||||
|
if (current->children[index] == NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
current = current->children[index];
|
||||||
|
}
|
||||||
|
return (current != NULL && current->isendofword);
|
||||||
|
}
|
||||||
|
bool isempty(TrieNode *root) {
|
||||||
|
for (int i = 0; i < ALPHABET_SIZE; i++) {
|
||||||
|
if (root->children[i] != NULL) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
TrieNode *deleteHelper(TrieNode *root, const char *key, int depth) {
|
||||||
|
if (root == NULL) {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
if (depth == strlen(key)) {
|
||||||
|
if (root->isendofword) {
|
||||||
|
root->isendofword = false;
|
||||||
|
}
|
||||||
|
if (isempty(root)) {
|
||||||
|
free(root);
|
||||||
|
root = NULL;
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
int index = key[depth] - 'a';
|
||||||
|
root->children[index] = deleteHelper(root->children[index], key, depth + 1);
|
||||||
|
if (isempty(root) && !root->isendofword) {
|
||||||
|
free(root);
|
||||||
|
root = NULL;
|
||||||
|
}
|
||||||
|
return root;
|
||||||
|
}
|
||||||
|
void deletekey(TrieNode *root, const char *key) {
|
||||||
|
deleteHelper(root, key, 0);
|
||||||
|
}
|
||||||
|
int main() {
|
||||||
|
TrieNode *root = createNode();
|
||||||
|
insert(root, "example");
|
||||||
|
insert(root, "word");
|
||||||
|
printf("%s\n", search(root, "word") ? "Found" : "Not Found");
|
||||||
|
printf("%s\n", search(root, "example") ? "Found" : "Not Found");
|
||||||
|
printf("%s\n", search(root, "trude") ? "Found" : "Not Found");
|
||||||
|
deletekey(root, "word");
|
||||||
|
printf("%s\n", search(root, "word") ? "Found" : "Not Found");
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
BIN
content/notes/ready/algorithms_and_data/trie.png
Normal file
|
After Width: | Height: | Size: 143 KiB |
BIN
content/notes/ready/binary_operations/addition.png
Normal file
|
After Width: | Height: | Size: 8.2 KiB |
BIN
content/notes/ready/binary_operations/binarycalc.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
content/notes/ready/binary_operations/hand_addition1.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
content/notes/ready/binary_operations/hand_addition2.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
content/notes/ready/binary_operations/image68.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
content/notes/ready/binary_operations/image69.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
content/notes/ready/binary_operations/image70.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
content/notes/ready/binary_operations/image71.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
content/notes/ready/binary_operations/image72.png
Normal file
|
After Width: | Height: | Size: 33 KiB |
BIN
content/notes/ready/binary_operations/image73.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
content/notes/ready/binary_operations/image74.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
BIN
content/notes/ready/binary_operations/image75.png
Normal file
|
After Width: | Height: | Size: 17 KiB |
389
content/notes/ready/binary_operations/index.md
Normal file
@@ -0,0 +1,389 @@
|
|||||||
|
---
|
||||||
|
title: Binary Operations
|
||||||
|
description:
|
||||||
|
draft: false
|
||||||
|
tags:
|
||||||
|
- computer-science
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Binary
|
||||||
|
|
||||||
|
Binary is a base-2 numeral system: A simple way to represent numbers using only two states.
|
||||||
|
|
||||||
|
|Binary|Decimal|Hexadecimal|
|
||||||
|
|---|---|---|
|
||||||
|
|0000|00|00|
|
||||||
|
|0001|01|01|
|
||||||
|
|0010|02|02|
|
||||||
|
|0011|03|03|
|
||||||
|
|0100|04|04|
|
||||||
|
|0101|05|05|
|
||||||
|
|0110|06|06|
|
||||||
|
|0111|07|07|
|
||||||
|
|1000|08|08|
|
||||||
|
|1001|09|09|
|
||||||
|
|1010|10|0A|
|
||||||
|
|1011|11|0B|
|
||||||
|
|1100|12|0C|
|
||||||
|
|1101|13|0D|
|
||||||
|
|1110|14|0E|
|
||||||
|
|1111|15|0F|
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Speaking Binary
|
||||||
|
|
||||||
|
> The information in this section is non-standard, and mostly a curiosity.
|
||||||
|
|
||||||
|
You may struggle to pronounce large binary numbers, as saying a long list of 0s and 1s is very inefficient. Instead, we can do something like this:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
To be able to say any binary number, list the number, starting by the last digit:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
And pronounce the ones that correspond to a `1` bit.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Pronounce a Binary Number at a Glance
|
||||||
|
|
||||||
|
1. Break the number at its largest pair of bits.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2. Represent the left and right sides.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
In this example, there is a `two` in the order of magnitude `hex`.
|
||||||
|
|
||||||
|
3. Continue to represent the left and right sides recursively.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
The last number is `four`.
|
||||||
|
|
||||||
|
#### Decode a Spoken Binary Number
|
||||||
|
|
||||||
|
Starting with `two hex four`:
|
||||||
|
|
||||||
|
1. Find the largest power of two.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
2. The number is equal to the left side, times the order of magnitude, plus the right side.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Avoiding Repetition
|
||||||
|
|
||||||
|
Repetition can be avoided by combining some very common, small numbers:
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
These shortcuts essentially create a quaternary system to pronounce binary, but in this case, the result improves spoken efficiency by a lot.
|
||||||
|
|
||||||
|
## Arithmetic Operations
|
||||||
|
|
||||||
|
### Addition
|
||||||
|
|
||||||
|
Adding two numbers can be done using a simple, manual algorithm: By adding the last bit of both numbers first, carry if necessary, then move on to the next number, and so on.
|
||||||
|
|
||||||
|
| **+** | 0 | 1 |
|
||||||
|
| ------- | --- | ---- |
|
||||||
|
| 0 | 0 | 1 |
|
||||||
|
| 1 | 1 | 10 |
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> To add numbers more efficiently by hand, you can group bits together and memorize the patters, effectively doubling your speed.
|
||||||
|
>
|
||||||
|
> 
|
||||||
|
>
|
||||||
|
> To improve calculation speed even further, you can group more bits, and learn those patterns as well.
|
||||||
|
>
|
||||||
|
> 
|
||||||
|
|
||||||
|
#### Half Adder
|
||||||
|
|
||||||
|
Add 2, single-digit binary numbers.
|
||||||
|
|
||||||
|
| **A** | **B** | **Carry** | **Sum** |
|
||||||
|
| ----- | ----- | --------- | ------- |
|
||||||
|
| 0 | 0 | 0 | 0 |
|
||||||
|
| 0 | 1 | 0 | 1 |
|
||||||
|
| 1 | 0 | 0 | 1 |
|
||||||
|
| 1 | 1 | 1 | 0 |
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Full Adder
|
||||||
|
|
||||||
|
When adding 2 binary numbers, one operation might return a carry value, which the `half adder` can't accept, as it only has 2 inputs.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
To solve this issue, a `full adder` accepts 3 inputs.
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 8-Bit Adder
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Subtraction
|
||||||
|
|
||||||
|
Subtraction can result in negative numbers. Like how additions need a carry, subtraction needs a borrow.
|
||||||
|
|
||||||
|
#### Half Subtractor
|
||||||
|
|
||||||
|
Subtract 2, single-digit binary numbers.
|
||||||
|
|
||||||
|
| **A** | **B** | Diff | **Borrow** |
|
||||||
|
| ----- | ----- | ---- | ---------- |
|
||||||
|
| 0 | 0 | 0 | 0 |
|
||||||
|
| 0 | 1 | 1 | 1 |
|
||||||
|
| 1 | 0 | 1 | 0 |
|
||||||
|
| 1 | 1 | 0 | 0 |
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### Full Subtractor
|
||||||
|
|
||||||
|
A `full subtractor` accepts the borrow value, allowing us to chain results.
|
||||||
|
|
||||||
|
| **A** | **B** | **B**in | **Diff** | **B**out |
|
||||||
|
| ----- | ----- | ------- | -------- | -------- |
|
||||||
|
| 0 | 0 | 0 | 0 | 0 |
|
||||||
|
| 0 | 0 | 1 | 1 | 1 |
|
||||||
|
| 0 | 1 | 0 | 1 | 1 |
|
||||||
|
| 0 | 1 | 1 | 0 | 1 |
|
||||||
|
| 1 | 0 | 0 | 1 | 0 |
|
||||||
|
| 1 | 0 | 1 | 0 | 0 |
|
||||||
|
| 1 | 1 | 0 | 0 | 0 |
|
||||||
|
| 1 | 1 | 1 | 1 | 1 |
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
#### 8-Bit Subtractor
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Multiplication
|
||||||
|
|
||||||
|
Multiplication is also similar to its decimal counterpart, but because binary is so small compared to decimal, the steps are also much simpler.
|
||||||
|
|
||||||
|
First, multiply the top number to every digit of the bottom one, and then add the results together.
|
||||||
|
|
||||||
|
| X | 0 | 1 |
|
||||||
|
| --- | --- | --- |
|
||||||
|
| 0 | 0 | 0 |
|
||||||
|
| 1 | 0 | 1 |
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
||.|
|
||||||
|
x ||.
|
||||||
|
....
|
||||||
|
||.|
|
||||||
|
+ ||.|
|
||||||
|
|..|||.
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 2-Bit By 2-Bit Multiplier
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
### Division
|
||||||
|
|
||||||
|
1. Find the smallest part of the dividend greater than or equal to the ==divisor==.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
|.| ||..|
|
||||||
|
```
|
||||||
|
|
||||||
|
2. Write the first digit of ==the answer==, and ==copy the original divisor down==.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
|
|
||||||
|
|.| ||..|
|
||||||
|
|.|
|
||||||
|
```
|
||||||
|
|
||||||
|
3. Subtract ==the aligned dividend digits== by ==the digits under the dividend==.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
|
|
||||||
|
|.| ||..|
|
||||||
|
|.|
|
||||||
|
|
|
||||||
|
```
|
||||||
|
|
||||||
|
4. Lower ==the next dividend digit==.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
|
|
||||||
|
|.| ||..|
|
||||||
|
|.|
|
||||||
|
|.
|
||||||
|
```
|
||||||
|
|
||||||
|
5. Is ==the total== greater or equal to the ==divisor==? If so, add a `1` to the answer. If not, ==add a== ==`0`== ==to the answer== ==and return to step 4==.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
|.
|
||||||
|
|.| ||..|
|
||||||
|
|.|
|
||||||
|
|.
|
||||||
|
```
|
||||||
|
|
||||||
|
6. Return to step 2, until you reach the end of the number. If you reached the end, you found ==the answer==.
|
||||||
|
|
||||||
|
```Plain
|
||||||
|
|.|
|
||||||
|
|.| ||..|
|
||||||
|
|.|
|
||||||
|
|.|
|
||||||
|
|.|
|
||||||
|
.
|
||||||
|
```
|
||||||
|
|
||||||
|
### ASCII
|
||||||
|
|
||||||
|
Binary can also be used to represent characters.
|
||||||
|
|
||||||
|
| Dec | Hex | Binary | HTML | Char | Description |
|
||||||
|
| --- | --- | -------- | -------- | ----------- | ------------------------- |
|
||||||
|
| 0 | 00 | 00000000 | `�` | NUL | Null |
|
||||||
|
| 1 | 01 | 00000001 | `` | SOH | Start of Heading |
|
||||||
|
| 2 | 02 | 00000010 | `` | STX | Start of Text |
|
||||||
|
| 3 | 03 | 00000011 | `` | ETX | End of Text |
|
||||||
|
| 4 | 04 | 00000100 | `` | EOT | End of Transmission |
|
||||||
|
| 5 | 05 | 00000101 | `` | ENQ | Enquiry |
|
||||||
|
| 6 | 06 | 00000110 | `` | ACK | Acknowledge |
|
||||||
|
| 7 | 07 | 00000111 | `` | BEL | Bell |
|
||||||
|
| 8 | 08 | 00001000 | `` | BS | Backspace |
|
||||||
|
| 9 | 09 | 00001001 | `	` | HT | Horizontal Tab |
|
||||||
|
| 10 | 0A | 00001010 | ` ` | LF | Line Feed |
|
||||||
|
| 11 | 0B | 00001011 | `` | VT | Vertical Tab |
|
||||||
|
| 12 | 0C | 00001100 | `` | FF | Form Feed |
|
||||||
|
| 13 | 0D | 00001101 | ` ` | CR | Carriage Return |
|
||||||
|
| 14 | 0E | 00001110 | `` | SO | Shift Out |
|
||||||
|
| 15 | 0F | 00001111 | `` | SI | Shift In |
|
||||||
|
| 16 | 10 | 00010000 | `` | DLE | Data Link Escape |
|
||||||
|
| 17 | 11 | 00010001 | `` | DC1 | Device Control 1 |
|
||||||
|
| 18 | 12 | 00010010 | `` | DC2 | Device Control 2 |
|
||||||
|
| 19 | 13 | 00010011 | `` | DC3 | Device Control 3 |
|
||||||
|
| 20 | 14 | 00010100 | `` | DC4 | Device Control 4 |
|
||||||
|
| 21 | 15 | 00010101 | `` | NAK | Negative Acknowledge |
|
||||||
|
| 22 | 16 | 00010110 | `` | SYN | Synchronize |
|
||||||
|
| 23 | 17 | 00010111 | `` | ETB | End of Transmission Block |
|
||||||
|
| 24 | 18 | 00011000 | `` | CAN | Cancel |
|
||||||
|
| 25 | 19 | 00011001 | `` | EM | End of Medium |
|
||||||
|
| 26 | 1A | 00011010 | `` | SUB | Substitute |
|
||||||
|
| 27 | 1B | 00011011 | `` | ESC | Escape |
|
||||||
|
| 28 | 1C | 00011100 | `` | FS | File Separator |
|
||||||
|
| 29 | 1D | 00011101 | `` | GS | Group Separator |
|
||||||
|
| 30 | 1E | 00011110 | `` | RS | Record Separator |
|
||||||
|
| 31 | 1F | 00011111 | `` | US | Unit Separator |
|
||||||
|
| 32 | 20 | 00100000 | ` ` | space | Space |
|
||||||
|
| 33 | 21 | 00100001 | `!` | ! | exclamation mark |
|
||||||
|
| 34 | 22 | 00100010 | `"` | " | double quote |
|
||||||
|
| 35 | 23 | 00100011 | `#` | # | number |
|
||||||
|
| 36 | 24 | 00100100 | `$` | $ | dollar |
|
||||||
|
| 37 | 25 | 00100101 | `%` | % | percent |
|
||||||
|
| 38 | 26 | 00100110 | `&` | & | ampersand |
|
||||||
|
| 39 | 27 | 00100111 | `'` | ' | single quote |
|
||||||
|
| 40 | 28 | 00101000 | `(` | ( | left parenthesis |
|
||||||
|
| 41 | 29 | 00101001 | `)` | ) | right parenthesis |
|
||||||
|
| 42 | 2A | 00101010 | `*` | * | asterisk |
|
||||||
|
| 43 | 2B | 00101011 | `+` | + | plus |
|
||||||
|
| 44 | 2C | 00101100 | `,` | , | comma |
|
||||||
|
| 45 | 2D | 00101101 | `-` | - | minus |
|
||||||
|
| 46 | 2E | 00101110 | `.` | . | period |
|
||||||
|
| 47 | 2F | 00101111 | `/` | / | slash |
|
||||||
|
| 48 | 30 | 00110000 | `0` | 0 | zero |
|
||||||
|
| 49 | 31 | 00110001 | `1` | 1 | one |
|
||||||
|
| 50 | 32 | 00110010 | `2` | 2 | two |
|
||||||
|
| 51 | 33 | 00110011 | `3` | 3 | three |
|
||||||
|
| 52 | 34 | 00110100 | `4` | 4 | four |
|
||||||
|
| 53 | 35 | 00110101 | `5` | 5 | five |
|
||||||
|
| 54 | 36 | 00110110 | `6` | 6 | six |
|
||||||
|
| 55 | 37 | 00110111 | `7` | 7 | seven |
|
||||||
|
| 56 | 38 | 00111000 | `8` | 8 | eight |
|
||||||
|
| 57 | 39 | 00111001 | `9` | 9 | nine |
|
||||||
|
| 58 | 3A | 00111010 | `:` | : | colon |
|
||||||
|
| 59 | 3B | 00111011 | `;` | ; | semicolon |
|
||||||
|
| 60 | 3C | 00111100 | `<` | < | less than |
|
||||||
|
| 61 | 3D | 00111101 | `=` | = | equality sign |
|
||||||
|
| 62 | 3E | 00111110 | `>` | > | greater than |
|
||||||
|
| 63 | 3F | 00111111 | `?` | ? | question mark |
|
||||||
|
| 64 | 40 | 01000000 | `@` | @ | at sign |
|
||||||
|
| 65 | 41 | 01000001 | `A` | A | |
|
||||||
|
| 66 | 42 | 01000010 | `B` | B | |
|
||||||
|
| 67 | 43 | 01000011 | `C` | C | |
|
||||||
|
| 68 | 44 | 01000100 | `D` | D | |
|
||||||
|
| 69 | 45 | 01000101 | `E` | E | |
|
||||||
|
| 70 | 46 | 01000110 | `F` | F | |
|
||||||
|
| 71 | 47 | 01000111 | `G` | G | |
|
||||||
|
| 72 | 48 | 01001000 | `H` | H | |
|
||||||
|
| 73 | 49 | 01001001 | `I` | I | |
|
||||||
|
| 74 | 4A | 01001010 | `J` | J | |
|
||||||
|
| 75 | 4B | 01001011 | `K` | K | |
|
||||||
|
| 76 | 4C | 01001100 | `L` | L | |
|
||||||
|
| 77 | 4D | 01001101 | `M` | M | |
|
||||||
|
| 78 | 4E | 01001110 | `N` | N | |
|
||||||
|
| 79 | 4F | 01001111 | `O` | O | |
|
||||||
|
| 80 | 50 | 01010000 | `P` | P | |
|
||||||
|
| 81 | 51 | 01010001 | `Q` | Q | |
|
||||||
|
| 82 | 52 | 01010010 | `R` | R | |
|
||||||
|
| 83 | 53 | 01010011 | `S` | S | |
|
||||||
|
| 84 | 54 | 01010100 | `T` | T | |
|
||||||
|
| 85 | 55 | 01010101 | `U` | U | |
|
||||||
|
| 86 | 56 | 01010110 | `V` | V | |
|
||||||
|
| 87 | 57 | 01010111 | `W` | W | |
|
||||||
|
| 88 | 58 | 01011000 | `X` | X | |
|
||||||
|
| 89 | 59 | 01011001 | `Y` | Y | |
|
||||||
|
| 90 | 5A | 01011010 | `Z` | Z | |
|
||||||
|
| 91 | 5B | 01011011 | `[` | [ | left square bracket |
|
||||||
|
| 92 | 5C | 01011100 | `\` | \|backslash | |
|
||||||
|
| 93 | 5D | 01011101 | `]` | ] | right square bracket |
|
||||||
|
| 94 | 5E | 01011110 | `^` | ^ | caret / circumflex |
|
||||||
|
| 95 | 5F | 01011111 | `_` | _ | underscore |
|
||||||
|
| 96 | 60 | 01100000 | ``` | ` | grave / accent |
|
||||||
|
| 97 | 61 | 01100001 | `a` | a | |
|
||||||
|
| 98 | 62 | 01100010 | `b` | b | |
|
||||||
|
| 99 | 63 | 01100011 | `c` | c | |
|
||||||
|
| 100 | 64 | 01100100 | `d` | d | |
|
||||||
|
| 101 | 65 | 01100101 | `e` | e | |
|
||||||
|
| 102 | 66 | 01100110 | `f` | f | |
|
||||||
|
| 103 | 67 | 01100111 | `g` | g | |
|
||||||
|
| 104 | 68 | 01101000 | `h` | h | |
|
||||||
|
| 105 | 69 | 01101001 | `i` | i | |
|
||||||
|
| 106 | 6A | 01101010 | `j` | j | |
|
||||||
|
| 107 | 6B | 01101011 | `k` | k | |
|
||||||
|
| 108 | 6C | 01101100 | `l` | l | |
|
||||||
|
| 109 | 6D | 01101101 | `m` | m | |
|
||||||
|
| 110 | 6E | 01101110 | `n` | n | |
|
||||||
|
| 111 | 6F | 01101111 | `o` | o | |
|
||||||
|
| 112 | 70 | 01110000 | `p` | p | |
|
||||||
|
| 113 | 71 | 01110001 | `q` | q | |
|
||||||
|
| 114 | 72 | 01110010 | `r` | r | |
|
||||||
|
| 115 | 73 | 01110011 | `s` | s | |
|
||||||
|
| 116 | 74 | 01110100 | `t` | t | |
|
||||||
|
| 117 | 75 | 01110101 | `u` | u | |
|
||||||
|
| 118 | 76 | 01110110 | `v` | v | |
|
||||||
|
| 119 | 77 | 01110111 | `w` | w | |
|
||||||
|
| 120 | 78 | 01111000 | `x` | x | |
|
||||||
|
| 121 | 79 | 01111001 | `y` | y | |
|
||||||
|
| 122 | 7A | 01111010 | `z` | z | |
|
||||||
|
| 123 | 7B | 01111011 | `{` | { | left curly bracket |
|
||||||
|
| 124 | 7C | 01111100 | `|` | \| | vertical bar |
|
||||||
|
| 125 | 7D | 01111101 | `}` | } | right curly bracket |
|
||||||
|
| 126 | 7E | 01111110 | `~` | ~ | tilde |
|
||||||
|
| 127 | 7F | 01111111 | `` | DEL | delete |
|
||||||
BIN
content/notes/ready/binary_operations/sb1.png
Normal file
|
After Width: | Height: | Size: 82 KiB |
BIN
content/notes/ready/binary_operations/sb10.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
content/notes/ready/binary_operations/sb2.png
Normal file
|
After Width: | Height: | Size: 25 KiB |
BIN
content/notes/ready/binary_operations/sb3.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
content/notes/ready/binary_operations/sb4.png
Normal file
|
After Width: | Height: | Size: 3.6 KiB |
BIN
content/notes/ready/binary_operations/sb5.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
content/notes/ready/binary_operations/sb6.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
content/notes/ready/binary_operations/sb7.png
Normal file
|
After Width: | Height: | Size: 16 KiB |
BIN
content/notes/ready/binary_operations/sb8.png
Normal file
|
After Width: | Height: | Size: 7.6 KiB |
BIN
content/notes/ready/binary_operations/sb9.png
Normal file
|
After Width: | Height: | Size: 91 KiB |
694
content/notes/ready/c-language.md
Normal file
@@ -0,0 +1,694 @@
|
|||||||
|
---
|
||||||
|
title: C Language
|
||||||
|
description:
|
||||||
|
draft: false
|
||||||
|
tags:
|
||||||
|
- c
|
||||||
|
- programming
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Tools
|
||||||
|
|
||||||
|
- `indent` (format code)
|
||||||
|
- `gcc` / `clang` (compile code)
|
||||||
|
- `man <function>` (see function documentation)
|
||||||
|
- `tldr <command>` (quick command usage examples)
|
||||||
|
- `valgrind` (Look for memory leaks)
|
||||||
|
- `valgrind —tool=massif` (check a program's RAM usage)
|
||||||
|
- View the output with `Massif-Visualizer`
|
||||||
|
- `gdb` (debugger)
|
||||||
|
- `gdb —args <program>` (if the program has command line args)
|
||||||
|
- Type `run` to start debugging, and `backtrace` for error details.
|
||||||
|
- `file` Check file information and, if it is an executable, compilation details.
|
||||||
|
- `perf stat -r 10 -d <program>` Benchmark a program.
|
||||||
|
|
||||||
|
## Data Types and Variables
|
||||||
|
|
||||||
|
The binary length of each data type depends on the CPU, OS, and compiler, but in general, they follow the C specifications. To check the exact values for your platform, see `limits.h`.
|
||||||
|
|
||||||
|
| Type | C SPEC | x64 Linux (Example) |
|
||||||
|
| ------------- | --------- | ------------------- |
|
||||||
|
| `char` | ≥ 8 bits | 8 bits |
|
||||||
|
| `short` | ≥ 16 bits | 16 bits |
|
||||||
|
| `int` | ≥ 16 bits | 32 bits |
|
||||||
|
| `long` | ≥ 32 bits | 64 bits |
|
||||||
|
| `long long` | ≥ 64 bits | 64 bits |
|
||||||
|
| `float` | | 32 bits |
|
||||||
|
| `double` | | 64 bits |
|
||||||
|
| `long double` | | 128 bits |
|
||||||
|
|
||||||
|
| Unsigned Bytes (8 bits) | Maximum Decimal Value |
|
||||||
|
| ----------------------- | --------------------------------------------------- |
|
||||||
|
| 1 | 255 |
|
||||||
|
| 2 | 65.535 |
|
||||||
|
| 4 | 4.294.967.295 |
|
||||||
|
| 8 | 18.446.744.073.709.551.615 |
|
||||||
|
| 16 | 340.282.366.920.938.463.463.374.607.431.768.211.455 |
|
||||||
|
| 32 | 1.157 × 10^76 |
|
||||||
|
|
||||||
|
Examples
|
||||||
|
|
||||||
|
```C
|
||||||
|
char a = 'C'; // single character %c ''
|
||||||
|
char b[] = "Trude" // array of characters %s ""
|
||||||
|
unsigned int // Unsigned. The number must be positive.
|
||||||
|
int // Signed. Negative and positive numbers.
|
||||||
|
char f = 100; // %d (number) %c (character)
|
||||||
|
unsigned char g = 255; // %d (number) %c (character)
|
||||||
|
short h = 32767; // %d
|
||||||
|
unsigned short i = 65535; // %d
|
||||||
|
int j = 2147483647; // %d
|
||||||
|
unsigned int k = 4294967295; // %u
|
||||||
|
long long l = ... // %lld
|
||||||
|
unsigned long long m = ...32U // %llu
|
||||||
|
float c = 3.141592; // %f
|
||||||
|
double d = 3.141592653589793; // %lf
|
||||||
|
```
|
||||||
|
|
||||||
|
### Format Specifiers
|
||||||
|
|
||||||
|
These format codes indicate which data type is being used. They are needed for `printf` and `scanf`, for example.
|
||||||
|
|
||||||
|
| `%` | Description |
|
||||||
|
| ------ | ------------------------------------------- |
|
||||||
|
| `%%` | `%` |
|
||||||
|
| `%-` | left align |
|
||||||
|
| `%.1` | decimal precision |
|
||||||
|
| `%1` | minimum field width |
|
||||||
|
| `%c` | character |
|
||||||
|
| `%d` | signed integer of base 10 |
|
||||||
|
| `%e` | scientific notation |
|
||||||
|
| `%f` | float |
|
||||||
|
| `%hd` | small decimal (short) |
|
||||||
|
| `%hhd` | very small decimal (char) |
|
||||||
|
| `%i` | integer of any base (detects automatically) |
|
||||||
|
| `%lf` | double |
|
||||||
|
| `%o` | octal (base 8) |
|
||||||
|
| `%p` | address/pointer |
|
||||||
|
| `%s` | string (array of characters) |
|
||||||
|
| `%u` | unsigned integer of base 10 |
|
||||||
|
| `%x` | hexadecimal (base 16) |
|
||||||
|
|
||||||
|
```C
|
||||||
|
float item1 = 5.75;
|
||||||
|
printf("Item1: %-8.2\n", item1);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Numbers
|
||||||
|
|
||||||
|
`C` can handle multiple numeric bases.
|
||||||
|
|
||||||
|
```C
|
||||||
|
int x = 255; // Decimal
|
||||||
|
int y = 0xff; // Hexadecimal
|
||||||
|
```
|
||||||
|
|
||||||
|
### Type Casting
|
||||||
|
|
||||||
|
Convert a type into another.
|
||||||
|
|
||||||
|
```C
|
||||||
|
int x = 1, y = 10;
|
||||||
|
float z = (float) x / (float) y;
|
||||||
|
```
|
||||||
|
|
||||||
|
## Escape Sequences
|
||||||
|
|
||||||
|
Escape sequences are used to allow typing characters in a string that would otherwise be interpreted as `C` instructions.
|
||||||
|
|
||||||
|
| Seq | Name | Description |
|
||||||
|
| ------ | ------------------ | -------------------------------------------------------------------------------------- |
|
||||||
|
| `\a` | Alarm or Beep | It is used to generate a bell sound in the C program. |
|
||||||
|
| `\b` | Backspace | It is used to move the cursor one place backward. |
|
||||||
|
| `\f` | Form Feed | It is used to move the cursor to the start of the next logical page. |
|
||||||
|
| `\n` | New Line | It moves the cursor to the start of the next line. |
|
||||||
|
| `\r` | Carriage Return | It moves the cursor to the start of the current line. |
|
||||||
|
| `\t` | Horizontal Tab | It inserts some whitespace to the left of the cursor and moves the cursor accordingly. |
|
||||||
|
| `\v` | Vertical Tab | It is used to insert vertical space. |
|
||||||
|
| `\\` | Backlash | Use to insert backslash character. |
|
||||||
|
| `\'` | Single Quote | It is used to display a single quotation mark. |
|
||||||
|
| `\"` | Double Quote | It is used to display double quotation marks. |
|
||||||
|
| `\?` | Question Mark | It is used to display a question mark. |
|
||||||
|
| `\ooo` | Octal Number | It is used to represent an octal number. |
|
||||||
|
| `\xhh` | Hexadecimal Number | It represents the hexadecimal number. |
|
||||||
|
| `\0` | `NULL` | It represents the NULL character. |
|
||||||
|
| `\e` | Escape sequence | It represents the ASCII escape character. |
|
||||||
|
| `\s` | Space Character | It represents the ASCII space character. |
|
||||||
|
| `\d` | Delete Character | It represents the ASCII DEL character. |
|
||||||
|
|
||||||
|
## Constants
|
||||||
|
|
||||||
|
Add `const` before a variable declaration to prevent the value from being changed.
|
||||||
|
|
||||||
|
```C
|
||||||
|
const float PI 3.14159;
|
||||||
|
```
|
||||||
|
|
||||||
|
Another option is to use `define`.
|
||||||
|
|
||||||
|
```C
|
||||||
|
#define MAX 9
|
||||||
|
```
|
||||||
|
|
||||||
|
This command replaces the 'MAX' word with '9', using the preprocessor (before compiling). No extra memory required.
|
||||||
|
|
||||||
|
## Arithmetic Operators
|
||||||
|
|
||||||
|
```C
|
||||||
|
// + (addition)
|
||||||
|
// - (subtraction)
|
||||||
|
// * (multiplication)
|
||||||
|
// / (division)
|
||||||
|
// % (modulus / remainder)
|
||||||
|
// ++ (increment)
|
||||||
|
// -- (decrement)
|
||||||
|
int x = 1;
|
||||||
|
int y = 2;
|
||||||
|
int z = x + y; // 3
|
||||||
|
// Augmented assignment operators
|
||||||
|
x++; // x = x + 1
|
||||||
|
y--; // y = y - 1
|
||||||
|
x+=2; // x = x + 2
|
||||||
|
x*=2; // x = x * 2
|
||||||
|
```
|
||||||
|
|
||||||
|
## Control Flow
|
||||||
|
|
||||||
|
### Boolean Values
|
||||||
|
|
||||||
|
In `C`, there are no `true` or `false` keywords, so integers are used instead.
|
||||||
|
- `0` generally represents `false`.
|
||||||
|
- Any non-zero value (`1`, `-1`, etc…) represents `true`.
|
||||||
|
|
||||||
|
### IF Statement
|
||||||
|
|
||||||
|
```C
|
||||||
|
if(a == 1) printf("A is 1.\\n");
|
||||||
|
```
|
||||||
|
|
||||||
|
Use `{}` for multiple items.
|
||||||
|
|
||||||
|
```C
|
||||||
|
if(age == 18){
|
||||||
|
printf("You are 18.");
|
||||||
|
}
|
||||||
|
else if(age < 0){
|
||||||
|
printf("You haven't been born yet.");
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
printf("You are not 18.");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Switch Statement
|
||||||
|
|
||||||
|
Faster than IF when over 5 cases.
|
||||||
|
|
||||||
|
```C
|
||||||
|
switch(grade){
|
||||||
|
case 'A':
|
||||||
|
printf("perfect.\n");
|
||||||
|
break;
|
||||||
|
case 'B':
|
||||||
|
printf("good.\n");
|
||||||
|
break;
|
||||||
|
case 'C':
|
||||||
|
printf("okay.\n");
|
||||||
|
break;
|
||||||
|
case 'D':
|
||||||
|
printf("meh.\n");
|
||||||
|
break;
|
||||||
|
case 'F':
|
||||||
|
printf("failed.\n");
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Enter only valied grades.\n");
|
||||||
|
}
|
||||||
|
// If break; is missing, the next case is also executed.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Operators
|
||||||
|
|
||||||
|
### Logical Operators
|
||||||
|
|
||||||
|
#### AND (`&&`)
|
||||||
|
|
||||||
|
```C
|
||||||
|
if(temp >= 0 && temp <= 30){
|
||||||
|
printf("\nThe weather is good.")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### OR (`||`)
|
||||||
|
|
||||||
|
```C
|
||||||
|
if(temp <= 0 || temp >= 30){
|
||||||
|
printf("\nThe weather is good.")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### NOT (`!`)
|
||||||
|
|
||||||
|
```C
|
||||||
|
if(!(temp <= 0 || temp >= 30)){
|
||||||
|
printf("\nThe weather is bad.")
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
##### **NOT** Truth Table
|
||||||
|
|
||||||
|
| `condition` | `!(condition)` |
|
||||||
|
| ----------- | -------------- |
|
||||||
|
| 1 | 0 |
|
||||||
|
| 0 | 1 |
|
||||||
|
|
||||||
|
### Ternary Operator
|
||||||
|
|
||||||
|
Shorthand syntax for if/else when assigning or returning a value.
|
||||||
|
|
||||||
|
```C
|
||||||
|
// (condition) ? value if true : value if false
|
||||||
|
int max = (x > y) ? x : y;
|
||||||
|
```
|
||||||
|
|
||||||
|
### Bitwise Operators
|
||||||
|
|
||||||
|
Special operators used in bit-level programming. (Logic gates)
|
||||||
|
|
||||||
|
```C
|
||||||
|
int x = 6; // 6 = 00000110
|
||||||
|
int y = 12; // 12 = 00001100
|
||||||
|
int z = 0; // 0 = 00000000
|
||||||
|
z = x & y; // AND - 00000100 (4)
|
||||||
|
z = x | y; // OR - 00001110 (14)
|
||||||
|
z = x ^ y; // XOR - 00001010 (10)
|
||||||
|
z = x << 1; // Left Shift - 00001100 (12) (Shift all bits to the left.)
|
||||||
|
z = x >> 1; // Right Shift - 00000011 (3) (Shift all bits to the right.)
|
||||||
|
```
|
||||||
|
|
||||||
|
## Functions
|
||||||
|
|
||||||
|
Functions are snippets of code that can be reused multiple times across the same file. These can receive multiple arguments as input, but can only return a single value.
|
||||||
|
|
||||||
|
```C
|
||||||
|
void myFunction(); // Function Prototype
|
||||||
|
int main() {
|
||||||
|
myFunction(); // Call function
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void myFunction() { // Function Definition
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arguments
|
||||||
|
|
||||||
|
```C
|
||||||
|
void greet(char x[], int y);
|
||||||
|
int main() {
|
||||||
|
char name[] = "Trude";
|
||||||
|
int age = 132;
|
||||||
|
greet(name, age);
|
||||||
|
}
|
||||||
|
void greet(char x[], int y) {
|
||||||
|
printf("\nHello %s, you are %d years old.", x, y);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Return Values
|
||||||
|
|
||||||
|
```C
|
||||||
|
double square(double x);
|
||||||
|
int main() {
|
||||||
|
double x = square(3.14);
|
||||||
|
printf("%lf", x);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
double square(double x) {
|
||||||
|
return x * x;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Recursion
|
||||||
|
|
||||||
|
A function can call itself, creating a loop.
|
||||||
|
|
||||||
|
```C
|
||||||
|
int i = 0;
|
||||||
|
void plusOne(int n) {
|
||||||
|
printf("%d", n);
|
||||||
|
if (n < 10000) plusOne(n);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Function Prototypes
|
||||||
|
|
||||||
|
Function declaration without a body, before `main()`.
|
||||||
|
Prototypes ensure that calls to a function are made with the correct arguments, and allow functions to be defined under the function call.
|
||||||
|
|
||||||
|
```C
|
||||||
|
void hello(char[], int); // Function Prototype
|
||||||
|
int main() {
|
||||||
|
hello(//...);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
void hello(char name[], int age){
|
||||||
|
//...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
> **Note:** Many C compilers don't check for parameter matching, so missing arguments can lead to unexpected behavior.
|
||||||
|
>
|
||||||
|
> Function prototypes flag errors when arguments are missing.
|
||||||
|
>
|
||||||
|
> While not necessary if functions are declared before `main()`, using prototypes first and then declaring functions after `main()` improves readability and aids debugging.
|
||||||
|
|
||||||
|
## Loops
|
||||||
|
|
||||||
|
### For Loop
|
||||||
|
|
||||||
|
Loop through an interval.
|
||||||
|
|
||||||
|
```C
|
||||||
|
for(int i = 0; i < 10; i++){
|
||||||
|
printf("%d\n", I); //0-9
|
||||||
|
}
|
||||||
|
//Multiple initial variables
|
||||||
|
for(int i = 0, int y = 1; i < 10; i++){
|
||||||
|
printf("%d\n", I); //0-9
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### While Loop
|
||||||
|
|
||||||
|
Loop until a condition is met.
|
||||||
|
|
||||||
|
```C
|
||||||
|
while(test == 1){
|
||||||
|
printf("Test is not 1.\n");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Do While Loop
|
||||||
|
|
||||||
|
Run the code once, then repeat until a condition is met.
|
||||||
|
|
||||||
|
```C
|
||||||
|
do {
|
||||||
|
printf("Enter a number above 0: ");
|
||||||
|
scanf("%d", &number)
|
||||||
|
} while (number > 0);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Endless Loop
|
||||||
|
|
||||||
|
```C
|
||||||
|
while (true) {
|
||||||
|
...
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Continue & Break Statements
|
||||||
|
|
||||||
|
- `continue` - Skips rest of code and forces the next iteration of the loop.
|
||||||
|
- `break` - Exits a loop/switch.
|
||||||
|
|
||||||
|
## Structs
|
||||||
|
|
||||||
|
Structs can group values. They are similar to classes, but can't hold methods.
|
||||||
|
Being able to group variables avoids repetition and name collision (when two variables have the same name).
|
||||||
|
|
||||||
|
```C
|
||||||
|
struct Player {
|
||||||
|
char name[12];
|
||||||
|
int score;
|
||||||
|
};
|
||||||
|
int main(){
|
||||||
|
struct Player player1;
|
||||||
|
struct Player player2;
|
||||||
|
strcpy(player1.name, "Trude");
|
||||||
|
player1.score = 4;
|
||||||
|
strcpy(player2.name, "JCionx");
|
||||||
|
player2.score = 7;
|
||||||
|
player1.score; //4
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Arrays of Structs
|
||||||
|
|
||||||
|
```C
|
||||||
|
struct Student {
|
||||||
|
char name[12];
|
||||||
|
float gpa;
|
||||||
|
};
|
||||||
|
int main() {
|
||||||
|
struct Student s1 = {"Peter", 3.0};
|
||||||
|
struct Student s2 = {"Jean", 4.0};
|
||||||
|
struct Student s3 = {"David", 2.5};
|
||||||
|
struct Student students[] = {s1, s2, s3};
|
||||||
|
printf("%f\n", students[0].gpa); // Print the student 1 gpa.
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Typedef
|
||||||
|
|
||||||
|
Create a shortcut for a type of data.
|
||||||
|
|
||||||
|
```C
|
||||||
|
typedef char user[25];
|
||||||
|
int main() {
|
||||||
|
user user1 = "Trude";
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
Typedef can be used to simplify structs.
|
||||||
|
|
||||||
|
```C
|
||||||
|
typedef struct {
|
||||||
|
char name[25];
|
||||||
|
char password[12];
|
||||||
|
int id;
|
||||||
|
} User;
|
||||||
|
int main(){
|
||||||
|
User user1 = {"Trude", "hello123", 12335};
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Nul Character
|
||||||
|
|
||||||
|
```C
|
||||||
|
\0 // This character represents 00000000 and marks the end of a string.
|
||||||
|
// Same as 0x0 and null.
|
||||||
|
```
|
||||||
|
|
||||||
|
## Command-Line Arguments
|
||||||
|
|
||||||
|
- `argc` is the number of arguments in `argv`.
|
||||||
|
- `argv[0]` is the name of the program, all others are the user arguments.
|
||||||
|
|
||||||
|
```C
|
||||||
|
int main(int argc, char argv[]) {
|
||||||
|
if (argc == 2) {
|
||||||
|
printf("hello, %s\n", argv[1]);
|
||||||
|
} else {
|
||||||
|
printf("You need to add 1 argument.\n");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Enums
|
||||||
|
|
||||||
|
Enums are a list of constant values that help make programs more readable.
|
||||||
|
Enums are treated as integers.
|
||||||
|
|
||||||
|
```C
|
||||||
|
// enum Day{Sun, Mon, Tue, Wed, Thu, Fri, Sat}; (This enum starts from 0 to 6.)
|
||||||
|
enum Day{Sun = 1, Mon = 2, Tue = 3, Wed = 4, Thu = 5, Fri = 6, Sat = 7};
|
||||||
|
int main(){
|
||||||
|
enum Day today = Sun;
|
||||||
|
if(today == Sun || today == Sat){
|
||||||
|
printf("It's the weekend.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
## Memory Management
|
||||||
|
|
||||||
|
- `a` - A variable
|
||||||
|
- `&a` - The address of the variable `a` in memory. (The format is `%p`)
|
||||||
|
- `int *p` - A pointer. Holds the memory address of another variable. (8 bits usually, depends on the CPU architecture (max RAM supported).
|
||||||
|
- `*p` - Dereference a pointer. Returns the value in the address stored. (go to address's variable)
|
||||||
|
|
||||||
|
```C
|
||||||
|
int age = 21;
|
||||||
|
int *pAge = &age;
|
||||||
|
int valueOfAge = *pAge;
|
||||||
|
printf("%p and %p are the same.", &age, pAge);
|
||||||
|
```
|
||||||
|
|
||||||
|
NOTE: A pointer must be `int`, as it points to a memory address.
|
||||||
|
|
||||||
|
### Strings
|
||||||
|
|
||||||
|
Strings are arrays of characters.
|
||||||
|
A string can be returned as a memory address.
|
||||||
|
A string ends in `\0`, the null character.
|
||||||
|
|
||||||
|
```C
|
||||||
|
/* Use char[] when:
|
||||||
|
- The maximum string length is known.
|
||||||
|
- No need to modify the whole string.
|
||||||
|
- No need to pass the string to a function [that modifies it]
|
||||||
|
*/
|
||||||
|
char name[] = "Trude"; // 6 bits on stack memory.
|
||||||
|
name[0] = 'T'; // Elements of an array can be modified.
|
||||||
|
/* Use char* when:
|
||||||
|
- The maximum string length is NOT known.
|
||||||
|
- The string will later be modified.
|
||||||
|
- The string will be passed to a function [that modifies it].
|
||||||
|
*/
|
||||||
|
const char *name = "Trude"; // 8 bits in stack + 6 bits read-only.
|
||||||
|
name = "TrudeEH"; // Pointers can be overwritten.
|
||||||
|
name++; // rudeEH - Works because the pointer is shifted to the next value.
|
||||||
|
peintf("%c\n", *(name+1)); // Prints 'r'.
|
||||||
|
printf("%c\n", name[1]); // Works with both for reading.
|
||||||
|
printf("%s\n", name); // Print a string.
|
||||||
|
// The string in memory:
|
||||||
|
// [T][r][u][d][e][\\0]
|
||||||
|
// The memory address of T is stored.
|
||||||
|
```
|
||||||
|
|
||||||
|
### String Operations
|
||||||
|
|
||||||
|
#### Compare String
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
char s* = "Trude";
|
||||||
|
char t* = "Trude";
|
||||||
|
if (strcmp(s, t) == 0) {
|
||||||
|
printf("Same string.");
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Copy String (`malloc` example) Manually
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdlib.h>
|
||||||
|
char *s = "Trude";
|
||||||
|
char *t = malloc(strlen(s) + 1);
|
||||||
|
// 2 variables are declared, so strlen isn't called with every iteration.
|
||||||
|
for (int i = 0, n = strlen(s) + 1; i < n; i++) {
|
||||||
|
t[i] = s[i];
|
||||||
|
)
|
||||||
|
//...
|
||||||
|
free(t);
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Copy String (string.h)
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
char *s = "Trude";
|
||||||
|
char *t = malloc(strlen(s) + 1);
|
||||||
|
strcpy(t, s);
|
||||||
|
//...
|
||||||
|
free(t);
|
||||||
|
```
|
||||||
|
|
||||||
|
Note: Use `valgrind` to detect memory leaks (lack of `free()`)
|
||||||
|
|
||||||
|
> **Always** initialize variables to a value, or random garbage values may be still in the variable's memory address.
|
||||||
|
|
||||||
|
### Input
|
||||||
|
|
||||||
|
#### Get Integer
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(void){
|
||||||
|
int x;
|
||||||
|
scanf("%i", &x);
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
#### Get String (Length is Known, safe)
|
||||||
|
|
||||||
|
`scanf` reads up to a whitespace.
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main(void){
|
||||||
|
char s[4];
|
||||||
|
scanf("%4s", s); //No &, s is an address already.
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`fgets` reads whitespaces.
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
int age;
|
||||||
|
char name[25];
|
||||||
|
printf("What is your name? ");
|
||||||
|
fgets(name, 25, stdin); // name of variable, max size, input.
|
||||||
|
name[strlen(name)-1] = '\0'; // removes the line break fgets adds. String library is required.
|
||||||
|
printf("How old are you? ");
|
||||||
|
scanf("%d", &age);
|
||||||
|
```
|
||||||
|
|
||||||
|
## Files
|
||||||
|
|
||||||
|
### Write to a File
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main() {
|
||||||
|
FILE *file = fopen("test.txt", "w"); // w - overwrite / a - append
|
||||||
|
fprintf(file, "Some Text");
|
||||||
|
fclose(file);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Delete a File
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main() {
|
||||||
|
if(remove("test.txt") == 0){
|
||||||
|
printf("File removed.\n");
|
||||||
|
} else {
|
||||||
|
printf("Failed to delete file.\n");
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Read a File
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <stdio.h>
|
||||||
|
int main() {
|
||||||
|
FILE *pF = fopen("test.txt", "r") // r - read.
|
||||||
|
char buffer[255]; // Will hold 1 line of the file.
|
||||||
|
if(pF == NULL){
|
||||||
|
printf("File does not exist.");
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
fgets(buffer, 255, pF);
|
||||||
|
printf("%s", buffer); // Print first line of file. Use in a while loop to print all of them.
|
||||||
|
fclose(pF);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
File manipulation accepts relative and absolute file paths.
|
||||||
38
content/notes/ready/c-snippets.md
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
---
|
||||||
|
title: C Snippets
|
||||||
|
description:
|
||||||
|
draft: false
|
||||||
|
tags:
|
||||||
|
- c
|
||||||
|
- programming
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
## Cast Strings to Numbers
|
||||||
|
|
||||||
|
The `atoi()` function in `stdlib` is implemented similarly to the one below.
|
||||||
|
|
||||||
|
ASCII encodes numbers in order, after special characters.
|
||||||
|
|
||||||
|
The encoded value for `'0'` is 48, so subtracting any numeric char by 48 outputs its real numerical value.
|
||||||
|
|
||||||
|
```C
|
||||||
|
char number = '7';
|
||||||
|
int result = number - 48;
|
||||||
|
int same_result = number - '0';
|
||||||
|
```
|
||||||
|
|
||||||
|
Algorithm to convert strings to numbers:
|
||||||
|
|
||||||
|
```C
|
||||||
|
int str_to_int(char *str) {
|
||||||
|
int result = 0;
|
||||||
|
for (int i = 0; str[i] != '\0'; i++) {
|
||||||
|
if (str[i] < '0' && str[1] > '9') return -1; // Error if NaN
|
||||||
|
result = (result * 10) + (str[i] - '0');
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
`(result * 10)` is shifting the previous number to the left, as it is an order of magnitude above the following digit.
|
||||||
79
content/notes/ready/compiling.md
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
---
|
||||||
|
title: Compiling [MAKE / GCC]
|
||||||
|
description:
|
||||||
|
draft: false
|
||||||
|
tags:
|
||||||
|
- c
|
||||||
|
- programming
|
||||||
|
author: TrudeEH
|
||||||
|
showToc: true
|
||||||
|
---
|
||||||
|
|
||||||
|
|
||||||
|
Convert `C` code into machine code in 4 steps:
|
||||||
|
1. **Preprocessing** (Convert all preprocessor instructions: `#…`)
|
||||||
|
2. **Compiling** (Convert `C` code to machine code)
|
||||||
|
3. **Assembling** (Compile the necessary libraries)
|
||||||
|
4. **Linking** (Merge the compiled code with the compiled libraries)
|
||||||
|
|
||||||
|
## Libraries
|
||||||
|
|
||||||
|
Libraries are pre-written collections of code that can be reused in other programs. On **UNIX* systems, they are usually located in the `/lib/` and `/usr/include` directories.
|
||||||
|
|
||||||
|
### Math.h
|
||||||
|
|
||||||
|
For example, `math.h` is very useful to implement complex arithmetic operations.
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <math.h>
|
||||||
|
double A = sqrt(9);
|
||||||
|
double B = pow(2, 4);
|
||||||
|
int C = round(3.14);
|
||||||
|
int D = ceil(3.14);
|
||||||
|
int E = floor(3.99);
|
||||||
|
double F = fabs(-100);
|
||||||
|
double G = log(3);
|
||||||
|
double H = sin(45);
|
||||||
|
double I = cos(45);
|
||||||
|
double J = tan(45);
|
||||||
|
```
|
||||||
|
|
||||||
|
### Using Libraries
|
||||||
|
|
||||||
|
To use a library, we first have to include it in the `C` code.
|
||||||
|
|
||||||
|
```C
|
||||||
|
#include <cs50.h> // cs50.h library will be included.
|
||||||
|
```
|
||||||
|
|
||||||
|
Then, the library must be linked at compile time.
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
gcc -o hello hello.c -lcs50
|
||||||
|
./hello
|
||||||
|
```
|
||||||
|
|
||||||
|
## Optimization Flags
|
||||||
|
|
||||||
|
- `-O2` Optimize for speed
|
||||||
|
- `-O3` Optimize for speed aggressively
|
||||||
|
- `-Os` Optimize for size
|
||||||
|
- `-Og` Optimize for debugging
|
||||||
|
- `-Oz` Optimize for size aggressively
|
||||||
|
|
||||||
|
## Make
|
||||||
|
|
||||||
|
`Make` Is a build automation tool that automates the process of compiling, linking and building executables.
|
||||||
|
An example `Makefile` could look like the following:
|
||||||
|
|
||||||
|
```Makefile
|
||||||
|
hello:
|
||||||
|
gcc -o hello hello.c -lcs50
|
||||||
|
clean:
|
||||||
|
rm -f hello
|
||||||
|
```
|
||||||
|
|
||||||
|
```Shell
|
||||||
|
make #Compiles hello.c
|
||||||
|
make clean #Removes the executable (hello) generated by the make command.
|
||||||
|
```
|
||||||
BIN
content/notes/ready/cpu_architecture/image10.png
Normal file
|
After Width: | Height: | Size: 213 KiB |
BIN
content/notes/ready/cpu_architecture/image11.png
Normal file
|
After Width: | Height: | Size: 219 KiB |
BIN
content/notes/ready/cpu_architecture/image12.png
Normal file
|
After Width: | Height: | Size: 36 KiB |
BIN
content/notes/ready/cpu_architecture/image13.png
Normal file
|
After Width: | Height: | Size: 186 KiB |
BIN
content/notes/ready/cpu_architecture/image14.png
Normal file
|
After Width: | Height: | Size: 214 KiB |
BIN
content/notes/ready/cpu_architecture/image15.png
Normal file
|
After Width: | Height: | Size: 297 KiB |
BIN
content/notes/ready/cpu_architecture/image16.png
Normal file
|
After Width: | Height: | Size: 306 KiB |
BIN
content/notes/ready/cpu_architecture/image17.png
Normal file
|
After Width: | Height: | Size: 121 KiB |
BIN
content/notes/ready/cpu_architecture/image18.png
Normal file
|
After Width: | Height: | Size: 139 KiB |
BIN
content/notes/ready/cpu_architecture/image19.png
Normal file
|
After Width: | Height: | Size: 358 KiB |
BIN
content/notes/ready/cpu_architecture/image20.png
Normal file
|
After Width: | Height: | Size: 357 KiB |
BIN
content/notes/ready/cpu_architecture/image21.png
Normal file
|
After Width: | Height: | Size: 244 KiB |
BIN
content/notes/ready/cpu_architecture/image22.png
Normal file
|
After Width: | Height: | Size: 217 KiB |
BIN
content/notes/ready/cpu_architecture/image23.png
Normal file
|
After Width: | Height: | Size: 205 KiB |
BIN
content/notes/ready/cpu_architecture/image24.png
Normal file
|
After Width: | Height: | Size: 89 KiB |
BIN
content/notes/ready/cpu_architecture/image25.png
Normal file
|
After Width: | Height: | Size: 313 KiB |
BIN
content/notes/ready/cpu_architecture/image26.png
Normal file
|
After Width: | Height: | Size: 318 KiB |
BIN
content/notes/ready/cpu_architecture/image27.png
Normal file
|
After Width: | Height: | Size: 338 KiB |
BIN
content/notes/ready/cpu_architecture/image28.png
Normal file
|
After Width: | Height: | Size: 324 KiB |
BIN
content/notes/ready/cpu_architecture/image29.png
Normal file
|
After Width: | Height: | Size: 187 KiB |
BIN
content/notes/ready/cpu_architecture/image30.png
Normal file
|
After Width: | Height: | Size: 228 KiB |
BIN
content/notes/ready/cpu_architecture/image31.png
Normal file
|
After Width: | Height: | Size: 216 KiB |
BIN
content/notes/ready/cpu_architecture/image32.png
Normal file
|
After Width: | Height: | Size: 97 KiB |
BIN
content/notes/ready/cpu_architecture/image33.png
Normal file
|
After Width: | Height: | Size: 64 KiB |