Halaman

Jumat, 30 November 2012

[Debian VPS]Installing lamp, till bind9

Edited: 29 Jan 2015
To manage this kind of things, let's use a more powerfull thing which is called Webmin. Download the debian package, and then setup Apache Virtual Hosts, and Bind Configuration from there.

side note: when installing bind to the VPS, we should set the DNS Server to 127.0.0.1 (localhost) and then set the bind dns forwarding accordingly.

-----------OLD ARTICLE STARTING-------->>

I was tempted with the low price on vps these days, and it's my goal someday to create a multiplayer game.. err not multiplayer.. but online where people could play and compete with each other online.. ;)

any whoo..

the steps..

  1. After you receive your username, password, and ip address, log in to you vps SSH by ussing putty
  2. Start by upgrading.. aptitude update && aptitude upgrade
  3. Next, install mysql aptitude install mysql-server mysql-client
  4. Enter you mysql username and password, don't lose it
  5. install the server aptitude install apache2 apache2-doc

Minggu, 25 November 2012

[c++]Void Ptr storing your pointer to classes

A quick note, if you do store your inherited class, and then store them to a void pointer. Later on you call a method which is "public" from the parent class, please remember to static cast your void ptr to the parent class because:

DerivedClass *dc = new DerivedClass();
void *ptr = dc;

..
..
some mumbo jumbo.. :)
..
..

void SomeFunction(void *ptr)
{
BaseClass *base = (BaseClass*)ptr;
//this will give you access violation which willl gives you a head scratcher.. i've been there.. :'(
}

to fix above situation, you should

BaseClass *dc = new DerivedClass();
void *ptr = dc

//.. now it is safe to use
//that SomeFunction

..why?? dunno.. but it worth as a note.. well at least for me that is.. hehe ;) Cheers!

Jumat, 02 November 2012

[c++] Function Pointers Snippet

Hi there, let the code speaks for it self.. ;)


// funtors.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"

typedef float (*MyFuncPtrType)(int, char *);
MyFuncPtrType my_func_ptr;

float test_func(int a, char *c)
{
 fprintf(stderr, "in a function with argument: %d, %s\n", a, c);
 fflush(stderr);

 return a + 10.123f;
}

class functors;

typedef float (functors::*ClassMemFuncPtr)(int, char *);
// For const member functions, it's declared like this:
typedef float (functors::*ClassConstMemFuncPtr)(int, char *) const;

class functors
{
public:
 virtual ~functors()
 {
  obj = 0;
 }

 void invoke()
 {
  (obj->*memx)(10, "Yeah!!");
 }

 void bind_x(MyFuncPtrType funcPtr)
 {
  x = funcPtr;
 }

 float invoke_x(int a, char* c)
 {
  return x(a, c);
 }

 void bind_memx(functors *obj, ClassMemFuncPtr mem_func)
 {
  this->obj = obj;
  memx = mem_func;
 }

 float invoke_memx()
 {
  return (obj->*memx)(11, "Uh yeahh.. i'm invoked!!");
 }


private:
 MyFuncPtrType x;
 ClassMemFuncPtr memx;

 functors *obj;
};

class derived: public functors
{
public:
 float derived_func(int a, char *c)
 {
  fprintf(stderr, "I got called with the following params: %d, %s", a, c);
  return 1.01111f;
 }
};

int _tmain(int argc, _TCHAR* argv[])
{
 my_func_ptr = test_func;

 float a = my_func_ptr(10, "yohan");
 fprintf(stderr, "%f\n", a);
 fflush(stderr);

 functors *base = new functors();

 base->bind_x(test_func);

 a = base->invoke_x(11, "pandewi");
 fprintf(stderr, "%f\n", a);
 fflush(stderr);

 //testing member function..
 derived *the_derived = new derived();

 base->bind_memx(the_derived, static_cast(&derived::derived_func));

 base->invoke_memx();

 delete the_derived;

 base->invoke_memx();

 delete base;

 return 0;
}