Skip to content

Instantly share code, notes, and snippets.

View yehchge's full-sized avatar
:octocat:
Working from office

yehchge yehchge

:octocat:
Working from office
View GitHub Profile
@yehchge
yehchge / display_filesize.php
Last active February 8, 2022 07:23
display filesize
<?php
function display_filesize($filesize){
if(is_numeric($filesize)){
$decr = 1024; $step = 0;
$prefix = array('Byte','KB','MB','GB','TB','PB');
while(($filesize / $decr) > 0.9){
$filesize = $filesize / $decr;
$step++;
@yehchge
yehchge / php-8.1-strftime.php
Created January 18, 2022 05:51 — forked from bohwaz/php-8.1-strftime.php
strftime() replacement function for PHP 8.1
<?php
namespace PHP81_BC;
/**
* Locale-formatted strftime using IntlDateFormatter (PHP 8.1 compatible)
* This provides a cross-platform alternative to strftime() for when it will be removed from PHP.
* Note that output can be slightly different between libc sprintf and this function as it is using ICU.
*
* Usage:
* use func \PHP81_BC\strftime;
@yehchge
yehchge / DBATest.php
Last active January 27, 2021 15:44
phpunit PDOException Assert
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
class DBA
{
public function getRowCount($table)
{
$pdo = new PDO("mysql:host=localhost;dbname=test",'root','');
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
@yehchge
yehchge / .editorconfig
Created June 11, 2020 03:02
專案預設規格
# 通常建議專案最頂層的配置文件設定該值
root = true
# 表示以 Unix 風格的換行符號結尾另外刪除換行字元所有的空白
[*]
end_if_line = lf
insert_final_newline = true
trim_trailing_whitespace = true
indent_style = space
@yehchge
yehchge / pagebar.php
Last active May 8, 2020 16:28
pagebar
<?php
function sMakePageBar($iAllItems,$iPageItems,$iPg=0,$sUrl){
$iPages = 0;
$sPageBar = '';
$current = 0;
$PHP_SELF = $_SERVER['PHP_SELF'];
if ($iPageItems) $iPages = (INT)($iAllItems/$iPageItems);
@yehchge
yehchge / stars.html
Created January 14, 2020 08:33 — forked from ziminds/stars.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Star Rating System</title>
<meta name="viewport" content="width=device-width">
<style>
.star{
color: goldenrod;
font-size: 2.0rem;

Web Development with Laravel 5

目標

如何在開發的過程中加入測試。

  1. Model
  2. Repository
  3. Controller
  4. Auth
<?php
/**
* Replace non-breaking spaces with normal spaces
*
* @param $str
* @return string
*/
function removeNbsp($str)
{
@yehchge
yehchge / ansi-color.php
Created April 22, 2019 04:25 — forked from superbrothers/ansi-color.php
ANSI color terminal output module for php
<?php
/**
* php-ansi-color
*
* Original
* https://github.com/loopj/commonjs-ansi-color
*
* @code
* <?php
* require_once "ansi-color.php";
<?php
/**
* @desc decorator
*/
function save_db($str){
$wrap_func = function() use ($str) {
echo "run wrap_func".PHP_EOL;
echo "string = $str".PHP_EOL;