Skip to content

Instantly share code, notes, and snippets.

View khanhtran3005's full-sized avatar

Khanh Tran khanhtran3005

  • Inspectorio
  • Vietnam
View GitHub Profile
@khanhtran3005
khanhtran3005 / gist:81c8758743964b7802a0d91e4ca90835
Created January 23, 2018 10:26
Get Postfix email credentials
/usr/local/psa/admin/bin/mail_auth_view | grep email_address@abc.com
@khanhtran3005
khanhtran3005 / scrollTop.js
Created December 18, 2017 12:29
A properly way to do scrollTop. It's correct for positive and negetive element's offsetY
var body = $('.modal-body');
body.animate({
scrollTop: body.scrollTop() + error.offset().top - 65
}, 500);
@khanhtran3005
khanhtran3005 / dateValidation.js
Created December 15, 2017 09:39
dd/mm/yyyy validation. Including leap year check
function Validator() {}
Validator.min = function(number, min) {
return number >= min;
}
Validator.max = function(number, max) {
return number <= max;
}
@khanhtran3005
khanhtran3005 / gist:b45ad2fdc138e0ba6ed3e782787daa61
Created November 24, 2017 09:22 — forked from Steven-Rose/gist:3943830
VI: Select all + delete, select all + copy
Select all and delete (actually move to buffer)
:%d
Select all and copy to buffer
:%y
Use p to paste the buffer.
@khanhtran3005
khanhtran3005 / curl.md
Created November 24, 2017 06:42 — forked from subfuzion/curl.md
curl POST examples

Common Options

-#, --progress-bar Make curl display a simple progress bar instead of the more informational standard meter.

-b, --cookie <name=data> Supply cookie with request. If no =, then specifies the cookie file to use (see -c).

-c, --cookie-jar <file name> File to save response cookies to.

@khanhtran3005
khanhtran3005 / process-checking.md
Created May 22, 2017 03:23
Check a process whether running for not using PHP
function processExists($processName) {
    $exists= false;
    exec("ps -aux | grep -i $processName | grep -v grep | grep -v /bin/sh", $pids);
    if (count($pids) > 1) {
        $exists = true;
    }
    return $exists;
}
@khanhtran3005
khanhtran3005 / load_class.pm
Created April 22, 2016 01:53
Load Perl's class by package name
sub load_class {
my($class, $prefix) = @_;
if ($prefix) {
unless ($class =~ s/^\+// || $class =~ /^$prefix/) {
$class = "$prefix\::$class";
}
}
my $file = $class;
@khanhtran3005
khanhtran3005 / putty-git.md
Last active April 18, 2016 03:24
How to use Putty private key with git
  1. Convert Putty private key to OpenSSH private key.
  • Linux: with your package manager, install PuTTY (or the more minimal PuTTY-tools):
    • Ubuntu sudo apt-get install putty-tools
    • Debian-like apt-get install putty-tools
  1. Generate the private key: puttygen id_dsa.ppk -O private-openssh -o id_dsa
  2. Generate the public key: puttygen id_dsa.ppk -O public-openssh -o id_dsa.pub
  3. Copy id_dsa (600) and id_dsa.pub (644) to ~/.ssh folder
  4. In ~/.ssh/config, add:
@khanhtran3005
khanhtran3005 / ip_in_range.php
Created March 31, 2016 02:20 — forked from tott/ip_in_range.php
php check if IP is in given network range
/**
* Check if a given ip is in a network
* @param string $ip IP to check in IPV4 format eg. 127.0.0.1
* @param string $range IP/CIDR netmask eg. 127.0.0.0/24, also 127.0.0.1 is accepted and /32 assumed
* @return boolean true if the ip is in this range / false if not.
*/
function ip_in_range( $ip, $range ) {
if ( strpos( $range, '/' ) == false ) {
$range .= '/32';
}
@khanhtran3005
khanhtran3005 / SublimeLinter.md
Last active March 20, 2016 08:31
Set up Sublime Linter

Preferences->Package Settings->SublimeLinter->Settings – User

{

  "sublimelinter_executable_map":
    {
        "javascript":"C:/Program Files/nodejs/node.exe",
 "css":"C:/Program Files/nodejs/node.exe",