Skip to content

Instantly share code, notes, and snippets.

View cuonghuynh's full-sized avatar
🏠
Working from home

Cuong Huynh cuonghuynh

🏠
Working from home
View GitHub Profile
function isObjectEmpty(obj: object): boolean {
for (const property in obj) {
return false;
}
return true;
}
function formatBytes(bytes: number): string {
const decimals = 2;
if (bytes === 0) return "0 B";
const k = 1024;
const dm: number = decimals < 0 ? 0 : decimals;
const sizes: string[] = ["B", "KB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB"];
const i: number = Math.floor(Math.log(bytes) / Math.log(k));
@cuonghuynh
cuonghuynh / MySection.tsx
Created March 3, 2021 08:42
React pass custom prop to ForwardRef component
export const MySection = React.forwardRef<
HTMLDivElement,
{ myAttribute: boolean }
>(({ myAttribute }, ref) => {
return (
// your component
)
}
<MySection ref={mySectionRef} myAttribute={true} />
@cuonghuynh
cuonghuynh / newincident.hbs
Created January 7, 2021 16:25 — forked from caeb92/newincident.hbs
Example nodejs typescript : Send emails with Nodemailer - Handlebars
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.card {
@cuonghuynh
cuonghuynh / .htaccess
Created April 23, 2020 17:05
Combine Apache's HTTP authentication with X-Forwarded-For IP whitelisting in a reverse proxy Loadbalancer
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 September 8, 2019 16:24
The video autoplay when the modal is shown and stop as the modal is closed.
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 November 15, 2018 15:05
Unable to load dynamic library '/usr/local/opt/php71-intl/intl.so'

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 October 22, 2018 07:45
Symfony: Mask sensitive data in the log file

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 October 20, 2018 02:20
Study case: "InnoDB: Database was not shutdown normally! "

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 October 2, 2018 18:37
Disable listing directory in browser

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