Halaman

Jumat, 03 Juli 2015

Install Desktop on Linux VPS

Follow the following simple steps :

  1. sudo apt-get update
  2. sudo apt-get upgrade
  3. sudo apt-get install xfce4
  4. sudo apt-get install vnc4server
  5. vncserver :3000
  6. sudo fallocate -l 4G /swapfile
  7. sudo chmod 600 /swapfile
  8. sudo mkswap /swapfile
  9. sudo swapon /swapfile
  10. Set permanent swapfile: nano /etc/fstab
  11. add the line to /etc/fstb : /swapfile   none    swap    sw    0   0
now your vncserver is running on port : 8900 (because when running vnc server, we specify :3000, so it is 5900 + 3000 = 8900)

Connect using vncviewer client to the ip address xxx.xxx.xxx.xxx:8900 specify the password you typed on step 5, and then when loged in to the desktop on the terminal run startxfce4

Enjoy!

Senin, 08 Juni 2015

More simpler, setup wildcard subdomain on Ubuntu

$ sudo nano /etc/NetworkManager/NetworkManager.conf
- search for "dns=dnsmasq"
- replace with "#dns=dnsmasq"
$ sudo apt-get install dnsmasq
$ sudo nano /etc/dnsmasq.conf
- append line: "listen-address=127.0.0.1"
- append line: "bind-interfaces"
- append line: "address=/dev/127.0.0.1"
$ sudo netstat -plant | grep :53
- look for "NUMBER/dnsmasq"
$ sudo kill -9 NUMBER
- fill in the number you found for "NUMBER"
$ sudo service dnsmasq restart
$ sudo nano /etc/dhcp/dhclient.conf
- append line: "prepend domain-name-servers 127.0.0.1;"
$ sudo service network-manager restart

and to add a wildcard subdomain add to the virtual host directive
ServerAlias *.vhostdomain.com

On the courtesy of: http://www.leaseweblabs.com/2013/08/wildcard-dns-ubuntu-hosts-file-using-dnsmasq/

Selasa, 14 April 2015

Recursively chmod only on directories or files

A Very simple neat trick to chmod the directories/files
chmod 755 $(find /path/to/base/dir -type d)
and
chmod 644 $(find /path/to/base/dir -type f)
alternative: executing one by one, instead..
for files:
sudo find . -type f -exec chmod 644 {} \;
for directories
sudo find . -type d -exec chmod 755 {} \;
And if you are using that chmod, you are likely using that for your web server. Don't forget to install suPHP on apache, and then setup the configuration at /etc/suphp/suphp.conf and on your virtual host(s) add the 
php_admin_flag engine off
suPHP_Engine on

or perhaps using the fast-cgi approach

Cheers! :D

Setup Wildcard SubDomain on local computer


  1. Install Bind
  2. Install Webmin
  3. Configure server using webmin
    1. check if webmin service is run by running sudo service webmin start
    2. browse to the http://{YOUR_IP or LOCALHOST}:10000
    3. enter your root / sudoer account password
      1. Configure the bind service
        1. Forwarding and Transfer
          1. Enter google dns servers (8.8.8.8, 8.8.4.4)
      2. Configure the server (Servers >> Existing DNS Zones), if this is not shown, use the following command to install the bind-server:
        sudo apt-get install bind9 bind9utils bind9-doc and then refresh the modules on webmin
        1. Create master zone
        2. Domain name: enter your domain, example domain.do
        3. Email address: enter your valid email address format
        4. Edit master zone domain.do
          1. Name: domain.do
            Address: 127.0.0.1
          2. Name: *.domain.do
            Address: 127.0.0.1
        5. try to ping domain.do it should returns 127.0.0.1
If you are receiving a 503 error, try to change the directory mode to 0755 and the file to 0644
It is also important to put index.php (indexes file) on your root.
Don't forget to also add the directory to the list of accessible directory by Apache, **see the Apache configuration files**

:) Cheers!

Jumat, 05 September 2014

[MySQL] Using temporary variables on select statements

When your query need a long formula, to make it "maintainable" and "readable" you sometime need  the help of a temporary variable, simply put: you assign them on the select term by using the syntax:

@tempName := price * discount_percent as disc, @tempName2 := @tempName + price as net_price

And that should be it folks! ;)

Senin, 18 Agustus 2014

Solving Git always shows modified files even if they are not modified

Sometime when working on multiple environment(Windows, *nix), the new line character at the end is not visible to the human eye, but even if that is not visible, versioning system such as git will treat them as modifications.

When installing Git on windows machine, we usually press the "next" button rapidly that we are not aware that we are telling the Git to add automated "crlf" or "lf" to each line of the checked-out source code. The symptom such as :
  1. Always shows modified files even if we are not changing a particular file
  2. Even after revert or a hard --reset the modified files is showing
To remedy the situation use the following command in sequence:
  1. git config --global core.autocrlf false
  2. git reset --hard
  3. git status
The list of modified files which we are not modify should be gone now. 

Cheers! ;)

Jumat, 25 Juli 2014

[Haxe] Operator overloading!

yep, Haxe is powerful, but every language has their own weaknesses and strengths. To do a simple class overloading, we need to declare compilers meta and using 'abstracts' which are not quite comfy.. but for the sake of knowledge.. here is a snippet to implement a simple operator overloading in haxe..

@:allow(Mimit)
class _MyBase {
 var v: Int;
 public var y: Int;
 
 public function new(v: Int)
 {
  this.v = v;
  y = v * v;
 }
}

class _Mimit extends _MyBase{
 public function test() {
  trace(v);
 }
}

@:forward
abstract Mimit(_Mimit) from _Mimit to _Mimit {
 public function new(v:Int) this = new _Mimit(v);
 
 @:op(A + B) public function add(rhs:Mimit):Mimit {
  var t: Mimit = new Mimit(this.v + rhs.v);
  return t;
 }
}
let's analyze here for a momment...

  1. The class _MyBase needs a syntatix sugar of operator overloading, so that user could simply call _MyBase * _MyBase and use them accordingly
  2. Since the operator need to access 'private' member of the class we add the compiler's meta @:allow(Mimit) since the abstract Mimit will provided the overloads..
  3. And since the programmer will directly use the abstract class "Mimit" we declare another meta @:forward to the declaration, and telling the abstract to "implicitly" support _Mimit class on usages(fields and methods) by writing from _Mimit to _Mimit
  4. The from _Mimit to _Mimit basicly tells the compiler to please implicitly assign the this variable to _mimit and assign the this variable from _Mimit
There we have it, an operator overloading which works on haxe..
For the Usage: 
var m1: Mimit = new Mimit(10);
var m2: Mimit = new Mimit(20);
var m3: Mimit = m1 + m2;
  
m3.test();
trace(m3.y);
Frankly i'm not quite satisfied with things done this way.. a simple operator overloading made a bloated code base, i think i will stick to the static function..Cheers! :)

Rabu, 23 Juli 2014

[OpenFL/Haxe/HXCPP] Debugging

Playing with OpenFL is fun! mainly because of it's power for cross platform development.
Debugging program which target the flash platform is very easy, you just need the FlashDevelop software and download the flash player with the debug support

a step by step procedure to debug the "FLASH" target
  1. Open the project
  2. "Menu" »"Debug" »"Start Remote Session"
  3. Make sure you are using the "debug" configuration, and then press the "Play / Run" button
  4. Set's your breakpoints, inspect variables, etc is a snap..
If we are debugging windows target (hxcpp) this will introduce different approach, FlashDevelop currently working to support it 

But for those who like to use the command prompt, here is a step by step procedure..
  1. run "haxelib install hxcpp-debugger"
  2. on your project's application.xml add
    <haxedef name="HXCPP_DEBUGGER" />
    <haxelib name="hxcpp-debugger" />
  3. on your MAIN class file, add the import: "import debugger.Local;"
  4. on main haxe file, you need to add the function call
    new Local(true);
  5. run the program on your command prompt:
    lime test window
  6. It will run and then hit a default breakpoint, from there you should type "help" and read the documentation to proceed
  7. nice........
Haxe is quite mature, but it's cross platform nature made the debugging process which should be simple, becomes quite a challenging process, OpenFL supports html5 target, next i will try to learn on mapping js to haxe's source code using the technology source-code mappings on chrome and firefox browser..

Kamis, 05 Juni 2014

[Javascript] Uploading File Field using AJAX

This simple snippet will show you how to upload file through the AJAX `protocol` using pure Javascript
<form id="form" method="post" action="" enctype="multipart/form-data">
<input type="file" name="file"/>
<input type="submit" name="submit" value="submit"/>
</form>

<script>
 var form = document.getElementById('form');
 
 form.onsubmit = function(a){
  //get the file we would likt to submit
  var theFile = form.elements.namedItem("file").files[0];
  
  if(theFile != undefined){
   var xhr = new XMLHttpRequest(); 
   
   //monitor the on upload data progress (so we could implement the simple progress bar perhaps..?)
   xhr.upload.addEventListener("progress", function(e){ 
    console.log(e);
   }, false);
   
   //POST method with the target url of 'test.php'
   xhr.open( "POST" , "test.php");  
   
   var ff= new FormData();
   //append any post data here
   ff.append( "submit" , 1 );
   //append the file here
   ff.append( "file" , theFile );
   //finally send the ajax request!
   xhr.send(ff);
  }
  
  return false;
 }
</script>

Sabtu, 01 Februari 2014

[MySQL] Note about, listing table rows which is not mentioned on some other table row

Straight from StackOverflow:

SELECT table1.*
FROM table1
LEFT JOIN table2 ON table2.name=table1.name
LEFT JOIN table3 ON table3.name=table1.name
WHERE table2.name IS NULL AND table3.name IS NULL

MySQL, as well as all other systems except SQL Server, is able to optimize LEFT JOIN / IS NULL to return FALSE as soon the matching value is found, and it is the only system that cared to document this behavior. […] Since MySQL is not capable of using HASH and MERGE join algorithms, the only ANTI JOIN it is capable of is the NESTED LOOPS ANTI JOIN

Essentially, [NOT IN] is exactly the same plan that LEFT JOIN / IS NULL uses, despite the fact these plans are executed by the different branches of code and they look different in the results of EXPLAIN. The algorithms are in fact the same in fact and the queries complete in same time.

It’s hard to tell exact reason for [performance drop when using NOT EXISTS], since this drop is linear and does not seem to depend on data distribution, number of values in both tables etc., as long as both fields are indexed. Since there are three pieces of code in MySQL that essentialy do one job, it is possible that the code responsible for EXISTS makes some kind of an extra check which takes extra time.

Jumat, 31 Januari 2014

Lua, Function List on Notepad++

New feature for the notepad++ version 6.5.2! it could shows you the function list for the currently viewed document, function list for php, c++, c, perl is supported out-of the box

For those of you Lua programmer using notepad++, here is a simple how to add Lua function list to the notepad++
  1. Locate your %APP_DATA% folder, if you are using the zip distribution, go to your extraction directory
  2. Open functionList.xml
  3. On NotepadPlus >> functionList >> associationMap , see the commented LangID for LUA, on my installation it is 23
  4. Add the following
    <association langID="23" id="lua_function"/> on that section
  5. Creating the parser:
    on NotepadPlus >> functionList >> parsers add the following section
    <parser id="lua_function" displayName="Lua" commentExpr="((--\[\[.*--\]\])|(--.*?$))">
     <function
      mainExpr="function\s+(\w+[:\.])?(\w+\s*\(\s*[\w,\s]*\s*\))"
      displayMode="$className->$functionName">
      <functionName>
       <nameExpr expr="\w+\s*\(\s*[\w,\s]*\s*\)"/>
      </functionName>
      <className>
       <nameExpr expr="[\w]+(?=[\s]*[:.])"/>
      </className>
     </function>
    </parser>
    
  6. Warning: if you copy paste xml content on line 5, please make sure that the xml properties are in one line, if they appear to be 2 line, it is because html page wordwrapping ;)
  7. Restart notepad++
  8. Open your lua file, open function list panel (Menu >> View >> FunctionList)
If the functions is not showing, chances are :
  1. You are using Gary's mod lua lexer.. uninstalling it should overcome the problem
  2. Wrong language ID noted from step 3
That's all! :)
Have fun!

Minggu, 26 Januari 2014

How to find out built in defines from a specific GCC compiler?

A little trick i read from LuaJit's makefile and the gcc manual page. To list all built-in defines use the following (assuming that you don't have yohan.h file on the current directory..)

# touch yohan.h
# gcc -E -dM yohan.h

and if the "yohan.h" contains your own code of defines, it will also be resolved.. giving you the exact picture of what's happening with your sources defines

Selasa, 07 Januari 2014

[c++, c#] Journey of cross compiling mono 3.2.5, utilizing ScratchBox2

This one is a tough one, usually i get away compiling just by trial-and-error after successfully compiling the library for the windows target. But compiling this one is very much a challenge.. and then out of curiosity.. here i am writing this blog entry so that someday i could revisit and think .. what the **** am i doing compiling libraries and not doing those projects!

Well if my future me see this post, "I do it because of cross environment, playbook, win 7.5, vala, mono, xna, cocos2dxna, and Pou.. i bet you will understand and remember.. hehe, and yes, i know, it is very silly.. but Y.O.L.O!"

So let's go with it shall we..

After trying to compile using BB NDK SDK version 2.1 i encountered problem with the assembler compilation. If i can recall the error correctly, the message was "invalid operation $03" or something similar like that..

After 2 nights of blackened eyes, i give up and then tried to compile on a virtual machine, for that machine i choose LINUX Mint 15 for the OS, chosen simply because the OS iso file lying around on my hard-disk. For the virtualization, i'm using vmware

I was thinking about using linux because i could simply use ./configure and then make, but i think to myself it would be better if i could directly compile this for the arm architecture, after diving to google, there is a very exciting project callled Scratchbox2, and then here i am using the command

$ sudo apt-get install scratchbox2
$ sudo apt-get install qemu

Then i tried to find linux arm compiler toolchain, for this purpose i search for the file arm2009q1-203-none-linux-gnueabi simply because that is the compiler i used in Windows when venturing with WebOS.. (love that platform.. hixs..)

here is the name of the file i downloaded from codesourcery: arm-2009q1-203-arm-none-linux-gnueabi.bin

What?? you need the web address you say? here it is: http://sourcery.mentor.com/public/gnu_toolchain/arm-none-linux-gnueabi/

Let's go to the terminal and then type the following..

$ chmod +x arm2009*
$ ./arm2009*

Follow those installation screen with care, i choose to install on default directory.. and that is at $HOME/CodeSourcery

Here is the trick! if i use sb2-init with the -c and without -C -static it will fail to run sb2-build-libtool! don't know about that -c, but if i did not specify -C -static, the compiled will try to find the library linux.so.3, about the -lpthread, that's because when compiling mono, there are undefined references to pthread, so i decided to put that to default.. maybe we should find a cleaner solution to this

Therefore here is the command i use to initialize sb2

$ sb2-init -d -C "-static -lpthread" arm $HOME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc

$ sb2-init -d arm $HOME/CodeSourcery/Sourcery_G++_Lite/bin/arm-none-linux-gnueabi-gcc

when not using this arm-2009q1-203-arm-none-linux-gnueabi.bin release, for example using built in arm-linux-gnuebi-gcc (from the apt), i failed to run sb2-build-libtool, a workaround would be adding parameter -C "-static" to sb2-init but i guess this would break some build system.. note to self: Need to find-out building custom rootfs! (finger crossed, perhaps copying the libc content? hehe..)

important! you need to init sb2 in $HOME/CodeSourcery/Sourcery_G++_Lite/arm-none-linux-gnueabi/libc because that is the rootfs for that toolchain

let's try with a simple hello world program shall we..

$ sb2
$ gcc hello.cpp -o hello
$ file hello --> this should show that we have compiled for the arm-architecture! ;)
$ ./hello --> will run!
$ exit ->> this will exit us from the "jail" arm-environment we had setup earlier

Ok, now is the fun part, let's go to the extracted tarball mono source folder, cross your fingers :p and then type

$ sb2
$ ./configure --with-monotouch=no --without-mcs-docs --disable-mono-debugger CFLAGS="-DBROKEN_64BIT_ATOMICS_INTRINSIC -DARM_FPU_NONE" LIBS=-lpthread --disable-mcs-build

The configuration is a success!

But, the potential horror might now came along.. anyway.. let's proceed!

before make! i add the patch to the mono/mini/mini.arm.h
#define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1
change that to
//#define MONO_ARCH_SOFT_DEBUG_SUPPORTED 1

on the same terminal, lets go make some!

$ make
$ make install DESTDIR=$HOME/mymono

there you have it! a compiled mono for arm architecture!

Some hints:

for the mono's ./configure script, to show the options accepted by the configure run
$ ./configure --help

Ps. If you like and learn something from other people, and you can't or don't want to donate to them directly, show your support by sharing the article, google+ing the article, or perhaps checking out the advertisements which may appear on the website ;) many thanks before!







Rabu, 13 November 2013

c++ defines, what is the meaning of that dreaded ## signs.. :)

That ## syntax maybe looks like evil, but as a lovely c++ programmer, you need to use and get familiar with that syntax

When i first saw this syntax.. the ants starts to creep on my stomach as my lack of skill in pronounces, i could not find the right keyword to google that '##' syntax.. :(

when you see something like this on some c++ header file:

#define CF(className) create##ClassName(){}


this macro if applied for example..

CF(kittyClass);

That macro, by the compiler will be translated to

createKittyClass(){};

Yep, and that is all folks.. :)

Jumat, 02 Agustus 2013

[Tizen] Problem starting emulator

Does your hardware support hardware virtualization? if not i share your pain :( if you download and install the Tizen SDK ver 2.1 there is a solution posted to make your emulator runs.. yes it runs.. but it is veeeryyyy slooowww..

Steps:

  1. Create your new emulator
  2. Run the emulator
  3. Wait for it to load
  4. Right click and then open the shell
  5. Type the following command : 
    1. su
    2. sed -i 's/notify/oneshot/g' /usr/lib/systemd/system/user-session@.service
  6. If you would like to use the manual way of changing that one, buut this one is on your OS'es command prompt
    1. sdb pull /usr/lib/systemd/system/user-session@.service user-session@.service
    2. Edit that file using notepad, Modify "Type=notify" to "Type=oneshot"
    3. sdb push user-session@.service /usr/lib/systemd/system/user-session@.service
    4. Now verify by typing these on your emulator's shell:
      cat /usr/lib/systemd/system/user-session@.service
  7. Restart the emulator

Senin, 01 Juli 2013

[Wordpress]problem of wordpress post thumbnail images not resized correctly

Let's open the article with the following code snippet, taken from WP's(WordPress'es) function image_get_intermediate_size from the file media.php from

   if ( ( $data['width'] == $size[0] && $data['height'] <= $size[1] ) || ( $data['height'] == $size[1] && $data['width'] <= $size[0] ) ) {
   $file = $data['file'];
    list($width, $height) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
    return compact( 'file', 'width', 'height' );
   }

Well, what's wrong with that statement? there is nothing wrong with that statement, it is just that when you have an original image size which width or height was the same as the default thumbnail size, since the autogenerated thumbnail width is always lesser than the original image, then the 'autogenerated' thumbnail size will always be returned

Consider the following example, you have your original image at the resolution of 200px * 135px.
Note that the default thumbnail size generated by WP is 150px * 135px, and then you have the following code which is intended to show the featured image for the current page:

<?php echo get_the_post_thumbnail($page->ID, array(200, 135)); ?>

You will not get your 200px * 135px as you intended, instead the code will give you a 150px * 135px thumbnail size, since the later rule from the if stament presented earlier fits to these sizes perfectly, it will gives you a cropped and scaled image of 150px * 135px

A fast fix would be specifying get_the_post_thumbnail($page->ID, array(200, 136)) which will give you a 'slightly distorted' thumbnail, another fix would be implementing a default thumbnail size via WP's function set_post_thumbnail_size on your theme's function.php file

Minggu, 26 Mei 2013

[Delphi] DevExpress Ribbon - how to

Since it's is a rather sparse documentation, i think i will try to post how to add a Ribbon Control to the Delphi XE application

  1. Open Delphi!
  2. Create a new VCL Form Application
  3. Open your main pas file
  4. Change the ancestor for the TForm, to TdxCustomRibbonForm
  5. Add the unit dxRibbon
  6. Drop a dxBarManager and then assign it to your dxRibbon
  7. On dxRibbon, right click and then choose Tabs Editor..
  8. Add a TdxRibbonTab, and then highlight that newly created ribbon tab
  9. On you inspector, click on Groups and then click on the ellipsis to create a new Ribbon Tab Group
  10. For the time being, leave it as is..
  11. Double click you dxBarManager, create a new Toolbar
  12. Create a new command and then drop that command to your toolbar
  13. Now let's go back to your previously created Ribbon Tab Group, in the inspector, see the property Toolbar and assign it the toolbar you created on step 11
  14. Okayh, that's one great strong basic, now go wild!
Cheers!

Kamis, 17 Januari 2013

[YII] Quick Start, YII Tutorial in 2 minutes!

Yii as simple as 1..2..3 For this tutorial, i assume that you are working in windows environtment and already setup your local webserver (xampp, wamp, etc..)
  1. Download Yii anywhere you wanted, extract them to any folder you wanted.., for this example let's say after you download the zip file, you extract it to c:\yii
  2. Open up command prompt / terminal
  3. Change your dir to the directory where you put your php.exe, in my case it is in C:\xampp\php
  4. On that dir, execute the command:
    php "C:\yii\framework\yiic" webapp MyAppName
  5. Now move the folder MyAppName to your htdocs folder,
    in my case i move entire folder to C:\xampp\htdocs
  6. That is it.. now you have a fully working MVC Yii application
    Open your browser and then go to the address http://localhost/MyAppName

Rabu, 16 Januari 2013

[Delphi] MDI On a TPanel, RTTI power example

Ummh, since it's 3 AM, and just as a quick note on delphi power, MDI child on a TPanel and an introduction to a RTTI usage..
You will need Delphi XE and TMS Component
procedure TForm1.AdvOfficeMDITabSet1TabClose(Sender: TObject;
  TabIndex: Integer; var Allow: Boolean);
var
  form : TForm;
begin
  form := AdvOfficeMDITabSet1.GetChildForm(AdvOfficeMDITabSet1.AdvOfficeTabs[TabIndex]);
  form.Close;
  Allow := False;
end;

procedure TForm1.New1Click(Sender: TObject);
var
  c : TForm;
begin
  c := TForm2.Create(Self);
  c.Parent := Panel2;
  c.SetBounds(0, 0, Panel2.Width, Panel2.Height);
  c.Caption := 'Yohan ' + IntToStr(Panel2.ControlCount);
  (c as TForm2).EllipsLabel1.Caption := c.Caption;
  c.Show;

  //introducing the power of delphi RTTI!
  if(c.ClassType = TForm2) then
    AdvOfficeMDITabSet1.AddTab(c);
end;


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