Skip to content

Instantly share code, notes, and snippets.

View FAST-JE's full-sized avatar
🏠
Working from home

FAST FAST-JE

🏠
Working from home
View GitHub Profile
@FAST-JE
FAST-JE / repository.md
Created February 5, 2023 08:05 — forked from maestrow/repository.md
Паттерн репозиторий

Паттерн репозиторий

Репозиторий - это слой абстракции, инкапсулирующий в себе всё, что относится к способу хранения данных. Назначение: Разделение бизнес-логики от деталей реализации слоя доступа к данным.

Паттерн Репозиторий стал популярным благодаря DDD (Domain Driven Design). В противоположность к Database Driven Design в DDD разработка начинается с проектирования бизнес логики, принимая во внимание только особенности предметной области и игнорируя все, что связано с особенностями базы данных или других способов хранения данных. Способ хранения бизнес объектов реализуется во вторую очередь.

Применение данного паттерна не предполагает создание только одного объекта репозитория во всем приложении. Хорошей практикой считается создание отдельных репозиториев для каждого бизнес-объекта или контекста, например: OrdersRepository, UsersRepository, AdminRepository.

Пример

@FAST-JE
FAST-JE / gist:c18e07a778e819cbaf6bfc0cd1988e89
Created February 4, 2021 12:21 — forked from feulf/gist:4587709
Keep the same PHP session between different domains

a simple idea is to force the session_id between the domains with an ajax call or an hidden iframe.

The concept is simple, you have [A,B,C] domains, where you create a script sid.php:

<?php session_id( $_GET['sid'] );

and a script sid_update.php that you have to place inside the PHP code of the front controller:

@FAST-JE
FAST-JE / cron-debugger.sh
Created December 26, 2020 18:19 — forked from hn-support/cron-debugger.sh
Debug script to log all cron output to a logfile
#!/bin/bash
# This script is a debug utility for cronjobs as explained in:
# - https://support.hypernode.com/knowledgebase/configure-cronjobs-on-hypernode/
# It logs all output and timing to a log file
#
# To use it, download the script, add the executable bit and put it in your cronjob:
# */5 * * * * /data/web/bin/debug-cron php -f /data/web/public/cron.php
LOGDIR="/data/web/public/var/log/crons"
TIMESTAMP="$( date '+%Y%m%d%H%M' )"
<?php
class usersOnline
{
private Redis $redis;
static string $prefix = 'users_online';
static int $userActiveTime = 10;
public function __construct($pathToSock)
@FAST-JE
FAST-JE / gist:2b4799eb9088caee601510ce11ad63b8
Created October 9, 2020 08:55 — forked from jaydson/gist:1780598
How to detect a click event on a cross domain iframe
var myConfObj = {
iframeMouseOver : false
}
window.addEventListener('blur',function(){
if(myConfObj.iframeMouseOver){
console.log('Wow! Iframe Click!');
}
});
document.getElementById('YOUR_CONTAINER_ID').addEventListener('mouseover',function(){
CENTRIFUGO=/usr/bin/centrifugo
CENTRIFUGO_ARGS="--config=/etc/centrifugo/config.json --log_file=/var/log/centrifugo.log"
PIDFILE=/var/run/centrifugo.pid
case "$1" in
start)
echo -n "Starting Centrifugo"
start-stop-daemon --start --quiet --pidfile $PIDFILE --make-pidfile --background --exec $CENTRIFUGO -- $CENTRIFUGO_ARGS
echo "."
;;
stop)
@FAST-JE
FAST-JE / terminal-git-branch-name.md
Created November 26, 2019 08:35 — forked from joseluisq/terminal-git-branch-name.md
Add Git Branch Name to Terminal Prompt (Mac)

Add Git Branch Name to Terminal Prompt (Mac)

image

Open ~/.bash_profile in your favorite editor and add the following content to the bottom.

# Git branch in prompt.

parse_git_branch() {
@FAST-JE
FAST-JE / import.md
Created November 14, 2019 11:34 — forked from iamstoick/import.md
How to import database in MySQL in Docker?

This is a simple way of importing MySQL database in Docker.

  1. In you Dockerfile you must have a shared folder. Shared folder is a directory in your host machine that is mounted to Docker instance.

  2. Put the exported sql file in the shared folder.

  3. Login to your Docker instance via docker exec -it DOCKER_CONTAINER_ID bin/bash.

  4. Login to MySQL via mysql -u USERNAME -p.

@FAST-JE
FAST-JE / mysql-docker.sh
Created November 14, 2019 11:34 — forked from spalladino/mysql-docker.sh
Backup and restore a mysql database from a running Docker mysql container
# Backup
docker exec CONTAINER /usr/bin/mysqldump -u root --password=root DATABASE > backup.sql
# Restore
cat backup.sql | docker exec -i CONTAINER /usr/bin/mysql -u root --password=root DATABASE
@FAST-JE
FAST-JE / README.md
Created September 11, 2017 14:18 — forked from joyrexus/README.md
Vanilla JS equivalents of jQuery methods

Sans jQuery

Events

// jQuery
$(document).ready(function() {
  // code
})