Skip to content

Commit

Permalink
Merge pull request #41 from zyriab/chore/refactor-snippets-and-skills
Browse files Browse the repository at this point in the history
chore: refactor snippets and skills
  • Loading branch information
zyriab authored Aug 15, 2024
2 parents ae06000 + 5549d70 commit ea2e5f8
Show file tree
Hide file tree
Showing 5 changed files with 119 additions and 113 deletions.
46 changes: 23 additions & 23 deletions data/skills.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
{
"data": [
{
"name": " Go",
"content": [
"Go is a {{programming language}} mainly used for {{backend}} development.\nIt is {{fast}}, {{simple}}, {{powerful}} and {{fun}}.",
"For some programmers, its {{simplicity}} can also be its {{downfall}} as it does not have all the bell and whistles as some languages, such as JavaScript.\nOn the other hand, it is much {{less bloated}} and gives a lot of {{freedom}} to the programmer, very much like its big brother {{C}}.",
"It is {{fast}} because it is {{compiled}} to {{machine code}}.\nIt is {{powerful}} because it is {{statically typed}} and {{concurrent}}.\nIt is {{simple}} because it is {{opinionated}}, has a very {{complete}} standard library and only contains {{25 keywords}}.",
"I have been using Go for less than {{1 year}} and I am getting the hang of it.\nI have used it to {{fast-prototype}} a {{web crawler}} and I am currently working on a {{video game}} with it.",
"If I were {{Maïté}}, Go would be my {{Ortolan}}."
],
"snippet": "go"
},
{
"name": " C",
"content": [
"C is a {{programming language}} mainly used for {{low-level}} development.\nIt is {{fast}}, {{simple}}, and extremely {{powerful}}.",
"It has been around since the {{70s}} and is still used today in {{operating systems}}, {{embedded systems}}, {{video games}}, {{time-sensitive}} algorithms and much more.\nThe device that you are currently using has its very {{core}} written in C, all kind of devices like {{your monitor}}, {{car}}, and {{spaceships}} (hi Elon) do {{extensive}} use of C.",
"It is {{fast}} because it is {{compiled}} to {{machine code}}.\nIt is {{powerful}} because it is {{statically typed}} and {{low-level}}.\nIt is {{simple}} because it comes with almost {{no bloat}}.",
"C can be {{difficult}} to {{learn}} and {{maintain}} but it is a {{very powerful}} tool that can be used to {{build}} almost anything.\nOne of its {{strength}} (but also pitfall) is the fact that the programmer has to {{manually}} allocate and free {{memory}}, opening the possibility for {{extremely efficient}} software but also for dreaded {{memory leaks}}.",
"C is {{my very first}} programming language, I've been dabbling with it since {{2010}} and I am still learning a lot about it.\nI mainly use it to work on {{embedded systems}}, as I enjoy {{bare-metal}} programming.\nIt is also an invaluable {{learning tool}}, especially when coupled with very low-level projects and {{algorithms}} development.",
"If I were {{King Arthur}}, C would be my {{Excalibur}}."
],
"snippet": "c"
},
{
"name": " HTML",
"content": [
Expand Down Expand Up @@ -138,29 +161,6 @@
],
"snippet": null
},
{
"name": " Go",
"content": [
"Go is a {{programming language}} mainly used for {{backend}} development.\nIt is {{fast}}, {{simple}}, {{powerful}} and {{fun}}.",
"For some programmers, its {{simplicity}} can also be its {{downfall}} as it does not have all the bell and whistles as some languages, such as JavaScript.\nOn the other hand, it is much {{less bloated}} and gives a lot of {{freedom}} to the programmer, very much like its big brother {{C}}.",
"It is {{fast}} because it is {{compiled}} to {{machine code}}.\nIt is {{powerful}} because it is {{statically typed}} and {{concurrent}}.\nIt is {{simple}} because it is {{opinionated}}, has a very {{complete}} standard library and only contains {{25 keywords}}.",
"I have been using Go for less than {{1 year}} and I am getting the hang of it.\nI have used it to {{fast-prototype}} a {{web crawler}} and I am currently working on a {{video game}} with it.",
"If I were {{Maïté}}, Go would be my {{Ortolan}}."
],
"snippet": "go"
},
{
"name": " C",
"content": [
"C is a {{programming language}} mainly used for {{low-level}} development.\nIt is {{fast}}, {{simple}}, and extremely {{powerful}}.",
"It has been around since the {{70s}} and is still used today in {{operating systems}}, {{embedded systems}}, {{video games}}, {{time-sensitive}} algorithms and much more.\nThe device that you are currently using has its very {{core}} written in C, all kind of devices like {{your monitor}}, {{car}}, and {{spaceships}} (hi Elon) do {{extensive}} use of C.",
"It is {{fast}} because it is {{compiled}} to {{machine code}}.\nIt is {{powerful}} because it is {{statically typed}} and {{low-level}}.\nIt is {{simple}} because it comes with almost {{no bloat}}.",
"C can be {{difficult}} to {{learn}} and {{maintain}} but it is a {{very powerful}} tool that can be used to {{build}} almost anything.\nOne of its {{strength}} (but also pitfall) is the fact that the programmer has to {{manually}} allocate and free {{memory}}, opening the possibility for {{extremely efficient}} software but also for dreaded {{memory leaks}}.",
"C is {{my very first}} programming language, I've been dabbling with it since {{2010}} and I am still learning a lot about it.\nI mainly use it to work on {{embedded systems}}, as I enjoy {{bare-metal}} programming.\nIt is also an invaluable {{learning tool}}, especially when coupled with very low-level projects and {{algorithms}} development.",
"If I were {{King Arthur}}, C would be my {{Excalibur}}."
],
"snippet": "c"
},
{
"name": " Arduino",
"content": [
Expand Down
2 changes: 1 addition & 1 deletion data/snippets/snippet.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package utils
package datastructure

type Deque[T any] struct {
items []T
Expand Down
92 changes: 49 additions & 43 deletions data/snippets/snippet.js
Original file line number Diff line number Diff line change
@@ -1,49 +1,55 @@
function colorizeCode() {
const element = document.getElementsByTagName('code')[0];

if (element == null) {
return;
}

const text = element.innerText;
const language = element.classList[0];

const keywords = {
js: javascriptKeywords,
ts: typescriptKeywords,
html: htmlKeywords,
css: cssKeywords,
go: goKeywords,
c: cKeywords,
gql: graphqlKeywords,
sql: sqlKeywords,
jsx: reactKeywords,
jest: testKeywords,
sh: bashKeywords,
yml: yamlKeywords,
ino: arduinoKeywords,
}[language];

if (keywords == null) {
return;
}

let coloredText = text

keywords.forEach((subKeywords, i) => {
const regex = new RegExp(`\\b(${subKeywords.join('|')})\\b`, 'g');
coloredText = coloredText.replaceAll(regex, (match) =>
`<span class="${COLORS[i]}">${match}</span>`
);
})

element.innerHTML = coloredText;
const element = document.getElementsByTagName("code")[0];

if (element == null) {
return;
}

const text = element.innerText;
const language = element.classList[0];

const keywords = {
js: javascriptKeywords,
ts: typescriptKeywords,
html: htmlKeywords,
css: cssKeywords,
go: goKeywords,
c: cKeywords,
gql: graphqlKeywords,
sql: sqlKeywords,
jsx: reactKeywords,
jest: testKeywords,
sh: bashKeywords,
yml: yamlKeywords,
ino: arduinoKeywords,
}[language];

if (keywords == null) {
return;
}

let coloredText = text;

keywords.forEach(
(/** @type {[]string} **/ subKeywords, /** @type {number} **/ i) => {
const regex = new RegExp(`\\b(${subKeywords.join("|")})\\b`, "g");
coloredText = coloredText.replaceAll(
regex,
(match) => `<span class="${COLORS[i]}">${match}</span>`,
);
},
);

element.innerHTML = coloredText;
}

/**
* @param {string} snippet
* @returns {Promise<string>}
*/
async function getCodeSnippet(snippet) {
const response = await fetch(`../data/snippets/snippet.${snippet}`)
const text = await response.text();
const response = await fetch(`../data/snippets/snippet.${snippet}`);
const text = await response.text();

return text;
return text;
}

88 changes: 44 additions & 44 deletions data/snippets/snippet.ts
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
function colorizeCode(): void {
const element = document.getElementsByTagName('code')[0];

if (element == null) {
return;
}

const text = element.innerText;
const language = element.classList[0];

const keywords = {
js: javascriptKeywords,
ts: typescriptKeywords,
html: htmlKeywords,
css: cssKeywords,
go: goKeywords,
c: cKeywords,
gql: graphqlKeywords,
sql: sqlKeywords,
jsx: reactKeywords,
jest: testKeywords,
sh: bashKeywords,
yml: yamlKeywords,
ino: arduinoKeywords,
}[language];

if (keywords == null) {
return;
}

let coloredText = text

keywords.forEach((subKeywords, i) => {
const regex = new RegExp(`\\b(${subKeywords.join('|')})\\b`, 'g');
coloredText = coloredText.replaceAll(regex, (match: string) =>
`<span class="${COLORS[i]}">${match}</span>`
);
})

element.innerHTML = coloredText;
const element = document.getElementsByTagName("code")[0];

if (element == null) {
return;
}

const text = element.innerText;
const language = element.classList[0];

const keywords = {
js: javascriptKeywords,
ts: typescriptKeywords,
html: htmlKeywords,
css: cssKeywords,
go: goKeywords,
c: cKeywords,
gql: graphqlKeywords,
sql: sqlKeywords,
jsx: reactKeywords,
jest: testKeywords,
sh: bashKeywords,
yml: yamlKeywords,
ino: arduinoKeywords,
}[language];

if (keywords == null) {
return;
}

let coloredText = text;

keywords.forEach((subKeywords: string[], i: number) => {
const regex = new RegExp(`\\b(${subKeywords.join("|")})\\b`, "g");
coloredText = coloredText.replaceAll(
regex,
(match: string) => `<span class="${COLORS[i]}">${match}</span>`,
);
});

element.innerHTML = coloredText;
}

async function getCodeSnippet(snippet): Promise<string> {
const response = await fetch(`../data/snippets/snippet.${snippet}`)
const text = await response.text();
async function getCodeSnippet(snippet: string): Promise<string> {
const response = await fetch(`../data/snippets/snippet.${snippet}`);
const text = await response.text();

return text;
return text;
}

4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,8 @@
<div></div>
</div>
<div class="ui-list">
<div><img src="images/go.svg" alt="" decoding="async" />Go</div>
<div><img src="images/c.svg" alt="" decoding="async" />C</div>
<div><img src="images/html.svg" alt="" decoding="async" />HTML</div>
<div><img src="images/css.svg" alt="" decoding="async" />CSS</div>
<div><img src="images/js.svg" alt="" decoding="async" />JavaScript</div>
Expand All @@ -178,8 +180,6 @@
<div><img src="images/gh.svg" alt="" decoding="async" />GitHub Actions</div>
<div><img src="images/aws.svg" alt="" decoding="async" />AWS</div>
<div><img src="images/git.svg" alt="" decoding="async" />Git</div>
<div><img src="images/go.svg" alt="" decoding="async" />Go</div>
<div><img src="images/c.svg" alt="" decoding="async" />C</div>
<div><img src="images/arduino.svg" alt="" decoding="async" />Arduino</div>
<div><img src="images/linux.svg" alt="" decoding="async" />Linux</div>
<div><img src="images/shopify.svg" alt="" decoding="async" />Shopify Apps</div>
Expand Down

0 comments on commit ea2e5f8

Please sign in to comment.