Skip to content

Instantly share code, notes, and snippets.

View ahgood's full-sized avatar

Guojun ahgood

  • Fullstack Developer
  • Halifax
View GitHub Profile
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Youtube sample</title>
<style>
#video-link {
position: relative;
top: -100px;
left: 100px;
<?php
$time_start = microtime(true); //record the execution time
$xml = simplexml_load_file('data.xml');
$country = '';
$city = '';
$search = '';
if (isset($_GET["search"])) {
$search = trim(htmlspecialchars($_GET["search"]));
@ahgood
ahgood / crawl.js
Created April 29, 2016 23:09
PhantomJS sample script
var page = require('webpage').create();
page.onConsoleMessage = function(msg) {
console.log(msg);
};
page.open("http://www.somewebsite.com", function(status) {
if ( status === "success" ) {
page.evaluate(function() {
document.querySelector("input[name='MAIL_ADDRESS']").value = "[email protected]";
<!DOCTYPE html>
<html>
<head>
<script src="https://npmcdn.com/@reactivex/[email protected]/dist/global/Rx.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<!DOCTYPE html>
<html>
<head>
<script src="https://cdnjs.cloudflare.com/ajax/libs/rxjs/4.0.6/rx.all.js"></script>
<script src="https://code.jquery.com/jquery-2.1.4.js"></script>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
@ahgood
ahgood / yyyy-mm-dd.js
Created May 28, 2016 02:27
Create a file name is YYYY-MM-DD.js, if file existes, append content to file
var fs = require('fs');
var date = new Date();
var month = date.getMonth() + 1;
month = (month < 10 ? '0' : '') + month;
var day = date.getDate();
day = (day < 10 ? '0' : '') + day;
var filename = date.getFullYear() + '-' + month + '-' + day + '.js';
content = 'Content to add/append to file';
@ahgood
ahgood / filter_urls.js
Created June 13, 2016 02:29
4 scripts in 1 file, break them before use
/*
1. Sort lines
2. Check each line, if start with string "http", add to "_http_list.txt", other add to "_no_http_list.txt"
3. If one line contains 2 URLs, keep the first one only.
*/
var _http_list = '';
var _no_http_list = '';
var fs = require("fs");
var urls = fs.readFileSync('input.txt').toString().split('\n');
var sorted_urls = [];
//CSS effect: -webkit-transition: all 0.4s ease; transition: all 0.4s ease;
jQuery('h2:contains("KEY")').parent().attr('id', 'sticky-nav');
jQuery('head').append('<style>.sticky-nav {width: 100%;position: fixed;top: 0;background-color: #fff;text-align: center;}.sticky-nav > div {float: none; display: inline-block;}</style>');
jQuery(window).scroll(function() {
if (jQuery(this).scrollTop() > 428 && $(this).scrollTop() < 3827){
jQuery('#sticky-nav').addClass('sticky-nav');
} else{
@ahgood
ahgood / WordPress JWT .htaccess
Created June 19, 2016 05:53
A working sample of .htaccess file for JWT workaround, /wp1/ is WordPress root folder.
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule ^(.*) - [E=HTTP_AUTHORIZATION:%1]
RewriteBase /wp1/
RewriteRule ^index\.php$ - [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /wp1/index.php [E=X-HTTP_AUTHORIZATION:%{HTTP:Authorization},QSA,L]
</IfModule>