Skip to content

Instantly share code, notes, and snippets.

View alsamitech's full-sized avatar

Sami Alameddine alsamitech

  • Alsami Technologies
  • United States of America
View GitHub Profile
@alsamitech
alsamitech / getline.c
Last active May 22, 2021 19:12
getline - Gets a line from a stream
char* getline(FILE* stream){
size_t bytes=0;
unsigned int capacity=64;
char* buf=malloc(capacity);
char c;
#ifdef __unix__
while((c=fgetc(stream))!=EOF&&c!='\n')
#else
while((c=fgetc(stream))!=EOF&&c!='\n'&&c!='\r')
#endif // __unix__
@hapejot
hapejot / read_file.c
Last active October 1, 2023 12:13
read_file
char *string_from_file( char *name ) {
int fd;
fd = open( name, O_RDONLY );
assert( fd > 0 );
struct stat buf;
fstat( fd, &buf );
assert( S_ISREG( buf.st_mode ) );
char *result = calloc( buf.st_size + 1, 1 );
@straker
straker / README.md
Last active June 30, 2024 11:15
Basic Snake HTML and JavaScript Game

Basic Snake HTML and JavaScript Game

Snake is a fun game to make as it doesn't require a lot of code (less than 100 lines with all comments removed). This is a basic implementation of the snake game, but it's missing a few things intentionally and they're left as further exploration for the reader.

Further Exploration

  • Score
  • When the snake eats an apple, the score should increase by one. Use context.fillText() to display the score to the screen