Close Remote Socket 2020-07-05 [code] [english] I got used to close sockets in Windows using TCP View, but I haven't learned yet how to do this in Linux. Some Google and now I know. It is kinda simple in terminal mode, as any task a programmer needs to do in your system. You just need to find the process using netstat, find the socket descriptor using lsof, debug the process with gdb, close the socket using call command, close the debugger.
Some things I learned in a Hacker Rank exercise 2019-08-08 [code] [ccpp english] A couple of days ago I subscribed to Hacker Hank, a website specialized in provide interview exercises. The site is as a better version of Code Jam, with the possibility to Compile & Run the code, as well as running several test cases. Talking with friends about one of them proposed a interesting puzzle called Find the Running Median. This is a good problem because it is easy to understand and tricky to implement.
Real Programmers Don't Use Java 2014-02-20 [english] When I was a newbie (and a wanna-be) I enjoyed reading "Real Programmers Don't Use Pascal", a satiric text that influenced and encouraged me into the path of "C/C++ enlightenment", most even than K&R's book. Since then I thought that being a "Real Programmer" was something close to everything one needs to know to get (hard) things done (quickly). Being a "Quiche Eater" was, in couterpart, comparable to nothing. Real Programmers solve real problems!
Using TodoList and Microsoft Project together 2010-04-10 [code] [english] The next article about bits is still in the oven. Taking vacation (40 days) had drop me out of ideas! At the moment, I can explain the tips and tricks using TodoList to manage my team and synchronize my tasks in a Microsoft Project timesheet. The reasons why I am using TodoList are kind of obvious: it does everything I need to organize my day to day tasks and it is portable.
What I've been doing in the last 10 years 2009-08-17 [english] This week I dedicate myself to update my resumè and I have the brilliant idea of put into it my technical historical, what resuming is a list of things I did or was involved with during my brief ten years stay in the programming world. So I thought: "this could be useful to the people read me". Why not? Perhaps you got some doubt waiting to be solved and is unable to find a guy who knows something about this.
Static Polymorphism 2009-07-10 [code] [english] To explain the polymorphism nothing is better than see how stuff used to be. If you were a twenty old C programmer in the past and created the following functions: int soma(int x, int y); double soma(double x, double y); int main() { int zi = soma(2, 3); double zd = soma(2.5, 3.4); return 0; } Immediately the compiler would blame you about the following errors: overload.c overload.c(2) : warning C4028: formal parameter 1 different from declaration overload.
How to run anything as a service 2008-05-27 [code] [english] The biggest advantage running an application as a service, interactive or not, is to allow its start before a logon be performed. An example that happens to me is the need of debugging a GINA. In order to do this, I need the Visual Studio remote debugger be started before logon. The easiest and fastest solution is to run Msvcmon, the server part of debugging, as a service. Today I've figured out a pretty interesting shortcut to achieve it.
Funky do-while 2008-02-13 [code] [english] It's a known habit to use do-while constructions when there's a need to define a macro that has more than one command instead of using the { simple multicommand brackets }. What was never clear is why this is so. Let's imagine a trace macro that's enabled in debug mode, whilst kept in silence in release builds: #ifdef NDEBUG #define MYTRACE( message ) /* nothing */ #else #define MYTRACE( message ) \ { \ char buffer[500]; \ sprintf(buffer, \ "MYTRACE: %s(%d) %s\n", \ __FILE__, \ __LINE__, \ message); \ OutputDebugString(buffer); \ } #endif /* NDEBUG */ Nothing much, but it seems to work.
Silly regex trick: finding the project who failed inside a big VS solution 2008-02-07 [code] [english] I know what you going to think about this one: "silly trick". That's why I just put it in the title. Anyway, that is something I use everyday, so I thought it might be useful to who cares about productivity. Let's say you have to manage a big solution in Visual Studio made of more than 30 projects, and needs to rebuild all them. Suddenly, something goes wrong. The question is: how to discover, in a heartbeat, what project has failed?
MouseTool 2007-11-13 [english] Well, as most of you already know, I really don't like mice. Nevertheless I respect the users who use it and like it. That is the reason why I am writing a little more about it. This time, I going to show a program I use every day: MouseTool, for the users who does not use the mouse and like it. The program main purpose is to avoid clicking the mouse, simulating a click every time the user stops to move the cursor.
Why is my DLL locked? 2007-09-24 [code] [english] The Windows code responsible to call DllMain for each loaded and unloaded DLLs uses an exclusive access object, the so-called mutex, to synchronize its calls. The result is that inside a process just one DllMain can be called at a given moment. This object-mutex is called "loader lock" into the Microsoft documentation. I wrote a silly code that represents quite well what I've seen in lots of production code. For many times I was unable to realize what was going on (whether because I didn't know about the loader lock or the code readability was too bad).
C and C++ Operators Precedence Table 2007-07-30 [code] [ccpp english] Wanderley, your explanation about why a program compiles in C++ and not in C seems to me logic and correct, but gave me some doubts, because I always learned that the C and C++ operator precedence are the same thing. I checked out the Appendix A in the "C ++ - How To Program" (sixth edition) and the book table is equal to the C operators precedence table and it is different from the C++ precedence table presented by you in the article.
What happens inside the sizeof operator 2007-07-16 [code] [ccpp english] The question: how to get the size of a struct member without declaring it as a variable in memory? In pseudocode: static const size_t FIELD_SIZE_MSGID = 15; struct FEEDER_RECORD_HEADER { char MessageID[FIELD_SIZE_MSGID]; char MessageIndex[10]; }; // error C2143: syntax error : missing ')' before '.' char MessageIndexBuffer[sizeof(FEEDER_RECORD_HEADER.MessageIndex) + 1]; // error C2070: '': illegal sizeof operand char MessageIndexBuffer[sizeof(FEEDER_RECORD_HEADER::MessageIndex) + 1]; In this first try (even being a nice one) we can clearly see by instinct that the construction is not supposed to work.
Precedence difference 2007-07-10 [code] [ccpp english] Once upon a time my old friend Kabloc wrote this little and "harmless" function in order to print the multiplication table: #include <stdio.h> int main() { int f1,f2,s=0; for(f1=1;(f1==11&&s!=5)?s=5,f1=0,putchar(10):(f1<=10)?f1=f1:f1=12,f1<=11;f1++) for(f2=1+s;f2<=5+s;f2++)printf("%dx%d=%d%c",f2,f1,f1*f2,(f2==5+s)?10:9); return 0; } Despite the fact the result is a strong candidate to The International Obfuscated C Code Contest the Linux guys told him the code was not successful on GCC, and somewhere inside those four lines there was a non-standard piece of code.
Google shortcuts 2007-07-06 [english] I love shortcuts. Since my very first years using computers, shortcuts had become my obsession. I research them through the time, collecting them, using them. For a long time I avoid myself from touching the mouse, trainning to remember all keystroke sequences I know. I have nothing against using the mouse neither the people that do it. I'm just not very much enthusiastic in using mice. For sometime, I even believed that the cursor pointer was getting me annoyed, so I developed a program to get rid of it from the screen (using a shortcut, of course).
Disassembling the array operator 2007-06-22 [code] [ccpp english] Arrays are fascinating in C language because they are so simple and so powerful at the same time. When we start to really understand them and realize all its power we are very close to understand another awesome feature of the language: pointers. When I was reading the K&R book (again) I was enjoying the language specification details in the Appendix A. It was specially odd the description as an array must be accessed: