Skip to content

Instantly share code, notes, and snippets.

View endihunter's full-sized avatar

Terzi Eduard endihunter

View GitHub Profile
@endihunter
endihunter / inclusion.ts
Created November 8, 2022 14:10
Loyalty Orchestration Merchant Inclusion Flow
function main() {
// IMPORT loyalty accounts from merchant SQ1
importLoyaltyAccounts('SQ1');
// IMPORT loyalty accounts from merchant SQ2
importLoyaltyAccounts('SQ2');
// throttler that limits the # of requests up to 20rps to LoyaltyAPI and up to 100rps for FS application
// throttler will pause requests either if # or requests to LoyaltyAPI exis
@endihunter
endihunter / Users.php
Created July 10, 2017 15:05
Admin Architect Eloquent Image Mutator example
<?php
namespace App\Http\Terranet\Administrator\Modules;
use function admin\output\image;
use Illuminate\Database\Eloquent\Model;
use Terranet\Administrator\Form\Type\Image;
use Terranet\Administrator\Modules\Users as CoreUsersModule;
/**
@endihunter
endihunter / patch
Created July 3, 2017 10:47
translatable + stapler conflict
use HasTranslations, EloquentTrait {
HasTranslations::getAttribute as getTranslatedAttribute;
HasTranslations::setAttribute as setTranslatedAttribute;
EloquentTrait::getAttribute as getStaplerableAttribute;
EloquentTrait::setAttribute as setStaplerableAttribute;
}
public function getAttribute($key)
{
@endihunter
endihunter / translatable_staplerable_conflicts.php
Created April 11, 2017 08:22
Workaround to fix translatable & staplerable methods collision.
<?php
class SomeClass {
use HasTranslations, EloquentTrait {
HasTranslations::getAttribute as getTranslatedAttribute;
HasTranslations::setAttribute as setTranslatedAttribute;
EloquentTrait::getAttribute as getStaplerableAttribute;
EloquentTrait::setAttribute as setStaplerableAttribute;
}
@endihunter
endihunter / levenshtein.sql
Created February 17, 2017 06:28
MySQL Levenshtein distance algorithm
-- ---------------------------------------------------------------------------
-- Levenshtein distance
-- from the Artful Common Queries page
-- http://www.artfulsoftware.com/infotree/qrytip.php?id=552
-- ---------------------------------------------------------------------------
-- The Levenshtein distance between two strings is the minimum number of
-- operations needed to transform one string into the other, where an operation
-- may be insertion, deletion or substitution of one character.
@endihunter
endihunter / delete.php
Created February 6, 2017 14:00
scaffolding delete method
<?php
public function delete(Module $module)
{
$this->authorize('delete', $eloquent = app('scaffold.model'));
app('scaffold.actions')->exec('delete', [$eloquent]);
$message = trans('administrator::messages.remove_success');
@endihunter
endihunter / Resources.patch
Created February 6, 2017 13:55
patch a navigation middleware, activate module navigation
From f0f3fe15becb32c85613728c67694b9a0bc91a82 Mon Sep 17 00:00:00 2001
From: Endi <endi@terranet.md>
Date: Mon, 6 Feb 2017 15:52:01 +0200
Subject: [PATCH] Set default active status
---
src/Middleware/Resources.php | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
diff --git a/src/Middleware/Resources.php b/src/Middleware/Resources.php
<?php
...
public function form()
{
return $this
->scaffoldForm()
->update('fieldname', function ($e) {
return $e->setInput((new \Terranet\Administrator\Form\Type\Key('fieldname')));
});
@endihunter
endihunter / adminarchitect_relationships
Created October 17, 2016 14:42
adminarchitet relationships usage
Hello.
Nothing can say more than an example :)
Let's say you have a model Post and a Post::user() belongsTo relationship as like as Post::tags() serves as many to many relationship to another tags table.
<?php
namespace App;
<?php
function getId($chunks = 4, $chunkLen = 4) {
$max = pow(36, $chunkLen) - 1;
$id = '';
for ($i = 0; $i < $chunks; ++$i) {
$r = (mt_rand(0, $max) * (microtime(true) * 10000)) / mt_rand(0, $max);
$id .= str_pad(base_convert($r, 10, 36), $chunkLen, "0", STR_PAD_LEFT);
}