sobota, 30 listopada 2013

few first step in Java

1.

public class for_loop {
    public static void main(String[] args) {
        for (int i = 0; i < 3; i++) {
            System.out.println("Marek");
        }
    }
}


remember that name of the class should be equal to filename

2.

to compile your "program" type:
javac for.loop.java

3.

execute:

┌─[marek@localhost]─[~/Dokumenty/java]
└──╼ ls -ltr
razem 8
-rwxrwxr-x 1 marek marek 167 11-30 23:39 for_loop.java
-rw-rw-r-- 1 marek marek 467 11-30 23:39 for_loop.class

java for_loop 

czwartek, 28 listopada 2013

check if service is running - systemd fedora

┌─[marek@localhost]─[~]
└──╼ systemctl is-enabled sshd.service; echo $?
enabled
0

file reader python

#!/usr/bin/python

import time

try:
    f = file('/etc/passwd')
    while True:
        line = f.readline()
        if len(line) == 0:
            break
        time.sleep(2)
        print line,
finally:
    f.close()
    print "cleaning up ... closed the file"

almost like kindle :)


python lits again

#!/usr/bin/python

a = [1, 2, 3, 33, 123, 111]
print a
print "total element's len: ",len(a)

a.insert(2, -1) """insert in second place value - -1"""
a.append(666) """append 666 to list"""
print a, len(a)

data = raw_input("enter something: ")

a.append(data) """append from variable"""
print a, len(a)

print "sorting"
a.sort() """sorting the list"""
print a

from file 2 file python

#!/usr/bin/python

from sys import argv
from os.path import exists

script, from_file, to_file = argv
try:
    print "copying from %s to %s" % (from_file, to_file)
    print "check if first file is excist"
    in_file = open(from_file)
    indata = in_file.read()

    print "The input file is %d bytes long" %len(indata)
    raw_input()
    out_file = open(to_file, 'w')
    out_file.write(indata)
    print "all done"
    out_file.close()
    in_file.close()
except IOError:
    print "I/O Error"

file truncate python

#!/usr/bin/python
from sys import argv
import os

script, filename = argv

check = os.stat(filename)[6]==0

if check == False:
    print "the file %r. " %filename, "will be erased"
    print "press enter to continue.."
    raw_input("?")
    print "opening the file: ..%r" %filename
    target = open(filename, 'w')
    print "erasing..."
    target.truncate()

    print "closing ... "
    target.close()
else:
    print "file is empty"


check if file is empty - python


#!/usr/bin/python
import os
check = os.stat("testfile")[6]==0
if check == True:
    print "file is empty"
else:
    print "open file"
    with open("testfile", "rt") as in_file:
        text = in_file.read()
    print (text)


python
Python 2.7.5 (default, Nov 12 2013, 16:18:42)
[GCC 4.8.2 20131017 (Red Hat 4.8.2-1)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
&gt;&gt;&gt; import os
&gt;&gt;&gt; os.stat("testfile")
posix.stat_result(st_mode=33204, st_ino=5113343, st_dev=2056L, st_nlink=1, st_uid=1000, st_gid=1000, <i><b>st_size=0</b></i>, st_atime=1385626955, st_mtime=1385627001, st_ctime=1385627001)

poniedziałek, 25 listopada 2013

vim file compare

[marek@lati]─[/tmp] echo marek > 1 && echo borkowski > 2 [marek@lati]─[/tmp] ╼ vim -d 1 2 2 file to edit

python mysql mariadb fedora :)


yum install python-pip.noarch
yum install python-devel
yum install mysql-devel

┌─[lati]─[~]
└──╼ easy_install mysql-python

┌─[lati]─[~]
└──╼ pip install MySQL-python

change mysql default password in fedora

After installation we need to:
1. start service: service mysqld start

┌─[lati]─[~]
└──╼ service mysqld status
Redirecting to /bin/systemctl status  mysqld.service
mysqld.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; disabled)
   Active: active (running) since pon 2013-11-25 13:28:14 CET; 2s ago
  Process: 5746 ExecStartPost=/usr/libexec/mysqld-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 5672 ExecStartPre=/usr/libexec/mysqld-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 5745 (mysqld_safe)
   CGroup: name=systemd:/system/mysqld.service
           ├─5745 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           └─5902 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql...

lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: The latest information abou...
lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: You can find additional inf...
lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: http://dev.mysql.com
lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: Support MariaDB development...
lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: Monty Program Ab. You can c...
lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: Alternatively consider join...
lis 25 13:28:11 lati mysqld-prepare-db-dir[5672]: http://kb.askmonty.org/en/c...
lis 25 13:28:12 lati mysqld_safe[5745]: 131125 13:28:12 mysqld_safe Logging ....
lis 25 13:28:12 lati mysqld_safe[5745]: 131125 13:28:12 mysqld_safe Starting...l
lis 25 13:28:14 lati systemd[1]: Started MariaDB database server.

2. go to mysql "admin shell"
mysql -u root -p [password is blank press enter]

3. in mysql shell execute-
use mysql;

MariaDB [(none)]> use mysql
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed


MariaDB [mysql]> update user set password=PASSWORD("marek1983") where User='root';Query OK, 4 rows affected (0.00 sec)Rows matched: 4  Changed: 4  Warnings: 0


flush privileges;
quit


wtorek, 19 listopada 2013

os.module Python part1

#!/usr/bin/python
import os

path = raw_input("enter path: ")
state = os.path.isdir(path)
print state
if state == False:
print "there is no: ",path

check_size = raw_input("enter full path to file: ")
fo = os.path.getsize(check_size)
print fo

print "path2file"
print "select only file name"
only_file = os.path.split(check_size)
print only_file

print "get the extension of a file"
sufix = os.path.splitext(check_size)
print sufix

poniedziałek, 4 listopada 2013

postgresql - add account and change password

marek@lati:/var/cache/apt$ sudo -u postgres createuser marek

marek@lati:/var/cache/apt$ sudo -u postgres psql
psql (9.2.5)
Wpisz "help" by uzyskać pomoc.

postgres=# postgres=# \password marek

Wprowadź nowe hasło:
Powtórz podane hasło:

postgres-#
postgres-# \q

niedziela, 3 listopada 2013

apt

apt ubuntu tutorial:

1. install

marek::mbo { ~ }-> sudo apt-get install apache2
Czytanie list pakietów... Gotowe
Budowanie drzewa zależności      
Odczyt informacji o stanie... Gotowe
Zostaną zainstalowane następujące dodatkowe pakiety:
  apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common
  libaprutil1-dbd-sqlite3 libaprutil1-ldap
Sugerowane pakiety:
  apache2-doc apache2-suexec apache2-suexec-custom
Zostaną zainstalowane następujące NOWE pakiety:
  apache2 apache2-mpm-worker apache2-utils apache2.2-bin apache2.2-common
  libaprutil1-dbd-sqlite3 libaprutil1-ldap
0 aktualizowanych, 7 nowo instalowanych, 0 usuwanych i 81 nieaktualizowanych.
Konieczne pobranie 3472 kB archiwów.
Po tej operacji zostanie dodatkowo użyte 10,3 MB miejsca na dysku.
Kontynuować [T/n]?



2. search

marek::mbo { ~ }-> sudo apt-cache search xclock
x11-apps - Aplikacje X
xarclock - reversed xclock
rxvt - Emulator terminala VT102 dla X Window System
rxvt-beta - Emulator terminala VT102 dla X Window System

3. package info

marek::mbo { ~ }-> apt-cache show xterm
Package: xterm
Priority: optional
Section: x11
Installed-Size: 1437
Maintainer: Ubuntu X-SWAT <ubuntu-x@lists.ubuntu.com>
Original-Maintainer: Debian X Strike Force <debian-x@lists.debian.org>
Architecture: amd64
Version: 278-1ubuntu2

..

4. check package dependenties

marek::mbo { ~ }-> apt-cache showpkg xterm
Package: xterm
Versions:
278-1ubuntu2 (/var/lib/apt/lists/pl.archive.ubuntu.com_ubuntu_dists_raring_main_binary-amd64_Packages) (/var/lib/dpkg/status)
 Description Language:
                 File: /var/lib/apt/lists/pl.archive.ubuntu.com_ubuntu_dists_raring_main_binary-amd64_Packages
                  MD5: c1e47d60a01948be9aae7a2a4f63a0fe
 Description Language: en
                 File: /var/lib/apt/lists/pl.archive.ubuntu.com_ubuntu_dists_raring_main_i18n_Translation-en
                  MD5: c1e47d60a01948be9aae7a2a4f63a0fe
 Description Language: pl
                 File: /var/lib/apt/lists/pl.archive.ubuntu.com_ubuntu_dists_raring_main_i18n_Translation-pl
                  MD5: c1e47d60a01948be9aae7a2a4f63a0fe


Reverse Depends:
  kdm,xterm
  xterm:i386,xterm
....
  grun,xterm
  grass-gui,xterm
  grace,xterm
  gman,xterm
  gkdebconf,xterm
  gfceu,xterm
  gexec,xterm
  exmh,xterm
  epoptes-client,xterm
  epoptes,xterm
  dwb,xterm
  draai,xterm
  debroster,xterm
  debian-installer-launcher,xterm
  ddd,xterm
  codelite,xterm
  codeblocks,xterm
  clusterssh,xterm
  barrydesktop,xterm
  axel-kapt,xterm
  apt-watch-backend,xterm
  advi-examples,xterm
  xorg,xterm
  xinit,xterm
  ubuntu-desktop,xterm
  tk8.5,xterm
Dependencies:
278-1ubuntu2 - xbitmaps (0 (null)) libc6 (2 2.15) libfontconfig1 (2 2.9.0) libice6 (2 1:1.0.0) libtinfo5 (0 (null)) libutempter0 (2 1.1.5) libx11-6 (0 (null)) libxaw7 (0 (null)) libxft2 (4 2.1.1) libxmu6 (0 (null)) libxt6 (0 (null)) xfonts-cyrillic (0 (null)) x11-utils (0 (null)) xterm:i386 (0 (null))
Provides:
278-1ubuntu2 - xterm:i386 x-terminal-emulator:i386 x-terminal-emulator
Reverse Provides:
xterm:i386 278-1ubuntu2



ncdu

ncdu (NCurses Disk Usage) is a command line version of the most popular du command. 
If you don't have much time to compose advanced command. Use ncdu:

1. sudo apt-get install ncdu (also availavle in redhat distros)
2. ncdu

ncdu 1.10 ~ Use the arrow keys to navigate, press ? for help                        
--- /home/marek/Pobrane ------------------------------------------------------------
  694,0MiB [##########]  elementaryos-stable-amd64.20130810.iso                     
  390,3MiB [#####     ] /occam-jwr66y
  355,0MiB [#####     ]  occam-jwr66y-factory-74b1deab.tgz
  276,1MiB [###       ] /pa_aosp_mako
  190,0MiB [##        ]  pa_gapps-full-4.4-20131102-signed.zip
  166,6MiB [##        ]  pa_aosp_mako.zip
   40,2MiB [          ]  google-chrome-stable_current_i386.deb
    8,1MiB [          ]  openrecovery-twrp-2.4.1.0-mako.img
    4,4MiB [          ]  recovery-clockwork-5.0.2.8-marvel.img
    1,2MiB [          ]  UPDATE-SuperSU-v1.50.zip
   60,0KiB [          ]  elementaryos-stable-amd64.20130810.iso.torrent
   24,0KiB [          ]  Harmonogram_szczyt_klimatyczny.xlsx




ncdu / - it will be scan all your disk and give you:

ncdu 1.10 ~ Use the arrow keys to navigate, press ? for help                        
--- / ------------------------------------------------------------------------------
.   8,3GiB [##########] /home                                                       
    2,8GiB [###       ] /usr
.   1,7GiB [##        ] /var
  411,0MiB [          ] /lib
  173,7MiB [          ] /opt
   57,6MiB [          ] /boot
.  13,2MiB [          ] /etc
   10,8MiB [          ] /sbin
    9,5MiB [          ] /bin
.   1,5MiB [          ] /run
.  36,0KiB [          ] /tmp
!  16,0KiB [          ] /lost+found
    8,0KiB [          ] /media
    4,0KiB [          ] /dev
    4,0KiB [          ] /lib64
e   4,0KiB [          ] /srv
!   4,0KiB [          ] /root
e   4,0KiB [          ] /mnt
e   4,0KiB [          ] /cdrom
.   0,0  B [          ] /proc
.   0,0  B [          ] /sys
@   0,0  B [          ]  initrd.img.old
@   0,0  B [          ]  initrd.img
@   0,0  B [          ]  vmlinuz.old
@   0,0  B [          ]  vmlinuz

short introduction to dpkg ubuntu/debian

1. install package
dpkg -i package_name.deb

2. list all installed package
dpkg -l
dpkg -l vlc

marek@lati:~$ dpkg -l vlc

Wybór:U=nieznany/I=instalacja/R=usunięcie/P=wyczyszczenie/H=zatrzymanie
| Stan:N=brak/I=zainstalowany/C=skonfigurowany/U=rozpakowany/
|/  F=częśc. skonfigurowany/H=częśc. zainstalowany/W=wyzw. czek./T=wyzw. zapl.

|| Błędy?=(brak)/R-do pon. inst. (duże litery w "Stan" i "Błędy"=problemy)
||/ Nazwa          Wersja       Architektura Opis
+++-==============-============-============-=================================
ii  vlc            2.0.8-1      amd64        multimedia player and streamer


3. remove package
dpkg -r packagename.deb

4. view the package content

dpkg -c packagename.deb

marek@lati:~/Pobrane$ dpkg -c google-chrome-stable_current_i386.deb
drwx------ root/root         0 2013-10-21 20:00 ./
drwxr-xr-x root/root         0 2013-10-21 20:00 ./opt/
drwxr-xr-x root/root         0 2013-10-21 20:00 ./opt/google/
drwxr-xr-x root/root         0 2013-10-21 20:00 ./opt/google/chrome/
-rw-r--r-- root/root   2327028 2013-10-21 20:00 ./opt/google/chrome/libffmpegsumo.so
-rw-r--r-- root/root      4818 2013-10-21 20:00 ./opt/google/chrome/product_logo_32.xpm
......


5. check if package is installed or not

marek::mbo { ~ }-> sudo dpkg -s zip
Package: zip
Status: install ok installed
Priority: optional
Section: utils
Installed-Size: 589
Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
Architecture: amd64
Multi-Arch: foreign
Version: 3.0-6ubuntu1
Replaces: zip-crypt (<= 2.30-2)
Depends: libbz2-1.0, libc6 (>= 2.14)
Recommends: unzip
Conflicts: zip-crypt (<= 2.30-2)
Description: Archiver for .zip files
 This is InfoZIP's zip program. It produces files that are fully
 compatible with the popular PKZIP program; however, the command line
 options are not identical. In other words, the end result is the same,
 but the methods differ. :-)
 .
 This version supports encryption.
Homepage: http://www.info-zip.org/Zip.html
Original-Maintainer: Santiago Vila <sanvila@debian.org>