Skip to content

Instantly share code, notes, and snippets.

View ahgood's full-sized avatar

Guojun ahgood

  • Fullstack Developer
  • Halifax
View GitHub Profile
@ahgood
ahgood / Get post id from meta key and value.php
Created October 31, 2018 19:33
Get post id from meta key and value
<?php
/**
* Get post id from meta key and value
* @param string $key
* @param mixed $value
* @return int|bool
* @author David M&aring;rtensson <david.martensson@gmail.com>
*/
function get_post_id_by_meta($key, $value) {
global $wpdb;
@ahgood
ahgood / wp-bootstrap4.1-pagination.php
Created September 17, 2018 13:13 — forked from mtx-z/wp-bootstrap4.4-pagination.php
Wordpress Bootstrap 4.1 pagination (with custom WP_Query() and global $wp_query support)
<?php
/**
* @param WP_Query|null $wp_query
* @param bool $echo
*
* @return string
* Accepts a WP_Query instance to build pagination (for custom wp_query()),
* or nothing to use the current global $wp_query (eg: taxonomy term page)
* - Tested on WP 4.9.5
<?php
namespace App\Http\Controllers;
use App\Result;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\StreamedResponse;
class ExportController extends Controller
{
@ahgood
ahgood / Instruction
Created July 18, 2018 05:00
Lumen step by step
####################################
Quick start:
####################################
mysql -u root -p -e "create database bookstore";
mysql -u root -p bookstore < bookstore.sql
DROP TABLE IF EXISTS `books`;
CREATE TABLE `books` (
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
@ahgood
ahgood / JSONP
Created July 11, 2018 06:35
PHP + jQuery JSONP Example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<script src="jquery-3.2.1.min.js"></script>
<script>
jQuery.ajax({
@ahgood
ahgood / Controller.php
Created June 6, 2018 07:59
Export db data to csv
use App\MyModel;
...
use Symfony\Component\HttpFoundation\StreamedResponse;
...
public function Export() {
$results = MyModel::all()->toArray();
$headers = $this->getFileResponseHeaders('export.csv');
return $this->streamFile(function () use ($results) {
@ahgood
ahgood / Enable ligature in Sublime Text and VS Code
Last active October 29, 2019 13:41
[Mac] Enable ligature in Sublime Text and VS Code
# 0. Install brew if you don't have it.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
# 1. Install font fira code
brew tap homebrew/cask-fonts
brew cask install font-fira-code
# # # # # # Sublime Text # # # # # #
# 2. Menu Sublime Text > Preferences > Settings (shortcut: ⌘,), add following code:
@ahgood
ahgood / wordpress-get-started-steps.txt
Created June 1, 2018 02:04
WordPress Get Started
# Download and install XAMPP
https://www.apachefriends.org/download.html
# Create a database, you may need to cd to mysql bin folder first to execute mysql command
cd /path/to/mysql/bin
mysql -u root -p
enter
create database db_name_you_want;
exit
@ahgood
ahgood / Electron Get Started.txt
Last active May 24, 2018 08:23
Electron Get Started
1 git clone https://github.com/electron/electron-quick-start nodeapp
2 cd nodeapp
3 npm install
4 npm install jquery bootstrap popper.js request electron-connect
5 npm install gulp-cli -g
6 npm install gulp -D
7 create file gulpfile.js
'use strict';
var gulp = require('gulp');
@ahgood
ahgood / delay.js
Created May 18, 2018 02:18 — forked from eteeselink/delay.js
ES7 async/await version of setTimeout
const delay = ms => new Promise(resolve => setTimeout(resolve, ms));
async function something() {
console.log("this might take some time....");
await delay(5000);
console.log("done!")
}
something();