Skip to content

Instantly share code, notes, and snippets.

View ahgood's full-sized avatar

Guojun ahgood

  • Fullstack Developer
  • Halifax
View GitHub Profile
<?php
function crawl_page($url, $depth = 5)
{
static $seen = array();
if (isset($seen[$url]) || $depth === 0) {
return;
}
$seen[$url] = true;
@ahgood
ahgood / gist:fff9810b0e7df85ae16fef20096d5c75
Created August 2, 2017 12:55 — forked from ScottPhillips/gist:4138804
Animate scrolling to an element or offset
/*!
* requires jQuery
* usage:
* Scroller.to({ offset: 100 });
* Scroller.to({ target: $('#main') });
*
* advanced usage (with additional easing function not provided here)
* Scroller.to({ target: $('#main'), delay: 500, multiplier: 1.5, easing: 'easeOutQuad' });
*/
var Scroller = (function()
@ahgood
ahgood / .htaccess
Created August 2, 2017 12:53 — forked from ScottPhillips/.htaccess
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@ahgood
ahgood / insert-posts.php
Created July 7, 2017 00:45
WordPress: Insert a post into WordPress from an external script
<?php
// Load WordPress
require_once 'path/to/www/wp-load.php';
require_once ABSPATH . '/wp-admin/includes/taxonomy.php';
// Set the timezone so times are calculated correctly
date_default_timezone_set('Europe/London');
// Create post
@ahgood
ahgood / Postfix_Procmail.txt
Created July 6, 2017 01:40
Postfix and Procmail to monitor incoming email and trigger PHP script sample
Install Postfix and Procmail:
yum install postfix
yum install procmail
(Optional)Setup mail relay: /etc/postfix/main.cf
relayhost = [Relay server IP]
Setup procmail: /etc/postfix/main.cf
mailbox_command = /usr/bin/procmail
@ahgood
ahgood / readme.md
Created July 5, 2017 04:40 — forked from nishinoshake/readme.md
PostfixとProcmailで迷惑メールの振り分け

Procmailとは

メールの振り分けをしてくれるソフトウェア。
設定ファイルにルールを記載するとよきに計らってくれる。

インストール

yum install procmail

Postfixの設定

# procmailのパス調べる

which procmail

@ahgood
ahgood / sampleBoxFileUpload.js
Created July 4, 2017 01:50 — forked from seanrose/sampleBoxFileUpload.js
A sample file upload in javascript to the Box API
// Requires JQuery and CORS enabled for the Origin you're testing from.
// Uncomment the next 4 lines to import JQuery
// var script= document.createElement('script');
// script.type= 'text/javascript';
// script.src= '//cdnjs.cloudflare.com/ajax/libs/jquery/2.0.0/jquery.min.js';
// document.head.appendChild(script);
// Set up the multipart form using HTML5 FormData object
// https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest/FormData
var form = new FormData();
@ahgood
ahgood / Download_images_and_html.html
Last active April 12, 2024 03:07
Download multiple images with html file by pure JavaScript(jszip.js)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script type="text/javascript" src="//stuk.github.io/jszip/dist/jszip.js"></script>
<script type="text/javascript" src="//stuk.github.io/jszip-utils/dist/jszip-utils.js"></script>
@ahgood
ahgood / get_all_words.js
Last active May 10, 2017 06:49
Get all words from a HTML
var uni_words = [];
var all_words = jQuery('body').text().split(/ |\&nbsp;/);
jQuery.each(all_words, function(index, item){
if (item.length > 1 && /^[A-Za-z][A-Za-z0-9]*$/.test(item)) {
if(jQuery.inArray(item, uni_words) === -1) {
uni_words.push(item);
}
}
});
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>JS Bin</title>
</head>
<body>
<script src="https://fb.me/react-15.1.0.js"></script>
<script src="https://fb.me/react-dom-15.1.0.js"></script>