Skip to content

Instantly share code, notes, and snippets.

Avatar
Hello World!

Hi girvan

Hello World!
  • US
View GitHub Profile
@girvan
girvan / disable_adsense.php
Created Apr 30, 2020
disable adsense on 404 pages in wordpress
View disable_adsense.php
<?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 Jan 10, 2020
run promise / task in sequence
View promise-sequence.js
var tasks = [
function(resolve) {
return setTimeout(function() {
console.log(1);
resolve();
}, 300);
},
function(resolve) {
return setTimeout(function() {
console.log(2);
View workers_proxy.js
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 Oct 25, 2019
detect browser and append classname on html element
View detect-browser.js
(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 Oct 24, 2019
[bootstrap-4] pure js for burger icon of navbar toggler
View bs4-navbar-toggler.js
document.querySelector('.navbar-toggler').addEventListener('click', function(){
document.querySelector('.navbar-collapse').classList.toggle('show');
});
@girvan
girvan / cloudflare.html
Created Jun 27, 2019
track cloudflare's edge location by using GA event
View cloudflare.html
<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 Mar 27, 2019
Exclude some file paths in git file changes
View gist:f2c1755abc7f5409eb3bd756611cb2e5
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);
});
View testing.sh
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 Dec 7, 2016
Fix Google Analytics tracking
View ga_patch.js
/*
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 Aug 31, 2016 — 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.
View country-code-to-currency-code-mapping.csv
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
You can’t perform that action at this time.