json to csv download in the browser

While using a javascript based datagrid that was displaying json data provided to a page, I thought it smart to not have to re-download all the data again just to make export a csv file.

My solution was to use the “Papa Parse” library to create the CSV file and use URL.createObjectURL() to actually make local data appear as a file which can be downloaded.

I also tried directly setting base64 encoded data to the window like this solution but it choked on my 6-10MB report results.

jQuery(document).ready(function() {
 //My json formatted data from php.
 var dataSet = <?=json_encode($data)?>;
 //select our link, create an objectURL Blob of CSV data.
 jQuery('#downloadCsv').attr('href',URL.createObjectURL(new Blob([Papa.unparse(dataSet)], { type:"text/csv" } ) ) );
 });

and the html for the link:

<a id="downloadCsv" class="button button-secondary" download="reportdata.csv">Download CSV</a>

 

Debugging git push/clone issues with ip6

Problem: You're doing "git push" or "git clone" and it takes forever to connect.

This could be a lot of things. In my case it was a firewall issue on a dual stack server hosting my repository.

How can you tell?

git config -global core.sshCommand "ssh -vvv"

This enabled verbose mode for SSH. Now try to clone your repo and you'll get a lot more information.

In my case, it was a DNS resolution problem.

[email protected]:test $ git pull origin master
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/dkilgo/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug2: resolving "test.me" port 49001
debug2: ssh_connect_direct: needpriv 0
debug1: Connecting to test.me [xxxx:xx:xxxx:x:xxx:xx:xx:xxx] port 49001.
debug1: connect to address xxxx:xx:xxxx:x:xxxx:xx:xx:xxx port 49001: Operation timed out
debug1: Connecting to test.me [000.00.00.000] port 49001.
debug1: Connection established.
….

I got a timeout on the ip6 address. The SSH port on this dual-stack server is being blocked. Once it fails, git will try ip4 which works.

Since I don't have control over the network here, I can work around this issue with ssh's config.

How do I fix this without breaking everything else that uses ip6?

You could just disable ip6 in your network settings. In 2017, that's not the most practical solution. We can do that for just one host in our SSH settings and get the same effect.

Edit your ~/.ssh/conf and add

Host test.me
AddressFamily inet

This tells ssh to only use ip4 for this host. This makes my one buggy host happy and doesn't mess with the rest of the internet. If you discover ip4 is the problem for you and ip6 works, set that to "inet6" instead. 

Don't forget to turn off that verbose logging we turned on earlier.

git config -global core.sshCommand "ssh"

 

If this didn't fix your issue, try git's debug options.

GIT_CURL_VERBOSE=1 GIT_TRACE=1 git pull origin master

The GIT_TRACE environment var makes git output more debug info during any operation. Setting it like this means it will only impact this command.

If you want this to work for any user or app, you can export that var.

EXPORT GIT_TRACE=1

and any call to git will output debug info, even from a tool like source tree or git embeded in an IDE. More info on git environment variables.