Son 5 Gönderi :

Kod etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
Kod etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

14 Kasım 2009 Cumartesi

PHP ve curl ile form gönderme örneği

  $cnt = 0;
  $path = "./list.csv";
  $handle = fopen($data_file, "r");
  $lines=file($data_file);

  $idx = 0;
  $line = $lines[$i];
  $licensePre = 0;

  while (is_null($lines[$idx]) != true)
    {
      $line = $lines[$idx];
      $raw = explode(',',$line);


      if ($licensePre == (int)$raw[0])
    {
      $idx = $idx + 1;
      continue;
    }

      $url = "http://www.*****.***/****/";
      $formUrl = '*****.php?tpl=***&main=33';

      $nameSurname = explode(' ',$raw[1]);
      $nameSize = count($nameSurname);
      $name = $nameSurname[0];
      $ns = 1;

      if ($nameSize > 2)
        {
          for ($ns=1; $ns<$nameSize-1; $ns++)
        $name = $name . " " . $nameSurname[$ns];
        }

      $surname = $nameSurname[$nameSize - 1];
      $licenseNo = $raw[0];
      $teamName = $raw[5];

      $rawLicenseDate = explode('/',$raw[4]);
      $rawBirthDate = explode('/',$raw[2]);

      $birthPlace = ($raw[3]) ? $raw[3] : '            ';

      $licenseDay = ($rawLicenseDate[1]) ? $rawLicenseDate[1] : '';
      $licenseMonth = ($rawLicenseDate[0]) ? $rawLicenseDate[0] : '';
      $licenseYear = ($rawLicenseDate[2]) ? $rawLicenseDate[2] : '';
      $birthDay = ($rawBirthDate[1]) ? $rawBirthDate[1] : '';
      $birthMonth = ($rawBirthDate[0]) ? $rawBirthDate[0] : '';
      $birthYear = ($rawBirthDate[2]) ? $rawBirthDate[2] : '';

      $filename = "./pic/{$licenseNo}.jpg";

      if (file_exists($filename))
        $img = "@{$filename}";
      else
        $img = '';

      $data = array(
          'emails' => '****',
          'password' => '***',
          'txtPlayerName' => $name,
          'txtPlayerSurname' => $surname,
          'txtLicenseNo' => $licenseNo,
          'playerPosition' => '0',
          'teamName' => (int)$teamName,
          'national_team_id' => '-1',
          'license_given_day' => $licenseDay,
          'license_given_month' => $licenseMonth,
          'license_given_year' => $licenseYear,
          'license_end_day' => '',
          'license_end_month' => '',
          'license_end_year' => '',
          'birth_day' => $birthDay,
          'birth_month' => $birthMonth,
          'birth_year' => $birthYear,
          'placeOfBirth' => $birthPlace,
          'btnSubmit' => 'Submit >>',
          'image' => $img,
      );

      $ch = curl_init();

      curl_setopt($ch, CURLOPT_URL, $url . $formUrl);
      curl_setopt($ch, CURLOPT_POST, true);
      curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
      curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

      $curlrt = curl_exec($ch);
      $licensePre = $licenseNo;

      $cnt++;

      echo $cnt . "   " . $line . "\n";
      $idx = $idx + 1;
    }
?>

16 Ağustos 2008 Cumartesi

bolumle.m

%    Yayıncı     : Şenol Korkmaz < senol.korkmaz@gmail.com >
% Dosya Adı : bolumle.m
% Gerekenler : partitions.m < http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12009&objectType=file >
% Tanım : Sayı Bölümleme maksatlı MATLAB işlevi
% Kullanım : bolumle(n,m,k)
%
% Girdi : n --> Bölümlenecek sayı
% : m --> Bölümlemelerin kaçar sayıdan oluşacağını belirten vektör
% : k --> Bölümlemede kullanılacak sayıların seçileceği vektör
%
% Çıktı : Bu işlev bölümlemeleri döndürür
%
% Sürüm : 1.0
%
% Lisans : GNU/GPL v3 <http://www.gnu.org/licenses/>

function bolumler = bolumle(n,m,k) % İşlevi ve girdilerini tanımla

if (nargin==1) % Eğer sadece bir girdi var (n) ise
m = 1:n; % m = 1 den n'ye kadar tamsayıları içeren vektör
k = m; % k = 1 den n'ye kadar tamsayıları içeren vektör
end

if (nargin==2) % Eğer sadece iki girdi var (n & m) ise
k = 1:n; % k = 1 den n'ye kadar tamsayıları içeren vektör
end

% k vektöründeki sayıları kullanarak harici partitions fonksiyonu ile n'i bölümle
% hamBolumler, her bölümlemede hangi sayının kaçar defa kullanıldığı bilgisini içerecek
hamBolumler = partitions(n,k);

hamBolumler = hamBolumler(find(ismember(sum(hamBolumler,2),m)==1),:); % m vektöründe belirtilenler kadar sayı kullanılmış bölümlemeleri al

bolumler = zeros(size(hamBolumler,1),max(m)); % Çıktı şablonu

for i = 1:size(hamBolumler,1) % Her bir ham bölüm için döngü

buSatir = []; % O an işlenecek satır için boş vektör

for j = 1 : size(hamBolumler,2) % Her bir ham bölümü oluşturan her bir sayı için döngü

% hamBolumler vektöründe her sayının kaçar defa kullanıldığı bilgisi yer almaktadır
% bu bilgiyi kullanarak buSatır vektörüne o sayıları kullanıldıkları kadar ( repmat ile)
% ekler ve onları azalan sıra ile sıralarız
buSatir = horzcat(buSatir,repmat(k(j),1,hamBolumler(i,j)));
end

% buSatır vektörünün boyu max(m) kadar olmalıdır, bu yüzden kalan yerlere 0 doldurulur
buSatir = horzcat(buSatir,repmat(0,1,size(bolumler,2)-size(buSatir,2)));

% buSatır vektörünü çıktıya ekle
bolumler(size(hamBolumler,1)-i+1,:) = sort(buSatir,'descend') ;
end

11 Ağustos 2008 Pazartesi

intpart.m

%    Author      : Senol Korkmaz < senol.korkmaz@gmail.com >
% Filename : intpart.m
% Requires : partitions.m < http://www.mathworks.com/matlabcentral/fileexchange/loadFile.do?objectId=12009&objectType=file >
% Description : A Matlab Function to calculate partitions of an integer
% Usage : intpart(n,m,k)
%
% Input : n is an integer to find out its partitions
% : m is a vector which indicates that how many numbers can be used
% : k is a vector which indicates that which numbers can be used
%
% Output : This function returns a matrice that includes partitions of n
%
% Version : 1.0
%
% License : GNU/GPL v3
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.

function iparts = intpart(n,m,k) % Declare function and its arguments

if (nargin==1) % There is only one input (n)
m = 1:n; % Consider that m is a vector that contains all integers from 1 to n
k = m; % Consider that k is a vector that contains all integers from 1 to n
end

if (nargin==2) % There are two inputs ( n & m)
k = 1:n; % Consider that k is a vector that contains all integers from 1 to n
end

partlist = partitions(n,k); % Calculate the partitions of n with the numbers whis is in the vector k

% Code explanations will be written as soon as possible

partlist = partlist(find(ismember(sum(partlist,2),m)==1),:);

iparts = zeros(size(partlist,1),max(m));

for i = 1:size(partlist,1)

tmpROW = [];

for j = 1 : size(partlist,2)
tmpROW = horzcat(tmpROW,repmat(k(j),1,partlist(i,j)));
end

tmpROW = horzcat(tmpROW,repmat(0,1,size(iparts,2)-size(tmpROW,2)));
iparts(i,:) = sort(tmpROW,'descend') ;
end

12 Temmuz 2008 Cumartesi

loto0.m

%    #######################  loto0.m DRAFT  #######################
%
% Author : Senol Korkmaz <senol.korkmaz@gmail.com>
% Filename : loto0.m
% Description : A MATLAB script to calculate n/m\k
% Usage : Run script and follow instructions.
% Version : 0 (Draft)
%
% License :
GNU/GPL v3
% This program is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <http://www.gnu.org/licenses/>.

%% Clear all variables and screen
clear;
clc;

%% Get user inputs n,m,k and validate
n = input(' n : ');
if ~(n>1)
error(' n must be greater than 1 (n=%d)',n);
end;

m = input(' m : ');
if ~(m>n)
error(' m must be greater than n (m=%d , n=%d)',m,n);
end;

k = input(' k : ');
if (k>n)
error(' k cannot be greater than n (k=%d , n=%d)',k,n)
end;

%% Generate variables

tmp = 0; % Temporary variable
flg = false; % Flag variable
covered = false; % Is selections covered target_pool in scope k ?
sub_combinations = 0; %

i = 0; % index to be used within loops
j = 0; % index to be used within loops
l = 0; % index to be used within loops
z = 0; % index to be used within loops

target_pool = combnk(1:m,n); % One of these combinations will be selected in loto
source_pool = target_pool; % Min of these combinations should be selected to cover target_pool at scope k
selections = zeros(1,n); % Current selections to test
selections_scope = [];
show_info = 0;

%% cycle throught combinations

while ~(covered) % Main loop
i = i + 1; % It is not enought, increase i
sub_combinations = combnk(1:size(source_pool,1),i); % Generate subcombinations
j=0;
z=size(sub_combinations,1);
show_info_period = z/100;

while ( (j < z) && ~(covered)) % #######
j = j+1;
selections = source_pool(sub_combinations(j,:),:);
show_info = show_info+1;

if (show_info > show_info_period)
disp(sprintf('is %d enought ? sub-Combination %d/%d , Completed = %d %%',i,j,z,fix(j/show_info_period)));
show_info = 0;
end;

selections_scope = selections(1,1:k); % ###################

for
l=1:i % Prepare k scope to test target_pool ########
selections_scope = union(selections_scope,combnk(selections(l,:),k),'rows');
end;

for l=1:size(target_pool,1)
if (size(intersect(combnk(target_pool(l,:),k),selections_scope,'rows'),1)==0)
break;
end;
if (l==size(target_pool,1))
covered = true;
end;
end;
end;
end;

%% Show results

disp(sprintf('Answer = %d',i));

Konular

Matematik (5) Kod (4) Gündem (2) Bilgisayar (1) İnternet (1)