Skip to content

Instantly share code, notes, and snippets.

View besrabasant's full-sized avatar
🏠
Working from home

Basant Besra besrabasant

🏠
Working from home
View GitHub Profile
image: node:8.15.0-jessie
build:
stage: build
only:
- master
script:
- cd site/web/app/themes/$THEME_DIR
- yarn && yarn build:production
artifacts:
@besrabasant
besrabasant / script.js
Last active May 7, 2020 15:02
Get Query String Parameters as JSON Object with JavaScript
function getUrlParameter(name, defaultValue = "") {
query = query.substring(location.search.indexOf("?") + 1);
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g;
var decode = function(str) {
return decodeURIComponent(str.replace(decodeRE, " "));
};
@besrabasant
besrabasant / WordPressMultisiteValetDriver.php
Created April 11, 2019 04:17
Valet WP Multisite Driver
<?php
/*
Valet driver for Wordpress Multisite
Usage: Drop this file into your ~/.valet/Drivers/ directory
*/
class WordPressMultisiteValetDriver extends WordPressValetDriver
{
/**
* @var string The public web directory, if deeper under the root directory
*/
@besrabasant
besrabasant / xdebug.sh
Last active April 20, 2019 04:01
XDebug Toggler
#!/bin/bash
# Simple script to enable or disable the xdebug extension
# Note that xargs removes whitespace
PHPINIDIR=`php --ini | head -1 | cut -d ":" -f 2 | xargs echo`
PHPDIR=${PHPINIDIR//"/cli"/}
case $1 in
on)
@besrabasant
besrabasant / Laravel-Container.md
Created April 23, 2019 02:35
Laravel's Dependency Injection Container in Depth

Laravel's Dependency Injection Container in Depth

Translations: Korean (by Yongwoo Lee)

Laravel has a powerful Inversion of Control (IoC) / Dependency Injection (DI) Container. Unfortunately the official documentation doesn't cover all of the available functionality, so I decided to experiment with it and document it for myself. The following is based on Laravel 5.4.26 - other versions may vary.

Introduction to Dependency Injection

I won't attempt to explain the principles behind DI / IoC here - if you're not familiar with them you might want to read What is Dependency Injection? by Fabien Potencier (creator of the Symfony framework).

@besrabasant
besrabasant / TreeBuilder.php
Created August 20, 2019 14:51 — forked from mistic100/TreeBuilder.php
[PHP] Recursive builder pattern
<?php
/**
* Recursive builder pattern
*
* Usage:
* $tree = \Tree\Builder::init()
* ->setName('parent')
* ->addChild()
@besrabasant
besrabasant / 1.md
Last active November 10, 2019 03:59
Add notification bubble for to custom admin menu page

There are two classes used by WordPress to display the notification bubbles:

  • update-plugins
  • awaiting-mod

Your notifications have nothing to do with plugins, so it will be nicer to use the second class. You should change your function like this:

function contact_form_create() {
 $notification_count = 2; // Notification value
@besrabasant
besrabasant / onDomReady.js
Created February 24, 2020 23:57
On DOM Ready function
var domLoadedPromise = null
export default function onDomReady(documentReadyCallback) {
if (!domLoadedPromise) {
const readyReg = /complete|loaded|interactive/
domLoadedPromise = new Promise(function (resolve) {
if (readyReg.test(document.readyState) && document.body) {
resolve()
@besrabasant
besrabasant / NoDebugBar.php
Last active March 3, 2020 05:28
A handy middleware to disable Laravel Debugbar.
<?php
namespace App\Http\Middleware;
use Closure;
use Barryvdh\Debugbar\Facade as Debugbar;
class NoDebugbar
{
/**
@besrabasant
besrabasant / about.md
Last active March 3, 2023 06:48
Submitting Forms with Turbolinks ( tested with Laravel );