Skip to content

Instantly share code, notes, and snippets.

View greentornado's full-sized avatar

Hai Nguyen greentornado

View GitHub Profile
@greentornado
greentornado / gist:6b34936a886c50b70eaa90f185ff946a
Created July 15, 2023 02:57 — forked from lanqy/gist:8514345
How to detect Safari, Chrome, IE, Firefox and Opera browser?
//from http://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// At least Safari 3+: "[object HTMLElementConstructor]"
var isChrome = !!window.chrome && !isOpera; // Chrome 1+
var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
@greentornado
greentornado / sshPemKey.md
Created March 28, 2023 04:01 — forked from rxm/sshPemKey.md
Create an SSH key in PEM format

Create an SSH key in PEM format

I have not been able to use ssh-keygen -e to reliably generate a private key for SSH in PEM format. This format is sometimes used by commercial products. Instead, I had to convert the key using openssl.

# generate an RSA key of size 2048 bits
ssh-keygen -t rsa -b 2048 -f jabba -C 'ronnie-jabba'

# copy key to 10.1.56.50 and add to authorized_keys
@greentornado
greentornado / pngquant_all
Created December 19, 2022 08:18 — forked from trevorwang/pngquant_all
pngquant an entire folder
find . -name '*.png' -exec pngquant --ext .png --force {} \;

NGINX Performance Tuning

Content Compressions and Decompression

  • Documentation
    • NGINX http_gzip module
    • NGINX http_gunzip module
  • Enable gzip. by default, we’re not going to compress the responses that we’re getting from proxied servers or any piece of content that isn’t HTML.
  • But if one of our proxied servers happens to send us a pre-compressed response then we probably want to decompress it for clients that can’t handle gzip. In this situation, we’ll use the gunzip module
    $ vim /etc/nginx/nginx.conf
Can I Remove MySQL Binary Log Yes, as long as the data is replicated to Slave server, it’s safe to remove the file. It’s recommend only remove MySQL Binary Log older than 1 month.
Besides, if Recovery of data is the main concern, it’s recommend to archive MySQL Binary Log.
There are several ways to remove or clean up MySQL Binary Log, it’s not recommend to clean up the file manually, manually means running the remove command.
Remove MySQL Binary Log with RESET MASTER Statement Reset Master statement is uses for new database start up during replication for Master and Slave server. This statement can be used to remove all Binary Log.
To clean up Binary Log on Master Server
@greentornado
greentornado / jpg-png-optimize.md
Created November 5, 2021 08:49 — forked from w33zy/jpg-png-optimize.md
Optimize your jpg & png images with jpegoptim and optipng on linux

JPG and PNG image bulk optimization

Install jpegoptim and optipng

apt update && apt install jpegoptim optipng -y

JPG optimization

cd /path/to/your/image/folder
@greentornado
greentornado / youtube-id.php
Created July 5, 2021 15:37 — forked from leogopal/youtube-id.php
PHP function to get youtube ID from URL
<?php
function get_youtube_video_ID($youtube_video_url) {
/**
* Pattern matches
* http://youtu.be/ID
* http://www.youtube.com/embed/ID
* http://www.youtube.com/watch?v=ID
* http://www.youtube.com/?v=ID
* http://www.youtube.com/v/ID
* http://www.youtube.com/e/ID
@greentornado
greentornado / RNfontWeights.js
Created November 8, 2020 15:51 — forked from knowbody/RNfontWeights.js
React Native Font Weight Cheatsheet iOS
{ fontWeight: '100' }, // Thin
{ fontWeight: '200' }, // Ultra Light
{ fontWeight: '300' }, // Light
{ fontWeight: '400' }, // Regular
{ fontWeight: '500' }, // Medium
{ fontWeight: '600' }, // Semibold
{ fontWeight: '700' }, // Bold
{ fontWeight: '800' }, // Heavy
{ fontWeight: '900' }, // Black
@greentornado
greentornado / file.java
Created August 27, 2020 09:11
Java audio to byte array
import java.io.*;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.util.LinkedHashMap;
import javax.sound.sampled.*;
// Copy from https://stackoverflow.com/questions/10397272/wav-file-convert-to-byte-array-in-java
/**
* This class reads a .wav file and converts it to a bunch of byte arrays.
*
* The info represented by these byte arrays is then printed out.
@greentornado
greentornado / homebrew.md
Created April 17, 2020 08:59 — forked from indiesquidge/homebrew.md
How to and Best of Homebrew

Homebrew

How To

Homebrew is a package management system for OS X. You can read more about it here, or simply run

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

to install it.