Skip to content

Instantly share code, notes, and snippets.

@imliam
imliam / bind_methods.php
Created January 10, 2018 18:10
Trait to dynamically bind methods to a class.
<?php
trait BindMethods
{
private $boundMethods = [];
public function bindMethod($methodName, $method) {
$this->boundMethods[$methodName] = Closure::bind($method, $this, get_class());
}
@mkjiau
mkjiau / axios-interceptors-refresh-token.js
Last active September 20, 2025 02:01
Axios interceptors for token refreshing and more than 2 async requests available
let isRefreshing = false;
let refreshSubscribers = [];
const instance = axios.create({
baseURL: Config.API_URL,
});
instance.interceptors.response.use(response => {
return response;
}, error => {
@bwente
bwente / FormItPDF.php
Created November 27, 2017 15:29
FormItPDF
<?php
$fileIn = $hook->formit->config['fileIn'];
$fileOut = $hook->formit->config['fileOut'];
$fileInPath = $modx->config['base_path'].$fileIn;
$fileOutPath = $modx->config['base_path'].$fileOut;
$formData = $hook->getValues();
// FDF header section
@vojtasvoboda
vojtasvoboda / .gitlab-ci.yml
Last active December 5, 2020 16:29
GitLab CI FTP deploy with mwienk/docker-lftp docker image
stages:
- test
- deploy
cache:
paths:
- vendor
# test job
test:
@jeffochoa
jeffochoa / Response.php
Last active October 6, 2025 22:11
Laravel HTTP status code
<?php
// This can be found in the Symfony\Component\HttpFoundation\Response class
const HTTP_CONTINUE = 100;
const HTTP_SWITCHING_PROTOCOLS = 101;
const HTTP_PROCESSING = 102; // RFC2518
const HTTP_OK = 200;
const HTTP_CREATED = 201;
const HTTP_ACCEPTED = 202;
@zabaala
zabaala / BindDatabaseServiceProvider.php
Last active March 2, 2021 07:50
php artisan db:log <start> <stop>
<?php
namespace App\Commands\Database;
use Illuminate\Support\ServiceProvider;
class BindDatabaseServiceProvider extends ServiceProvider
{
public function boot()
{
@mariocesar
mariocesar / api.js
Created September 26, 2017 04:21
Axios single configured instance
import axios from "axios";
const singleton = Symbol();
const singletonEnforcer = Symbol();
function readCookie(name) {
const match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
return (match ? decodeURIComponent(match[3]) : null);
}
@simonhamp
simonhamp / AppServiceProvider.php
Last active August 4, 2025 20:56
A pageable Collection implementation for Laravel
<?php
namespace App\Providers;
use Illuminate\Support\Collection;
use Illuminate\Pagination\LengthAwarePaginator;
class AppServiceProvider extends ServiceProvider
{
public function boot()
@nitpum
nitpum / Download streaming video .js
Last active June 21, 2021 10:24
Download streaming video all .ts from .m3u8
/*
Requirement:
ffmpeg: https://ffmpeg.org/
Command line:
ffmpeg -i <URL> -vcodec copy -acodec copy -f mpegts "<OUTPUT>.mp4"
Example:
ffmpeg -i 'http://www.github.com' -vcodec copy -acodec copy -f mpegts "output.mp4"
<?php
/**
* Trait EnumTrait
* @author Philipp Dahse <[email protected]>
*/
trait EnumTrait
{
/**
* @return array