Who's programming right now?

notfred

Lifer
Feb 12, 2001
38,241
4
0
Who's up late working on some kind of program, for whatever reason?

if so, express your true geekiness by posting a code fragment!

----------------------------------------------------------------------------------------
sub check_login{
my $name = $_[0];
my $pass = $_[1];
my @array = user_info($userlist);
for(my $i=0; $i<=$#array; $i++){
if(lc($array[$i][0]) eq lc($name) && $array[$i][1] eq $pass){
return 1;
}
}
return 0;
}
----------------------------------------------------------------------------------------
 

joohang

Lifer
Oct 22, 2000
12,340
1
0
RichText.cs:

using System;
using System.ComponentModel;
using System.Windows.Forms;
using System.Drawing;

namespace entier.helloworld
{

public class frmHelloWorld : Form
{
protected internal System.Windows.Forms.RichTextBox rtxtHello;
protected internal System.Windows.Forms.TextBox txtHi;


public static void Main()
{
Application.Run(new frmHelloWorld());
}

public frmHelloWorld()
{
// InitializeComponent();

this.Text = "Hello World";
this.txtHi = new TextBox();
// this.Controls.Add(this.txtHi);
this.rtxtHello = new RichTextBox();
rtxtHello.Dock = DockStyle.Fill;
rtxtHello.LoadFile("\\\\majora\\d$\\my documents\\Chemistry 12 Provincial Exam Tips.rtf");
this.Controls.Add(this.rtxtHello);
}
}

}


Menu.cs

using System;
using System.Windows.Forms;
using System.Drawing;

namespace entier.menu.test
{

public class frmMenuTest : Form
{

protected internal System.Windows.Forms.Label lblTest;
protected internal System.Windows.Forms.ContextMenu ctxTest;

public static void Main()
{
Application.Run(new frmMenuTest());
}

public frmMenuTest()
{
this.Text = "Menu Test Form";
this.Opacity = 0.5;

this.ctxTest = new ContextMenu();
ctxTest.MenuItems.Add("Hello");

this.lblTest = new Label();
lblTest.Text = "Hello?";
lblTest.Size = new Size(360,50);
lblTest.ContextMenu = this.ctxTest;

this.Controls.Add(this.lblTest);
}
}
}
 

SendTrash

Platinum Member
Apr 18, 2000
2,581
0
76
I was doing homework in MatLab

while abs(b - a) > 10^-6
midpoint = (b + a)/2;
f_at_midpoint = 12*midpoint^3 + 5*midpoint - 40;
f_at_a = 12*a^3 + 5*a - 40;
f_at_b = 12*b^3 + 5*b - 40;

if( f_at_midpoint*f_at_a < 0 )
b = midpoint;
elseif( f_at_midpoint*f_at_b < 0 )
a = midpoint;
end

end
 

AndyHui

Administrator Emeritus<br>Elite Member<br>AT FAQ M
Oct 9, 1999
13,141
17
81
Visual Fox Pro, form_init

Public gnNonActiveRowBackcolor
gnPersonRecno = Recno('Person')
gnCompNotesRecno = Recno('Notes')
gnPersNotesRecno = Recno('Notes1')
gnActiveRowBackcolor = RGB(192,255,255) && Pastel Blue
gnNonActiveRowBackcolor = RGB(255,255,255) && white

ThisForm.grdPerson.setall('DynamicBackColor', ;
"IIF(RECNO() = gnPersonRecno, gnActiveRowBackcolor, gnNonActiveRowBackcolor)", "Column")
ThisForm.Pageframe1.Page5.grdCompNotes.setall('DynamicBackColor', ;
"IIF(RECNO() = gnCompNotesRecno, gnActiveRowBackcolor, gnNonActiveRowBackcolor)", "Column")
ThisForm.Pageframe1.Page1.grdPersNotes.setall('DynamicBackColor', ;
"IIF(RECNO() = gnPersNotesRecno, gnActiveRowBackcolor, gnNonActiveRowBackcolor)", "Column")

* This section returns the user logged into the system in gcUser_Init.
Public gcUser_Init
lcID = sys(0)
lnPos = rat("#", lcID)
gcUser_Init = substr(lcID, lnPos + 2, len(lcID) - lnPos - 1)

* The remaining initialises the form.
thisform.gcLastButton = ""
select company
go top
Thisform.grdPerson.AfterRowColChange && update grid highlight and refresh form
ThisForm.Pers_notes_grid_refresh
 

juiio

Golden Member
Feb 28, 2000
1,433
4
81
Not homework, seeing as I've been out of school for a while, but here ya go. Have fun with this

int a=10000,b,c=2800,d,e,f[2801],g;main(){for(;b-c ; )f[b++]=a/5;for(;d=0,g=c*2;c-=14,printf("%.4d",e+d/a),e=d%a)for(b=c;d+=f[ b ]*a,f[ b ]=d%--g,d/=g--,--b;d*=b);}
 

Phil21

Golden Member
Dec 4, 2000
1,015
0
0
so which is better..

my @array = user_info($userlist);
for(my $i=0; $i<=$#array; $i++){
if(lc($array[$i][0]) eq lc($name) && $array[$i][1] eq $pass){
return 1;
}


or..

my @array = user_info($userlist);
my $i = 0;
foreach (@array) {
if(lc($array[$i][0]) eq lc($name) && $array[$i][1] eq $pass){
return 1;
}
$i++;
}

Hmm. I think a foreach is less "expensive" than a for, but I could be wrong.

they both should work though. Anonymous arrays are real "fun" for me. Blah.

Yes, I'm up coding a stupid UI for the admin section of a website. I *hate* coding UI's, it's such dull boring pointless work (check user input for sanity, parse stuff, return output. repeat forever+year until phil == dead)

-Phil
 

crackersjacks

Member
Aug 29, 2001
156
0
0
Up all night, so I'll post a little for the fans.
sub no_invalids {
my ($string) = @_;
my $string_length = length ($string);

if ($string_length == 0) {
return $string;
}
else {
my $char = substr ($string, 0, 1);
if ($char =~ m"[: ]") {
$cursor_move = 1;
return '' . (no_invalids (substr ($string, 1)));
}
else {
return $char . (no_invalids (substr ($string, 1)));
}
}
}
 

AndyHui

Administrator Emeritus<br>Elite Member<br>AT FAQ M
Oct 9, 1999
13,141
17
81
Actaully, VFP is very good....far better and more consistent than VB. This is the Windows version, not the DOS version...
 

notfred

Lifer
Feb 12, 2001
38,241
4
0


<< so which is better..

my @array = user_info($userlist);
for(my $i=0; $i<=$#array; $i++){
if(lc($array[$i][0]) eq lc($name) && $array[$i][1] eq $pass){
return 1;
}


or..

my @array = user_info($userlist);
my $i = 0;
foreach (@array) {
if(lc($array[$i][0]) eq lc($name) && $array[$i][1] eq $pass){
return 1;
}
$i++;
}

Hmm. I think a foreach is less "expensive" than a for, but I could be wrong.

they both should work though. Anonymous arrays are real "fun" for me. Blah.

Yes, I'm up coding a stupid UI for the admin section of a website. I *hate* coding UI's, it's such dull boring pointless work (check user input for sanity, parse stuff, return output. repeat forever+year until phil == dead)

-Phil
>>



I like mine better, just cause it's easier to see what it's doing :)
 

joohang

Lifer
Oct 22, 2000
12,340
1
0
Have you tried version 7.0 yet? I read an MSDN magazine article on it, and looked interesting. It didn't make any sense to me, but it looked interesting. :)

I'm also surprised that Microsoft didn't kill it yet. And keeps adding new features to it. :)
 

NikPreviousAcct

No Lifer
Aug 15, 2000
52,763
1
0


<< Actaully, VFP is very good....far better and more consistent than VB. This is the Windows version, not the DOS version... >>



DOS version??
**barf**
I used to have Visual Studio 6.0 Enterprise. I fooled around with VFP but couldn't figure out much of it on my own. :)
 

AndyHui

Administrator Emeritus<br>Elite Member<br>AT FAQ M
Oct 9, 1999
13,141
17
81
Doing it in VFP 6 at the moment. We are still testing VFP 7. It is supposed to be good as they are continually cleaning up the last few bugs and adding new features.
 

Phil21

Golden Member
Dec 4, 2000
1,015
0
0
notfred: That's up for contention, I actually got drawn to that piece of code because I didn't immediately recognize it. Add proper indentation to mine and it's extremely clear. ;) But, that's just code styles. Perl is never super-performance minded anyways.

Sorry, gonna have to be the code nazi here (hey, I love it when people critique my stuff.. helps me get more effecient, so I'll assume the same)

sub no_invalids {
my ($string) = @_;
my $string_length = length ($string);

if ($string_length == 0) {
return $string;
}

....


why not..

if(length($string) == 0) { return 0; }

or better yet, which should work in most cases...

if($string eq "") { return 0; }

since it seems all that you're doing is checking for an empty value, the less functions you have to perform the better. ;)

Ah well. Bedtime for me it seems.

-Phil
 

tarak

Member
Sep 27, 2001
128
0
0
Same project as crackersjacks, different language/component:

/* write udboc information to file */
fprintf(fptr, "Node %d\n", rank);
for (udboc_cursor = node_cursor->udbocs_head; udboc_cursor != NULL; udboc_cursor = udboc_cursor->link) {
timeinfo = *localtime(&(udboc_cursor->tv.tv_sec));
fprintf(fptr, "%d::%d%06d::%s::%s::%s\n", udboc_cursor->start_stop, udboc_cursor->tv.tv_sec, udboc_cursor->
tv.tv_usec, udboc_cursor->udboc_name, udboc_cursor->group_name, udboc_cursor->color);
}

for (message_cursor = node_cursor->messages_head; message_cursor != NULL; message_cursor = message_cursor->li
nk) {
fprintf(fptr, "%d::%d%06d::%d::%d::%d\n", message_cursor->sendreceive, message_cursor->tv.tv_sec, message_c
ursor->tv.tv_usec, message_cursor->to_node, message_cursor->from_node, message_cursor->amount);
}
fclose(fptr);

linked lists are FUN
 

notfred

Lifer
Feb 12, 2001
38,241
4
0


<< notfred: That's up for contention, I actually got drawn to that piece of code because I didn't immediately recognize it. Add proper indentation to mine and it's extremely clear. ;) But, that's just code styles. Perl is never super-performance minded anyways.

Sorry, gonna have to be the code nazi here (hey, I love it when people critique my stuff.. helps me get more effecient, so I'll assume the same)

sub no_invalids {
my ($string) = @_;
my $string_length = length ($string);

if ($string_length == 0) {
return $string;
}

....


why not..

if(length($string) == 0) { return 0; }

or better yet, which should work in most cases...

if($string eq "") { return 0; }

since it seems all that you're doing is checking for an empty value, the less functions you have to perform the better. ;)

Ah well. Bedtime for me it seems.

-Phil
>>



or:

if(!$string){return 0} :)
 

crackersjacks

Member
Aug 29, 2001
156
0
0


<< Sorry, gonna have to be the code nazi here (hey, I love it when people critique my stuff.. helps me get more effecient, so I'll assume the same)

sub no_invalids {
my ($string) = @_;
my $string_length = length ($string);

if ($string_length == 0) {
return $string;
}

....


why not..

if(length($string) == 0) { return 0; }

or better yet, which should work in most cases...

if($string eq "") { return 0; }

since it seems all that you're doing is checking for an empty value, the less functions you have to perform the better. ;)

Ah well. Bedtime for me it seems.

-Phil
>>



Nah, I don't mind the lesson. Thanks for looking at it, it's definitely a way I didn't think about and would work for what I need. The problem is that this code is definitely going to be looked at and altered to work with other projects so I wanted to be specific as possible in case someone wishes to change it or figure out what's going on. Also, my program here is the farthest from being efficient, it doesn't have to be, tarak's part does but mine can be as slow as molasses. Thanks for the input though, I definitely learned something here tonight.
Edit for my lack of reading before I post
 

NaughtyusMaximus

Diamond Member
Oct 9, 1999
3,220
0
0
import java.applet.Applet;
import java.awt.*;

public class Lab4_2 extends Applet {

final int squareWidth = 40;
final int boardAlign = 50;
final int squareNumber = 8;
final int squareColour1R = 255;
final int squareColour1G = 0;
final int squareColour1B = 0;
final int squareColour2R = 255;
final int squareColour2G = 255;
final int squareColour2B = 0;

public void paint (Graphics page) {

//Sets the RGB values of the colours of the chessboard (Black in this case)
Color squareColour1 = new Color (squareColour1R,squareColour1G,squareColour1B);
Color squareColour2 = new Color (squareColour2R,squareColour2G,squareColour2B);

page.setColor (Color.cyan);
page.fillRect (0, 0, getSize ().width, getSize ().height);

page.setColor(squareColour1);

//Sets the size of the board using the predefined final variables entered above
page.drawRect (boardAlign, boardAlign, squareWidth*squareNumber, squareWidth*squareNumber);
page.drawRect (boardAlign-1, boardAlign-1, squareWidth*squareNumber, squareWidth*squareNumber);

for (int columns=0; columns<8; columns++) {

if (page.getColor() == squareColour1)
page.setColor(squareColour2);
else
page.setColor(squareColour1);

for (int rows=0; rows<8; rows++) {
if (page.getColor() == squareColour1)
page.setColor(squareColour2);
else
page.setColor(squareColour1);

page.fillRect(squareWidth*rows+boardAlign, squareWidth*columns+boardAlign, squareWidth, squareWidth);

}
}
}
}

----
I thought it was java too.. :D
 

crackersjacks

Member
Aug 29, 2001
156
0
0
Thanks for all the input guys, it's a recursive subroutine editting a string so you gotta change all those return 0 lines to return '' or return $string, but the principle's the same.