Tips Random

Python

import sys
for i in range(0,16):
    for j in range(0,16):
        code = str(i*16+j)
        sys.stdout.write(u"\u001b[38;5;" + code + "m " + code.ljust(4))
    print u"\u001b[0m"
import sys
for i in range(0,16):
    for j in range(0,16):
        code = str(i*16+j)
        sys.stdout.write(u"\u001b[48;5;" + code + "m " + code.ljust(4))
    print u"\u001b[0m"
import time
def loading():
    print "loading..."
    for i in range(0, 100):
        time.sleep(0.03)
        sys.stdout.write(u"\u001b[1000D" + str(i+1) + "%")
        sys.stdout.flush()
    print

loading()
import time, sys
def loading():
    print "loading..."
    for i in range(0, 100):
        time.sleep(0.03)
        width = (i+1)/4
        bar = "[" + "#" * width + " " * (25 - width) + "]"
        sys.stdout.write(u"\u001b[1000D" + bar)
        sys.stdout.flush()
    print

loading()

Remake view terminal

nano ~/.bashrc

edit PS1 :

PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\\$\[\e[0m\]"

edit PS1 di root :

sudo su
nano /root/.bashrc

edit PS1 :

PS1="\[\033[0;31m\]\342\224\214\342\224\200\$([[ \$? != 0 ]] && echo \"[\[\033[0;31m\]\342\234\227\[\033[0;37m\]]\342\224\200\")[$(if [[ ${EUID} == 0 ]]; then echo '\[\033[01;31m\]root\[\033[01;33m\]@\[\033[01;96m\]\h'; else echo '\[\033[0;39m\]\u\[\033[01;33m\]@\[\033[01;96m\]\h'; fi)\[\033[0;31m\]]\342\224\200[\[\033[0;32m\]\w\[\033[0;31m\]]\n\[\033[0;31m\]\342\224\224\342\224\200\342\224\200\342\225\274 \[\033[0m\]\[\e[01;33m\]\\$\[\e[0m\]"

Setting mendadak rusak saat hapus

sudo apt-get remove unity-control-center
sudo apt-get install unity-control-center

jika ada lagi yg rusak, maka : (jika benar-benar urgent)

sudo apt-get install ubuntu-desktop

git graph

git log --all --decorate --oneline --graph

atau buat command graph

alias graph="git log --all --decorate --oneline --graph"

Input-Output Redirection

coba > 1> 2> >&0 >&1 >&2

python -c "print('tes'); print(1/0)" > tes.txt

output

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
cat tes.txt
tes

python -c "print('tes'); print(1/0)" 1> tes.txt

output

Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero
cat tes.txt
tes

python -c "print('tes'); print(1/0)" 2> tes.txt

output

tes
cat tes.txt
Traceback (most recent call last):
  File "<string>", line 1, in <module>
ZeroDivisionError: division by zero

Linux Cheatsheet

# list size
du -sh *
ls -lha
du -sk * | sort -n
du -sk * | sort -h
du -sh * | sort -hr

# random
php -i | grep /.+/php.ini -oE
ps -ef | grep apache2
grep -rnw '.' -e 'ssl'

kill `number`

sudo lsof -i -P -n | grep LISTEN
sudo netstat -tulpn | grep LISTEN
sudo ss -tulpn | grep LISTEN
sudo lsof -i:22 ## see a specific port such as 22 ##
sudo nmap -sTU -O IP-address-Here
sudo nmap -sT -O localhost