Skip to content

Instantly share code, notes, and snippets.

View banqhsia's full-sized avatar

Benyi banqhsia

  • Taiwan
View GitHub Profile
@OrionReed
OrionReed / dom3d.js
Last active May 15, 2025 11:15
3D DOM viewer, copy-paste this into your console to visualise the DOM topographically.
// 3D Dom viewer, copy-paste this into your console to visualise the DOM as a stack of solid blocks.
// You can also minify and save it as a bookmarklet (https://www.freecodecamp.org/news/what-are-bookmarklets/)
(() => {
const SHOW_SIDES = false; // color sides of DOM nodes?
const COLOR_SURFACE = true; // color tops of DOM nodes?
const COLOR_RANDOM = false; // randomise color?
const COLOR_HUE = 190; // hue in HSL (https://hslpicker.com)
const MAX_ROTATION = 180; // set to 360 to rotate all the way round
const THICKNESS = 20; // thickness of layers
const DISTANCE = 10000; // ¯\\_(ツ)_/¯
@ls-dac-chartrand
ls-dac-chartrand / swagit.php
Last active April 17, 2025 12:27
Swag It: Reverse engineer Swagger-PHP annotations from an existing JSON payload
<?php
// -------------------------------------------------------------------------------------
// Add your JSON in the $input to generate Swagger-PHP annotation
// Inspired by: https://github.com/Roger13/SwagDefGen
// HOWTO:
// php -S localhost:8888 -t .
// http://localhost:8888/swagit.php
// -------------------------------------------------------------------------------------
@reinink
reinink / validation_macros.php
Created March 1, 2017 20:11
Laravel request validation macros
<?php
Request::macro('validate', function ($rules, $messages = [], $customAttributes = []) {
$this->lastValidated = array_keys($rules);
(new class() {
use ValidatesRequests;
})->validate($this, $rules, $messages, $customAttributes);
});
@aloha1003
aloha1003 / custom
Last active February 26, 2017 06:45
動態調整validation 規則
<?php
class Model extends BaseModel {
public $defaultRuleAry = []; //預設規則
public function validation() { //驗證輸入
//根據 $this->defaultRuleAry 來驗證
return true;
}
public function save(array $options = array())
@sgpopov
sgpopov / ruleset.xml
Last active July 15, 2019 10:07
PHP Code Sniffer Rules
<?xml version="1.0" encoding="UTF-8"?>
<ruleset name="MentorMate">
<description>
The coding standard of the MentorMate team, based on the Generic, PSR2,
Squiz and Zend coding standards.
</description>
<arg name="colors"/>
<ini name="memory_limit" value="128M"/>
@jmny
jmny / migration.php
Last active December 14, 2023 04:44
phinx outside cli
// see also https://github.com/robmorgan/phinx/issues/364
$phinxApp = new \Phinx\Console\PhinxApplication();
$phinxTextWrapper = new \Phinx\Wrapper\TextWrapper($phinxApp);
$phinxTextWrapper->setOption('configuration', '/path/to/phinx.yml');
$phinxTextWrapper->setOption('parser', 'YAML');
$phinxTextWrapper->setOption('environment', 'development');
@jaceju
jaceju / web_development_with_laravel_5.md
Last active November 1, 2024 08:20
Laravel 5 測試起手式

Web Development with Laravel 5

目標

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

  1. Model
  2. Repository
  3. Controller
  4. Auth
@mnapoli
mnapoli / gist:5e1361846ff1e93f8a96
Created February 3, 2015 09:23
PHPUnit + PHP-DI
<?php
use ...;
class GeneratingArgumentsTest extends \PHPUnit_Framework_TestCase
{
/**
* @var VariableArgumentCollectionFactory
* @Inject
*/
@zamicol
zamicol / Installation of Laravel on Apache on Debian and Ubuntu
Created December 7, 2014 20:32
Installation of Laravel on Apache on Debian and Ubuntu
After installing, make sure the permissions are proper
sudo chmod -R g+w storage/
sudo chown -R :www-data storage/
Then modify the .htaccess file under yourProjectName/public/.htaccess
RewriteBase /yourProjectName/
Then add an alias to the Apache conf
Alias /yourProjectName /var/www/whatever/yourProjectName/public
@joemaller
joemaller / webhook_validate.php
Last active November 20, 2021 12:29
Validate Github webhook signatures with PHP
<?php
$sig_check = 'sha1=' . hash_hmac('sha1', Request::getContent(), $_ENV['github_webhook_secret']);
if ($sig_check === Request::header('x-hub-signature')) { // php >=5.6 and above should use hash_equals() for comparison
// sigs match, do stuff
}