Skip to content

Instantly share code, notes, and snippets.

View chaoswey's full-sized avatar

chaoswey chaoswey

  • Taichung, Taiwan
View GitHub Profile
@jaceju
jaceju / AbstractStep.php
Last active July 19, 2018 02:32
Chain of Responsibility Pattern Example
<?php
abstract class AbstractStep
{
protected $successor;
protected $shouldPassToSuccessor = true;
public static function registerSteps(array $steps): AbstractStep
{
@edwinheij
edwinheij / streamLargeFile.php
Last active August 20, 2022 22:17
Stream large file with Laravel
<?php
//disable execution time limit when downloading a big file.
set_time_limit(0);
/** @var \League\Flysystem\Filesystem $fs */
$fs = Storage::disk('local')->getDriver();
$fileName = 'bigfile';
$metaData = $fs->getMetadata($fileName);
@brenopolanski
brenopolanski / npm-list-globally.md
Created November 1, 2016 19:34
Listing globally installed NPM packages and version
npm list -g --depth=0
@overtrue
overtrue / gist:f540fbea3c33e3da53fd
Created January 12, 2015 09:23
移动端头部meta大全
<!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 -->
<html lang="zh-cmn-Hans"> <!-- 更加标准的 lang 属性写法 http://zhi.hu/XyIa -->
<head>
<!-- 声明文档使用的字符编码 -->
<meta charset='utf-8'>
<!-- 优先使用 IE 最新版本和 Chrome -->
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/>
<!-- 页面描述 -->
<meta name="description" content="不超过150个字符"/>
<!-- 页面关键词 -->
<?php
/**
* Converts elements divided by newline characters to list items
* @param String $text
* @param Array $htmlAttrs
*/
function nl2li($text, array $htmlAttrs = null) {
if (!empty($htmlAttrs)) {
$attributes = array_walk($htmlAttrs, function($key, $value) {
@0xnbk
0xnbk / .php
Created October 8, 2010 04:56
File download with speed limit
<?php
// local file that should be send to the client
$local_file = 'test-file.zip';
// filename that the user gets as default
$download_file = 'your-download-name.zip';
// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
if(file_exists($local_file) && is_file($local_file)) {
// send headers