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 / unix-commands.md
Last active June 26, 2018 01:48
Some useful Unix commands for SysAd
  • Disable a service which starts automatically sudo update-rc.d -f nginx disable

  • Space investigation:

    • Find top biggest directories under particular partition: du -a /home/xxx | sort -n -r | head -n 5

    • To display the above result in human readable format: du -Sh /home/xxx | sort -rh | head -5

@khanhtran3005
khanhtran3005 / python-journey.md
Last active September 15, 2018 07:59
Learning Python's notes

String Formatting

# Basic usage
print('We are the {} who say "{}!"'.format('knights', 'Ni'))

# Using index of the passed object
print('Low limit: {0}, high limit: {1}'.format(10, 200))

# using the name of the argument.
@khanhtran3005
khanhtran3005 / users-groups.md
Last active May 30, 2018 04:00
Manage Linux users and groups
  • User(s) in a group: getent group groupname
  • To add user to a group: sudo gpasswd -a username sudo | sudo usermod -aG sudo username
  • To add a new user: sudo adduser new_username
  • To remove/delete a user: sudo userdel username | Then remove user's folder if needed: sudo rm -r /home/username or sudo deluser --remove-home username
  • To remove user from a group: gpasswd -d username group
  • To modify the username: usermod -l new_username old_username
  • To change the password for a user: sudo passwd username
  • To change the shell for a user: sudo chsh username
  • To allow user to connect via SSH: add username to the line AllowUsers in /etc/ssh/sshd_config
  • To grant user to root: visudo and add username (same with root)
@khanhtran3005
khanhtran3005 / sublime_setup.md
Last active July 20, 2021 13:43
Some useful configurations

Preferences > Key Bindings - User

[
  { "keys": ["ctrl+t", "ctrl+w"], "command": "toggle_setting", "args": {"setting": "word_wrap"}},
  { "keys": ["ctrl+alt+p"], "command": "prompt_select_workspace" } 
]

> Preferences > Settings - User

@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",
function loadStyleSheet(src) {
    if(document.createStyleSheet) {
       document.createStyleSheet(src);
    } else {
        var css;
        css         = document.createElement('link');
        css.rel     = 'stylesheet';
        css.type    = 'text/css';
 css.media = "all";
@khanhtran3005
khanhtran3005 / ChristmasTree-vs-Return.md
Last active August 29, 2015 14:27
Which one do you choose?

#Christmas Tree

<?php 
    if($a) {
        if($b) {
            if($c) {
                if($d) {
                    // This is what I really want to do
                } else {
 //Do something something else