Get Cloudflare geolocation data client side
Cloudflare provides a very handy HTTP Header called `CF-IPCountry` which you can use to detect your users’ geolocation. You can read more about that here (https://support.cloudflare.com/hc/en-us/articles/200168236-Configuring-Cloudflare-IP-Geolocation)
Now, most people recommend creating an ajax request to get that geolocation data clientside as the header is only available from Cloudflare => Server not from Cloudflare => Client. This is all well and good however this can cause a fair bit of noise on a busy site as this request needs to be uncached.
Recently I was pointed to what might be a little hack where you can actually use Cloudflares `cdn-cgi/trace` URL to pull through your geolocation data.
return axios
.get('https://cloudflare.com/cdn-cgi/trace')
.then({data} => {
let country_code = 'XX';
let lines = data.split('\n');
let keyValue;
lines.forEach(line => {
keyValue = line.split('=');
if (keyValue[0] === 'loc') {
country_code = decodeURIComponent(keyValue[1] || '');
}
});
return country_code;
})
.catch(error => {
return 'XX';
});
Chrome bugging you about insecure connections on localhost?
Sick of clicking Trust this site on your own Localhost. Like seriously chrome 🤦🏼♂️
Exclude a folder from your git diff
Need a way to show your git diff in your terminal while excluding a folder from your results? While boy do I have a trick for you!
Sync your uploads
I’ve had to do this a few times recently and I had to keep looping through my bash history to find it. If you need to pull down your prod / staging uploads directory from a server you have ssh access to:
What y’all thought