User:Sgorjuno: Difference between revisions
From ICO wiki
Jump to navigationJump to search
No edit summary |
|||
(2 intermediate revisions by the same user not shown) | |||
Line 73: | Line 73: | ||
<source lang="python"> | <source lang="python"> | ||
#!/usr/bin/python | #!/usr/bin/python | ||
# -*- coding: utf-8 -*- | |||
#Autor: Sergei Gorjunov, A21, sgorjuno@itcollege.ee | #Autor: Sergei Gorjunov, A21, sgorjuno@itcollege.ee | ||
#Versioon 0. | #Versioon 0.3 | ||
# | # | ||
# Skript, mis lisab 1 rida | # Skript, mis lisab 1 rida failis. | ||
import locale, codecs; locale.setlocale(locale.LC_ALL, '') | |||
encoding = "utf-8" | |||
import os.path | |||
import sys; reload(sys); sys.setdefaultencoding(encoding) | |||
try: | try: | ||
fail = sys.argv[1] | fail = sys.argv[1] | ||
rida = sys.argv[2] | rida = sys.argv[2] | ||
reanumber = sys.argv[3] | reanumber = sys.argv[3] | ||
except IndexError: | except IndexError: | ||
print 'Pole argumente. Näide: ./script.py /txt/faili/aadress/ "mis on vaja kirjutada" faili reanumber' | print 'Pole argumente. Näide: ./script.py /txt/faili/aadress/ "mis on vaja kirjutada" faili reanumber' | ||
sys.exit() | sys.exit() | ||
reanumber = int(reanumber) # reanumber täisarvuks konverteerimine | |||
f = open(fail , 'r') | |||
l = f.readlines() # | l = [] | ||
l.insert(reanumber | #kui fail on, salvestan kõik, mis failis oli | ||
if os.path.isfile(fail): | |||
f = open(fail , 'r') | |||
l = f.readlines() | |||
s = unicode( rida, "utf-8" ) #tähetabeli kodeering | |||
l.insert(reanumber-1, s+"\n") #lisan rida | |||
# faili salvestamine | # faili salvestamine | ||
f = open(fail , 'w') | f = open(fail , 'w') | ||
for x in l: | for x in l: | ||
f.write(x) | f.write(x) | ||
f.close() | f.close() | ||
</source> | </source> | ||
= Powershell = | = Powershell = | ||
Line 127: | Line 136: | ||
}while($I -eq 0) | }while($I -eq 0) | ||
CreateUser ($Name, $Password) | CreateUser ($Name, $Password) | ||
</source> | |||
= Powershell arvestuseks = | |||
<source lang="powershell"> | |||
# Powershell | |||
# Versioon: 2.0 | |||
# Autor: Sergei Gorjunov | |||
# Kuupaev: 28.05.2011 | |||
# | |||
# Skript kontrollib, kas programm töötab voi mitte. | |||
param ([string]$nimi) | |||
if ($nimi -eq ""){ | |||
Write-Host "Pole argumente. Kirjutage programmi nimi. Näiteks: .\open_close.ps1 -nimi notepad" | |||
exit | |||
} | |||
$process = Get-Process $nimi -ea SilentlyContinue | |||
if ($process){ | |||
Write-Host $nimi " töötab" | |||
} | |||
else{ | |||
Write-Host "programm ei tööta" | |||
} | |||
</source> | </source> |
Latest revision as of 17:08, 1 June 2011
Bash
#!/bin/bash
#Autor: Sergei Gorjunov, A21, sgorjuno@itcollege.ee
#Versioon 0.2
#
# Pildi ühendamine videosse (video-slideshow)
# See skript otsib pilte aadressist, kopeerib neid töökausta,
# muudab pildide nimed (001.jpg 002.jpg 003.jpg jne). Järgmiselt
# ühendab pildid videoks ja kustutab kõik piltide koopiad.
# Kõige parem on kui pildid on ühesuurused.
if [ "$1" = "" ]; then
echo "Kirjutage kausta aadress mis sisaldab pilte"
echo "Naiteks: ./script.sh /pildikausta/aadress/"
echo "-h abi"
exit 1
fi
if [ "$1" = "-h" ]; then
echo "Script on lihtne (on vaja ainult 1 argument - pildikausta aadress)"
exit 0
fi
# ffmpeg kodeki paigaldamine
dpkg --status ffmpeg | grep -q not-installed
if [ $? -eq 0 ]; then
if [ "$UID" -ne 0 ]; then {
sudo apt-get install ffmpeg
}
else {
apt-get install ffmpeg
}
fi
fi
# töökausta loomine
if [ ! -d "$HOME/video" ]; then
echo "töökausta loomine..."
mkdir $HOME/video
# omaniku muutmine
chown $USER $HOME/video
# ainult omanik saab kasutada kausta
chmod u+rwx $HOME/video
chmod g-rwx $HOME/video
chmod o-rwx $HOME/video
fi
# pildi otsing ja nende kopeerimine töökausta
echo "piltide otsing..."
find $1 -name "*.jpg" -exec cp {} $HOME/video \;
cd $HOME/video
# ümber nimetamine (to format "xxx.jpg")
I=1
for F in *.jpg; do
mv "$F" `printf %03d.jpg $I` 2>/dev/null || true
I=$((I + 1))
done
echo "Mille kiirusega kaadrite muuta (minimum ja optimaalne 0.2):"
read KIIRUS
# kogu piltide ühendamine videoks
echo "video loomine..."
ffmpeg -r $KIIRUS -i %03d.jpg video.avi
find -name "*.jpg" -exec rm -rf ./{} \;
# video mängimine
ffplay video.avi
exit 0
Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
#Autor: Sergei Gorjunov, A21, sgorjuno@itcollege.ee
#Versioon 0.3
#
# Skript, mis lisab 1 rida failis.
import locale, codecs; locale.setlocale(locale.LC_ALL, '')
encoding = "utf-8"
import os.path
import sys; reload(sys); sys.setdefaultencoding(encoding)
try:
fail = sys.argv[1]
rida = sys.argv[2]
reanumber = sys.argv[3]
except IndexError:
print 'Pole argumente. Näide: ./script.py /txt/faili/aadress/ "mis on vaja kirjutada" faili reanumber'
sys.exit()
reanumber = int(reanumber) # reanumber täisarvuks konverteerimine
l = []
#kui fail on, salvestan kõik, mis failis oli
if os.path.isfile(fail):
f = open(fail , 'r')
l = f.readlines()
s = unicode( rida, "utf-8" ) #tähetabeli kodeering
l.insert(reanumber-1, s+"\n") #lisan rida
# faili salvestamine
f = open(fail , 'w')
for x in l:
f.write(x)
f.close()
Powershell
#Autor: Sergei Gorjunov A21, sgorjuno@itcollege.ee
#Versioon: 0.1
#Skript, mis loob uut kasutajat.
function CreateUser ($Name, $Password){
trap {"Error......"; break} #Kui mingid vead on
$computer = [ADSI]"WinNT://$env:computername"
$user = $computer.Create("user", $Name)
$user.SetPassword($Password)
$user.SetInfo()
Write-Host "Uus kasutaja on tehtud..."
}
$I=0
$Name = Read-Host "Kirjutage uus kasutaja nimi: "
do{
$Password = Read-Host "Uus kasutaja pass: "
$Confirm = Read-Host "Pass veel kord: "
if ($Password -eq $Confirm){
$I=1
}else{
Write-Host "Salasonad on erinevad. Proovi veel kord."
}
}while($I -eq 0)
CreateUser ($Name, $Password)
Powershell arvestuseks
# Powershell
# Versioon: 2.0
# Autor: Sergei Gorjunov
# Kuupaev: 28.05.2011
#
# Skript kontrollib, kas programm töötab voi mitte.
param ([string]$nimi)
if ($nimi -eq ""){
Write-Host "Pole argumente. Kirjutage programmi nimi. Näiteks: .\open_close.ps1 -nimi notepad"
exit
}
$process = Get-Process $nimi -ea SilentlyContinue
if ($process){
Write-Host $nimi " töötab"
}
else{
Write-Host "programm ei tööta"
}