moose-mousse - Electronic Moose
Electronic Moose

Helloooo! I am Moose! They/Them/He/Him I am a embedded software engineer with autism, depression and anxiaty ( Wooo! ). I post about... whatever I want... software things, mental health things... whatever I feel like Feel very wellcome to send me asks about... anything that strikes your fancy :3

266 posts

I Just Downloaded A Program, As A Git Repository.It Allowed You To Have It Work In Several Different

I just downloaded a program, as a git repository. It allowed you to have it work in several different ways. Which was achieved by simply using "git checkout" to check out whatever branch you want. I love it. That is so smart!

  • fallen-juniper-leaves
    fallen-juniper-leaves liked this · 1 year ago
  • code-es
    code-es liked this · 1 year ago
  • mcgeese
    mcgeese liked this · 1 year ago
  • nourhanlwt
    nourhanlwt liked this · 1 year ago
  • frog707
    frog707 liked this · 1 year ago

More Posts from Moose-mousse

1 year ago

A beginners guide to GIT: Part 4 - How to use GIT as 1 person

Table of content: Part 1: What is GIT? Why should I care?

Tumblr
Table of content: Part 1: What is GIT? Why should I care? <-------- You are here Part 2: Definitions of terms and concepts Part 3: How to

Part 2: Definitions of terms and concepts

A beginners guide to GIT:
Part 2 - Concepts and terms
Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. <-------- You are here Part 3: How to

Part 3: How to learn GIT after (or instead of ) this guide.

Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to learn GIT after (or in

Part 4: How to use GIT as 1 person

A beginners guide to GIT:
Part 4 - How to use GIT as 1 person
Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to learn GIT after (or in

Part 5: How to use GIT as a group.

A beginners guide to GIT:
Part 5 - How to use GIT as a group.
Tumblr
Table of content: Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to lea

When it comes to not getting in each other's way, working alone is the simplest (It has a lot of other drawbacks). This is the simplest way to use GIT. You can do it with an external repository as a backup or just locally on your computer. It depends on how important your project is. If your laptop crashes tomorrow, which projects would you have a really hard time losing? Better to have an external backup for that. Github is often used for this (Maybe less now that Github makes machine learning AI’s, and so ARE stealing your code to train their AI on.) but you can also use Bitbucket (Which... may also steal your code...) and there are many many others out there. GIT is often used in certain patterns, called “workflows”. These have you working in more or less rigid ways to make it simple to work together. But since you are working alone, you do not risk others changing your code while you are working, so you can do it the simplest way :D

I will be doing a step by step guide that you can follow along. I will be doing it on a completely empty project and making a tiiiiiny program in C. This is because it is super simple. You do NOT have to know C to follow. You can also follow the steps with your own already existing project.

I PROMISE you, GIT cannot hurt you. Worst case scenario is that you fiddle around and break the repository part. (Meaning the files in the .git folder). But your files will always be safe.

(If you do not have git installed, check out part 3 for that)

First, I make a folder, navigate my shell into it, and call git init:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

By the way, you can get used to GIT messages like this that tell you all your options, and explain what GIT has done for you. GIT is very good about giving you as much help and info as possible,

Now I will teach you the most important command in GIT.

It is more important than any other. Ready?

git status

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

This makes GIT tell you what git thinks is happening right now. What issues there are and what files are tracked, untracked or have been changed. Use this command often, especially while you are new to GIT, run it after every other command. It is how you learn what GIT is doing and thinking :3

Since our repo is empty it tells you what branch you are on (master. The only branch we will need since we are working alone)

and that you have not made any commits.

It also tells you the commands git think you will want to use on files. Since our repository is empty, it tells us to create some files, and then how to add them :3 So let's do that:

I have added my tiny program, as you can see:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

Now let us see what GIT thinks we did:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

Now, since there have been changes, git shows us them.

Files can be untracked tracked and not changed (In which case, git status does not show them) tracked and changed.

Right now, main.c is untracket. Which basically means GIT have no idea about this file, other than it is in the folder.

Ok, let us commit(save) the file. GIT tells us this is done with git add <File> . So we will write git add main.c

Then we use git status again to see what happened git status

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

And yeah, our file is now ready to be committed. So lets do it! git commit -m “My first commit!”

The “-m” option is to write the git update explanation directly in the console instead of using an external program to do it. Done You have now committed your code! It is now saved!

git status shows that everything in the working tree is as it was last time we committed (Duh. We JUST committed)

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

I will now make some changes to the main file:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

Git status shows us main.c was changed...but what if we wanted to know what was changed in more detail? How will we get status to do that for us? Let us find out! git help status

git then shows the help page for status And there we can see this part:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

So if we write status with 2 -v arguments, we get all the details. Let us try:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

And look! It shows us EXACTLY what lines were changed! I stage the changes and commit:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

And you have now learning enough about GIT to use it.. You now have all your work saved, in different commits. If you ever want to know all the commits you have made, write git log:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

And if you want to know what a specific commit did, you copy the name of the commit, and write git show:

A Beginners Guide To GIT:Part 4 - How To Use GIT As 1 Person

Now, everytime you want to save your work, you

1: Write/change the files you want

2: Add the files you want as part of this commit

3: make the commit These three steps are your workflow.

If you have a remote repository, then you add them steps

4: push to remote repository

To do this step, you can actually just write

git push

If you have set up a remote repository, then it just works. If you have not, then git will tell you what to do Whichever remote repository you use will tell you if you need to do other steps, like setting up passwords or ssh keys. They will also tell you how to set up the remote repository (That is not a GIT thing, that is a bitbucket or a github thing, so refer to whichever of those sites you want to use) And that is all! Every time you commit, your project is saved (it is smart to commit often, but usually only commit when your project can be compiled.) And whether you use a remote repository or not, you now have a fully valid GIT repository, and all the git tricks can be used on your project!


Tags :
1 year ago

What are strings???

So, on the codeblr discord there was a question which is hard to answer unless you already fully understand what a string is... So, what is a string?

And this is a great question! Because to answer it we will learn a hell of a lot!

To answer this, one needs to know what an array really is. This is important in any language you write in. But in most languages it only becomes important to know when you get to optimizing code.

So for most, it is fine to think of arrays simply as collections. But in C, you need to know what they truly are to work with them (Which is why newbies are often taught C to learn these things)

I will use drawings and links to godbolt code examples I made, to help you understand things.

To explain what strings and arrays are, I will use a trick that you may also want to copy if you have a hard time learning concept in programming or electronics.

Try to to "re-invent" it. By going step by step into the things that required it to be invented, and how it was done.

So arrays. They are a way of storing many variables in one place, and work on them very very efficiently.

We start with having variables. Each variable have an address where they are in memory, and a value at that address.

An address is just a number. Nothing more. But to make it clear when we are talking about them, traditionally you write it in HEX. These numbers are marked with "0x", as in, to write "6" in Hex, we write "0x6"

Now, on each address you can store 8 bit. To store values that are larger, we use more than one memory address.

Ok, with all info, let us draw the example we will use, and write the code:

We will have 3 numbers. Each takes 16 bits:

What Are Strings???

https://gcc.godbolt.org/z/cse64Kd6x

(Notice that the adresses counts DOWN. This is for stack and heap reasons we will not explain here. But just know that we count DOWN, not up when it comes to adresses on the stack, which is all we will work with here.)

If we know the type of a variable, we also know how much space it takes.

So to really know a variable, we need to know its type, and its memory address.

Now, if we create these variables one after the other they will be placed right next to each other in memory.

Then we can create a pointer! A pointer have a type they point to, so it knows how much space the variables takes, and a memory address. We will create it pointing at the first variable!

Let us draw it on the example:

What Are Strings???

https://gcc.godbolt.org/z/9abqMjrs3

And now, if we want to work on all of our values, we simply do whatever we want, and then subtract 2 from the pointer to get to the next value, and then work on that one, and so on.

If we want to add 1 to every value, we could do this:

Step 1, add 1

What Are Strings???

Step 2: Move pointer

What Are Strings???

Step 3: Add 1

What Are Strings???

And so on and on! :D

https://gcc.godbolt.org/z/7KGadT868

This is how arrays works. But instead of us having to remember to count DOWN, and what size variables are we have gotten all this build into the language. It also GARANTEES that the variables are placed next to each-other in memory (This is not actually guaranteed when you use single variables like we have in the examples... NAUGTY US!)

So this code does exactly the same as we just did. And as you can see it is MUCH easier:

https://gcc.godbolt.org/z/KWxc939v4

So as you can see, a array is... more or less a pointer that you cannot change (because it always point at the first element), also known as a const pointer. And instead of moving the pointer, we use the index... which is just "The adress of the first variable, and then move it down as many times as the variables size times the variable number we want"

And a string... is a specific kind of array we often need, because we often need strings of characters. A string is a array containing elements that are characters.

If you are using ASCII, that is 8 bit signed values

If you are using UTF-16 then it is 16 bit signed values

See? It is super easy to explain what strings are!

... IF you know what arrays are... and why we use them....


Tags :
1 year ago

Help learning c++

So at my internship a whole bunch of people have to switch to C++. And because management is incompetent, there are no learning package or company resources to help this. So I am converting some of my code notes to help this along. And I am also sharing them here. They are created on, and meant to be used on godbolt. They contain explanations and some of them instructions for how to investigate what you are looking at. The ones I have for now are: Understanding objects ( Constructor, destructor, assignment and copy operators ) https://godbolt.org/z/EaMc1fW44 Access modifiers (IE, do you know what public, private and protected means?) https://godbolt.org/z/v3nejaYhh

Pointers (Basically, to not use raw pointers and what to use instead) https://godbolt.org/z/4745PK38n


Tags :
1 year ago

FINALLY got done with the Beginners guide to GIT

So a long time ago I made a poll to help me make a Begginers guide to GIT because a lot of people seem to have trouble with it. https://www.tumblr.com/moose-mousse/722172571753365504/going-to-make-a-getting-started-with-git-post?source=share

And I know for a fact that my University taught it horribly. (Or rather... did not teach it at all)

I REALLY tried making this guide as short as I possibly could. Explaining only what you need to know, while trying to clarify what most people find confusing. But it still is too long for a single post. So, I have split it into 5. The post each links to each other, so you should be able to go back and forth easily.

This guide is going to be pure GIT done via the command line. 2 reasons for this:

1: GIT GUI’s are really handy, but they abstracts away a lot of the newbie help GIT is trying to give you. Bitbucket, Github, Jira, and other services use GIT but usually add extra bits that are specific to them. So to know how they are different, it is smartest to learn pure GIT first. And since they are 99% GIT, you will be able to use them with no/little trouble.

2: Because I use the command line, it is easy to build your own automation tools. Simply have a program write git commands to the shell and/or read outputs from git commands and use them to visualize whatever you want, however you want. That way you can have whatever shiney graphics your heart can code up. All the tools you can find (Like Github desktop or gitk) are simply doing this. (incidentally, if any of you make a pretty visualization of GIT? Show me! I wanna see a dog themed GIT graph! I wanna see pink log outputs! Make it yours!)

Table of content: Part 1: What is GIT? Why should I care?

Tumblr
Table of content: Part 1: What is GIT? Why should I care? <-------- You are here Part 2: Definitions of terms and concepts Part 3: How to

Part 2: Definitions of terms and concepts

A beginners guide to GIT:
Part 2 - Concepts and terms
Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. <-------- You are here Part 3: How to

Part 3: How to learn GIT after (or instead of ) this guide.

Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to learn GIT after (or in

Part 4: How to use GIT as 1 person

A beginners guide to GIT:
Part 4 - How to use GIT as 1 person
Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to learn GIT after (or in

Part 5: How to use GIT as a group.

A beginners guide to GIT:
Part 5 - How to use GIT as a group.
Tumblr
Table of content: Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to lea

Tags :
1 year ago

A beginners guide to GIT: Part 5 - How to use GIT as a group.

Table of content: Part 1: What is GIT? Why should I care?

Tumblr
Table of content: Part 1: What is GIT? Why should I care? <-------- You are here Part 2: Definitions of terms and concepts Part 3: How to

Part 2: Definitions of terms and concepts

A beginners guide to GIT:
Part 2 - Concepts and terms
Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. <-------- You are here Part 3: How to

Part 3: How to learn GIT after (or instead of ) this guide.

Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to learn GIT after (or in

Part 4: How to use GIT as 1 person

A beginners guide to GIT:
Part 4 - How to use GIT as 1 person
Tumblr
Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to learn GIT after (or in

Part 5: How to use GIT as a group.

A beginners guide to GIT:
Part 5 - How to use GIT as a group.
Tumblr
Table of content: Table of content: Part 1: What is GIT? Why should I care? Part 2: Definitions of terms and concepts. Part 3: How to lea

For this, I will describe a workflow, called “feature branch workflow.” There are others that are simpler, and are sometimes better,  but I will describe one that always works, for any amount of people, and most likely is what your future workplace uses.. And yes, it involves branching (which sounds scary, but it is not so bad.)

Why? Well because of 2 goals we have that somewhat clash.

1: To use GIT in a way that is easy on ourselves and will give us all the benefits of GIT. This means committing often. Pretty much every time we have made a change, and we can compile.

2: We want to sync our work with our fellow workers. But this takes effort every time we do it because we might have made changes that clashes with changes someone else have made.

(Notice though that this is not a problem originating in GIT. This is a problem that comes from people working together on the same thing. GIT just makes it easy to spot the problems and describe them in an accurate way.)

We alleviate this by only syncing up when we have made a larger chunk of self contained work. Usually we use  the term "feature" for this. And they can be quite small (For example 4 commits, making a "Return to previous page" button ) or large (For example,  38 commits, which also used branches, to implement a GUI on top of the backend code we have made).

It is best to make features as small as you can, so that a feature branch does not end up being an entirely different sister project to the main branch.

The first thing we do is declare the main/master branch holy. Just like any branch, it must always compile, but now we add " May only have fully realized features". It must ALWAYS be ready to be shown to the customer/your boss/your adviser/your teacher.

So when we want to do some work, we coordinate it with our teammates so people are not working on the same thing, and thus wasting their time. ( This can be done with tickets, verbally at meetings, in group chats. Whichever fits your team )

Then we make a branch with its base at the tip of the main/master branch. We then do work, commit and push every commit onto that branch. This has all the benefits we had from working alone. We cannot get merge conflicts, as we are the only one working on this branch.

So let us show how this works! For this example I have set up a remote repository on bitbucket containing only a standard README that I have not written in at all., I then cloned it down in 2 different directories. Each of which I have opened with a console. This is how I will represent multiple people:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

So first, we show off one person making a change, and the other getting it. So I add a main.c file in there, add it so it is staged for commit, and then commit it:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

And if we write git status, we can see that we are 1 commit ahead of the remote repository:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

We then push our commits to the remote repository:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

The other user can now use git fetch (Which gets the latest information from the remote repository, but does not change anything):

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

We then pull the latest update from the remote repository with git pull:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

This is the simple way to work. But of course, if we have changed the same file, we will get a merge conflict.

As we talked about, we will minimize those by using branches. So we will say that each of these two people now will work on a different feature. Each of which will be a function that prints something. And each will be in another c file, with a header. We will do this with branching. We want to make a branch, and then switch to it. Switching to branches is called “checkout”. We can do both in one step by checking out a branch that does not exist, with the option -b (You can as always read about checkout, by writing “git help checkout”)

git checkout -b My_Spiffy_Feature

When we then write git status, we can see that we are on the new branch:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

I then add the new files. with the new function in, and we want test that they work by calling the function in main:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

We then compile our program (which gets default name a.out) and run it:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

It works! Great, time to commit. We add the new files, BUT NOT main.c or a.out . They were just for testing, and is otherwise not related to our feature.

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

And we then push to the remote repository:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

As you can see, git complained, because while we have created our branch, we had not really configured it yet (Specifically, we never told git what branch this new branch should originate from from. We just created it out in the void). But GIT TELLS you what to do. So I simply wrote the recommended command, and bam, branch is working as we want it to

I update the new feature file, just so we have more than one commit. I add the changes, commit and push again:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

Now that our feature is done, we want to merge the branch into the master branch.

To showcase something, I will first have the other person make a change to main, add, commit and push it:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

The first person will now merge their spiffy new feature in. They do that by switching to the master branch with git checkout:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

We see that we are behind 1 commit, so we pull.

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

But horror! Since we have the unstaged changes, we cannot pull, since we changed main.c to tests our new feature, AND the other person have changed main, those two cannot exist at the same time. So what do we do? Well, in this case, we are ok with our tiny test in main.c being lost. So we remove it like so:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

Notice how EVERYTHING I did here, was just read what GIT said was the problem, then write git status, and do the actions that GIT tells me I can do, which solves the problem. Ok, now we have the latest update of the master branch. Time to merge our feature in:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

This time I did not use the -m feature (Because I forgot) so I just used the external program to write the commit message.

And if we write git log, we can see every single one of the commits. Both in the branch, and in the master:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

And if we want to get a bit of a graphical representation of what happened, we can use git log --graph:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

Now, this is the simple way to do branching. You actually have full control over how exactly you want to merge your branch in. In this case, the two commits of the branch was added AFTER the commit on master. But we COULD have merged the branch in so that the two commits on the spiffy function was done BEFORE the changes on master. When you are still starting out, do not worry about this. But that is the workflow. You create a branch, you work on your feature in it, where you cannot get in the way of anyone else. When your feature is done, you merge it into the master. This way, the master was always ready to show to your teacher/boss, and did not have half implemented things that you would have to explain should be ignored at any point.

Half of the benefit of the feature branch workflow is that it minimizes the chance for merge conflicts. For them to happen, 1 group would have to go to the master branch and pull. AFTER they pulled, but before they managed to merge their branch in, another group must pull from master, and merged their feature in.

Unlikely.

But let us talk about merge conflicts.

Are those not horrible things that break everything?

No. Merge conflicts simply means GIT could not figure out how to merge something, and so a human will have to do it for it. GIT is nice, and shows you exactly where the problem is, and how to solve it. Let us create a merge conflict. The first person adds in the function that uses their new spiffy feature after the hello world prinf, stages the changes and commits them. But do not yet push

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

The other person creates 2 more printf statements in main, stages the changes for commit, and commits them:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

Now we have 2 commits, that both changes main.c How should these two be merged? Should the spiffy feature be called before or after the newly added prinf lines? GIT cannot know this, and so will tell the humans to do it. And the job falls to whoever wanted to push in a change that creates the merge conflict. In our example, I will have the second person, who added the extra printf lines push first:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

And now the first person with their spiffy feature pushes, and:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

It fails... But we are fine. Nothing actually happened here. The remote is still fine, and we locally are still fine. But we have to figure out how to fix this. When in doubt, use git fetch to get all the info but change nothing, and then git status:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

(By the way, I made an honest mistake here, and did not push the branch changes after I merged. But I am not really in trouble, because GIT saved me! :D) And as we can see, GIT is once again telling us what to do. Great!

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

And we are now at the place where we need to decide what to do. While you are still new, I recommend the default strategy. So we do as GIT tells us to:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

And now, FINALLY, we have our merge error. But notice that we only got it this way, because we asked for it. So… what does that mean? Git status to the rescue once more!

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

As expected, the problem is in main.c Let us check out what is in that file:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

We have our changes first, then a separation, and then the other changes. And fixing it is piss easy. We remove the lines GIT inserted to tell us where the conflict was, and put the code in order. WE decide if the spiffy feature should be put before, after or in the middle of the two printf statements. I decide to put them in the middle like so:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

Merging the two versions together, is in of itself, a change to the code. So we will now do what we always do when we have made changes. Add the files that we changed, and make a commit, and then push:

A Beginners Guide To GIT:Part 5 - How To Use GIT As A Group.

We have now resolved the merge conflict.

Notice how the problems that we ran into were not GIT problems. We ran into issues that ALWAYS come up when multiple people are working on the same project. But GIT made it really clear what the issues were, and forced us to deal with them in a smart way! :D


Tags :