Thursday, December 22, 2016

Linux - Convenience Settings

To make directory color and VIM comment color visible in dark background
.vimrc:  set bg=dark
.dir_colors:  DIR 01;36

To make VIM tab space = 4 instead of 8
.vimrc:  set tabstop=4

How to create React apps with "Create-React-App"?

https://github.com/facebookincubator/create-react-app

Installation
npm install -g create-react-app


Create app

create-react-app my-app
cd my-app/

Start Server to see your app
npm start

Then open http://localhost:3000/ to see your app.


Deployment

When you’re ready to deploy to production, create a minified bundle with 

npm run build

Inside the directory

Inside that directory, you can run several commands:

  npm start
    Starts the development server.

  npm run build
    Bundles the app into static files for production.

  npm test
    Starts the test runner.

  npm run eject
    Removes this tool and copies build dependencies, configuration files
    and scripts into the app directory. If you do this, you can’t go back!

We suggest that you begin by typing:

  cd MyReactApp1
  npm start


Tuesday, April 19, 2016

How to overcome 2gb ram limit on visual studio 2015 emulators?

https://guido1993.wordpress.com/2015/05/05/how-to-overcome-the-2-gb-ram-limit-on-android-visual-studio-2015-emulators/

“Visual Studio Emulator for Android: The emulator is unable to verify that the virtual machine is running: Not enough memory is available in the system to start an emulator that uses 2048 MB of startup RAM. Please close other applications and try to launch the emulator again. If closing other applications doesn’t help, please follow the instructions on this KB article: http://support.microsoft.com/kb/2911380/en-us”

C:\Users\[YourUserName]\AppData\Local\Microsoft\VisualStudioEmulator\Android\Containers\Local\Devices


In the config files, change 

device.vm.ram.size=2048 to
device.vm.ram.size=1024


FROM: device.vm.ram.size=2048
TO: device.vm.ram.size=1024

Wednesday, November 11, 2015

Clean Install Windows 10 from Windows 8 (resolve activation problem)

1. From within Windows 8, update to Windows 10
2. Activate Windows 10
3. Create Installation Media (Thumbdrive)
4. Boot from Installation Media, format disk and install Windows 10 again
5. If have problem activating - type "slmgr.vbs /ato" (without quotes)  from command prompt (as administrator)

Wednesday, October 21, 2015

How to dramatically increase the performance of WinForm DataGridView?

Add this extension method:

public static void DoubleBuffered(this DataGridView dgv, bool setting)
{
    Type dgvType = dgv.GetType();
    PropertyInfo pi = dgvType.GetProperty("DoubleBuffered",
          BindingFlags.Instance | BindingFlags.NonPublic);
    pi.SetValue(dgv, setting, null);
}

Monday, February 23, 2015

How to make an eventhandler run asynchronously?

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace WindowsFormsApplication6
{
    public partial class Form1 : Form
    {
        private Thread SecondaryThread;

        public Form1()
        {
            InitializeComponent();

            OperationFinished += callback1;
            OperationFinished += callback2;
            OperationFinished += callback3;
        }
       
        private void Form1_Load(object sender, EventArgs e)
        {
            SecondaryThread = new Thread(new ThreadStart(SecondaryThreadMethod));
            SecondaryThread.Start();
        }

         private void SecondaryThreadMethod()
         {
            Stopwatch sw = new Stopwatch();
            sw.Restart();

            OnOperationFinished(new MessageEventArg("test1"));
            OnOperationFinished(new MessageEventArg("test2"));
            OnOperationFinished(new MessageEventArg("test3"));

            OnOperationFinished(new MessageEventArg("test4"));
            OnOperationFinished(new MessageEventArg("test5"));
            OnOperationFinished(new MessageEventArg("test6"));

            OnOperationFinished(new MessageEventArg("test7"));
            OnOperationFinished(new MessageEventArg("test8"));
            OnOperationFinished(new MessageEventArg("test9"));
            //This is where the program waits for whatever operations take
                 //place when OperationFinished is triggered.

            sw.Stop();

            Invoke((MethodInvoker)delegate
            {
                richTextBox1.Text += "Time taken (ms): " + sw.ElapsedMilliseconds + "\n";
            });
         }

        void callback1(object sender, MessageEventArg e)
        {
            Thread.Sleep(2000);
            Invoke((MethodInvoker)delegate
            {
                richTextBox1.Text += e.Message + "\n";
            });
        }
        void callback2(object sender, MessageEventArg e)
        {
            Thread.Sleep(2000);
            Invoke((MethodInvoker)delegate
            {
                richTextBox1.Text += e.Message + "\n";
            });
        }

        void callback3(object sender, MessageEventArg e)
        {
            Thread.Sleep(2000);
            Invoke((MethodInvoker)delegate
            {
                richTextBox1.Text += e.Message + "\n";
            });
        }

        public event EventHandler<MessageEventArg> OperationFinished;

        protected void OnOperationFinished(MessageEventArg e)
        {
            //##### Method1 - Event raised on the same thread #####
            //EventHandler<MessageEventArg> handler = OperationFinished;

            //if (handler != null)
            //{
            //    handler(this, e);
            //}

            //##### Method2 - Event raised on (the same) separate thread for all listener #####
            EventHandler<MessageEventArg> handler = OperationFinished;

            if (handler != null)
            {
                Task.Factory.StartNew(() => handler(this, e));
            }

            //##### Method3 - Event raised on different threads for each listener #####
            //if (OperationFinished != null)
            //{
            //    foreach (EventHandler<MessageEventArg> handler in OperationFinished.GetInvocationList())
            //    {
            //        Task.Factory.FromAsync((asyncCallback, @object) => handler.BeginInvoke(this, e, asyncCallback, @object), handler.EndInvoke, null);
            //    }
            //}
        }
    }

    public class MessageEventArg : EventArgs
    {
        public string Message { get; set; }

        public MessageEventArg(string message)
        {
            this.Message = message;
        }
    }
}

Tuesday, July 15, 2014

Setting up GCC in Linux

Setting Cloud Linux Server
http://aws.amazon.com/ec2/

Setting up GCC in Linux
http://www.cyberciti.biz/faq/centos-linux-install-gcc-c-c-compiler/ (G++ V4.4)
http://unix.stackexchange.com/questions/63587/how-to-install-g-4-7-2-c11-on-centos-5-x (G++  V4.7)