Skip to content

Instantly share code, notes, and snippets.

View plehanov's full-sized avatar

Takamura plehanov

  • 05:08 (UTC +03:00)
View GitHub Profile
@plehanov
plehanov / OptimisticTransaction.php
Created June 16, 2020 14:08 — forked from aslrousta/OptimisticTransaction.php
Optimistic Locking for Transaction
<?php
function transfer($fromAccountId, $toAccountId, $balance)
{
$fromQuery = Account::whereId($fromAccountId);
if (! $fromQuery->exists()) {
throw new InvalidAccountException();
}
$toQuery = Account::whereId($toAccountId);
@plehanov
plehanov / PessimistTransaction.php
Created June 16, 2020 14:07 — forked from aslrousta/PessimistTransaction.php
Pessimistic Locking for Transaction
<?php
function transfer($fromAccountId, $toAccountId, $amount)
{
DB::beginTransaction();
try {
$fromQuery = Account::whereId($fromAccountId);
if (! $fromQuery->exists()) {
throw new InvalidAccountException();
@plehanov
plehanov / SftpServiceProvider.php
Created February 26, 2018 07:28 — forked from rtconner/SftpServiceProvider.php
Provider so you can add a 'sftp' connection in Laravel 5 filesystems.php - "Call to undefined method League\Flysystem\Filesystem::createSftpDriver"
<?php
namespace App\Providers;
use League\Flysystem\Sftp\SftpAdapter;
use Storage;
use League\Flysystem\Filesystem;
use Illuminate\Support\ServiceProvider;
/**
// Put at the top of ./config/app.php
// Custom Monolog Configuration - https://laravel.com/docs/5.2/errors#configuration
use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Illuminate\Mail\TransportManager;
$app->configureMonologUsing(function($monolog) use ($app) {
// Set bubble to false to keep logs separate and clean
@plehanov
plehanov / git-tag-delete-local-and-remote.sh
Created December 28, 2017 08:11 — forked from mobilemind/git-tag-delete-local-and-remote.sh
how to delete a git tag locally and remote
# delete local tag '12345'
git tag -d 12345
# delete remote tag '12345' (eg, GitHub version too)
git push origin :refs/tags/12345
# alternative approach
git push --delete origin tagName
git tag -d tagName
@plehanov
plehanov / new_gist_file.js
Created December 25, 2017 04:22 — forked from nmsdvid/new_gist_file.js
Simple JavaScript Debounce Function
// Returns a function, that, as long as it continues to be invoked, will not
// be triggered. The function will be called after it stops being called for
// N milliseconds. If `immediate` is passed, trigger the function on the
// leading edge, instead of the trailing.
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
clearTimeout(timeout);
@plehanov
plehanov / BulkInsertOrUpdate.php
Last active November 29, 2017 10:53
bulk update with Model to Laravel 5.4
<?php
/**
* Created by PhpStorm.
* User: Valentin Plehanov (Takamura) valentin@plehanov.pro
* Date: 28.06.17
* Time: 23:51
*
* Bulk insert or update on duplicate for Laravel 5
*
* bulkInsertOrUpdate(
@plehanov
plehanov / massInsertOrUpdate.php
Created June 28, 2017 03:16 — forked from RuGa/massInsertOrUpdate.php
Mass (bulk) insert or update on duplicate for Laravel 4/5
/**
* Mass (bulk) insert or update on duplicate for Laravel 4/5
*
* insertOrUpdate([
* ['id'=>1,'value'=>10],
* ['id'=>2,'value'=>60]
* ]);
*
*
* @param array $rows
@plehanov
plehanov / Laravel PHP7 LEMP AWS.md
Created June 23, 2017 12:29 — forked from santoshachari/Laravel PHP7 LEMP AWS.md
Laravel 5.x on Ubuntu 16.x, PHP 7.x, Nginx 1.9.x

#Steps to install latest Laravel, LEMP on AWS Ubuntu 16.4 version. This tutorial is the improvised verision of this tutorial on Digitalocean based on my experience.

Install PHP 7 on Ubuntu

Run the following commands in sequence.

sudo apt-get install -y language-pack-en-base
sudo LC_ALL=en_US.UTF-8 add-apt-repository ppa:ondrej/php
sudo apt-get update
sudo apt-get install zip unzip