Open Side Menu Go to the Top

01-26-2012 , 01:38 PM
Yeah definitely, especially things like blog posts you will get ~90% bounce rate (<= 80% is excellent). However we like to think it takes 3 impressions before you leave an impression, so the same visitor might visit one good blog post and leave, see another good one from you and leave again, but the third time they might start taking an interest in what you are doing as they recognise you now as someone who provides things that interest them.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
01-26-2012 , 03:36 PM
Skier/Thac,
I dont really know Java and haven't used it in 5+ years but I did see there is an isDigit() and isLetter() which would make it much easier.

http://www.tutorialspoint.com/java/c...r_isletter.htm

I think the below would work.

A general rule for me is that if you have tons of cascading if / elses the code becomes very hard to maintain and read. There typically is a easier / better way to code it IME.

Code:
String enteredLetter = "";

if (enteredLetter.isLetter() 
{
     System.out.println("The uppercase equivalent of " + enteredLetter + " is " + enteredLetter.toUpperCase() + ".");
}
else
{
	System.out.println("The entered value was not a valid letter");
}

Last edited by Jeff_B; 01-26-2012 at 03:44 PM. Reason: fixed code, not 100% on it though, I seriously dont know Java
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-26-2012 , 04:12 PM
the isLetter(char c) method is a static method of the Character class. You are calling it on a String. Replace enteredLetter with Character, and you also need to pass it a char (enteredLetter is a String).

So something like

Code:
char c = 'a';

if(Character.isLetter(c)){
     //it's a letter
}
else{
     //it's not a letter
}
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-26-2012 , 05:33 PM
For a few days i have been trying to make this homework, task is unix shell in c.
Shell has to run commands in background if '&' is at the end of users command.

Problem i'm having is with waiting pids (atleast it think)

In main program i have this

Code:
while(1)
	{
		input = getchar();
		switch (input)
		{
			case '\n':
				displayShell();
				break;
			default:
				getUserInput();
				processUserCommand();
				displayShell();
				break;
		}
	}
Problem is when i run in background 'displayShell();' runs before i get any response from process.

here are pics from terminal, arrow shows where work path should be




here is code from executeCommand function which i'm calling in processUserCommand

Code:
void executeCommand(char *cmd[], char *filePointer, int std , int mode)
{
	pid_t pid;
	int cmdStd;		/* to open file for input/output redirection */	
	fflush(stdout);
	
	pid = fork();
	
	switch (pid)
	{
		case -1:
			printf("Fork failure\n");
			fflush(stdout);
			exit(EXIT_FAILURE);
			break;
			
		case 0:
			fflush(stdout);
			signal(SIGINT, SIG_DFL);   
			signal(SIGQUIT,SIG_DFL);
			signal(SIGSTOP,SIG_DFL);
			signal(SIGCHLD, &childSignalHandler);
				
			if (std == STDIN) 
			{
                            cmdStd = open(filePointer, O_RDONLY);
                            dup2(cmdStd, STDIN_FILENO);
                            if(cmdStd != STDIN_FILENO)
					close(cmdStd);
			}
			
			if (std == STDOUT) 
			{
                              cmdStd = open(filePointer,O_WRONLY | O_CREAT, S_IRUSR | S_IWUSR);
                            dup2(cmdStd, STDOUT_FILENO);
                            if (cmdStd != STDOUT_FILENO)
					close(cmdStd);
			}
			
			if (mode == BACKGROUND)
			{
				fprintf(stderr,"BG Job pid = %d\n",getpid());
			}
			
			if (execvp(*cmd, cmd) == -1)
			{
                              printf("%s : greska pri pokretanju\n",cmd[0]);
                              exit(0);
			}
			
                        exit(EXIT_SUCCESS);
                        break;
            
		default:
			if (mode == FOREGROUND)
			{
				signal(SIGCHLD, NULL);
				
				waitpid(pid,NULL,0);
				
				signal(SIGCHLD, &childSignalHandler);
			}
			else
			{
				signal(SIGCHLD, &childSignalHandler);
			}
			
			break;
	}

}

here is childSignalHandler (here i monitor when bg process is done or killed

Code:
void childSignalHandler(int p)
{
	pid_t pid;
	int term_status;
	pid = waitpid(WAIT_ANY, &term_status, WUNTRACED | WNOHANG);
	
	if (pid > 0)
	{
		if (WIFEXITED(term_status))
		{
			fprintf(stderr,"\nBg process : %d done\n",pid);
			return;
		}
		else if (WIFSIGNALED(term_status))
		{
			fprintf(stderr,"\nBg process : %d killed\n",pid);
			return;
		}
	}
}

I want it write this fprintf(stderr,"BG Job pid = %d\n",getpid());
and then to displayShell(), but it does it other way around.
Does anyone have any suggestions for this
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-26-2012 , 08:10 PM
anyone here use visual studio a lot? what is the best language to use in it, or do they all have basically the same functionality? i'm most familiar with c++ so i've been using that but it seems there are some things better implemented in c# and/or vb
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-26-2012 , 08:27 PM
Quote:
Originally Posted by DarkMagus
anyone here use visual studio a lot? what is the best language to use in it, or do they all have basically the same functionality? i'm most familiar with c++ so i've been using that but it seems there are some things better implemented in c# and/or vb
C# and VB are the two languages that are best supported in VS. Nothing else comes close. If youve done C++, C# figures to be the language that is easier to transition to. Also, although everything that exist for C# in the .NET framework also exist for VB and vice versa, C# is far and away the most popular of the two, meaning finding help with problems is alot easier if you use C#

Mvh
Inga
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-26-2012 , 10:24 PM
Definitely use C#.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 05:22 AM
Slightly off track, but regarding Visual Studio, I found this hilarious

http://arstechnica.com/microsoft/new...nture-game.ars
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 05:24 AM
Anyone else subscribe to hackermonthly.com ? Just signed up for 1 year digital and its awesome... downloads strait to my kindle. They seem to have done a really good job of it, the articles are really well laid out.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 02:56 PM
alright thanks, i was definitely leaning towards c#
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 03:00 PM
VB.net can look friendlier to use if you're new, but C# is orders of magnitude better in terms of easier to get help with and used in industry.

Both VB.net and C# both compile to the same common language runtime (CLR) so you wont see any performance benefit from using C# over VB.net. The differences are mainly aesthetic (you can find vb.net to c# converters and vis versa) but because c# is way way more common in jobs etc you should pretty much always just go c#.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 03:22 PM
General Best Practice Question....
Code:
Class A 
{

public:
int a;

FunctionOne();
FunctionTwo();

};


FunctionOne()
{
a = 22333 * othervariable / variable3;
FunctionTwo();
}

FunctionTwo()
{
if (a == 3)  dostuff();
}
Is it normal for functions inside a class to never have parameters and basically pass the variables by setting them in the class?

Wouldn't it be more clear to call functiontwo with a parameter, especially when a can be any number of things, like in my case its user entered data read from a database.


Just seems to get super confusing and makes it very hard to track down bugs.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 03:28 PM
Yes, I think that's fine. If possible however it's sometimes best to make it call another method so that you don't have multiple methods doing the same thing, for example:

Code:
public class Game
{
    public int ID {get;set;}
    public string Name {get;set;}

    public disable()
    {
        Functions.disableGame(ID);
    }
}

public class Functions
{
    public static void disableGame(int GameID)
    {
        db.Execute("UPDATE Games SET Disabled = 1 WHERE ID = " + GameID);
    }
}
This way you can disable a game in any point in code by calling Functions.disableGame(ID) or with a game object you can simply do ThisGame.disable() all of which resolve to the same method which makes maintainance easy.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 03:45 PM
Quote:
Originally Posted by Gullanian
Yes, I think that's fine. If possible however it's sometimes best to make it call another method so that you don't have multiple methods doing the same thing, for example:

Code:
public class Game
{
    public int ID {get;set;}
    public string Name {get;set;}

    public disable()
    {
        Functions.disableGame(ID);
    }
}

public class Functions
{
    public static void disableGame(int GameID)
    {
        db.Execute("UPDATE Games SET Disabled = 1 WHERE ID = " + GameID);
    }
}
This way you can disable a game in any point in code by calling Functions.disableGame(ID) or with a game object you can simply do ThisGame.disable() all of which resolve to the same method which makes maintainance easy.
That makes sense I think, but in my case its
disableGame()
{
db.Execute("UPDATE Games SET Disabled = 1 WHERE ID = " + GameID);
}

where GameID is simply a member of the class that is routinely changed by other functions and in the case of disable it would be set when you click that one out of a list for example.

It almost seems like you HAVE to call a serious of functions in the correct order for it to be functional

I guess its really hard for me to explain without showing all the actual code which is 10365 lines for this class.

Last edited by Jeff_B; 01-27-2012 at 03:50 PM.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 04:16 PM
Quote:
Originally Posted by DarkMagus
anyone here use visual studio a lot? what is the best language to use in it, or do they all have basically the same functionality? i'm most familiar with c++ so i've been using that but it seems there are some things better implemented in c# and/or vb
C# and VB are very similar in capability. From C++ background C# will feel most natural. Theoretically you can do the same tasks in either. What kind of application are you building? F# is easier to use than C# for heavy calculations or handling large amounts of data.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 04:40 PM
Quote:
Originally Posted by Jeff_B
That makes sense I think, but in my case its
disableGame()
{
db.Execute("UPDATE Games SET Disabled = 1 WHERE ID = " + GameID);
}

where GameID is simply a member of the class that is routinely changed by other functions and in the case of disable it would be set when you click that one out of a list for example.

It almost seems like you HAVE to call a serious of functions in the correct order for it to be functional

I guess its really hard for me to explain without showing all the actual code which is 10365 lines for this class.
It's all about what your object represents, and what the variable your'e working on is.

In the game example, if the object represented a specific game instance, then using a member variable makes sense, since the game ID would (should) be initialized by the constructor. If the object represents a generic Game, and can operate on more than one game instance, then you have to pass it in the method.

If you have to initialize the member variable before calling the function, then you should instead be passing the variable in the method call. If the variable is a necessary part of the object, and is set as part of the initialization process (eg, in the constructor) then you can use the member variable.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-27-2012 , 08:16 PM
i like zurvan's answer.

i would add that there are ramifications for unit testing, so i would design my code such that it is easy to test as opposed to making it hard to test. dependency injection is easy, mocking up a whole class less so.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-28-2012 , 12:26 AM
Quote:
Originally Posted by MrWooster
Slightly off track, but regarding Visual Studio, I found this hilarious

http://arstechnica.com/microsoft/new...nture-game.ars
lol, this is A+
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-28-2012 , 07:37 AM
Quote:
Originally Posted by tyler_cracker
i like zurvan's answer.

i would add that there are ramifications for unit testing, so i would design my code such that it is easy to test as opposed to making it hard to test. dependency injection is easy, mocking up a whole class less so.
I do too. I think it boils down to keeping your abstraction consistent and managing complexity. Someone is going to read your code far more often than you write it.

I have a question of my own. I find when I serialize and deserialize objects that I use practically the same cod, but because fwrite and fread have different function signatures I can't use function pointers. Is something like this a good way to do it? If I want to create an object while reading, is using type traits (I think that's the right terminology) the best way?

Code:
typedef size_t (*readFn)(void*, size_t, size_t, FILE*);
typedef size_t (*writeFn)(const void*, size_t, size_t, FILE*);

readFn readInstance;
writeFn writeInstance;

createObject(readFn r, int count) { .. create object.. }
createObject(writeFn r, int count) {}

template <typename functionSignature_t, functionSignature_t readwrite_t>
void serialize() {
readwrite_t(...);
createObject(readwrite_t, count);
readwrite_t(...);
}

serialize<readFn, readInstance>();
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-29-2012 , 08:16 PM
What makes a good tech consultant?

A few pages back, a few of you gave me flack because I was (perhaps) overly critical of a consultant that contacted our company. I do want to point out that that consultant, or any consultant, has NOT been found by us via "word of mouth." All of them have cold-contacted us via stopping by, email, calling, etc. Remember that we are about as far-removed from "tech company" as it gets, so we are easy prey and even easy to please. Yes, I know this attitude is awful to have, but I am leery of people who are more salesmen than they are programmers selling programming services.

Looking online, no one seems to think that having requisite programming skills are needed, but rather, the skill to simply be liked. I take some issue with this, but I digress.

I'm nervous: I have to sit in on a meeting with an IT consultant that is visiting our company, and well, one person thinks that the person who did our current site did a great job and that he is "extremely knowledgeable" which is lol, in my opinion.

The guy who's coming in, once again, has a crummy site (table layouts, no doctypes, etc), and his site features a bunch of "solutions to projects" that involve a ton of expensive products (MSSQL, SAP, Oracle, etc), once again, with no links to prior work or anything. Maybe they hate open source?

They also sell themselves as "SEO experts" which is a huge laugh since their current site fails on all the basics.

What kind of questions would I want to ask? What are red-flags when dealing with these people. I mean, if he tries to push us into paying for a bunch of stuff and refuses to budge, acting like he is working for Oracle or something, then yeah, this is a red flag, but what else do I look for?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2012 , 12:55 PM
Quote:
Originally Posted by MrWooster
Anyone else subscribe to hackermonthly.com ? Just signed up for 1 year digital and its awesome... downloads strait to my kindle. They seem to have done a really good job of it, the articles are really well laid out.
Never heard of it until now. Thanks for the heads up. I may check it out, "Read Hacker Monthly in any device you want (PDF, MOBI, EPUB format), DRM-Free. Get access to all current/past issues right after your purchase.", that alone makes it real tempting.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2012 , 01:54 PM
Quote:
Originally Posted by bjordan
Never heard of it until now. Thanks for the heads up. I may check it out, "Read Hacker Monthly in any device you want (PDF, MOBI, EPUB format), DRM-Free. Get access to all current/past issues right after your purchase.", that alone makes it real tempting.
I am getting it sent strait to my kindle and its awesome. You just put in your kindle email address on their site and it arrives every month.

You also get access to all the back issues. Downloads are a zip file that contain the magazine in full colour PDF, iPad optimised full colour PDF, epub and mobi formats.
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2012 , 07:18 PM
Simple Q:

I'm writing some PHP and I want to display an individual card out of a PNG showing all the cards.

I'm sure this is ultra-simple but in Googling it I've found a lot of confusing ways of doing it and nothing simple.

Thanks!

** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
01-30-2012 , 07:27 PM
01-30-2012 , 08:57 PM
why not use individual pngs for each card? seems like it would be easier to code.

also why are clubs and diamonds duplicated?
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD ** Quote
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **
$25m Guaranteed WPM on CoinPoker
Join the action now
Daily Rewards • Splash Pots • CoinRaces
** UnhandledExceptionEventHandler :: OFFICIAL LC / CHATTER THREAD **

      
m