Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions .github/workflows/consolidate-snippets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,19 @@ jobs:
run: |
node utils/consolidateSnippets.js # Run the script located in the utils/ folder

- name: Commit and push changes
run: |
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"
git add public/consolidated/*
git add public/icons/*
git diff-index --quiet HEAD || git commit -m "Update consolidated snippets"
git push
- name: Commit and push changes
run: |
# Configure git
git config --global user.name "GitHub Action"
git config --global user.email "action@github.com"

# If there are changes in public/consolidated or public/icons,
# commit and push them. Otherwise, skip.
if ! git diff-index --quiet HEAD -- public/consolidated public/icons; then
echo "Changes detected. Committing and pushing."
git add public/consolidated/* public/icons/*
git commit -m "Update consolidated snippets"
git push
else
echo "No changes to commit. Skipping."
fi
11 changes: 11 additions & 0 deletions public/consolidated/c.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,17 @@
"contributors": [],
"code": "int factorial(int x) {\n int y = 1;\n\n for (int i = 2; i <= x; i++)\n y *= i;\n\n return y;\n}\n\n// Usage:\nfactorial(4); // Returns: 24\n"
},
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in C.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "#include <stdio.h>\n\nvoid fibonacci(int n) {\n int a = 0, b = 1, c, i;\n printf(\"%d \", a);\n if(n > 1) {\n printf(\"%d \", b);\n }\n for(i = 2; i < n; i++) {\n c = a + b;\n printf(\"%d \", c);\n a = b;\n b = c;\n }\n printf(\"\\n\");\n}\n\n// Usage:\nint main() {\n fibonacci(5); // Output: 0 1 1 2 3\n return 0;\n}\n"
},
{
"title": "Swap numbers",
"description": "Swaps two numbers without using third variable",
Expand Down
13 changes: 12 additions & 1 deletion public/consolidated/cpp.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
]
},
{
"categoryName": "Debuging",
"categoryName": "Debugging",
"snippets": [
{
"title": "Vector Print",
Expand Down Expand Up @@ -62,6 +62,17 @@
],
"contributors": [],
"code": "bool is_prime(int n) {\n if (n < 2) return false;\n if (n == 2 || n == 3) return true;\n if (n % 2 == 0) return false;\n for (int i = 3; i * i <= n; i += 2) {\n if (n % i == 0) return false;\n }\n return true;\n}\n\n// Usage:\nis_prime(29); // Returns: true\n"
},
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in C++.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "#include <iostream>\n\nvoid fibonacci(int n) {\n int a = 0, b = 1;\n std::cout << a << \" \";\n if(n > 1) {\n std::cout << b << \" \";\n }\n for(int i = 2; i < n; i++) {\n int c = a + b;\n std::cout << c << \" \";\n a = b;\n b = c;\n }\n std::cout << std::endl;\n}\n\n// Usage:\nint main() {\n fibonacci(5); // Output: 0 1 1 2 3\n return 0;\n}\n"
}
]
},
Expand Down
16 changes: 16 additions & 0 deletions public/consolidated/csharp.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@
}
]
},
{
"categoryName": "Math And Numbers",
"snippets": [
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in C#.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "using System;\n\npublic class FibonacciSeries {\n public static void fibonacci(int n) {\n int a = 0, b = 1;\n Console.Write(a + \" \");\n if(n > 1) {\n Console.Write(b + \" \");\n }\n\n for(int i = 2; i < n; i++) {\n int c = a + b;\n Console.Write(c + \" \");\n a = b;\n b = c;\n }\n Console.WriteLine();\n }\n\n // Usage:\n public static void Main() {\n fibonacci(5); // Output: 0 1 1 2 3\n }\n}\n"
}
]
},
{
"categoryName": "String Utilities",
"snippets": [
Expand Down
16 changes: 16 additions & 0 deletions public/consolidated/java.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,21 @@
"code": "// This is the main class of the Java program\npublic class Main {\n // The main method is the entry point of the program\n public static void main(String args[]) {\n // This statement prints \"Hello, World!\" to the console\n System.out.println(\"Hello, World!\");\n }\n}\n\n"
}
]
},
{
"categoryName": "Math And Numbers",
"snippets": [
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in Java.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "public class Fibonacci {\n public static void fibonacci(int n) {\n int a = 0, b = 1;\n System.out.print(a + \" \");\n if(n > 1) {\n System.out.print(b + \" \");\n }\n\n for(int i = 2; i < n; i++) {\n int c = a + b;\n System.out.print(c + \" \");\n a = b;\n b = c;\n }\n System.out.println();\n }\n\n // Usage:\n public static void main(String[] args) {\n fibonacci(5); // Output: 0 1 1 2 3\n }\n}\n"
}
]
}
]
11 changes: 11 additions & 0 deletions public/consolidated/javascript.json
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,17 @@
{
"categoryName": "Mathematical Functions",
"snippets": [
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in JavaScript.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "function fibonacci(n) {\n let a = 0, b = 1;\n let result = a + ' ';\n if (n > 1) {\n result += b + ' ';\n }\n\n for (let i = 2; i < n; i++) {\n let c = a + b;\n result += c + ' ';\n a = b;\n b = c;\n }\n console.log(result.trim());\n}\n\n// Usage:\nfibonacci(5); // Output: 0 1 1 2 3\n"
},
{
"title": "Greatest Common Divisor",
"description": "Calculates the largest positive integer that divides each of the integers without leaving a remainder. Useful for calculating aspect ratios.",
Expand Down
11 changes: 11 additions & 0 deletions public/consolidated/python.json
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,17 @@
"contributors": [],
"code": "def bytes_to_human_readable(num):\n for unit in ['B', 'KB', 'MB', 'GB', 'TB', 'PB']:\n if num < 1024:\n return f\"{num:.2f} {unit}\"\n num /= 1024\n\n# Usage:\nbytes_to_human_readable(123456789) # Returns: '117.74 MB'\n"
},
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in Python.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "def fibonacci(n):\n a, b = 0, 1\n print(a, end=\" \")\n if n > 1:\n print(b, end=\" \")\n for _ in range(2, n):\n c = a + b\n print(c, end=\" \")\n a, b = b, c\n print()\n\n# Usage:\nfibonacci(5) # Output: 0 1 1 2 3\n"
},
{
"title": "Find LCM (Least Common Multiple)",
"description": "Calculates the least common multiple (LCM) of two numbers.",
Expand Down
16 changes: 16 additions & 0 deletions public/consolidated/rust.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,22 @@
}
]
},
{
"categoryName": "Math And Numbers",
"snippets": [
{
"title": "Fibonacci Series",
"description": "Iterative approach to generate first N Fibonacci numbers in Rust.",
"author": "Karanjot786",
"tags": [
"fibonacci",
"math"
],
"contributors": [],
"code": "fn fibonacci(n: usize) {\n let (mut a, mut b) = (0, 1);\n \n print!(\"{} \", a);\n if n > 1 {\n print!(\"{} \", b);\n }\n\n for _ in 2..n {\n let c = a + b;\n print!(\"{} \", c);\n a = b;\n b = c;\n }\n println!();\n}\n\n// Usage:\nfn main() {\n fibonacci(5); // Output: 0 1 1 2 3\n}\n"
}
]
},
{
"categoryName": "String Manipulation",
"snippets": [
Expand Down
31 changes: 31 additions & 0 deletions snippets/c/mathematical-functions/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in C.
author: Karanjot786
tags: fibonacci, math
---

```c
#include <stdio.h>

void fibonacci(int n) {
int a = 0, b = 1, c, i;
printf("%d ", a);
if(n > 1) {
printf("%d ", b);
}
for(i = 2; i < n; i++) {
c = a + b;
printf("%d ", c);
a = b;
b = c;
}
printf("\n");
}

// Usage:
int main() {
fibonacci(5); // Output: 0 1 1 2 3
return 0;
}
```
31 changes: 31 additions & 0 deletions snippets/cpp/math-and-numbers/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in C++.
author: Karanjot786
tags: fibonacci, math
---

```cpp
#include <iostream>

void fibonacci(int n) {
int a = 0, b = 1;
std::cout << a << " ";
if(n > 1) {
std::cout << b << " ";
}
for(int i = 2; i < n; i++) {
int c = a + b;
std::cout << c << " ";
a = b;
b = c;
}
std::cout << std::endl;
}

// Usage:
int main() {
fibonacci(5); // Output: 0 1 1 2 3
return 0;
}
```
33 changes: 33 additions & 0 deletions snippets/csharp/math-and-numbers/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in C#.
author: Karanjot786
tags: fibonacci, math
---

```cs
using System;

public class FibonacciSeries {
public static void fibonacci(int n) {
int a = 0, b = 1;
Console.Write(a + " ");
if(n > 1) {
Console.Write(b + " ");
}

for(int i = 2; i < n; i++) {
int c = a + b;
Console.Write(c + " ");
a = b;
b = c;
}
Console.WriteLine();
}

// Usage:
public static void Main() {
fibonacci(5); // Output: 0 1 1 2 3
}
}
```
31 changes: 31 additions & 0 deletions snippets/java/math-and-numbers/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in Java.
author: Karanjot786
tags: fibonacci, math
---

```java
public class Fibonacci {
public static void fibonacci(int n) {
int a = 0, b = 1;
System.out.print(a + " ");
if(n > 1) {
System.out.print(b + " ");
}

for(int i = 2; i < n; i++) {
int c = a + b;
System.out.print(c + " ");
a = b;
b = c;
}
System.out.println();
}

// Usage:
public static void main(String[] args) {
fibonacci(5); // Output: 0 1 1 2 3
}
}
```
27 changes: 27 additions & 0 deletions snippets/javascript/mathematical-functions/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in JavaScript.
author: Karanjot786
tags: fibonacci, math
---

```js
function fibonacci(n) {
let a = 0, b = 1;
let result = a + ' ';
if (n > 1) {
result += b + ' ';
}

for (let i = 2; i < n; i++) {
let c = a + b;
result += c + ' ';
a = b;
b = c;
}
console.log(result.trim());
}

// Usage:
fibonacci(5); // Output: 0 1 1 2 3
```
22 changes: 22 additions & 0 deletions snippets/python/math-and-numbers/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in Python.
author: Karanjot786
tags: fibonacci, math
---

```py
def fibonacci(n):
a, b = 0, 1
print(a, end=" ")
if n > 1:
print(b, end=" ")
for _ in range(2, n):
c = a + b
print(c, end=" ")
a, b = b, c
print()

# Usage:
fibonacci(5) # Output: 0 1 1 2 3
```
30 changes: 30 additions & 0 deletions snippets/rust/math-and-numbers/fibonacci-series.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
title: Fibonacci Series
description: Iterative approach to generate first N Fibonacci numbers in Rust.
author: Karanjot786
tags: fibonacci, math
---

```rust
fn fibonacci(n: usize) {
let (mut a, mut b) = (0, 1);

print!("{} ", a);
if n > 1 {
print!("{} ", b);
}

for _ in 2..n {
let c = a + b;
print!("{} ", c);
a = b;
b = c;
}
println!();
}

// Usage:
fn main() {
fibonacci(5); // Output: 0 1 1 2 3
}
```