Skip to content

Posts from Programming

5.0 (1 rating)
In reply to slayer of dragons
User Avatar
18 years ago
Auto-translated
slayer of dragons;182946
Let me know what you think, your opinion matters to me :)
Anyone want to give me some feedback? I'm not sure if it's bad or really bad...
User Avatar
18 years ago
Auto-translated
I like it :). I just wish I knew what it is...
In reply to slayer of dragons
User Avatar
17 years ago
Auto-translated
Good afternoon.
slayer of dragons;183769
Someone, please rate it, because I don't know if it's bad or very bad)))
The beginning is good, I liked it.

Let's clarify a few things.
But I usually write in Delphi.
Delphi is not a programming language, but a development tool for programs in Pascal (specifically Object Pascal).

And now about what I have managed to "explore" in programming :) I started with Basic and Pascal (back in school), then Object Pascal, HTML, SQL, PHP. Now I am studying Perl (for fun and it will be useful for work), here is my first script (I didn't write it alone, a friend helped me, and I am very grateful to him).

use cyrillic qw/upcase win2dos/;
use strict;
use Time::HiRes qw/gettimeofday/;
use Data::Dumper;
use Net::SMTP;
use Net::POP3;
use warnings;
use subs qw/load_config mail_auth send_mail read_file write_log write_noping/;
my $debug = 1;
my $config = load_config;
my $offline_text = read_file('offline.txt');
my $online_text = read_file('online.txt');
my $err = "Can't Ping Host";
my @hosts;
#foreach my $host_str (@{$config->{hosts}})
#{
#	my $host = {};
#	$host_str =~ /^\s*(.*?)\s*\=\s*(.*)\s*$/;
#	$host->{descr} = $1;
#	$host->{adres} = $2;
#	$host->{state} = 'online';
#	$host->{fromtime} = gettimeofday();
#	$host->{oldstate} = 0;
#	push @hosts, $host;
#}
foreach my $host_str (@{$config->{hosts}})
{
	my $host = {};
	$host_str =~ /^\s*(.*?)\s*\=\s*(.*)\s*$/;
	$host->{descr} = $1;
	$host->{adres} = $2;
	my $result = "$err $host->{descr} ($host->{adres})";
	my $tm = gettimeofday();
	my $ping = qx/ping $host->{adres} -n 1/;
	$tm = gettimeofday() - $tm;
	foreach (split "\x0a", $ping)
	{
		if(/^.*?[\=\<\>]+.*?[\=\<\>]+(\d+)/)
		{
			$result = sprintf ("Ping to %s (%s) is %s", $host->{descr}, $host->{adres}, $1);
			last;
		}
	}
	my $state = $result =~ /$err/ ? 'offline' : 'online';
	$host->{state} = $state;
	$host->{fromtime} = gettimeofday();
	$host->{oldstate} = 0;
	push @hosts, $host;
}
my $host_descr = '';
my $host_adres = '';
my $namehost = '';
my $date = '';
my @ratio = (1900, 1, 0,0,0,0);
$date = sprintf("%04d-%02d-%02d %02d-%02d-%02d", map{$_+ shift(@ratio)}(localtime(time))[5,4,3,2,1,0]);
my $textlog = "Log file started ${date}\n";
my $namefile = $date;
open (LOGBIGIN, ">>$namefile") || die "Error opening $namefile: $!";
print LOGBIGIN $textlog;
close (LOGBIGIN);
my $sleep = 30; # In seconds
$date = '';
while(1)
{
	foreach my $host (@hosts)
	{
		my $result = "$err $host->{descr} ($host->{adres})";
		my $tm = gettimeofday();
		my $ping = qx/ping $host->{adres} -n 1/;
		$tm = gettimeofday() - $tm;
		foreach (split "\x0a", $ping)
		{
			if(/^.*?[\=\<\>]+.*?[\=\<\>]+(\d+)/)
			{
				$result = sprintf ("Ping to %s (%s) is %s", $host->{descr}, $host->{adres}, $1);
				last;
			}
		}
		my $state = $result =~ /$err/ ? 'offline' : 'online';
		if ($state ne $host->{state})
		{
			# state changed
			$host->{oldstate} = gettimeofday()
			if $host->{oldstate} eq 0;
			my $idle = gettimeofday() - $host->{oldstate};
			if ($idle > ($config->{timeout}*60))
			{
				# need to send emails
				print win2dos("Status change to $state for $host->{descr} ($host->{adres})\n");
				eval {mail_auth;};
				print $@ if $@;
				foreach my $rec (@{$config->{recipients}})
				{
					my $text;
					if ($state eq 'online')
					{
						$text = $online_text;
					}
					else
					{
						$text = $offline_text;
					}
					$host_adres = $host->{adres};
					$host_descr = $host->{descr};
					my @ratio_time = (1900, 1, 0,0,0,0);
					$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", map{$_+ shift(@ratio_time)}(localtime(time))[5,4,3,2,1,0]);
					my $text2 = $text;
					while($text =~ /\$([\w]+)/g)
					{
						my $var = $1;
						my $val;
						eval " \$val = \${$var};";
						#print "$var = $val\n";
						$text2 =~ s/\$$var/$val/ge;
					}
					eval { send_mail($rec, $text2);};
					print $@ if $@;
					write_log(sprintf("Change state of Host, last state: %3.2f %s time,", gettimeofday() - $host->{fromtime}, $host->{state})." $result (".sprintf("%0.5f sec", $tm).") $date\n", $namefile);
				}
				$host->{state} = $state;
				$host->{fromtime} = gettimeofday();
				$host->{oldstate} = 0;
			}
		}
		else
		{
			$host->{oldstate} = 0;
		}
		# If ping fails
		if ($state ne $host->{state})
		{
			if($state eq 'offline')
			{
				$namehost = $host->{adres};
				my @ratio = (1900, 1, 0,0,0,0);
				$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", map{$_+ shift(@ratio) }(localtime(time))[5,4,3,2,1,0]);
				write_noping(sprintf("%3.2f %s time,", gettimeofday() - $host->{fromtime}, $host->{state})." $result (".sprintf("%0.5f sec", $tm).") $date\n", $namehost);
			}
		}
		my @ratio = (1900, 1, 0,0,0,0);
		$date = sprintf( "%04d-%02d-%02d %02d:%02d:%02d", map{$_+ shift(@ratio) }(localtime(time))[5,4,3,2,1,0]);
		write_log(sprintf("%3.2f %s time,", gettimeofday() - $host->{fromtime}, $host->{state})." $result (".sprintf("%0.5f sec", $tm).") $date\n", $namefile);
	}
	# write_log("Sleep for $sleep sec (Wait Ping Hosts)\n", $namefile);
	print("Sleep for $sleep sec (Wait Ping Hosts)\n");
	sleep($sleep);
}
sub store_arg
{
	my $config = shift;
	my $arg    = shift;
	if($arg =~ /^\s*(.*?)\s*\=\s*(.*)\s*$/)
	{
		$config->{$1} = $2;
	}
	else
	{
		$config->{$arg} = 1;
	}
}
sub load_config
{
	my $file_name = shift || 'pinger.config';
	my $config = { };
	my $cur_section;
	open (FH, $file_name) || die "can't open config file";
	while (my $line = readline FH)
	{
		next if $line =~ /^\s*\#|^$/;
		$line =~ s/\#.*$//;#$line =~ s/\n//;
		if ($line =~ /^\s*[(\S*)]\s*$/)
		{
			$cur_section = $1;
		}
		elsif ($line =~ /^\s*\$\s*$/)
		{
			undef $cur_section;
		}
		else
		{
			if (defined $cur_section)
			{
				push @{$config->{$cur_section}}, $line;
			}
			else
			{
				store_arg($config, $line);
			}
		}
	}
	close FH;
	return $config;
}
sub mail_auth
{
	# authorization
	# print "$config->{pop3}\n$config->{user} : $config->{pass}\n";
	my $pop = new Net::POP3($config->{pop3}, Timeout => 240, Debug => $debug) || die "$!";
	my $msgs = $pop->login($config->{user}, $config->{pass});
	die "Incorrect login or password for ".$config->{pop3} unless defined $msgs;
	$pop->quit();
}
sub send_mail
{
	my $recipient = shift;
	my $text = shift;
	my $smtp = Net::SMTP->new(Host => $config->{smtp},
								Timeout => 30,
								Debug   => $debug, ); # Debug => 1 if you are interested in the communication protocol for debugging
	my $dom = $smtp->domain;
	$smtp->mail("$config->{user}\@$dom");
	$smtp->to("$recipient");
	$smtp->data();
	$smtp->datasend("TO: $recipient\n");
	foreach(split /\x0a/, $text)
	{
		$smtp->datasend("$_\n");
	}
	$smtp->dataend();
	$smtp->quit;
}
sub read_file
{
	my $fname = shift;
	open FH, $fname;
	my $text = '';
	while (my $line = )
	{
		$text .= $line;
	}
	close FH;
	return $text;
}
sub write_log
{
	my $text = shift;
	my $namefile = shift;
	open (w_LOG, ">>$namefile") || die "Error opening $namefile: $!";
	print w_LOG $text;
	close (w_LOG);
	print (win2dos($text));
}
sub write_noping
{
	my $text = shift;
	my $namehost = shift;
	open (w_PING, ">>$namehost") || die "Error opening $namehost: $!";
	print w_PING $text;
	close (w_PING);
	# print $text;
}
I plan to explore Assembler and Java as well.

Sincerely, K0Lb@zzeR.
16 years ago
Auto-translated
Currently, I am a student. My skill level is, of course, beginner, as I only started learning this language this academic year, but our teacher is strict, God bless her. For her, a correctly functioning program is not enough; it must also be optimized as much as possible! After school programming, where even simple tasks done haphazardly were accepted without problems, such requirements are shocking and slowly drive you crazy. In general, I wonder if there is anyone else on the forum who is familiar with this language? I am looking for a programmer to exchange experiences with :D
User Avatar
16 years ago
Auto-translated
Today, I found a floppy disk with 5 programs that I wrote a very, very long time ago. Four of them can be run once just for fun. The two best ones, with textures and lighting, didn't run due to the video card, but here are the other two. (I combined them into one.) I wrote them in C, but later I also rewrote them in Pascal. If you look at them, be sure to press F7 during the process.

#include 
#include
#include
#include
#include

float f, k, d;
int page, t;

struct Y
{

 private:

 float zindex ( int a )
 {

  int i;
  float r=0;

  switch(a)
  {
   case 12: for(i=0;i<12;i++) r+=z[i]; r/=12; break;
   case 13: for(i=0;i<12;i++) r+=z[i+12]; r/=12; break;
   case 11: r=(z[11]+z[0]+z[23]+z[12])/4; break;
   default: r=(z[a]+z[a+1]+z[a+12]+z[a+13])/4; break;
  }

  return r;

 }

 void DrawFlatness( int a )
 {

  int i, z[24];

  switch(a)
  {

   case 12:

   if((x[11]-x[0])*(y[1]-y[0])-(x[1]-x[0])*(y[11]-y[0])>=0)
   {
    for(i=0;i<12;i++) { z[2*i]=x[i]+320; z[2*i+1]=150-y[i]; }
    fillpoly(12, z);
   } break;

   case 13:

   if((x[12]-x[23])*(y[13]-y[12])-(x[13]-x[12])*(y[12]-y[23])>=0)
   {
    for(i=0;i<12;i++) { z[2*i]=x[i+12]+320; z[2*i+1]=150-y[i+12]; }
    fillpoly(12, z);
   } break;

   case 11:

   if((x[0]-x[11])*(y[12]-y[0])-(x[12]-x[0])*(y[0]-y[11])>=0)
   {
    z[0]=x[11]+320;
    z[1]=150-y[11];
    z[2]=x[0]+320;
    z[3]=150-y[0];
    z[4]=x[12]+320;
    z[5]=150-y[12];
    z[6]=x[23]+320;
    z[7]=150-y[23];
    fillpoly(4, z);
   } break;

   default:

   if((x[a+1]-x[a])*(y[a+13]-y[a+1])-(x[a+13]-x[a+1])*(y[a+1]-y[a])>=0)
   {
    z[0]=x[a]+320;
    z[1]=150-y[a];
    z[2]=x[a+12]+320;
    z[3]=150-y[a+12];
    z[4]=x[a+13]+320;
    z[5]=150-y[a+13];
    z[6]=x[a+1]+320;
    z[7]=150-y[a+1];
    fillpoly(4, z);
   }
  }
 }

 public:

 float x[24], y[24], z[24];

 Y ( void )
 {
  int i;

  x[0]=-50; y[0]=70;
  x[1]=-30; y[1]=70;
  x[2]=-1; y[2]=20;
  x[3]=17; y[3]=70;
  x[4]=37; y[4]=70;
  x[5]=-10; y[5]=-50;
  x[6]=-12; y[6]=-53;
  x[7]=-18; y[7]=-54;
  x[8]=-25; y[8]=-53;
  x[9]=-28; y[9]=-52;
  x[10]=-29; y[10]=-50;
  x[11]=-10; y[11]=0;

  for(i=0;i<12;i++) z[i]=10;
  for(i=12;i<24;i++)
  {
   x[i]=x[i-12];
   y[i]=y[i-12];
   z[i]=-z[i-12];
  }
 }

 void draw (int T)
 {
  int i, j, k, m[14];
  float p;
  setvisualpage(page);
  delay(d);
  page=(page==0)?1:0;
  setactivepage(page);
  cleardevice();

  if(T==1)
  {

   for(i=0;i<11;i++)
   line(x[i]+320, 150-y[i], x[i+1]+320, 150-y[i+1]);
   line(x[0]+320, 150-y[0], x[11]+320, 150-y[11]);

   for(i=12;i<23;i++)
   line(x[i]+320, 150-y[i], x[i+1]+320, 150-y[i+1]);
   line(x[12]+320, 150-y[12], x[23]+320, 150-y[23]);

   for(i=0;i<12;i++)
   line(x[i]+320, 150-y[i], x[i+12]+320, 150-y[i+12]);
  }
  else
  {
   if(zindex(0)<zindex(1)) { m[0]=0; m[1]=1; } else { m[0]=1; m[1]=0; } for(i=2;i<14;i++) { for(j=0;jzindex(i)&&i<12&&i!=4) { for(k=i; k>j; k--) m[k]=m[k-1]; break; }
    m[j]=i;
   }

   for(i=0;i<14;i++)
   DrawFlatness(m[i]);
  }
 }

 void increase ( void )
 {
  int i;
  for(i=0;i<24;i++) { x[i]*=k; y[i]*=k; z[i]*=k; }
 }

 void rotate_z( void )
 {
  int i;
  float xn[24], yn[24];
  for(i=0;i<24;i++)
  {
   xn[i]=x[i]*cos(f)-y[i]*sin(f);
   yn[i]=x[i]*sin(f)+y[i]*cos(f);
  }
  for(i=0;i<24;i++) { x[i]=xn[i]; y[i]=yn[i]; }
 }

 void rotate_y( void )
 {
  int i;
  float xn[24], zn[24];
  for(i=0;i<24;i++)
  {
   xn[i]=x[i]*cos(f)-z[i]*sin(f);
   zn[i]=x[i]*sin(f)+z[i]*cos(f);
  }
  for(i=0;i<24;i++) { x[i]=xn[i]; z[i]=zn[i]; }
 }

 void rotate_x( void )
 {
  int i;
  float yn[24], zn[24];
  for(i=0;i<24;i++)
  {
   yn[i]=y[i]*cos(f)-z[i]*sin(f);
   zn[i]=y[i]*sin(f)+z[i]*cos(f);
  }
  for(i=0;i<24;i++) { y[i]=yn[i]; z[i]=zn[i]; }
 }

 void MoveAlongAxisX(void)
 {
  int i;
  for(i=0;i<24;i++)
  x[i]+=f;
 }

 void MoveAlongAxisY(void)
 {
  int i;
  for(i=0;i<24;i++)
  y[i]+=f;
 }

 void MoveAlongAxisZ(void)
 {
  int i;
  for(i=0;i<24;i++)
  z[i]+=f;
 }


};


void main (void)
{
 Y y;

 int key, K, gd=VGA, gm=1;

 page=0; d=10; t=1;

 l:
 closegraph;
 printf("Just press F1 to show this help any time\n");
 printf("Press F5 to see the framework\n");
 printf("Press F6 for deleting invisible lines\n");
 printf("Press F7 for color facets\n");
 printf("Press w to rotate the letter around axis z clockwise\n");
 printf("Press q to rotate the letter around axis z anticlockwise\n");
 printf("Press s to rotate the letter around axis x clockwise\n");
 printf("Press a to rotate the letter around axis x anticlockwise\n");
 printf("Press x to rotate the letter around axis y clockwise\n");
 printf("Press z to rotate the letter around axis y anticlockwise\n");
 printf("Press 1 to increase the letter\n");
 printf("Press 2 to decrease the letter\n");
 printf("Press e or r to move the letter along axis x\n");
 printf("Press d or f to move the letter along axis y\n");
 printf("Press c or v to move the letter along axis z\n");
 printf("Press up or down to accelerate or decelerate moving and rotating\n");
 printf("Press Enter to stop any moving\n");
 printf("Press any key to begin to work with the letter imidiately\n");

 getch(); key=-1;
 initgraph(&gd, &gm, "");

 for(;;)
 {
  if(kbhit()!=0) key=getch();

  switch(key)
  {
   case '1': k=1.001; K=key; break;
   case '2': k=0.999; K=key; break;
   case 'q': f=0.005; K=key; break;
   case 'w': f=-0.005; K=key; break;
   case 'a': f=0.005; K=key; break;
   case 's': f=-0.005;K=key;  break;
   case 'z': f=0.005; K=key; break;
   case 'x': f=-0.005; K=key; break;
   case 'e': f=0.5; K=key; break;
   case 'r': f=-0.5; K=key; break;
   case 'd': f=0.5; K=key; break;
   case 'f': f=-0.5; K=key; break;
   case 'c': f=0.5; K=key; break;
   case 'v': f=-0.5; K=key; break;
   case 27:  closegraph(); return;
   case 72: f+=0.005; k+=0.001; d=d>5?d-0.01:d; key=0; break;
   case 80: f-=0.005; k-=0.001; d=d<15?d+0.01:d; key=0; break;
   case 13: K=key; break;
   case 63: t=1; key=0; break;
   case 64: t=2; setfillstyle(1, 0); key=0; break;
   case 65: t=2; setfillstyle(1, 2); key=0; break;
   case 59: goto l;
  }

  switch(K)
  {
   case '1': y.increase(); break;
   case '2': y.increase(); break;
   case 'q': y.rotate_z(); break;
   case 'w': y.rotate_z(); break;
   case 'a': y.rotate_x(); break;
   case 's': y.rotate_x(); break;
   case 'z': y.rotate_y(); break;
   case 'x': y.rotate_y(); break;
   case 'e': y.MoveAlongAxisX(); break;
   case 'r': y.MoveAlongAxisX(); break;
   case 'd': y.MoveAlongAxisY(); break;
   case 'f': y.MoveAlongAxisY(); break;
   case 'c': y.MoveAlongAxisZ(); break;
   case 'v': y.MoveAlongAxisZ(); break;
   case 27:  closegraph(); return;
  }
  y.draw(t);

 }
}
Attachments 1
1 file attached • Total size: 40.5 KB
In reply to Hermit
16 years ago
Auto-translated
Hermit
Today, I found a floppy disk with 5 programs that I wrote a very, very, very long time ago. Four of them can be run once just for fun. The two best ones, with textures and lighting, didn't run due to the video card, but I'm posting the other two. (I combined them into one.) I wrote them in C, but later I also rewrote them in Pascal. If you're going to watch them, be sure to press F7 during the process.
Well, I still have a long way to go before I can do something like that, but I'll try my best :D
And how much time did it take to learn how to write such things? And where did you learn? :)
User Avatar
15 years ago
Auto-translated
Are there any people who know Visual Basic?
User Avatar
15 years ago
Auto-translated
Why BASIC? In my opinion, it's outdated. P.S. I didn't know there was such a topic here! How could I have lived without it before? Hooray! :smile44: :smile44: :smile44: :smile44: :smile44: :smile44: :smile44: :smile44: :smile44:

Added 2 minutes later
I know Pascal, I really like Delphi, I understand a bit about C (not C++), I'm learning Java, and I like assembly language.
User Avatar
15 years ago
Auto-translated
You're awesome!
Why BASIC? Because our education system is constantly lagging behind, so we are forced to work with BASIC 6.0 and Word 2003, using manuals from Word 2001.
So, do you know BASIC or not? I just need to write a program, but I'm not very good at it.
User Avatar
15 years ago
Auto-translated
Unfortunately, no Basic. I wasn't even interested in it. I studied Pascal in school. But it looks like people here know it.
User Avatar
15 years ago
Auto-translated
Ugh, I'm so unlucky...

Added 42 minutes later
Where are you, programmers, when you are so needed?
User Avatar
15 years ago
Auto-translated
Aziral, I think they are all on Cyberforum.
User Avatar
15 years ago
Auto-translated
Points for advertising! Points for advertising!
In reply to Небо
User Avatar
14 years ago
Auto-translated
Sky
Where are you, programmers, when you are so needed?
You can contact me in 4 years.
User Avatar
14 years ago
Auto-translated
Are you studying BASIC? Sometimes I don't understand the school curriculum...

Statistics

Welcome our newest member: recijeb