Skip to content

Instantly share code, notes, and snippets.

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);
@girvan
girvan / gist:3204844
Created Jul 30, 2012
公平隨機抽獎產生器
View gist:3204844
<html>
<head>
<style type="text/css">
.help {}
#result { font-weight:bold; font-size: 24px;background-color:yellow;}
a:visited { color:blue; }
.main { font-size:22px; }
#title, #total,#str,#num { width:400px; height:2em;}
.help { cursor:pointer; }
#input-str { position:relative; }
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);
});
@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}
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)
You can’t perform that action at this time.