Skip to content

Instantly share code, notes, and snippets.

View nczz's full-sized avatar
🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。

一介資男 nczz

🇹🇼
寫 code 不一定會幫你賺到錢,但會寫 code 能生活的有意思點。
View GitHub Profile
@nczz
nczz / app.js
Created August 22, 2013 06:13 — forked from nulltask/app.js
/**
* Module dependencies.
*/
var express = require('express')
, routes = require('./routes')
, socket = require('socket.io')
, RedisStore = socket.RedisStore
, cluster = require('cluster');
var io = require('socket.io-client');
var connection = process.env.LATENCY_CONNECTION || 100;
var host = process.env.LATENCY_HOST || 'localhost';
var options = {
port: process.env.LATENCY_PORT || 3000,
'force new connection': true
};
for (var i = 0; i < connection; i++) {
(function() {
// The .config() part is the relevant part, 'SomeModule' is arbitrary name,
// but this config() call goes on your main ng-app="YourAppModule"
// The PHP $_POST expects data w/ a form content type, not a JSON payload
angular.module("YourAppModule", ["SomeModule"]).config(function($httpProvider) {
$httpProvider.defaults.headers.put['Content-Type'] =
'application/x-www-form-urlencoded';
$httpProvider.defaults.headers.post['Content-Type'] =
'application/x-www-form-urlencoded';
});
var serialize = function(obj, prefix) {
// http://stackoverflow.com/questions/1714786/querystring-encoding-of-a-javascript-object
var str = [];
for(var p in obj) {
var k = prefix ? prefix + "[" + p + "]" : p, v = obj[p];
str.push(typeof v == "object" ? serialize(v, k) : encodeURIComponent(k) + "=" + encodeURIComponent(v));
}
return str.join("&");
}
@nczz
nczz / WP-HTML-Compression
Created January 4, 2018 14:47 — forked from sethbergman/WP-HTML-Compression
Minify HTML for WordPress without a Plugin - Add to function.php
<?php
class WP_HTML_Compression
{
// Settings
protected $compress_css = true;
protected $compress_js = true;
protected $info_comment = true;
protected $remove_comments = true;
// Variables
@nczz
nczz / Math.php
Created February 20, 2018 14:37 — forked from jgrossi/Math.php
Math class from Taylor Otwell. Thanks to @brad (captain_jim1@yahoo.com) for the class content.
<?php
class Math {
/**
* The base.
*
* @var string
*/
private static $base = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
@nczz
nczz / get-order-detail-by-order-id.php
Last active September 8, 2018 17:28 — forked from web-hat/get-order-detail-by-order-id.php
Works with WooCommerce 3.x or above
<?php
if (!function_exists('getOrderDetailById')) {
//to get full order details
function getOrderDetailById($id, $fields = null, $filter = array()) {
if (is_wp_error($id)){
return false;
}
@nczz
nczz / get-order-detail-by-order-id-2_6.php
Created September 8, 2018 17:24 — forked from web-hat/get-order-detail-by-order-id-2_6.php
Works with WooCommerce 2.6.x or below
<?php
if (!function_exists('getOrderDetailById')) {
function getOrderDetailById($id, $fields = null, $filter = array()) {
if (is_wp_error($id))
return $id;
// Get the decimal precession
@nczz
nczz / install-postgres-10-ubuntu.md
Last active February 25, 2019 10:28 — forked from alistairewj/install-postgres-10-ubuntu.md
Install PostgreSQL 10 on Ubuntu

Install PostgreSQL 10 on Ubuntu

This is a quick guide to install PostgreSQL 10 - tested on Ubuntu 16.04 but likely can be used for Ubuntu 14.04 and 17.04 as well, with one minor modification detailed below.

(Optional) Uninstall other versions of postgres

To make life simple, remove all other versions of Postgres. Obviously not required, but again, makes life simple.

dpkg -l | grep postgres
@nczz
nczz / psql-error-fix.md
Created March 3, 2019 05:24 — forked from AtulKsol/psql-error-fix.md
Solution of psql: FATAL: Peer authentication failed for user “postgres” (or any user)

psql: FATAL: Peer authentication failed for user “postgres” (or any user)

The connection failed because by default psql connects over UNIX sockets using peer authentication, that requires the current UNIX user to have the same user name as psql. So you will have to create the UNIX user postgres and then login as postgres or use sudo -u postgres psql database-name for accessing the database (and psql should not ask for a password).

If you cannot or do not want to create the UNIX user, like if you just want to connect to your database for ad hoc queries, forcing a socket connection using psql --host=localhost --dbname=database-name --username=postgres (as pointed out by @meyerson answer) will solve your immediate problem.

But if you intend to force password authentication over Unix sockets instead of the peer method, try changing the following pg_hba.conf* line:

from