2010-11-24
Pesti Meló
Bunkos Tesók - Bolyai Club
2010-10-22
2010-10-19
The OMG Cat / Az "Óh, jajj, Istenem!" macska
Original / Eredeti
~ sees car accident / ~ autóbalesetet lát
2010-10-15
Ruby is not good at comments
Problem
Imagine that you are hard-coding some long list into your Ruby code and you need to- wrap the long line into multiple lines
- comment on some items
@@import_fields = [ \ "Name" \ , "Organization" \ , "Role" \ , "Internal ID" \ ];Pretty ugly, because the statement separator is the newline and you should escape it. But doable. Let's move on!
Completing the second goal is not possible. The only commenting option is the line-commenting which is starts with the
#
sign and ends when the line ends. If you place the comment before the backslash (\
), your interpreter will not detect the newline escaper backslash. If you place the comment after it, then it stops being a newline escaper.Nonexistent solutions
- The Ruby guys failed to add statement separators / terminators to the language and that remains this way. I think the intention was to make life easier, but I believe they made it harder. Someone someday may enlighten me.
- They should introduce block comments. It would be backward compatible and would make the World a better place.
- Or they should detect the newline escaping after the
#
sign.
Workaround
@@import_fields = [] @@import_fields << "Name" @@import_fields << "Organization" # Some clever saying about this field @@import_fields << "Role" @@import_fields << "Internal ID" # And some eternal wisdom about this
If you know a better way, don't hesitate to tell me!
2010-10-13
Indent with TABs, format with spaces
1st: Visible with
They say that TABs are rendered differently by different softwares and devices. I cannot accept that. Read on.UNICODE 2.0 released in year 1996. In around 2001 people wanted to kill me because I used UTF-8 characters on IRC, and they argued that their [not so good] software cannot render them correctly. I ignored them. Their [not so good] software became advanced, their minds became open.
Editors and devices where the visible width of TAB characters cannot be adjusted are not so good. TAB is not a new invention at all.
2nd: Formatting
TABs are not for formatting. They are only for indenting.int·main() { → printf("Hello·%s!\n",·//·I·like·to·move·it, → ·······"World");······//·move·it. → return 0; }
If you want to graphically align something then you should use SPACES. If you are expressing the depth of control, then you should use TAB. The above code will maintain it's visual, see:
int·main() { → {·//·Ad-hoc·block·begin → → printf("Hello·%s!\n",·//·I·like·to·move·it, → → ·······"World");······//·move·it. → → return·0; → }·//·Ad-hoc·block·end }
3rd: Freedom
See what happens when visible with of TAB is set to 8, because someone may like it that way:int·main() { → {·//·Ad-hoc·block·begin → → printf("Hello·%s!\n",·//·I·like·to·move·it, → → ·······"World");······//·move·it. → → return·0; → }·//·Ad-hoc·block·end }
The hairdo is still tight.
What if someone's favorite visual TAB size is 2?
int·main() { → {·//·Ad-hoc·block·begin → → printf("Hello·%s!\n",·//·I·like·to·move·it, → → ·······"World");······//·move·it. → → return·0; → }·//·Ad-hoc·block·end }
The hairdo is still tight.
4th: Symbolism
From my heart: http://www.mail-archive.com/vim_use@googlegroups.com/msg18895.htmlFavorite part: ... tabs for leading indent, spaces everywhere else. I prefer this strategy for the same reason I prefer to use symbolic names for constants, rather than embedding numeric literals throughout my source code ...
2010-09-09
2010-08-23
Stephen Fry & Hugh Laurie
Old stuff which is new for me. Another life of Doctor House.
2010-08-16
Villamosos üldözés / Tram pushuit
In current days, while the criminal acts are spreading, the daredevils of the gangland invent newer and newer ways to deliver their deeds.
The following police recording proofs that criminals are not picky about the vehicles they use during robbery.
2010-08-15
2010-08-12
Editing JPEG DPI without resampling
Exif editor. The best of the results which simply solves the problem is the
Exif Piloton an
Exif editorspage. Enjoy!
P.S.: I decided to publicate the fruit of every hard and exhausting search on this blog. Maybe it is not good for the regular visitor, but I'm sure it helps the Universe in general. :-)
--- Hungarian version
JPEG DPI szerkesztés: Ez a jó neked:
Exif Pilotaz
Exif editorsoldalról.
2010-08-11
Welcome to Ruby
myString = "Welcome to JavaScript!" => "Welcome to JavaScript!" myString[8..20]= "Ruby" => "Ruby" puts myString => "Welcome Ruby!"
2010-07-22
LOLCODE
lolcatInternet meme. The language was created in 2007 by Adam Lindsay, researcher at the Computing Department of Lancaster University.
The language is not clearly defined in terms of operator priorities and correct syntax, but several functioning interpreters and compilers already exist. The language has been proven Turing-complete.
-- Wikipedia
Examples
- Hello World!
HAI CAN HAS STDIO? VISIBLE "HAI WORLD!" KTHXBYE
- Print numbers from 1 to ROOF.
HAI CAN HAS STDIO? I HAS A ROOF, I HAS A VAR ITZ 0 GIMMEH ROOF BTW U R IN CONTROL IM IN YR LOOP UP VAR!!1 IZ VAR BIGGER THAN ROOF? KTHXBYE VISIBLE SMOOSH VAR AN ":)" MKAY IM OUTTA YR LOOP KTHXBYE
→ lolcode.com
2010-07-20
2010-07-18
Publishing detailed error messages
Design an error handling strategy. Error handling can be rather expensive for layered architectures with respect to processing time and, notably, programming effort. An error can either be handled in the layer where it occurred or be passed to the next higher layer. In the latter case, the lower layer must transform the error into an error description meaningful to the higher layer. As a rule of thumb, try to handle errors at the lowest layer possible. This prevents higher layers from being swamped with many different errors and voluminous error-handling code. As a minimum, try to condense similar error types into more general error types, and only propagate these more general errors. If you do not do this, higher layers can be confronted with error messages that apply to lower-level abstractions that the higher layer does not understand. And who hasn't seen totally cryptic error messages being popped up to the highest layer of all - the user?
I have to strongly disagree with the author on that point. It is far more worse if the highest layer of all gets an error like "Error." without any details. The error message should be as detailed as possible. Do not be confused! That does not mean that higher layers should not handle these errors in a grouped manner. For example if a file transfer fails on any reason the program logic should abort the transaction, whatever the reason of the failure is, so the so called voluminous error-handling code can be avoided. Not handling but publishing the details of the error can help the user understand and solve the problem. Making distinction between "Directory not found.", "Drive not ready.", and "Permission denied." is very useful at the level of the user (or customer care, product support line, developer, whoever).
Testing, debugging and user support can be a horror without detailed error messages. It can be counted in serious amount of money. If the user does understand the error message then it is an instant win for the user himself/herself and for the customer care both. If he/she doesn't understand then he/she has something to tell at official and unofficial support forums which will bring the solution closer. It is a win-win decision to keep the error messages detailed.
And again, it does not contradict the "keep the volume of error-handling code low" principle. Handling ≠ publishing.
→ 1: [Posa1996] Frank Buschmann et al.: Pattern-oriented software architecture, Volume 1: A system of patterns; © 1996 John Wiley and sons
2010-07-16
Processing.org
Processing is an open source programming language and environment for people who want to create images, animations, and interactions. Initially developed to serve as a software sketchbook and to teach fundamentals of computer programming within a visual context, Processing also has evolved into a tool for generating finished professional work. Today, tens of thousands of students, artists, designers, researchers, and hobbyists who use Processing for learning, prototyping, and production.
→ processing.org
The apropo for posting this is that I regenerated my toy applets that I wrote in this environment.
→ My graphic applets, with source code. Enjoy!
2010-07-14
Silver needle in the Skype
BlackHat Europe, March 2nd and 3rd, 2006
→ skype_BHEU06.pdf
Repost of a synsecblog entry.
If you can repeat their results you rock!!!
Codility (x)
Automated tests of programming skills.
Codility saves time of software talent recruiters by filtering out job candidates who cannot write correct programs.
Codility administers short programming tests and checks whether solutions are rock solid.
Our customers filter out up to 90% of candidates. Less wasted time. Better hires.
→ http://codility.com/
2010-07-09
2010-07-07
2010-06-28
2010-06-25
French and Italian soccer / Francia és olasz foci
A francia és az olasz csapat tagjai tegnap közösen meglátogattak egy fokvárosi árvaházat.
Szívszorító volt látni a szomorú kis arcukat és a reménytelenséget– nyilatkozta a 6 éves Dzsamal.
--- English version
The members of the French and Italian soccer teams joined together and visited a shelter for orphaned children in Cape Town.
It was heart-smothering seeing their little sad faces and the hopelessness– explained Jamal the 6 years old boy.
2010-06-23
2010-06-18
My penis is too short / A péniszem túl rövid
Azt mondta a rendszer, hogy meg kell adnom egy jelszót. Azt mondtam "faszom". Mire a rendszer közölte, hogy túl rövid.
Megkérdeztem egy kollégámat, hogy ilyenkor mit kell csinálni. Azt mondta, hogy elfelejtettem beírni a méretét, úgy mint "faszom45". Működött.
--- English version
The system said that give it a password. I typed "mydick". The system said it is too short.
I asked a colleague what to do. He said that I have to type in the size, like "mydick45". It worked.
2010-06-17
2010-06-09
Gibbets (game / játék)
Mentsd meg a felakasztott embereket!
→ http://www.notdoppler.com/gibbets.php
UPDATE: It has a second episode.
FRISSÍTÉS: Van második része is.
→ http://www.notdoppler.com/gibbets2.php
2010-06-07
C++: Class vs Struct (clarification)
Let's see equivalent examples, let's talk about the philosophy later...
struct Vector { double x,y; }; class Vector { public: double x,y; };
and
class Vector { public: Vector(double x_, double _y); Vector& SetXY(double x_,double y_); double GetX() const; double GetY() const; //... private: double x,y; }; struct Vector { Vector(double x_, double _y); Vector& SetXY(double x_,double y_); double GetX() const; double GetY() const; //... private: double x,y; };
In my opinion class's default visibility is not very useful because we used to start the class definition with the public members to ease the interpretation of it for the users of our class.
The big difference is in the intent of the declaration. If we want to create a composite behavior-less data unit that is passed around, then we should use the struct keyword so the reader will know what's going on. If you want to create an object which fulfills an abstract concept and has a behavior, then you should define a class.
IMPORTANT: If you use class you should really take care about the basic requirements like hiding data members (making them private or protected in order to maintain
principle of local responsibility), providing type-invariant safe public methods, disabling
copy semanticsif not needed explicitly, and so on ...
2010-06-06
C++: The static keyword (clarification)
Static function or variable
The variable or function name will not be propagated for the linker, that means that this variable or function will be available only in it's compilation unit. This feature is rarely used, only if we want to hide something explicitly from other compilation units.static int MySecretFunction(){ /* ... */ } static int MY_SECRET_VARIABLE = 7; // You should give a starting value
Static variable in a function
int Summarize(int next) { static int sum = 0; sum += next; return sum }The static variable in a function is initialized at the first time when the function is called. WARNING: Using this feature is not thread-safe in C++. In C++0x you will have the opportunity to write
thread_local static int sum = 0;which creates a global variable in the function's scope for each thread.
Static class members
Class member functions (methods) can be static or non-static. Non-static members are bound to the objects of the class, static members are not bound to the objects but are somehow related to the class. Study example:// matrix.h: class Matrix { public: Matrix(int n_, int m_); // Constructor Matrix& MultiplyByNumber(double lambda); // Non-static member function static Matrix CreateIdentityMatrix(int n); // Static member function // ... private: int n,m; // Non static emember variables double *pData; // Non static member variable static int serial; // Static member variable }; // matrix.cpp: int Matrix::serial = 0; // ...Note: You have to provide explicit storage place for the static member variables, that means you have to choose a compilation unit (.cpp file), where you write int Matrix::serial = 0;.
Non-static (or object-) methods can access both static and non-static member functions and variables. Static methods can access only static members. (And of course non-static members of the objects that are around.)
Simple global variables and initialization
// gadget.h: extern int dontUseGlobalVariablesIfPossible; // "Propagation" in the .h file // gadget.cpp: int dontUseGlobalVariablesIfPossible = 0; // Storage placeThe initialization of variables in
static storage class(simple global variables, static variables, static member variables, but not function's static variables) are done in the order that they are presented inside the compilation unit (see exception below). The order of initialization of two variables in different compilation units is
undefined.
The important exception is that primitive types (int, char, pointer, float, double, ...) are initialized upon loading if they are initialized with literals.
int x = 0; // Load time, practically before "everything" int y = f(); // Simply before main() based on the rules above.
2010-06-04
C++: References and pointers (clarification)
- pointer
- A pointer refers directly to (or "points to") another value stored elsewhere in the computer memory using its address. It can be also interpreted as a pointer to many objects, depending on the semantics of the usage.
- reference
- Is a pointer with some (useful) restrictions and a reliefs. It's value can be set only once (at declaration) and it can point only to one object. The relief is that you don't have to apply any syntax for dereferencing. Another benefit is that you know that the area pointed by a reference does not have to be freed by you.
Pointer examples
int array[10]; // Array with 10 elements allocated on the stack *array = 5; // Set the zeroth element to 5 *(array+1) = 6; // Set the first element to 6 array[2] = 7; // Set the second element to 7 int *array2 = new int[10]; // Array allocated on the heap *array2 = 5; // Set the zeroth element to 5 *(array2+1) = 6; // Set the first element to 6 array2[2] = 7; // Set the second element to 7 delete[] array2; // Freeing allocation int *p = array+3; // Create a pointer to the 3rd element *p = 8; // Set it to 8 char s1[] = {'H','E','L','L','O','!',0}; // Char array on stack (terminated by zero) char s2[] = "HELLO!"; // Char array on stack (terminated by zero) const char *s3 = "HELLO!"; // Pointer to string literal. "const" because you do not want to change a literal, do you?
- In the first case you don't really have a pointer that is stored anywhere. Handling of aggregated arrays (on stack or in a class/struct) is presented with pointer-syntax.
- In the second case you really have a pointer on the stack that points to the allocated area which is on the heap.
++array; // Will not compile ++array2; // Will incrase the array2 pointer by one // (it will point to the 1st element in the array - not the 0th)Note that you still have to call delete[] with a pointer that points to the 0th element!!! Something like
delete[] (array2-1);
Reference examples
Reference typed parameter
std::string ReverseText(const std::string& text) { size_t len = text.size(); std::string ret(len,'\0'); for(int i=0; i<len; ++i) { ret.at(i) = text.at(len-1-i); } return ret; // We love "named return value optimization" }Note: ret.at(i) returns a reference to the i-th character of the string.
- The parameter's value is not copied, just a pointer to it.
- You don't have to use pointer syntax like (*text).size() (or text->size()), you can use text.size() conveniently
- You don't have to test for NULL pointer. The user of the function can clearly see that he cannot pass a NULL pointer, that he/she must provide this parameter.
std::string s("Heavy Metal music"); std::cout << ReverseText(s) << std::endl;
Aliasing
A real life example would involve more complex concepts than the aliasing itself. It is rarely used, but very useful when needed. So let's see a l'art pour l'art teaching example!unsigned int LargestCommonDivider(unsigned int a, unsigned int b) { while(a!=b) { unsigned int &greater(a>b?a:b); unsigned int &smaller(a>b?b:a); greater -= smaller; } return a; }
- Let's see the usefulness and necessity of "functional programming minded" operator ?: here!
- The a and b variables are copies of the parameters given at the place of invocation, they can be used as ordinary local variables (which they are in reality).
Opening beer with a helicopter / Sörnyitás helikopterrel
Így kell csinálni.
2010-06-03
Gully at Guatemala / Guatemalai víznyelő
(Some of them are boring, but there are some treasure there)
Képek határok nélkül
(Néhányuk uncsi, de van pár igazi gyöngyszem)
→ @ index.hu
2010-05-31
2010-05-27
2010-05-26
2010-05-21
C++: Initializing containers with compile time list of data
template <typename T, size_t size> void FillSet(std::set<T>& target, const T (&list)[size]) { for(size_t i=0; i<size; ++i) target.insert(list[i]); }Usage example:
int startkit[] = {10,2,8,4,3,1}; std::set<int> numbers; FillSet(numbers,startkit);
Undefined increment
#include <stdio.h> #define COMPUTE(x,y) ((x*x*x) + (y)) int main() { int num1 = 100; int num2 = 10; printf("%d\n", COMPUTE(++num1, num2)); return 0; }The result is undefined in both C and C++, but the behavior is consistent and interesting. The result is in the first comment.
compute.c:10: warning: operation on ‘num1’ may be undefined
Attention by http://synsecblog.com/
2010-05-12
Programming homework
> Dear everyone,
> Can someone please help me on my HW. I'm trying to write a program
> that will display the following:
> * > *** > ***** > ******* > ********* > ********* > ******* > ***** > *** > *
> I'm having a hard time writing a code for this one. I tried several
> times, but I can't get it to work properly. I live in Japan and I take
> an online C++ course. The instructor lives in the US so whenever I am
> awake, he's asleep. Therefore, I cannot contact him directly when I
> need help. I have to get this program up and running ASAP. I tried
> searching everywhere for help, but there's none except for this group.
> My textbook isn't much of a help either. I WILL GREATLY APPRECIATE THE
> HELP I WILL GET!
My pleasure.
#define M 002354l #define A 000644l #define G 000132l #define I 000322l #define C 000374l #define a ; #define b for #define c ++ #define d % #define e int #define f , #define g - #define h 011 #define i = #define j { #define k ) #define l '\n' #define m main #define n < #define o } #define p > #define q && #define r ( #define s || #define t ? #define u putchar #define v void #define w '*' #define x : #define y ' ' #define _ / #define C_O_O_L return e u r e k a e m r v k j j j j j j j j j j j j j j j j j j j j j j j j e z a b r z i M _ A _ G _ I _ C a z n G a u r z d h + z _ h p M _ A q z d h + z _ h n M _ G q z _ h n z d h + M _ I q z _ h p z d h g M _ C t w x y k f z d h g h + 1 s u r l k f z c k a u r l k a j j j j j j j j j j j C_O_O_L M _ A _ G _ I _ C a o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o o -- Richard Heathfield "Usenet is a strange place" - dmr 29/7/1999 http://www.cpax.org.uk email: masked
2010-05-11
Funny programming yargons
http://stackoverflow.com/questions/2349378/new-programming-jargon-you-coined/2430307
Some highlights
Yoda condition
You write if(5==count) and you read
if five is the count.
Pokemon exception handling
When you catch them all!!!
A Duck
A feature added for no other reason than to draw management attention and be removed, thus avoiding unnecessary changes in other aspects of the product.
2010-05-07
Vízen járás / Walking on water
Valódi vagy kamu?
Real or fake?
2010-05-03
C++: Why initializer list?
class Parent; class Child { public: Child( Parent& parent_ , const std::string& name_ , const Color& eyeColor_ ) : parent(parent_) , name(name_) , eyeColor(eyeColor_) , money(0,"EUR") { } Parent& GetParent(){ return parent; } std::string GetName() const { return name; } Money GetMoney() const { return money; ); Money AdjustMoney(int diff) { money += diff; return money; } private: Parent &parent; const std::string name; Color eyeColor; Money money; };The initializer list in the above is this:
: parent(parent_) , name(name_) , eyeColor(eyeColor_) , money(0,"EUR")
- because of initializing references.
References are like pointers with two restrictions. Firstly: You (if you are sane) point only to one object with a reference, you never point to an array. Secondly: Once the location is pointed you will not point elsewhere. This "finally" sounding behavior is perfectly good when we want to point one's (abstract) parent.
If you want the language to force you to keep the second rule and still want your compiler in this millennium then you have to realize, that the initializer must be done before the begin ({) sign appears with it's endless possibilities.
- because of initializing const members.
Same as the above, but we are not talking about making up our mind early about a location but about a value. See the name member
- because of initializing an aggregated object which do not have default constructor.
Let's imagine the Color class which has only the copy constructor and that one: Color::Color(unsigned char r, unsigned char g, unsigned char b)! This class does not have default value / state by design, so it cannot be constructed without some instructions. See the eyeColor member.
- because of speed
You begin your program (constructor body) at the '{' sign. At that point all of your variables must be in a valid state. So if you give value to your members after that point you will waste processor time. One construction and one assignment, instead of simply one construction. See the money member.
In most of my codes the constructors' body used to be empty. If we want to work in that style we will have to have handy constructors for our classes, which is not a bad thing at all.
Important: The execution
of the initializer list is in the order of the data members because that order means the construction order and the reverse of that means the destruction order. If it wouldn't be like that then the program would have to remember the construction order and apply the reverse of it upon destruction. That would waste resources. So the rule came...
... and don't worry about hidden errors! Turn on the warnings in your compiler and take the advices and notes seriously! Seriously like Treat warnings as errors
compiler option.
C/C++: undefined behavior explained
char *s = "Hello?"; s[5] = '!'; printf("%s\n",s);Figure #2:
char *s = "Hello?"; char s2[] = "Jumbo?"; s = s2; s[5] = '!'; printf("%s\n",s);
It is impossible to tell that the line s[5] = '!'; contains error or not. You can have some speculation according to some static code analysis, but you cannot tell for sure. That's why it will be a run-time error (if it is an error).
Writing a string literal leads to undefined behavior. If we would say that in this case the compiler must generate a code that crashes, then it would be a feature, some kind of requirement for the compiler's manufacturer. Every usage of char * for writing would have a literal-check, which obviously has a very large overhead. The writers of the standard decided not to make any behavioral requirements in such cases. After that you can imagine other undefined behavior
cases or you can look them up and think about each of them individually.
Back to the example! In some cases it will lead to changing the literal, in other cases it will crash with "access violation" or "segmentation fault", because we are trying to write to a read-only area of the memory. ... To avoid accidents, I (the const fetishist) recommend you this:
const char *s = "Hello?";
You will have a compile time error instead of undefined behavior and you can fix your code and-or idea.
2010-04-26
Yes, it is C. The "const" keyword
- In parameter list
size_t strlen(const char *s);
The programmer of strlen() promises you that he/she will not alter the content pointed by s. It is good for you: You do not have to look up the manual for that bit of information. It tells more than you may think for the first time. It is good for the implementor of strlen(). He cannot accidentally write to the area pointed by s.
- Storing partial results as read-only variables.
const double aplusb = a + b; const double amulb = a * b; return 2*amulb/aplusb; // harmonic mean
It helps avoiding accidents and ease interpretation by humans.
- Pointing to literals
const char *appname = "Hello World!";
If you turn on the displaying of warnings in your compiler then you will see that pointing to a literal with non-const pointer is discouraged. It also helps not making bugs.
Kevlin Henney: C++ Stylistics
(Google Talks)
Feel free to watch multiple times.
Exit strategy: Single exit point is less readable
Single exit point produces the pyramid of code syndrome.
bool solve2 ( double a, double b, double c , double& x1, double& x2 ) { bool ret = true; if(a!=0) { double det = b*b - 4*a*c; if(det>=0) { ret = true; det = sqrt(det); double p2a = 1 / (2*a); x1 = (-b - det) * p2a; x2 = (-b + det) * p2a; // The top of the code pyramid } else ret = false; } else ret = false; return ret; }
Using early returns helps keeping the error handing and productive code apart.
bool solve2 ( double a, double b, double c , double& x1, double& x2 ) { // Checking for trivial errors and trivial solutions if(a==0) return false; double det = b*b - 4*a*c; if(det<0) return false; // Main part without pyramid det = sqrt(det); double p2a = 1 / (2*a); x1 = (-b - det) * p2a; x2 = (-b + det) * p2a; return true; }
Note: This function solves the quadratic equation (a * x^2 + b * x + c = 0).
Note: You have to be careful with the multiple exit point style if you are acquiring resources (opening files, allocating memory, ...), because it can lead to leaks. Avoiding these kind of leaks is simpler in C++ than in most languages, because the lifetime of acquisitions can be bound to scope.
Yes, it is C. Smaller scope better scope
- Variable scoping
- Lifecycle management by scope (calling destructor when execution reaches the end of it's scope)
- Bounding lifecycle of a variable to an object
for(int i=0; i<10; ++i){ printf("%d^2 = %d\n",i,i*i); }The new paradigm (woof) is that a variable should have the smallest scope possible to ease reading and interpretation of code (by humans).
Next: Exit strategy: Single exit point can be easily bad.
2010-04-20
How to create a fast thread-safe singleton initialization in C++
class Lock { CRITICAL_SECTION mSection; public: Lock(){ InitializeCriticalSection(&mSection); } ~Lock(){ DeleteCriticalSection(&mSection); } void Acquire(){ EnterCriticalSection(&mSection); } void Release(){ LeaveCriticalSection(&mSection); } };2nd: We need a guard for the lock. Just for convenience and to be foolproof. Keyword: RAII, guard. See also: auto_ptr.
class Guard { Lock *pLock; public: Guard(Lock &lock) : pLock(&lock) { pLock->Acquire(); } ~Guard(){ pLock->Release(); } };3rd: We can get down to business with our singleton. Do not forget to hide the default constructors and the '=' operator. Keywords: singleton, multi-thread, thread-safe, storage, operator overloading.
singleton.h:
class Singleton { public: static Singleton *GetInstance(); // other public members private: Singleton(); ~Singleton(); Singleton(const Singleton&); const Singleton& operator=(const Singleton&); static Singleton* pInstance; static Lock instanceLock; // other private members };singleton.cpp:
#include "singleton.h" // Storage place for static members: Singleton* Singleton::pInstance = 0; Lock Singleton::instanceLock; Singleton::Singleton(){ /* as you wish */ } Singleton::~Singleton(){ /* as you wish */ } Singleton* Singleton::GetInstance() { if(pInstance) return pInstane; Guard g(instanceLock); if(!pInstance) pInstance = new Singleton(); return pInstance; }
Feel free to search the web for the keywords, or any word you read here.
2010-04-16
Shut up wonan get on my horse!
Give it a lick. “MMMmm! It tastes just like raisins!”
Have a stroke of it’s mane, it turns into a plane,
and then it turns back again when you tug on it’s winky.
“Oooo that’s dirty!” Do you think so?
Well I better not show you where the lemonade is made -
Sweet lemonade, mmmm sweet lemonade.
Sweet lemonade, yeah sweet lemonade.
Get on my horse I’ll take you ’round the universe -
and all the other places, too.
“I think you’ll find that the universe pretty much covers everything.”
Shut up woman, get on my horse.
http://www.shutupwomangetonmyhorse.com/
2010-04-15
Dogs and polar bears
http://bazzinga.com/cute-animals/2010/02/26/dogs-and-polar-bears-are-friends.html
2010-04-13
Etióp szorzás / Ethiopian Multiplication
http://rosettacode.org/wiki/Ethiopian_Multiplication
Különösen finom / Extraordinarily tasty:
C++ template implementation
http://rosettacode.org/wiki/Ethiopian_Multiplication#C.2B.2B
2010-04-08
2010-04-07
Codepad
~ is an online compiler/interpreter, and a simple collaboration tool. Paste your code below, and codepad will run it and give you a short URL you can use to share it in chat or email.
http://www.codepad.org/
2010-04-02
Színesfém / Ferrous
Repülőtér: 500 milliárd forint. Drótvágó 500 forint. Két vágással megbénítani egy repülőteret: priceless.
http://bombahir.hu/belfoeld/hirek/1803-kabellopas-a-gripen-bazison
http://bombahir.hu/publicisztika/bombagyar/1804-dikma-szinesfim
Köszönet Csepinek
English version
Airport: 500 billion HUF. Wire cutter: 500 HUF. Disabling an airport with one cut: priceless.
Long story short: A piece of power wire was stolen from a Hungarian military airport by some poor people. The airport became disabled.
Thanks to Csepi
2010-03-30
Kenel Panic (game)
Kernel Panic is a game about computers. Systems, Hackers and Networks wage war in a matrix of DOOM! The only constraints are time and space; unlike other real time strategy games, no resource economy exists in KP.
All units are free in this game, every factory built will be spamming units at all times. You can build more factories, but only on pre-defined areas (geothermal vents). All that remains is pure strategy and tactics.
KP makes for a frantically fast-paced, action-oriented game, with a very unique graphical style.
http://springrts.com/wiki/Kernel_Panic
2010-03-29
2010-03-26
2010-03-23
Christ-Like Cruisin
http://www.youtube.com/watch?v=s7cAYV_lVNI
Paródia?
Segmentation fault, division by zero.
Webmail notifier / webmail értesítő
- Gmail (Gmail & Google Apps)
- Yahoo (yahoo.com, ymail.com, yahoo.co.jp)
- Hotmail (hotmail.com, msn.com, live.com)
- AOL (aol.com, aim.com, mail.com)
- Daum (daum.net, hanmail.net)
- Naver
- Nate (nate.com, empas.com)
- Paran (paran.com, hanmir.com)
- POP3/IMAP
2010-03-22
2010-03-19
Örökzöld / evergreen
Russian Singer Eduard Khil
http://hup.hu/treyblog/20100310/trolo_roll
Russian Singer Eduard Khil Remix
http://www.youtube.com/watch?v=MQ78IlJs5JQ
[HUN]
Mocsári Józsi (Jozin z Bazin magyarul)
http://hup.hu/treyblog/20100311/orokzold
2010-03-18
Project Euler
Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Although mathematics will help you arrive at elegant and efficient methods, the use of a computer and programming skills will be required to solve most problems.
The motivation for starting Project Euler, and its continuation, is to provide a platform for the inquiring mind to delve into unfamiliar areas and learn new concepts in a fun and recreational context.
Who are the problems aimed at?
The intended audience include students for whom the basic curriculum is not feeding their hunger to learn, adults whose background was not primarily mathematics but had an interest in things mathematical, and professionals who want to keep their problem solving and mathematics on the edge....
282 problems so far.
2010-03-17
[HUN] Társkeresés (x)
Non-artistic translation
I am a widow,
I live for my profession,
I am free of addictions,
I do serious scientific work,
I am a university professor.
I seek for a lady
who enjoys music,
likes nature,
goes to theatre,
romantic-minded, intelligent,
educated, and nice
who would suck me.