Tech C**P
14 subscribers
161 photos
9 videos
59 files
304 links
مدرس و برنامه نویس پایتون و لینوکس @alirezastack
Download Telegram
Did you push a very large file into git? Does everyone yell at you about your commit and your uselessness? Are you a junky punky like me that just ruin things? Oh I'm kidding...

Because of that big file cloning the repo again would take a long long time. Removing the file locally and pushing again would not solve the problem as that big file is in Git's history.

If you want to remove the large file from your git history, so that when everyone clone the repo should not wait for that large file, just do as follow:

git filter-branch --tree-filter 'rm path/to/your/bigfile' HEAD

git push origin master --force

I should note that you should be in the root of git repo.

If you need to do this, be sure to keep a copy of your repo around in case something goes wrong.

#git #clone #rm #remove #large_file #blob #rebase #filter_branch
How to upload a text content as a file in $.Ajax()?

FormData class is used to create a multipart/form-data inside of JS code. A sample code speaks thousand words:


var formData = new FormData();
var blob = new Blob([YOUR_CONTENT_HERE], { type: "text/html"});
formData.append("file", blob);


We have created a binary data from the text which is in the format of text/html, then I have appended the data as an input file with the name of file (which will be captured on server-side).

The Ajax part is utterly simple:


$.ajax({
type: 'POST',
url: 'https://www.example.com/storage',
data: formData,
processData: false,
contentType: false
}).done(function(data) {});


NOTE: DO NOT OMIT processData, contentType parameters.

#javascript #jQuery #ajax #FormData #Blob #upload
How to convert ByteArray to PDF and then upload it via jQuery?

var docData = [ yourByteArray ];
var blob = new Blob([new Uint8Array(docData)], { type: 'application/pdf' });

// Now create form to upload the file
var formData = new FormData();
formData.append("file", blob);

// Let's now upload the file
$.ajax({
type: 'POST',
url: 'https://www.YOUR-UPLOAD-FILE-ENDPOINT.com/storage',
beforeSend: request => set_ajax_headers(request),
data: formData,
processData: false,
contentType: false
}).done(function(data) {
console.log('File is uploaded!');
});

NOTE: function set_ajax_headers is a function that sets headers on the given request.

#javascript #ByteArray #PDF #Uint8Array #Blob #jQuery