29.04.2015 г.

Windows attribe hiden folder

Folder is Z:

attrib -H -S Z:\* /S /D


  • -    #Clear attribute
  • H   #Hidden file attribute
  • S   #Show system file attribute
  • /S  #Matching file in the curent and subdirectory
  • /D #Process folder as well

27.04.2015 г.

Find music and play it with shell find use


  • find /home/borko/Mp3 -name "*pls" -type f -print | while read file;do cvlc $file;done 

  • find /home/borko/Mp3 -name "*pls" -type f -print | sed 's/^/cvlc /' | sh -x


16.04.2015 г.

Use mstsc with menu options with bat file

Create file.bat and put text:



@echo off
SET /P myVariable="Choice options: 1 - First 2 - Second 3 - Third"

echo
if %myVariable%==1 goto :First 
if %myVariable%==2 goto :Second 
if %myVariable%==3 goto :Third 



:First 
echo "Set First "
cmdkey /generic:ip /user:username /pass:passwords & mstsc.exe /v:ip
exit

:Second 
echo "Set Second "
cmdkey /generic:ip /user:username /pass:pass:passwords & mstsc.exe /v:ip

:Third 
echo "Set Third "
cmdkey /generic:ip /user:username /pass:pass:passwords & mstsc.exe /v:ip


Bat file to change ip address

Create file change_bat_brat.bat with content:

@echo off
echo.......................................................
color 2
ipconfig | find "IPv4 Address"
echo ......................................................

set /p num1=Enter a number: 1 - First 2 - Second
echo
if %num1%==1 goto :First
if %num1%==2 goto :Second
:First
echo Choice First
netsh interface ip set address name="Local Area Connection" static 192.168.168.111 255.255.255.0 192.168.168.1 1
netsh interface ip set dns "Local Area Connection" static 1.1.0.1
exit

:Second
echo Choice Second
netsh interface ip set address name="Local Area Connection" static 192.168.10.111 255.255.255.0 192.168.10.1 1
netsh interface ip set dns "Local Area Connection" static 192.168.10.1
exit

14.04.2015 г.

bash alias to unrar some format

Create faile:
touch unrar.sh && chmod +x unrar.sh
And then paste this in terminal:


cat <<EOF >>unrar.sh
#!/bin/bash

if [ -z "$1" ]
then
  echo "Paramather #1 is zero lenght"
else
  echo "Paramether #1 is \"$1\""
case $1 in
*tar) tar -xvf $1
;;
*bz2) bunzip2 $1
;;
*rar) unrar e $1
;;
*zip) unzip $1
esac
fi
EOF


After this open ~./bashrc or this you use and write this:

alias unrar='sh /path/to/unrar.sh/

Same alias start with use sintax:

unrar somefile.tar

11.04.2015 г.

Python search for picture and resize it

# -*- coding: utf-8 -*-
from PIL import Image, ImageFilter, os

format = ["jpg", "JPEG", "jpeg", "png"]
size = (128, 128)


try:
    for root,dirname,filename in os.walk("d:\\snimki"):
        for file in filename:
            if file.endswith(tuple([x for x in format])):
                im = Image.open(os.path.join(root,file))
                print "Original Picture %s is in format %s and mode is %s " % (file, im.size, im.mode)
                im.thumbnail(size)
                im.save(os.path.join(root,"new"+file))
except:
    print "Somthing wrong has with script"

9.04.2015 г.

Search for avi file, and play them with vlc - Bash script

#!/bin/bash
#In variable filename save result for find 
filename="result.txt"

#use find command for search for file +1G search for file gt 1G
find /home/borko/ -maxdepth 6 -type f -name *.avi -size +1G > $filename &&

#If not result save data in file
if [ $? -ne 0 ]
then
        date >> $filename
 
fi

#Function read line by line and play with vlc
while read line
do
 name=$line
 echo "Played - $line"
 vlc "$name"
 kill -9 vlc
done < $filename



#If you not use file do this in same line for play mp3 file:
find /home/borko/ -maxdepth 6 -type f -name *.mp3 -size -exec vlc {} \;
#This is a little function
mp3(){
 cd "/home/borko/Музика/"
 o=$IFS
 IFS=$(echo -n "\n\b")
 find -type f -name "*.mp3" -print0 | while read -d $'\0' name
 do
   `vlc $name`
 done
 IFS=o
}

When a problem with the clock in dualboot Windows and Linux

Вhen boot windows or linux in dualboot config, may wrong time display on mashine.
The fix is:

Creata on windows mashine reg file:

  • Windows Registry Editor Version 5.00
    [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\TimeZoneInformation]
    “RealTimeIsUniversal”=dword:00000001
  • On Linux mashine run:
          ntpdate pool.ntp.org && hwclock –systohc –utc

7.04.2015 г.

Python search for duplicated files


##################################################
#   Search for duplicated files without,                                         #
#   meaningless file exstension                                                     #
#     NOT EDIT BY HAND!!!                                                   #
##################################################

#IMPORT MODULES FOR SCRIPT

import hashlib, os
from itertools import *
from operator import itemgetter

#THIS USE FOR GIVE MD5 FOR FILE'S

md = hashlib.md5()
#Directory = os.getcwd()
#ADD NEEDED LIST
Dir = "C:\\SCRIPT"
_File = []       #CONTAINED PATH FOR FILE
_File_H = []     #CONTAINED MD5 CODE FOR FILE
_duplicated = []   #CONTAINED DUPLIATED
_duplicated_sravnqva = [] #NEED FOR ZIP
subdirlist = []    #MAY DELETED IF YOU WON USED FOR FUNCTION search_file

#SEARCH WITH OS.LISTDIR NOT WORKING FOR MOMENT
# def search_file(Dir):

#  for file in os.listdir(Dir):
#   if os.path.isfile(file):
#    yield os.path.join(Dir,file)
#   else:
#    subdirlist.append(os.path.join(Dir, file))
#    try:
#     for subdir in subdirlist:
#      search_file(subdir)
#    except:
#     print "Somting wrong"

#SEARCH WITH OS.WALK

def search_os_walk(Dir):
    for path,dirlist,filelist in os.walk(Dir):
        for fn in filelist:
            yield os.path.join(path,fn)

#FUNCTION USE FOR ENCRIPT FILE TO MD5
def md_5(filePath):
    with open(filePath, 'rb') as fh:
        m = hashlib.md5()
        while True:
            data = fh.read(8192)
            if not data:
                break
            m.update(data)
        return m.hexdigest()

#SEARCH FOR FILE AND APPEND THEM TO REQUIRED LIST (LOOKED ABOVE FOR #DESCRIPTION'S )

for file in search_os_walk(Dir):
     _File.append(file)
     _File_H.append(md_5(file))

for f,z in (izip(_File, _File_H)):
    if z in _duplicated:
         _duplicated_sravnqva.append(z)
         _duplicated.append(z)

print "*"*80
_Dupliated =  [x[0] for x in zip(_File, _File_H) if x[1] in _duplicated_sravnqva]
one= []
two= []
for i in _Dupliated:
    one.append(i)
    two.append(md_5(i))

#RESULT IN DICTIONARI, NEEDED FOR FUNCTION GROUPBY

d = dict(zip(one,two))
di = sorted(d.iteritems(), key=itemgetter(1))
for k, g in groupby(di, key=itemgetter(1)):
#IF YOU WHANT TO SHOW IN COLUMN UNCHECK BOTTOM ROW'S
    # for i,z  in enumerate(map(itemgetter(0), g)):
    #  print i,z
    print "Duplicated ", map(itemgetter(0), g)
raw_input()

6.04.2015 г.

Python order dictionary by Value, hailstone sequence

import operator
def fff(number):
    se = [number]
    while number > 1:
       number = 3*number+1 if number%2 else number/2
       se.append(number)
    return  sum(se)

result={}

for i in range(1,20):
    result[i]=fff(i)
 
print max(result.items(), key=operator.itemgetter(1))

Check zodiac sign ,china and wester with python script

# -*- coding: utf-8 -*-
import time,datetime

chainese = ['monkey','rooster','dog','pig','rat','ox','tiger','rabbit','dragon','snake','horse','sheep']

zodia = {
'aries': ['3 21', '4 20'],
'taurus' : ['4 21' , '5 20'],
'gemini' : ['5 21' , '6 20'],
'cancer' : ['6 21' , '7 22'],
'leo' : ['7 23' , '8 22'],
'virgo' : ['8 23' , '9 22'],
'libra' : ['9 23' , '10 22'],
'scorpio' : ['10 23' , '11 21'],
'sagittarius' : ['11 22' , '12 21'],
'capricorn' : ['12 22' , '1 20'],
'aquarius' : ['1 21' , '2 19'],
'pisces' : ['2 19' , '3 20']
}



def check_zodia(month,day):
    """Check zodia use dictioanry zodia"""
    for i in zip(zodia.keys(),zodia.values()):
        if tuple(map(int, [x for x in [i[1][0]]][0].split())) < (month, day) < tuple(map(int,[x for x in [i[1][1]]][0].split())):
            print "Your Zodia is %s" % i[0].title()


def check_china_zodia(year):
    """Check China Zodia sign"""
    check_china_zodia = int(year%12)
    print "In Chaina calendar you'r zodia is : %s" % chainese[check_china_zodia].title()
 

if __name__ == "__main__":
    value = raw_input("Enter day/month/year of Birth :")
    result = map(int, value.split("/"))
    day=result[0]
    month=result[1]
    year=result[2]
    check_zodia(month,day)
    print "\n"
    check_china_zodia(year)

Python script for listen radion station online

# -*- coding: utf-8 -*-
"""
Created on Thu Sep 18 10:24:56 2014

@author: borko-8.1
"""

import platform
import os
print "---------------Radio Station's----------------"
trance={u'Трансе FM': 'http://listen.trance.fm/1/320', u'Elit trance music': 'http://www.slusham.com/radio/fmplus.m3u', u'Elit houce music': 'http://eilo.org:8000/house.m3u'}

bgradio={u'Energy':'http://80.72.68.217/nrj.ogg.m3u', u'Рок радио':'http://80.72.68.217/radio1rock_low.ogg', u'Радио Melody':'http://live.btvradio.bg/melody.mp3.m3u',u'Радио Nova':'http://149.13.0.81/nova.aac.m3u'}


def menu():
    print u"1 за меню"
    print u"2 за избор на жанр"
    print u"3 за изход"
    cmenu=0
    while cmenu !=3:
        print
        cmenu=input("Enter choice :")
        if cmenu == 1:
            menu()
            print
        elif cmenu == 2:
            chanel()
            print
        print
    
def chanel():
    print u"1 за трансе"
    print u"2 за БГ радио"
    print u"3 за изход"
    choice=0
    while choice!=3:
        choice = input("Choice radio vid :")
        if choice == 1:
            for i in range(len(trance)):
                print i, "-",trance.keys()[i]
            print
            tranceradio = input("Play radio")
            if platform.system() == "Windows":
                print "Windows system "
                path = "C:\\Program Files (x86)\\VideoLAN\\VLC"
                os.chdir( path )
                player = "vlc.exe "
                chanel = trance.values()[tranceradio]
                start = player+chanel
                os.system(start)
            if platform.system() == "linux":
                print "Linux system"
                player = "cvlc -vvv "
                chanel = trance.values()[tranceradio]
                start = player+chanel
                os.system(start)
        if choice == 2:
            for i in range(len(bgradio)):
                print i, "-",bgradio.keys()[i]
            print
            tranceradio = input("Push radio")
            if platform.system() == "Windows":
                print "Windows system "
                path = "C:\\Program Files (x86)\\VideoLAN\\VLC"
                os.chdir( path )
                player = "vlc.exe "
                chanel = bgradio.values()[tranceradio]
                start = player+chanel
                os.system(start)
            if platform.system() == "linux":
                print "Linux system"
                player = "cvlc -vvv "
                chanel = bgradio.values()[tranceradio]
                start = player+chanel
                os.system(start)


#if __name__ == "__main__":
#    menu()
menu()
raw_input()

5.04.2015 г.

ssh without password

Mashine A - Host
Mashine B - Client

On host B do this:

ssh-keygen -t rsa -b 2048 -C "Enibody Name"

After generate key.pub, copy into pashine B with command

ssh-copy-id -i id_rsa.pub user@mashineB
or
scp ~/path to id_rsa.pub username@ip:/home/usenname/.ssh/id_rsa.home.pub

on machine B do this:
cat id_rsa.home.pub >> authorized_keys


Hint2
On the mashine A in .ssh creata file caonfig with text:

Host virtual
    HostName 192.168.1.4
    Port 22
    User username

Change format number from 0888888888 to 0888-88-88-88 in text using python

#-*- coding:utf-8 -*-
import re, fileinput
File = "bbb.txt"
for line in fileinput.FileInput(File, inplace=1):
    pattern = re.compile(r'\d{10}')
    if re.search(pattern,line):
        line = re.sub(r'(\d{4})(\d{2})(\d{2})(\d{2})',r'\1-\2-\3-\4',line).strip()
        print line.strip()
    else:
         print line.strip()