Skip to content

Instantly share code, notes, and snippets.

@khanhtran3005
khanhtran3005 / unix-commands.md
Last active Jun 26, 2018
Some useful Unix commands for SysAd
View unix-commands.md
  • 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 Sep 15, 2018
Learning Python's notes
View python-journey.md

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
Manage Linux users and groups
View users-groups.md
  • 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 Jul 20, 2021
Some useful configurations
View sublime_setup.md

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 Apr 22, 2016
Load Perl's class by package name
View load_class.pm
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 Apr 18, 2016
How to use Putty private key with git
View putty-git.md
  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 Mar 31, 2016 — forked from tott/ip_in_range.php
php check if IP is in given network range
View ip_in_range.php
/**
* 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 Mar 20, 2016
Set up Sublime Linter
View SublimeLinter.md

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

{

  "sublimelinter_executable_map":
    {
        "javascript":"C:/Program Files/nodejs/node.exe",
        "css":"C:/Program Files/nodejs/node.exe",
View Load-CSS-Async.md
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";
View ChristmasTree-vs-Return.md

#Christmas Tree

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