Skip to content

Instantly share code, notes, and snippets.

View artyuum's full-sized avatar
🎯
Focusing

Dynèsh Hassanaly artyuum

🎯
Focusing
View GitHub Profile
@iamhosseindhv
iamhosseindhv / webpackEncore_browsersync.js
Created July 2, 2018 14:22
Browser sync for Webpack Encore Symfony 4
let config = Encore.getWebpackConfig();
config.watchOptions = { poll: true, ignored: /node_modules/ };
config.plugins.push(
new BrowserSyncPlugin(
{
host: 'aro.tech',
proxy: 'aro.tech',
files: [ // watch on changes
{
match: ['public/build/**/*.js'],
@whoisryosuke
whoisryosuke / incrementing-slugs.php
Last active March 21, 2022 13:17
Laravel: Check database for duplicate slugs and generate incrementing slug name (repeat-name-2, repeat-name-3). Found via: https://codereview.stackexchange.com/questions/162254/append-a-incrementing-number-to-a-slug-username
<?php
protected function create(array $data)
{
$slug = str_slug($data['first_name'] . '.' . $data['last_name']);
$next = 2;
// Loop until we can query for the slug and it returns false
while (User::where('slug', '=', $slug)->first()) {
$slug = $slug . '-' . $next;
$next++;
@stankusl
stankusl / excerpt.md
Created May 27, 2015 15:07
Text Excerpt PHP function

Function:

function shorten_text($text, $max_length = 140, $cut_off = '...', $keep_word = false)
{
    if(strlen($text) <= $max_length) {
        return $text;
    }

if(strlen($text) > $max_length) {

@ASergey
ASergey / nginx-ps-config
Last active July 9, 2022 10:40
Example prestashop 1.6 nginx host config
server {
listen 80;
server_name maxmobiles.lo *.maxmobiles.lo;
root /var/www/maxmobiles.lo;
error_log /var/www/maxmobiles.lo/log/error.log warn;
location / {
index index.html index.php; ## Allow a static html file to be shown first
@signalpoint
signalpoint / example.php
Last active July 16, 2022 23:41
Drupal 8 Set Message Example
<?php
// The drupal_set_message() function is being deprecated!
// @see https://api.drupal.org/api/drupal/core%21includes%21bootstrap.inc/function/drupal_set_message/8.5.x
// > Deprecated in Drupal 8.5.0 and will be removed before Drupal 9.0.0.
// > Use \Drupal\Core\Messenger\MessengerInterface::addMessage() instead.
// In some custom code.
\Drupal::messenger()->addMessage('Say something else');
@chrisguitarguy
chrisguitarguy / KeepValueListener.php
Created February 26, 2016 14:29
A way to keep original values around when a Symfony form is submitted with an empty value. Useful for password fields especially
<?php
/**
* Copyright (c) 2016 PMG <https://www.pmg.com>
*
* License: MIT
*/
use Symfony\Component\PropertyAccess\PropertyAccess;
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
use Symfony\Component\Form\FormEvents;
@ItsAdventureTime
ItsAdventureTime / .rtorrent.rc
Created August 8, 2014 20:03
This an optimized version of the rTorrent configuration file.
#
#
# The Seedbox From Scratch Script
# By Notos ---> https://github.com/Notos/
#
#
######################################################################
#
# Copyright (c) 2013 Notos (https://github.com/Notos/)
#
@miguelfrmn
miguelfrmn / simpleimage.php
Last active May 9, 2023 11:23
SimpleImage PHP Class
<?php
/**
* File: SimpleImage.php
* Author: Simon Jarvis
* Modified by: Miguel Fermín
* Based in: http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
@azhararmar
azhararmar / Symfony - Manual User Authentication
Last active June 16, 2023 15:35
Manually Authenticate User In Symfony
use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
// Manually authenticate user in controller
$token = new UsernamePasswordToken($user, null, 'main', $user->getRoles());
$this->get('security.token_storage')->setToken($token);
$this->get('session')->set('_security_main', serialize($token));
@codfish
codfish / .php_cs.dist
Last active July 6, 2023 19:12
PHP-CS-Fixer configuration file. PSR-2 plus some opinionated options to make code cleaner.
<?php
/**
* Rules we follow are from PSR-2 as well as the rectified PSR-2 guide.
*
* - https://github.com/FriendsOfPHP/PHP-CS-Fixer
* - https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md
* - https://github.com/php-fig-rectified/fig-rectified-standards/blob/master/PSR-2-R-coding-style-guide-additions.md
*
* If something isn't addressed in either of those, some other common community rules are