Code Optimization

Interesting things in software development and code optimization

Moving mouse makes video lagging - Windows 10

Hi friends,


have you noticed that, if you have windows 10 and Intel graphics chip, moving mouse over video or just moving mouse makes video lagging in a web video player?

I have Intel processor with built-in video card and I have noticed this problem. To solve it you need to do two simple steps under the Intel HD Graphics control panel:

- maximize performance on the plugged in mode

- maximize performance and disable power setting for the on-battery mode


more over, after I disabled it all I have noticed that YouTube video player started to work great in the full-screen (before this it didn't show video in full-screen mode) mode and whole laptop performance has been increased.


Enjoy it :)



1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Play audio with javascript under mobile browsers

Hello friends,


as some of you may know - there is a problem to start playing audio using javascript under mobile browsers.

This is a security feature and to be able to start playing audio you have to provide user with a button that user has to click to start playing audio.

In my case I was trying to play short audio file after some period of time but with no luck :(

After some research I found information that it was a security issue (not issue but security reason), and what I had come to is the following:

var audio = new Audio();

document.body.appendChild(audio);

audio.src='/Content/Audio/timer_001.mp3';

audio.loop = true;

var initSound = function () {

audio.play();

setTimeout(function () {

audio.pause();

}, 0);

document.removeEventListener('touchstart', initSound, false);

audio.pause();

}

document.addEventListener('touchstart', initSound, false);


So the main idea is to call audio.play and pause methods on first touch event.

After that each time your javascript code calls play or pause methods - browser plays audio.


Thank you,

see you :)




1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



There was an error running the selected code generator

Hi friends,


there is good article about OAuth/OWIN and MVC 5 that I did read to get an idea what this all is and how to work with that. But after I created a project and went through all steps in the article I had decided to add my own tables and controllers and I did face with the following problem:

so right after I did click the add button to add my controller and to extend the ApplicationDbContext with my models I did get this error again and again.

I did try all steps that I found through the internet but non of them did help me to solve this problem. After a few hours I spent on it I had come to the following solution:

- Open your working project folder.
- Delete the BIN folder
- Delete OBJ folder
- Clean Solution, Rebuild Solution and try to Add Controller


But if you will get another error, like I got, about something like " the AppData\Temp\xxxxx.dll can not be accessed because of it is used by another process" - you will have to stop your antivirus and in my case it was free Panda Antivirus.


Now everything should work and you don't need to change from System.Data.Entity.DbSet<> to System.Data.Entity.IDbSet<>

or whatever in your code.


Thank you :)


1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y



Print on Wood - Image overlay


Hello my dear friends,


in this post I will show you how to overlay one image over another image like if you would print an image over wood.

In this example we need two images, one is a wood image and another one is just a photo or whatever image do you like.

To make such effect we will do a few simple steps, here you are:

- create an empty image that will be a result image;

- draw your wood texture over that empty image;

- combine colors of the wood image and a photo, using the following formula c1 * c2 / 255.0;


The main thing here is to multiply each component of colors and divide it by 255.0. You do not need to do anything with alpha,

here is the short code:

for (int y = 0; y < surfWood.Bounds.Height; y++)

{

for (int x = 0; x < surfWood.Bounds.Width; x++)

{

color = surfWood.GetPixel(x, y);

color2 = surfSrc.GetPixel(x, y);

surfWood.SetPixelAsIs((byte)((double)color.R*(double)color2.R/255.0)

,(byte)((double)color.G*(double)color2.G/255.0)

,(byte)((double)color.B*(double)color2.B/255.0)

,color.A

, x, y);

}

}


 the result you will get is like the following:



so looks like you have printed out on a wood plate.


Thank you



1vqHSTrq1GEoEF7QsL8dhmJfRMDVxhv2y