Skip to content

Instantly share code, notes, and snippets.

@mikemand
mikemand / README.md
Last active August 25, 2016 16:38
MySQL IP Address octets from binary field

From: http://dev.mysql.com/doc/refman/5.7/en/bit-functions.html#c9386

Posted by Neil Davis on April 3, 2008
Revised by Phillip Temple on September 11, 2008

If you store your ip addresses as a 32 bit unsigned integer representation instead of strings(using INET_ATON()), you can use bitwise operators to pull the octets for grouping and sorting when you need to retrieve them:

select 
ipAddress, (ipAddress >> 24) as firstOctet,
@mikemand
mikemand / LoginByApiToken.php
Created March 14, 2017 17:41
LoginByApiToken middleware for AsgardCMS
<?php
namespace Modules\Module\Http\Middleware;
use Cartalyst\Sentinel\Laravel\Facades\Sentinel;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Modules\User\Entities\UserToken;
use Modules\User\Repositories\UserTokenRepository;
@mikemand
mikemand / _ide_macros.php
Last active September 28, 2017 16:18
Finally! Macro autocompletion for PhpStorm!
<?php
if (false) {
/**
* Class Collection
*
* @method static static pad(int $size, $value)
* @method static dd()
* @method static dump()
* @method static \Illuminate\Support\Collection ifEmpty(callable $callback)
@mikemand
mikemand / _README.md
Last active February 1, 2020 19:25
Laravel, Tailwind, & Alpinejs Password component

Usage:

@componenet('password', ['name' => 'Optional name/id. Defaults to "password".'])
    Optional label text. Defaults to "Password".
@endcomponent
@mikemand
mikemand / backend.js
Created July 1, 2022 19:23
Old-school dynamic/async Vue components
/**
* The following block of code may be used to automatically register your
* Vue components. It will recursively scan this directory for the Vue
* components and automatically register them with their "basename".
*
* Eg. ./components/ExampleComponent.vue -> <example-component></example-component>
*/
// Register all Async Vue components
for (const file of require.context('./', true, /\.vue$/i, 'lazy').keys()) {
const componentName = file