Computers & Life. Giving you as much crap as possible. Good, useful crap. «somahovering, soma-hover-ing, the act body hovering»
Showing posts with label Programming. Show all posts
Showing posts with label Programming. Show all posts
Sunday, January 25, 2015
ircmaxell's blog: Being A Responsible Developer
ircmaxell's blog: Being A Responsible Developer: Last night, I was listening to the combined DevHell and PHPTownHall Mashup podcast recording, listening to them discuss a topic I talked ab...
ircmaxell's blog: PHP Install Statistics
ircmaxell's blog: PHP Install Statistics: After yesterday's post , I decided to do some math to see how many PHP installs had at least 1 known security vulnerability. So I went t...
Wednesday, April 23, 2014
Game servers: UDP vs TCP by Christoffer Lernö
Game servers: UDP vs TCP by Christoffer Lernö, an article by Christoffer Lernö can be found at http://1024monkeys.wordpress.com/2014/04/01/game-servers-udp-vs-tcp/Why UDP is “hard”
Topics:
- Background
- What TCP means in practice
- Why UDP is “hard”
- The flawed case for TCP
- When TCP doesn’t work
- Myth: Reliable UDP is TCP implemented poorly
- The bottom line:
So UDP or TCP?
Use HTTP/HTTPS over TCP if you are making occasional, client-initiated stateless queries and an occasional delay is ok.
Use persistent plain TCP sockets if both client and server independently send packets but an occasional delay is ok (e.g. Online Poker, many MMOs).
Use UDP if both client and server may independently send packets and occasional lag is not ok (e.g. Most multiplayer action games, some MMOs)
These are mixable too: Your MMO client might first use HTTP to get the latest updates, then connect to the game servers using UDP.
Never be afraid of using the best tool for a task.
Topics:
- Background
- What TCP means in practice
- Why UDP is “hard”
- The flawed case for TCP
- When TCP doesn’t work
- Myth: Reliable UDP is TCP implemented poorly
- The bottom line:
So UDP or TCP?
Use HTTP/HTTPS over TCP if you are making occasional, client-initiated stateless queries and an occasional delay is ok.
Use persistent plain TCP sockets if both client and server independently send packets but an occasional delay is ok (e.g. Online Poker, many MMOs).
Use UDP if both client and server may independently send packets and occasional lag is not ok (e.g. Most multiplayer action games, some MMOs)
These are mixable too: Your MMO client might first use HTTP to get the latest updates, then connect to the game servers using UDP.
Never be afraid of using the best tool for a task.
Thursday, August 1, 2013
Basics of Function Pointers in C
A good article about Basics of Function Pointers in C by Dennis Kubes can be found in his website denniskubes.com
"This post is very detailed because I am attempting to create a mental model to help beginners understand the syntax and basics of function pointers. If you are ok with detail happy reading.
Function pointers are an interesting and powerful tool but their syntax can be a little confusing. This post will going into C function pointers from the basics to simple usage to some quirks about function names and addresses. In the end it will give you an easy way to think about function pointers so their usage is more clear."
... in which I found a link to Steve Friedl's Unixwiz.net Tech Tips - Reading C type declarations
"This post is very detailed because I am attempting to create a mental model to help beginners understand the syntax and basics of function pointers. If you are ok with detail happy reading.
Function pointers are an interesting and powerful tool but their syntax can be a little confusing. This post will going into C function pointers from the basics to simple usage to some quirks about function names and addresses. In the end it will give you an easy way to think about function pointers so their usage is more clear."
... in which I found a link to Steve Friedl's Unixwiz.net Tech Tips - Reading C type declarations
Animatable
Animatable by Lea Verou
One property, two values, endless possiblities...
One property, two values, endless possiblities...
Why there is no Hitchhiker’s Guide to Mathematics for Programmers ?
Good article at jeremykun.com
Why there is no Hitchhiker’s Guide to Mathematics for Programmers ?
Remember when you first learned how to program? I do. I spent two years experimenting with Java programs on my own in high school. Those two years collectively contain the worst and most embarrassing code I have ever written. My programs absolutely reeked of programming no-nos. Hundred-line functions and even thousand-line classes, magic numbers, unreachable blocks of code, ridiculous code comments, a complete disregard for sensible object orientation, negligence of nearly all logic, and type-coercion that would make your skin crawl. I committed every naive mistake in the book, and for all my obvious shortcomings I considered myself a hot-shot programmer! At least I was learning a lot, and I was a hot-shot programmer in a crowd of high-school students interested in game programming.
http://jeremykun.com/2013/02/08/why-there-is-no-hitchhikers-guide-to-mathematics-for-programmers/
Why there is no Hitchhiker’s Guide to Mathematics for Programmers ?
Remember when you first learned how to program? I do. I spent two years experimenting with Java programs on my own in high school. Those two years collectively contain the worst and most embarrassing code I have ever written. My programs absolutely reeked of programming no-nos. Hundred-line functions and even thousand-line classes, magic numbers, unreachable blocks of code, ridiculous code comments, a complete disregard for sensible object orientation, negligence of nearly all logic, and type-coercion that would make your skin crawl. I committed every naive mistake in the book, and for all my obvious shortcomings I considered myself a hot-shot programmer! At least I was learning a lot, and I was a hot-shot programmer in a crowd of high-school students interested in game programming.
http://jeremykun.com/2013/02/08/why-there-is-no-hitchhikers-guide-to-mathematics-for-programmers/
Labels:
Matemática,
math,
mathematics,
Programação,
Programming
Thursday, August 23, 2012
Javascript break out of frames script
Javascript break out of frames script.
A simple way to break out of frames on page load.
<script type="text/javascript">
if (top != self)
top.location = self.location;
</script>
A simple way to break out of frames on page load.
<script type="text/javascript">
if (top != self)
top.location = self.location;
</script>
Friday, August 10, 2012
Recursive Functions
Recursive functions
Recursive functions are functions that call themselves. Several problems are naturaly defined recursively. Those problems may be solved by using recursive functions.
Example: Factorial of a positive integer number.
0! = 1
1! = 1
n! = n * (n-1)! , if n > 1
int factorial(int val){
if(val <= 1) //stop condition.
return 1;
else
return val * factorial(val-1); //recursive call.
}
Stop condition: Condition to stop recursive calling and return. Written before recursive calling.
Recursive calling: The problem to solve should be simpler than the previous problem. The recursive calling ends at stop condition.
Advantages: compact code, easier to write and understand.
Disadvantages: intensive stack usage, recursive functions aren't faster than equivalent non recursive functions.
Some usage examples: String manipulation, linked list operations, binary tree operations.
Example: Count number of characters in a string.
int count(char *st)
{
if(*st == '\0')
return 0;
else
return 1+conut(st+1);
}
Example: Count number of characters in a string.
int count(char *st)
{
if(*st == '\0')
return 0;
else
return 1+conut(st+1);
}
Example: reverse a string.
void puts_inv(char *st)
{
if(*st == '\0')
return;
else
{
puts_inv(st+1);
putchar(*st);
}
}
Examples of incorrect recursive functions:
long int factorial(long int val)
{
return val * factorial(val-1);
if(val <= 1) return 1;
}
long int factorial(long int val)
{
if(val <= 1) return 1;
else return val * factorial(val);
}
long int factorial(long int val)
{
if(val <= 1) return 1;
else return val * factorial(val+1);
}
C function for getting user input
C function for getting user input.
Reads up to uinput-1 characters from stdin to uinput, removes \n adn adds \0.
Returns number of characters of uinput.
int getUserInput(char *uinput, int size){
size_t last;
fgets(uinput, size, stdin);
if (strlen(uinput) > 0){
last = strlen(uinput) - 1;
if (uinput[last] == '\n'){ //if last char is \n replace with \0
uinput[last] = '\0';
} else {
//no \n in buffer, discard additional characters.
fscanf (stdin, "%*[^\n]");
(void) fgetc (stdin); // discard \n
}
}
return strlen(uinput);
}
Subscribe to:
Posts (Atom)