Skip to content

Instantly share code, notes, and snippets.

<?php
declare(strict_types=1);
namespace App\Transactional;
use Illuminate\{
Database\DatabaseManager,
};
class EmailManager
{
public function confirmEmail(User $user): User
{
$user = \DB::transaction(function () use ($user) {
$user = User::lockForUpdate()->findOrFail($user->id);
$user->email_confirmed = true;
$user->save();
event(new UserErmailConfiming($user)); // DO some operations inside transactions (i.e. log user actions to DB)
@alsma
alsma / form.js
Last active October 26, 2016 15:03
import React, { Component, PropTypes } from 'react';
class FormClass extends Component {
static propTypes = {
onSubmit: PropTypes.func.isRequired,
setRef: PropTypes.func,
};
constructor(props) {
super(props);
@alsma
alsma / queries.sql
Last active June 18, 2017 06:44
Many-to-many interview question
-- select all query --
SELECT b.bookTitle, a.authorName FROM book b
INNER JOIN author_book ab ON ab.bookID = b.bookID
INNER JOIN author a ON a.authorID = ab.authorID
ORDER BY b.bookTitle
-- select all with authors concantenated --
SELECT b.bookTitle, GROUP_CONCAT(a.authorName) authors FROM book b
@alsma
alsma / Manager.php
Last active June 7, 2016 15:37
queue
<?php
use Ramsey\Uuid\Uuid;
class Manager
{
const DEFAULT_CONSUME_TIMEOUT = 12 * 60 * 60;
const DEFAULT_BLPOP_INTERVAL = 30;
/** @var \Redis */
@alsma
alsma / Action_ActionInterface.php
Last active January 6, 2016 16:09
Chain of responsibility
<?php
namespace models\Instant\Action;
interface ActionInterface
{
/**
* Executes action
*
* @param array $args