Skip to content

Instantly share code, notes, and snippets.

View girvan's full-sized avatar
Hello World!

Hi girvan

Hello World!
View GitHub Profile
@girvan
girvan / disable_adsense.php
Created April 30, 2020 02:45
disable adsense on 404 pages in wordpress
<?php
add_filter('widget_text', function( $content ) {
$adsense = 'src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"';
if ( is_404() ) {
$content = str_replace( $adsense, '', $content );
}
return $content;
}, 1 );
@girvan
girvan / promise-sequence.js
Created January 10, 2020 02:34
run promise / task in sequence
var tasks = [
function(resolve) {
return setTimeout(function() {
console.log(1);
resolve();
}, 300);
},
function(resolve) {
return setTimeout(function() {
console.log(2);
addEventListener('fetch', event => {
event.respondWith(handleRequest(event.request))
})
async function handleRequest(request) {
const url = request.url + (request.url.indexOf('?')===-1 ? '?' : '&')
const hook1Response = await fetch(url + 'workers_proxy_get=1', request)
@girvan
girvan / detect-browser.js
Created October 25, 2019 08:09
detect browser and append classname on html element
(function(ua){
var m = ua.match(/(msie|firefox|edge)/);
if(m) document.documentElement.className += m[1];
})(navigator.userAgent.toLowerCase())
@girvan
girvan / bs4-navbar-toggler.js
Last active October 24, 2019 02:35
[bootstrap-4] pure js for burger icon of navbar toggler
document.querySelector('.navbar-toggler').addEventListener('click', function(){
document.querySelector('.navbar-collapse').classList.toggle('show');
});
@girvan
girvan / cloudflare.html
Created June 27, 2019 06:49
track cloudflare's edge location by using GA event
<script>
(function(){
var request = new XMLHttpRequest();
request.open('GET', '/cdn-cgi/trace', true);
request.onload = function() {
if (request.status != 200) return;
var match = request.responseText.match(/(colo|loc)=(\w+)/g),
colo = match[0].split('=')[1], loc = match[1].split('=')[1];
ga('send', 'event', 'cloudflare', loc, colo);
};
@girvan
girvan / gist:f2c1755abc7f5409eb3bd756611cb2e5
Last active March 27, 2019 07:19
Exclude some file paths in git file changes
document.querySelectorAll("#toc li").forEach(function(li, idx){
if(li.innerText.indexOf('/SOME-PATH-YOU-WANT-TO-EXCLUDE/') === -1)
return;
var id = li.querySelector('a').href.split('#')[1];
var block = document.querySelector('a[name=' + id + ']').nextElementSibling;
block.parentNode.removeChild(block);
li.parentNode.removeChild(li);
});
cd ~/tmp/
url1=https://...
url2=https://...
url3=https://...
for i in {1..500000}; do
time1=$(curl -o /dev/null -s -w %{time_total} $url1)
time2=$(curl -o /dev/null -s -w %{time_total} $url2)
@girvan
girvan / ga_patch.js
Created December 7, 2016 05:30
Fix Google Analytics tracking
/*
setup: paste before ga('send', 'pageview');
features:
- fix *.search.yahoo.com to Organic
- fix Line and WeChat Apps to Social
*/
(function(r, M, S){
if(r.match(/^https?:\/\/\w+\.search\.yahoo\.com\//))
{ga('set',M,'Organic');ga('set',S,'Yahoo!');return}
@girvan
girvan / country-code-to-currency-code-mapping.csv
Last active August 31, 2016 07:42 — forked from HarishChaudhari/country-code-to-currency-code-mapping.csv
Country, Country Code, Currency code mapping in CSV format Taken from https://gist.github.com/304261 Contains 249 countries.
Country CountryCode Currency Code
New Zealand NZ New Zealand Dollars NZD
Cook Islands CK New Zealand Dollars NZD
Niue NU New Zealand Dollars NZD
Pitcairn PN New Zealand Dollars NZD
Tokelau TK New Zealand Dollars NZD
Australian AU Australian Dollars AUD
Christmas Island CX Australian Dollars AUD
Cocos (Keeling) Islands CC Australian Dollars AUD
Heard and Mc Donald Islands HM Australian Dollars AUD