piątek, 8 stycznia 2016

Java - Scanner input with formated output

import java.util.Scanner;


public class ScannerInput
{
public static void main(String[] args)
{
String input;
System.out.print("Enter name: ");
Scanner in = new Scanner(System.in);
input = in.next();
System.out.printf("Hello %s ",input);
in.close();
}
}

Java args test with arg index

public class HelloClass
{
public static void main(String[] args)
{
if(args.length > 0)
{
for(int i=0;i<args.length;i++)
{
System.out.println(i + " "+args[i]);
}
}
else
{
System.err.println("no args given");
}
}
}

output:

┌─[marek@lati]─[~/workspace/nauka_java/bin]
└──╼ java HelloClass Canada Australia Spain
0 Canada
1 Australia
2 Spain

poniedziałek, 4 stycznia 2016

Formated output in python

import time
'''simple multiplication'''

def drawline(l):
    print(l * "-=-")


def main():
    start = time.time()
    for x in xrange(10):
        for y in xrange(10):
            print("x %d * y %d = res %d" % (x,y,x*y))
    end = time.time()

    print(end - start)


if __name__ == "__main__":
    main()

Conversion Meaning
d Signed integer decimal.
i Signed integer decimal.
o Unsigned octal.
u Unsigned decimal.
x Unsigned hexadecimal (lowercase).
X Unsigned hexadecimal (uppercase).
e Floating point exponential format (lowercase).
E Floating point exponential format (uppercase).
f Floating point decimal format.
F Floating point decimal format.
g Same as "e" if exponent is greater than -4 or less than precision, "f" otherwise.
G Same as "E" if exponent is greater than -4 or less than precision, "F" otherwise.
c Single character (accepts integer or single character string).
r String (converts any python object using repr()).
s String (converts any python object using str()).
% No argument is converted, results in a "%" character in the result

piątek, 1 stycznia 2016

basics with python paramiko

import paramiko
import socket

x = socket.getaddrinfo('localhost', 8080)
print(x)
ssh = paramiko.SSHClient()
ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())
ssh.connect('192.168.1.178', port=22, username='root', password='marek1983')
stdin, stdout, stderr = (ssh.exec_command("uptime"))
output = stdout.readlines()
print('\n'.join(output))

output:

C:\Python27\python.exe C:/Users/Y700-15/PycharmProjects/python/remcon.py
[(23, 0, 0, '', ('::1', 8080, 0, 0)), (2, 0, 0, '', ('127.0.0.1', 8080))]
 21:52:18 up  2:00,  1 user,  load average: 0,00, 0,01, 0,05


Process finished with exit code 0


easiest way to check default firewalld zone

[root@virt ~]# firewall-cmd --get-zones
FedoraServer FedoraWorkstation block dmz drop external home internal public trusted work

[root@virt ~]# cat /etc/firewalld/firewalld.conf
# firewalld config file

# default zone
# The default zone used if an empty zone string is used.
# Default: public
DefaultZone=FedoraServer

[root@virt ~]# firewall-cmd --get-default-zone
FedoraServer


static interface fedora 23

create for example file: ifcfg-enp0s9 in /etc/sysconfig/network-scripts

[root@virt network-scripts]# vi ifcfg-enp0s9
DEVICE=enp0s9
BOOTPROTO=none
ONBOOT=yes
NETMASK=255.255.255.0
IPADDR=192.168.1.178




enable service fedora 23

[root@virt ~]# chkconfig httpd on
Uwaga: przekazano żądanie do "systemctl enable httpd.service".

Created symlink from /etc/systemd/system/multi-user.target.wants/httpd.service to /usr/lib/systemd/system/httpd.service.