Skip to content

Commit

Permalink
Merge branch 'main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
rzuckerm authored Dec 2, 2024
2 parents aecdef1 + 2940fe0 commit 967727d
Show file tree
Hide file tree
Showing 21 changed files with 951 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
archive/h/hack/*.hh linguist-language=Hack
5 changes: 4 additions & 1 deletion .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ on:
- 'archive/r/ruby/*.rb'
- 'archive/s/swift/*.swift'
- 'archive/t/typescript/*.ts'
schedule:
# Run every Thursday at 4:53 UTC (randomly chosen)
- cron: '53 4 * * 6'

jobs:
# We need this job to check if changed files should trigger analysis
Expand Down Expand Up @@ -77,7 +80,7 @@ jobs:
- name: Get CodeQL Languages
id: set-matrix
run: |
matrix=$(python scripts/get_codeql_languages.py ${{ steps.changed-files.outputs.all_changed_files }})
matrix=$(python scripts/get_codeql_languages.py --event ${{ github.event_name}} ${{ steps.changed-files.outputs.all_changed_files }})
echo "${matrix}"
echo "matrix={\"include\": ${matrix}}" >> $GITHUB_OUTPUT
Expand Down
17 changes: 17 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,20 @@ __pycache__/
.DS_Store
venv/
generated/

# Object directory
obj/

# Project files
*.fsproj
.*project
.*proj
.*targets

# Node.js
node_modules/
package.json
package-lock.json

# F#
Program.fs
4 changes: 2 additions & 2 deletions archive/c/c/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Welcome to Sample Programs in C! To find documentation related to the C code in this repo, look [here.](https://sampleprograms.io/languages/c)

## Sample Programs List - 25/37 :relaxed:
## Sample Programs List - 26/37 :relaxed:

In this section, we feature a list of completed and missing programs in C. See above for the current amount of completed programs in C. If you see a program that is missing and would like to add it, please submit an issue, so we can assign it to you.

Expand All @@ -14,6 +14,7 @@ Below, you'll find a list of completed code snippets in C. Code snippets precede
- :warning: [Binary Search in C](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+binary+search+c) [[Requirements](https://sampleprograms.io/projects/binary-search)]
- :warning: [Bubble Sort in C](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+bubble+sort+c) [[Requirements](https://sampleprograms.io/projects/bubble-sort)]
- :white_check_mark: [Capitalize in C](https://sampleprograms.io/projects/capitalize/c) [[Requirements](https://sampleprograms.io/projects/capitalize)]
- :warning: [Convex Hull in C](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+convex+hull+c) [[Requirements](https://sampleprograms.io/projects/convex-hull)]
- :warning: [Duplicate Character Counter in C](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+duplicate+character+counter+c) [[Requirements](https://sampleprograms.io/projects/duplicate-character-counter)]
- :white_check_mark: [Even Odd in C](https://sampleprograms.io/projects/even-odd/c) [[Requirements](https://sampleprograms.io/projects/even-odd)]
- :warning: [Factorial in C](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+factorial+c) [[Requirements](https://sampleprograms.io/projects/factorial)]
Expand All @@ -40,7 +41,6 @@ Below, you'll find a list of completed code snippets in C. Code snippets precede

The following list contains all of the approved programs that are not currently implemented in C. Click on the name of the project to easily open an issue in GitHub. Alternatively, click requirements to check out the description of the project.

- :x: [Convex Hull](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,convex+hull&template=code-snippet-request.md&title=Add+Convex+Hull+in+C) [[Requirements](https://sampleprograms.io/projects/convex-hull)]
- :x: [Depth First Search](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,depth+first+search&template=code-snippet-request.md&title=Add+Depth+First+Search+in+C) [[Requirements](https://sampleprograms.io/projects/depth-first-search)]
- :x: [Dijkstra](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,dijkstra&template=code-snippet-request.md&title=Add+Dijkstra+in+C) [[Requirements](https://sampleprograms.io/projects/dijkstra)]
- :x: [Fraction Math](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,fraction+math&template=code-snippet-request.md&title=Add+Fraction+Math+in+C) [[Requirements](https://sampleprograms.io/projects/fraction-math)]
Expand Down
184 changes: 184 additions & 0 deletions archive/c/c/convex-hull.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>

typedef struct {
int x;
int y;
} Point;

void printUsageAndExit() {
printf("Usage: please provide at least 3 x and y coordinates as separate lists (e.g. \"100, 440, 210\")\n");
exit(1);
}

int compare(const void *p1, const void *p2) {
Point *point1 = (Point *)p1;
Point *point2 = (Point *)p2;

if (point1->x != point2->x) {
return point1->x - point2->x;
}
return point1->y - point2->y;
}

int orientation(Point p, Point q, Point r) {
int val = (q.y - p.y) * (r.x - q.x) - (q.x - p.x) * (r.y - q.y);
return (val == 0) ? 0 : (val > 0) ? 1 : 2;
}

void convexHull(Point points[], int n) {
Point hull[n];
int hullCount = 0;

qsort(points, n, sizeof(Point), compare);

int l = 0;
for (int i = 1; i < n; i++)
if (points[i].x < points[l].x)
l = i;

int p = l, q;
do {
hull[hullCount++] = points[p];
q = (p + 1) % n;

for (int i = 0; i < n; i++) {
if (orientation(points[p], points[i], points[q]) == 2) {
q = i;
}
}

p = q;
} while (p != l);

for (int i = 0; i < hullCount; i++) {
printf("(%d, %d)\n", hull[i].x, hull[i].y);
}
}

// Function to check if a string is a valid number
bool isInteger(const char *s) {
char *end;
strtol(s, &end, 10); // Convert string to long
return (*end == '\0' || *end == '\n'); // Check if the entire string was valid
}

// Function to trim whitespace from a string
char* trimWhitespace(char *str) {
// Trim leading whitespace
while (isspace((unsigned char)*str)) str++;
// Trim trailing whitespace
char *end = str + strlen(str) - 1;
while (end > str && isspace((unsigned char)*end)) end--;
*(end + 1) = '\0'; // Null terminate after the last non-space character
return str;
}

// Function to parse input string and populate the array
int parseInput(const char *input, int **arr, int *size) {
char *token;
int capacity = 10; // Initial capacity
*arr = malloc(capacity * sizeof(int));
if (*arr == NULL) {
return false;
}

// Tokenize the input string based on commas
char *inputCopy = strdup(input);
if (inputCopy == NULL) {
free(*arr);
*arr = NULL;
return false;
}

token = strtok(inputCopy, ",");
*size = 0;
while (token) {
trimWhitespace(token); // Trim whitespace around token
if (!isInteger(token)) {
free(*arr);
free(inputCopy);
*arr = NULL;
return false; // Exit if a number is invalid
}

if (*size >= capacity) {
capacity *= 2;
*arr = realloc(*arr, capacity * sizeof(int));
if (*arr == NULL) {
free(inputCopy);
return false;
}
}
(*arr)[(*size)++] = atoi(token);
token = strtok(NULL, ",");
}

// Resize the array to the actual size
*arr = realloc(*arr, *size * sizeof(int));
free(inputCopy); // Free the input copy
if (*arr == NULL) {
return false;
}

return true; // Successful parsing
}

void parseCoordinates(char *inputX, char *inputY) {
int *xCoords = NULL;
int *yCoords = NULL;
int xSize = 0;
int ySize = 0;
if (!parseInput(inputX, &xCoords, &xSize) ||
!parseInput(inputY, &yCoords, &ySize) ||
xSize != ySize ||
xSize < 3) {
if (xCoords != NULL) {
free(xCoords);
}

if (yCoords != NULL) {
free(yCoords);
}

printUsageAndExit();
}

int count = xSize;
Point *points = malloc(sizeof(Point) * count);
if (points == NULL) {
free(xCoords);
free(yCoords);
printUsageAndExit();
}

for (int i = 0; i < count; i++) {
points[i].x = xCoords[i];
points[i].y = yCoords[i];
}

free(xCoords);
free(yCoords);

convexHull(points, count);
free(points);
}

int main(int argc, char *argv[]) {
if (argc != 3) {
printUsageAndExit();
}

char *inputX = argv[1];
char *inputY = argv[2];

if (strlen(inputX) == 0 || strlen(inputY) == 0) {
printUsageAndExit();
}

parseCoordinates(inputX, inputY);
return 0;
}
4 changes: 2 additions & 2 deletions archive/f/f-sharp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

Welcome to Sample Programs in F#! To find documentation related to the F# code in this repo, look [here.](https://sampleprograms.io/languages/f-sharp)

## Sample Programs List - 2/37 :disappointed:
## Sample Programs List - 3/37 :disappointed:

In this section, we feature a list of completed and missing programs in F#. See above for the current amount of completed programs in F#. If you see a program that is missing and would like to add it, please submit an issue, so we can assign it to you.

Expand All @@ -12,6 +12,7 @@ Below, you'll find a list of completed code snippets in F#. Code snippets preced

- :warning: [Baklava in F#](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+baklava+f#) [[Requirements](https://sampleprograms.io/projects/baklava)]
- :warning: [Hello World in F#](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+hello+world+f#) [[Requirements](https://sampleprograms.io/projects/hello-world)]
- :warning: [Remove All Whitespace in F#](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+remove+all+whitespace+f#) [[Requirements](https://sampleprograms.io/projects/remove-all-whitespace)]

### Missing Programs

Expand Down Expand Up @@ -45,7 +46,6 @@ The following list contains all of the approved programs that are not currently
- :x: [Prime Number](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,prime+number&template=code-snippet-request.md&title=Add+Prime+Number+in+F%23) [[Requirements](https://sampleprograms.io/projects/prime-number)]
- :x: [Quick Sort](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,quick+sort&template=code-snippet-request.md&title=Add+Quick+Sort+in+F%23) [[Requirements](https://sampleprograms.io/projects/quick-sort)]
- :x: [Quine](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,quine&template=code-snippet-request.md&title=Add+Quine+in+F%23) [[Requirements](https://sampleprograms.io/projects/quine)]
- :x: [Remove All Whitespace](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,remove+all+whitespace&template=code-snippet-request.md&title=Add+Remove+All+Whitespace+in+F%23) [[Requirements](https://sampleprograms.io/projects/remove-all-whitespace)]
- :x: [Reverse String](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,reverse+string&template=code-snippet-request.md&title=Add+Reverse+String+in+F%23) [[Requirements](https://sampleprograms.io/projects/reverse-string)]
- :x: [Roman Numeral](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,roman+numeral&template=code-snippet-request.md&title=Add+Roman+Numeral+in+F%23) [[Requirements](https://sampleprograms.io/projects/roman-numeral)]
- :x: [Rot13](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,rot13&template=code-snippet-request.md&title=Add+Rot13+in+F%23) [[Requirements](https://sampleprograms.io/projects/rot13)]
Expand Down
4 changes: 2 additions & 2 deletions archive/m/moonscript/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

Welcome to Sample Programs in Moonscript! To find documentation related to the Moonscript code in this repo, look [here.](https://sampleprograms.io/languages/moonscript)

## Sample Programs List - 2/37 :disappointed:
## Sample Programs List - 3/37 :disappointed:

In this section, we feature a list of completed and missing programs in Moonscript. See above for the current amount of completed programs in Moonscript. If you see a program that is missing and would like to add it, please submit an issue, so we can assign it to you.

### Completed Programs

Below, you'll find a list of completed code snippets in Moonscript. Code snippets preceded by :warning: link to a GitHub issue query featuring a possible article request issue. If an article request issue doesn't exist, we encourage you to create one. Meanwhile, code snippets preceded by :white_check_mark: link to an existing article which provides further documentation. To see the list of approved projects, check out the official Sample Programs projects list.

- :warning: [Fizz Buzz in Moonscript](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+fizz+buzz+moonscript) [[Requirements](https://sampleprograms.io/projects/fizz-buzz)]
- :white_check_mark: [Hello World in Moonscript](https://sampleprograms.io/projects/hello-world/moonscript) [[Requirements](https://sampleprograms.io/projects/hello-world)]
- :warning: [Reverse String in Moonscript](https://github.com//TheRenegadeCoder/sample-programs-website/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+reverse+string+moonscript) [[Requirements](https://sampleprograms.io/projects/reverse-string)]

Expand All @@ -29,7 +30,6 @@ The following list contains all of the approved programs that are not currently
- :x: [Factorial](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,factorial&template=code-snippet-request.md&title=Add+Factorial+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/factorial)]
- :x: [Fibonacci](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,fibonacci&template=code-snippet-request.md&title=Add+Fibonacci+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/fibonacci)]
- :x: [File Input Output](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,file+input+output&template=code-snippet-request.md&title=Add+File+Input+Output+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/file-input-output)]
- :x: [Fizz Buzz](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,fizz+buzz&template=code-snippet-request.md&title=Add+Fizz+Buzz+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/fizz-buzz)]
- :x: [Fraction Math](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,fraction+math&template=code-snippet-request.md&title=Add+Fraction+Math+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/fraction-math)]
- :x: [Insertion Sort](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,insertion+sort&template=code-snippet-request.md&title=Add+Insertion+Sort+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/insertion-sort)]
- :x: [Job Sequencing](https://github.com/TheRenegadeCoder/sample-programs/issues/new?assignees=&labels=enhancement,job+sequencing&template=code-snippet-request.md&title=Add+Job+Sequencing+in+Moonscript) [[Requirements](https://sampleprograms.io/projects/job-sequencing)]
Expand Down
12 changes: 12 additions & 0 deletions archive/m/moonscript/fizz-buzz.moon
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
for i = 1, 100
if i % 3 == 0 and i % 5 == 0
print "FizzBuzz"
continue
if i % 3 == 0
print "Fizz"
continue
if i % 5 == 0
print "Buzz"
continue
else
print i
Loading

0 comments on commit 967727d

Please sign in to comment.