To untrack files in local repository but keep at origin, as our scenario needed; to keep folder or files in git origin repository but untrack any local changes made in this folder, You can use “git update-index –assume-unchanged”. This will enable new developers to get all the files in the repository when cloning. The application can make all the changes it wants in the specified folder, but locally they won’t be committed an pushed to the origin. The only minor problem with this solution is that you have to do this on every new machine that clones the repo. But something positive that comes out of this is that when you need to update files in the untracked folder you can.
1. Preparing the repo
Make sure you add the folder with all the containing files(that you later want to untrack) to the repo. And then commit and push it to your origin. In this example my folder is named Library.
2. Add this folder to .gitignore
And then commit this update. If you need more information about how to use the .gitignore file you can look at git online documentation.
At this stage the folder library and its contents are still tracked by git. Any changes to a file in this folder will therefor be marked as changed still. Lets take care of that next.
3. Untrack files in local repository but keep at origin
Now run the following command to untrack the library folder and its contents:
Make a change to a file in this folder and git will assume it has not been changed, so you won’t commit anything in this folder.
4. Undo this change
Say you need to update a file in the library folder after a while. Then you need only one command to start track this folder again:
5. Make alias of these commands
If you like you can create aliases for these commands to something simpler:
When validating C-Sharp made JWT signature with PHP, or the other way around, you may run into some problems. What can happen is that the hash will be different but the data still won’t be tampered with. I noticed this when sending a JWT from a server using C# to a server using PHP. This code example will create the same signature with both PHP and C#.
C#:
This is what the method SHA256Sum looks like:
Base64 encode method looks like this:
Base64 decode method:
And a method to create a byte array to a string
PHP:
This is a class that will encode, decode and validate a JWT-token and will return the same signature as the C# methods. If the data has not be tampered with that is.
When sending data from an application to a backend server you can use json web token (JWT) to make sure the data has not been tampered with. The token is compact making it quick to send to the backend.
Here is an example of a token:
A token is separated into three parts; Header, payload and signature. And, as you can see in the example above, these parts are separated by a “.” All three parts are base64 encoded. Let’s go trough what the different parts contains.
Part 1 - Introduction
Header
The header mostly consists of two parts alg, and typ.
Alg defines what hashing algoritm has been used to create the signature(which we will look at soon). And typ defines type of token, which is JWT.
Payload
The payload contains the data that you want to send to your backend. Example:
Signature
The signature consists of a base64 encoded HS256-hash built on the first two parts of the token. And this is signed with a shared secret that the app and the backend has.
Part 2 - Example: Creating a JWT with PHP
Line 3: This line base64 encodes the header json.
Line 4: This line base64 encodes the payload json.
Line 6: Here the the base64 strings are concatenated to one that looks like this:
Line 10: Here the signature is created. It creates a hash with the s256 algoritm with the secret key that you can see on line 8. This is string is also base64 encoded.
Line 12: This line concatenates the signature with the rest of the values, and creating a jwt token looking like this:
Part 3: Example: Verifying signature
This code checks so that the signature that was received checks out.
Line 2: $recieved_jwt contains the jwt. This would be received from a $_POST value in real life.
Line 5: $jwt_values is an array with the jwt values in it.
Line 7: $recieved_signature contains the signature from the original jwt
Line 8: we separate the header and payload an concatenates them.
Line 10: We create a new signature with the new header and payload.
Line 12: Check if the signature we created is the same as the one we received. If it is the data has not been tampered with.
Part 4 - A quick checklist
Base64 encode a header JSON Object.
Base64 encode a payload JSON Object.
Concatenate the header and payload strings with “.” separator
Compute the signature of the header and payload.
Base64 encode the signature.
Concatenate the signature to the header and payload string.
Conclusion
A json web token is quite easy to create yourself. And it’s easy to validate the signature as well. If the shared key (or $secret_key as its called above) gets in the wrong hands you can not trust the signatures anymore and need to change it.
You can do this with Screenbar. It gives you a user interface instead of running it in the terminal.
Automate screenshots with shell script
I needed to automate screenshots in mac os x, but i needed to use both my hands to play a game at the same time as i was taking screenshots. So i found this gem at TrickyWays. The following script will take a screenshot with a unique name and save it on your desktop. Just copy and paste it into a terminal window:
Just edit the number 5 to a interval in seconds that fit your needs.
The last months i’ve picked up game development i Unity. Every week on Fridays I have a day off to work with this project. That project also comes with a new site and developer blog.
Honkbark studios
If you are interested in following that progress you can check it out at Honkbark studios