Skip to content

Instantly share code, notes, and snippets.

View ankurk91's full-sized avatar
Slow to respond

Ankur Kumar ankurk91

Slow to respond
View GitHub Profile
ilyasozkurt / FindRiskyNumericFields.php
Last active January 1, 2023 08:10
View FindRiskyNumericFields.php
namespace App\Console\Commands;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
class FindRiskyFieldsOnDatabases extends Command
vncsna /
Created June 6, 2021 01:59 — forked from mohanpedala/
set -e, -u, -o, -x pipefail explanation

set -e, -u, -o, -x pipefail

The set lines

  • These lines deliberately cause your script to fail. Wait, what? Believe me, this is a good thing.
  • With these settings, certain common errors will cause the script to immediately fail, explicitly and loudly. Otherwise, you can get hidden bugs that are discovered only when they blow up in production.
  • set -euxo pipefail is short for:
set -e
set -u
sindresorhus /
Last active December 4, 2023 14:57
Pure ESM package

Pure ESM package

The package that linked you here is now pure ESM. It cannot be require()'d from CommonJS.

This means you have the following choices:

  1. Use ESM yourself. (preferred)
    Use import foo from 'foo' instead of const foo = require('foo') to import the package. You also need to put "type": "module" in your package.json and more. Follow the below guide.
  2. If the package is used in an async context, you could use await import(…) from CommonJS instead of require(…).
  3. Stay on the existing version of the package until you can move to ESM.
maelvls /
Last active November 10, 2023 00:22
Ubuntu, libsecret, git-credential-helper

Dealing with secrets

GNOME comes with libsecret. You can use libsecret to store your git credentials:

sudo apt install libsecret-1-0 libsecret-1-dev libglib2.0-dev
sudo make --directory=/usr/share/doc/git/contrib/credential/libsecret
git config --global credential.helper /usr/share/doc/git/contrib/credential/libsecret/git-credential-libsecret
Jiab77 /
Last active July 26, 2023 18:40
Real-time PHP-FPM Status

Real-time PHP-FPM Status

This gist will explain you how to enable an undocumented feature of PHP-FPM which will give a real-time performance stats.

Everybody knows the famous phpinfo() and the page it generates, right? Then the real-time PHP-FPM status page design is very similar.


Some informations from the top are not displayed to avoid security issues.

Enable PHP-FPM Status

laravel-shift / .php-cs-fixer.php
Last active November 21, 2023 10:17
PHP CS Fixer - Laravel Coding Style Ruleset
View .php-cs-fixer.php
use PhpCsFixer\Config;
use PhpCsFixer\Finder;
$rules = [
'array_indentation' => true,
'array_syntax' => ['syntax' => 'short'],
'binary_operator_spaces' => [
'default' => 'single_space',
pepeloper / ProfileJsonResponse.php
Created December 15, 2017 08:56
Middleware to use Laravel debugbar on JSON responses.
View ProfileJsonResponse.php
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\JsonResponse;
class ProfileJsonResponse
joshbuchea /
Last active December 5, 2023 03:16
Semantic Commit Messages

Semantic Commit Messages

See how a minor change to your commit message style can make you a better programmer.

Format: <type>(<scope>): <subject>

<scope> is optional


Jeff-Russ / PHP: numeric array
Last active January 27, 2023 14:06
PHP: numeric array keys
View PHP: numeric array

PHP's Numeric & String Key Type Juggling

Arrays in PHP treat integer and string integers synonymously. If you set $a['1'] = '1' and access $a[1] you will get '1'. This is because php juggled your string key to an integer before assigning it; the assigment was actually made to an integer key. PHP also juggles in the process of accesssing too which means if you try to access [1] with ['1'] it will work. Therefore there is no real distinction between string integers and real integer, you can use them interchangably.

Remember that '1.0' does not equal '1' or 1 with strict comparison. This is true of array keys as well: you can have both ['1.0'] and ['1'] and they would be different elements but not [1] and ['1'].

RuGa / massInsertOrUpdate.php
Last active December 1, 2023 08:21
Mass (bulk) insert or update on duplicate for Laravel 4/5
View massInsertOrUpdate.php
* Mass (bulk) insert or update on duplicate for Laravel 4/5
* insertOrUpdate([
* ['id'=>1,'value'=>10],
* ['id'=>2,'value'=>60]
* ]);
* @param array $rows