Skip to content

Instantly share code, notes, and snippets.

@CarloCattano
Last active October 27, 2022 11:05
Show Gist options
  • Save CarloCattano/3d66643063822e568d366c930a012f99 to your computer and use it in GitHub Desktop.
Save CarloCattano/3d66643063822e568d366c930a012f99 to your computer and use it in GitHub Desktop.

shell & eval

Check for files

all files on folder and subfolders, useful before submitting or during eval.

  ls -l */*

The norm

check that all files follow the norm. On the project root:

norminette -R CheckForbiddenSourceHeader

Git

change repository url

(Fail -> retry) on the same folder.

git remote set-url origin [ Retry-repo-url ]

Git diff

view differences between last pushed work and N commits behind HEAD -> current ~N

git diff HEAD~1

.gitignore

Add a .gitignore in your repo root folder to avoid uploading files you dont want to upload.

cd C01/
nano .gitignore

for example, a.out files in all subfolders:

# inside your .gitignore file
**/a.out

You can check with

git status --ignored

Triple check by downloading your repo after a push to a test location and see if it worked.

set commit hash as HEAD

(a point in time when your project was working and now you want to revert back to that point(Careful!) Search for the commit hash that you would like to go back to using git log

git reset --hard <commit-hash-id-to-put-as-head>
git push -f

nano ~/.zshrc

Aliases

compilation & norminette helpers

Your aliases should be placed on ~/.zshrc for persistence. open your .zshrc file located in your home directory with nano , vim or texteditor

## end of ~/.zshrc file
alias norm='norminette -R CheckForbiddenSourceHeader'
alias comp='cc -Wall -Wextra -Werror -o test'

then source your zshrc source ~/.zshrc this will give you 2 aliases, the first one in this example is comp. it will compile with the flags and call the output test. If for some weird reason you still want to have it named a.out, you can delete -o test (ACHTUNG! update your gitignore accordingly) The second alias is for norminette with forbidden hearders check.

The theory behind it is simple

alias customCommandName="echo 'Running customCommandName will display this message or any command after the equal sign'"

To check what alias you have or where a program is

which [your program name]

So mine looks like this:

$ which norm
norm: aliased to norminette -R CheckForbiddenSourceHeader
$ which comp
comp: aliased to cc -Wall -Wextra -Werror -o test

ADVANCED

Function aliases

crun(){
  cc -Wall -Wextra -Werror -o test $1 && ./test
}

crunall(){
  cc -Wall -Wextra -Werror -o test *.c && ./test
}

evalme(){
 find . -wholename '*/.main.c' -type f -exec bash -c 'mv "$1" "${1/\/.main.c/\/main.c}"' -- {} \;
 echo "Hidden main.c tests restored"
}

cleanup(){
 echo "Hiding main.c files for submission"
 find . -wholename '*/main.c' -type f -exec bash -c 'mv "$1" "${1/\/main.c/\/.main.c}"' -- {} \;
}
  • crun its just compiling and running on the same command, needs to have the .c file you want to compile after it.
  • crunall its meant to compile all the *.c files to link several files together or run main.c (tests) + ex0X file
  • cleanup should hide all your main.c files and rename them .main.c ( so they are hidden on submission )
  • evalme its meant to be for when the evaluator is there and you want to get back your main.c files for testing

( DO NOT INCLUDE HIDDEN FILES FOR RUSH PROJECTS )

cleanup & eval me should be executed from the repository root folder , crun and crunall from the ex0X folder

Separating ft_* from main.c

Remember to include the ft_* prototypes in your main.c file

For example:

#include <stdio.h>

unsigned int	ft_strlcat(char *dest, char *src, unsigned int size);
int	ft_strlen(char *str);

int	main()
{
	char src[] = "1234";
	char dst[] = "abcd";
	printf("Final lenght:\t %d\n", ft_strlcat(dst,src,8));
	printf("String \t %s", dst);
}
@CarloCattano
Copy link
Author

thanks to @mhempel and @rwinder for the nice tips on git diff and remote url change

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment