Skip to content

Instantly share code, notes, and snippets.

Avatar
🤓
I may be slow to respond.

Cuong Huynh cuonghuynh

🤓
I may be slow to respond.
View GitHub Profile
@cuonghuynh
cuonghuynh / .htaccess
Created Apr 23, 2020
Combine Apache's HTTP authentication with X-Forwarded-For IP whitelisting in a reverse proxy Loadbalancer
View .htaccess
Require all denied
AuthName "Restricted Area"
AuthType Basic
AuthBasicProvider file
AuthUserFile /path/to/your/.htpasswd
Require valid-user
# Normal whitelist would just add Allow directives
@cuonghuynh
cuonghuynh / youtube_modal.js
Created Sep 8, 2019
The video autoplay when the modal is shown and stop as the modal is closed.
View youtube_modal.js
var src = $('#myModal iframe').attr('src');
$('#myModal').on('show.bs.modal', () => {
$('#myModal iframe').attr('src', src);
});
$('#myModal').on('hidden.bs.modal', () => {
$('#myModal iframe').attr('src', '');
});
@cuonghuynh
cuonghuynh / readme.md
Created Nov 15, 2018
Unable to load dynamic library '/usr/local/opt/php71-intl/intl.so'
View readme.md

The fix is actually quite easy. Since the library is now in the core of PHP and should be managed using pecl. One should delete the include in the conf.d directory of the PHP version you're running. E.G: For PHP 7.1 I would remove the following:

/usr/local/etc/php/7.1/conf.d/ext-intl.ini
@cuonghuynh
cuonghuynh / readme.md
Created Oct 22, 2018
Symfony: Mask sensitive data in the log file
View readme.md

Add processor to monolog handler

<service id="shopmacher.payment.logger.handler" class="Monolog\Handler\StreamHandler">
    //...
    <call method="pushProcessor">
        <argument type="service" id="service_processor.payment_logger_filtering" />
    </call>
</service>
@cuonghuynh
cuonghuynh / readme.md
Last active Oct 20, 2018
Study case: "InnoDB: Database was not shutdown normally! "
View readme.md

The out-of-memory killer would choose mysql to close down, because it was (usually) the biggest memory user in the system.

The command to sort down processes by memory usage:

ps aux --sort -rss | head -n15

Solution:

  • Try upgrade new version
  • Turn off optimize performance schema, edit /etc/mysql/my/cnf
@cuonghuynh
cuonghuynh / readme.md
Last active Oct 2, 2018
Disable listing directory in browser
View readme.md

Open apache2 config, remove Indexes option

$ sudo vim /etc/apache2/apache2.conf

Change from

<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
@cuonghuynh
cuonghuynh / code.md
Created Oct 2, 2018
Laravel: Pass and get the data via redirect response
View code.md

Pass data:

return redirect()->route('admin.article.index')->with('results', $results);

Get data:

session('results');
@cuonghuynh
cuonghuynh / code.php
Created Oct 2, 2018
Detect delimiter of csv file
View code.php
/**
* Class CsvHelpers
* @package App\Services\Common
*/
class CsvHelpers
{
/**
* @param $file
* @return string
*/
@cuonghuynh
cuonghuynh / guide.md
Last active Oct 1, 2018
How to Import a large CSV file to our storage?
View guide.md

Chunk data

If you have a large CSV file, you very likely can't store it all in an array in memory before you start inserting the data into the DB, so you need to be inserting the data in chunks as you read it from the CSV file.

Queue chunks

You would be lost the data if the process unfortinately broken.

Log errors

You should know why it is broken. :)

@cuonghuynh
cuonghuynh / solution.md
Last active Oct 1, 2018
Errors after upgrading mysql to 5.7
View solution.md

error-related-to-only-full-group-by-when-executing-a-query-in-mysq

As of MySQL 5.7.5, the default SQL mode includes ONLY_FULL_GROUP_BY which means when you are grouping rows and then selecting something out of that groups, you need to explicitly say which row should that selection be made from.

Fixing:

$ sudo vim /etc/mysql/my.cnf

Add them to bottom of file

You can’t perform that action at this time.