Skip to content

Instantly share code, notes, and snippets.

@tommywang
tommywang / cors.php
Last active June 24, 2016 08:37
An example CORS-compliant method. It will allow any GET, POST, or OPTIONS requests from any origin.
// Allow from any origin
if (isset($_SERVER['HTTP_ORIGIN'])) {
header("Access-Control-Allow-Origin: {$_SERVER['HTTP_ORIGIN']}");
header('Access-Control-Allow-Credentials: true');
header('Access-Control-Max-Age: 86400'); // cache for 1 day
}
// Access-Control headers are received during OPTIONS requests
if ($_SERVER['REQUEST_METHOD'] == 'OPTIONS') {
@tommywang
tommywang / mongo-autostart-osx.md
Created May 11, 2016 10:27 — forked from subfuzion/mongo-autostart-osx.md
mongo auto start on OS X

Install with Homebrew

brew install mongodb

Set up launchctl to auto start mongod

$ ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents

/usr/local/opt/mongodb/ is a symlink to /usr/local/Cellar/mongodb/x.y.z (e.g., 2.4.9)

add_action('admin_init', 'my_general_section');
function my_general_section() {
add_settings_section(
'my_settings_section', // Section ID
'My Options Title', // Section Title
'my_section_options_callback', // Callback
'general' // What Page? This makes the section show up on the General Settings Page
);
add_settings_field( // Option 1
<?php
/*
* Plugin Name: Media Upload Widget
* Plugin URI: http://www.paulund.co.uk
* Description: A widget that allows you to upload media from a widget
* Version: 1.0
* Author: Paul Underwood
* Author URI: http://www.paulund.co.uk
* License: GPL2
// http://paulirish.com/2011/requestanimationframe-for-smart-animating/
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
// requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
// MIT license
(function() {
var lastTime = 0;
var vendors = ['ms', 'moz', 'webkit', 'o'];
@tommywang
tommywang / MySQL databases backup
Created November 10, 2014 06:37
Backup all local MySQL databases
TIMESTAMP=$(date +"%F")
BACKUP_DIR=""
MYSQL_USER=""
MYSQL=/usr/local/bin/mysql
MYSQL_PASSWORD=""
MYSQLDUMP=/usr/local/bin/mysqldump
mkdir -p "$BACKUP_DIR/mysql"
databases=`$MYSQL --user=$MYSQL_USER -p$MYSQL_PASSWORD -e "SHOW DATABASES;" | grep -Ev "(Database|information_schema|performance_schema)"`
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="utf-8">
<title>Hello FB</title>
</head>
<body>
<div id="fb-root"></div>
<div id="fb-content"></div>
<div>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script type="text/javascript">
var f_page = "wvumountaineers"; // the page name for your fan page, e.g. the 'wvumountaineers' part of http://facebook.com/wvumountaineers
var t_page = "westvirginiau"; // the account name for your main twitter account
function add_commas(number) {
if (number.length > 3) {
var mod = number.length % 3;
@tommywang
tommywang / Deploy.php
Last active May 25, 2016 08:38 — forked from oodavid/README.md
Deploy your site with git
# Deploy your site with git
This gist assumes:
* you have a local git repo
* with an online remote repository (github / bitbucket etc)
* and a cloud server (Rackspace cloud / Amazon EC2 etc)
* your (PHP) scripts are served from /var/www/html/
* your webpages are executed by apache
* apache's home directory is /var/www/
<?php
return array(
// Uncomment the languages that your site supports - or add new ones.
// These are sorted by the native name, which is the order you might show them in a language selector.
// Regional languages are sorted by their base languge, so "British English" sorts as "English, British"
'supportedLocales' => array(
//'ace' => array('name' => 'Achinese', 'script' => 'Latn', 'dir' => 'ltr', 'native' => 'Aceh'),
//'af' => array('name' => 'Afrikaans', 'script' => 'Latn', 'dir' => 'ltr', 'native' => 'Afrikaans'),