10 sie 2010

Sprawdzenie czy string ma format godziny

Kod javascript:

function test() {
  let czas = '12:14:38';
  let re = new RegExp('([0-9]{2})\:([0-9]{2})\:([0-9]{2})','ig');
  tmp=re.exec(czas);
  if(tmp!=null) {
    let obiekt_property = '';
    for(j in tmp) obiekt_property += j + ' '+ tmp[j] + '';
    alert(obiekt_property);
  }
}

html:

<body onload="test()"></body>
3 lis 2009

Wyszukiwanie ciągu znaków w plikach

za pomocą grep:

grep -n -o "Warszawa" -a -R --include=*.php -l /

za pomocą find+grep:

find / -type f -name "*.php" -exec grep -l -H "Warszawa" {} \;

uruchomienie w php:

exec($command, $data);
19 lip 2009

Utworzenie połącznia z bazą przez stworzenia obiektu klasy PDO

try {  
 $pdo = new PDO('mysql:host='.$config['db']['host'].';dbname='.$config['db']['database'], $config['db']['user'], $config['db']['password']);
 $pdo -> exec("SET NAMES utf8");
<p class="mce_ws_kod">} catch (PDOException $e) {
<span class="mce_ws_kod"> print "Error!: " . $e->getMessage() . "<br/>";
 die();
}

PDO to uniwersalny interfejs baz danych.

21 cze 2009

Wydobycie tresci wyrażeniem regularnym RegExp

var tmp = null; var data =
'strona[ <a href="http://mapy.emiejsca.pl/egipt,egypt,miejsca.html">
http://mapy.emiejsca.pl/egipt,egypt,miejsca.html<a>
]';
var re = new RegExp(/strona\[(.*)\]/ig);
tmp=re.exec(data);
function deb_prop(tmp,ret) {
var obiekt_property = '';
for(j in tmp) obiekt_property += j + " "+ tmp[j] + "";
alert(obiekt_property);
}
alert(tmp[1]);
deb_prop(tmp);

W wyniku 2 alerty:
1:
---------------------------
Windows Internet Explorer
---------------------------
http://mapy.emiejsca.pl/egipt,egypt,miejsca.html
---------------------------
OK
---------------------------
2:
---------------------------
Windows Internet Explorer
---------------------------
input strona[ http://mapy.emiejsca.pl/egipt,egypt,miejsca.html ]
index 0
lastIndex 58
0 strona[ http://mapy.emiejsca.pl/egipt,egypt,miejsca.html ]
1 http://mapy.emiejsca.pl/egipt,egypt,miejsca.html
---------------------------
OK
---------------------------

2 kwi 2009

Sprawdzenie u uruchamianie GG w Vbs

Dim fso, stream, str, re, name
Dim wsh, oExec

Set wsh   =  CreateObject("WScript.Shell")
Set oExec = wsh.Exec("cmd /c " & "tasklist | find " & Chr(34) & "gg.exe" & Chr(34))
wynik     = oExec.StdOut.ReadAll

'msgbox wynik

Dim valid
Set objRegEx = CreateObject("VBScript.RegExp")

valid = False
objRegEx.Pattern = "^gg.exe"
valid = objRegEx.test(wynik)

If valid = True Then
 ''MsgBox(wynik)
Else
    wsh.Run Chr(34) & "C:\\Program Files\\Gadu-Gadu\\gg.exe" & Chr(34)
    Set wsh = Nothing
End if