Thursday, October 29, 2015

How to permanently disable Windows Defender

By default in Windows 10, Windows defender will turn back on again after being disabled after some time. However, if you are doing something that requires not having a AV (like creating a honeypot VM). You might find this handy.

Run the command gpedit.msc
This will bring up local group policy handling.
Navigate to:
Administrative templates - Windows components - Windows defender - Turn off Windows defender

Hit 'enable', and Windows defender should be turned off indefinently.


Friday, September 25, 2015

Counting all nodes and items in a tree structure (JS)

It's been a long time since last post, and altho this is rather mundane, here is an update:

Case: Im recieving data from the server as a gigantic object tree structure (like shown below). The data is displayed on a webpage in a suitable AngularJS directive. However, when the number of objects are more than 100 the view has to be set to only show a summary. So, how do you count a tree?
Solution:

var CountAllNodesInTree = function (treeObject) {
    this.counter = 0;
    self.countTree = function (treeObj) {
        self.counter = 0;
        self.countLeaves(treeObj);
        return self.counter;
    }

    self.countLeaves = function (treeObj) {
        if (treeObj) {
            self.counter++; // count department
            if (treeObj.Items) {
                self.counter += treeObj.Items.length; 
            }
            if (treeObj.Children) {
                if (treeObj.Children[0]) {
                    for (var i = 0; i < treeObj.Children.length; i++) {
                        if (treeObj.Children[i]) 
                            self.countLeaves(treeObj.Children[i]);
                    }
                }
            }
        }
    }
    return self.countTree(treeObject);
}

Monday, July 20, 2015

Multiple lines of code in chrome console

There are times when you need to run some code on your page to see how some changes would look. Or maybe just mess about on a friends computer. Nevertheless you might not be able to do all your console operations with just one line at a time.

So how do you run multiple lines of code in the Chrome debugger console?
Turns out you can just create a function:
And once you have declared your function, you run it.

Saturday, July 18, 2015

Watch that UTF8 when serving JSON

Im currently messing about with Node.JS after deploying a droplet on DigitalOcean.  Heard alot of people talking about DigitalOcean before, but never tried it untill now. That server was so incredibly simple to set up, i'm speechless.


I will post a guide on how to quickly get multiple node sessions running in a bit, but for now i will just mention this little detail i ran across. I had a bit of a head-scratcher when writing my first Node service for serving up some Json data. It worked nice and dandy, but coming from Norway my Json data contains alot of special characters, like Æ, Ø and Å.

These characters went missing when my file was being served. Turns out it was just bad encoding. Setting the encoding to UTF8 solved the problem. So check that!

Friday, July 17, 2015

MSMQ - Bare minimum example

Sometimes you need a project to be split into two programs but still pass data between eachother. A normal way of doing this would be with a webserver, like a WCF service.
There is however a simpler way of achieving this functionality, using a windows preinstalled component called MSMQ.

MSMQ is a message queue system. An application can push messages to a queue and another application can read them out. MSMQ also has the advantage of keeping queue messages even if a client goes offline. The messages can then be retrieved the next time the client comes online.

The code:
This first code snippet initializes the queue:
public static MessageQueue mq;
private void btnInitQueue_Click(object sender, EventArgs e)
{
 // Create queue or connect to an existing queue
 if (MessageQueue.Exists(@".\Private$\MyQueue"))
 {
  mq = new MessageQueue(@".\Private$\MyQueue");
 }
 else
 {
  mq = MessageQueue.Create(@".\Private$\MyQueue");
 }
}

This next snippet adds a string message to the queue:
private void btnSendMessage_Click(object sender, EventArgs e)
{
 // This adds a message to the queue
 System.Messaging.Message mm = new System.Messaging.Message();
 mm.Body = textBox1.Text;
 mq.Send(mm);
}

And this last snippet is used to read out the messages from the queue:
private void btnReadOutMessages_Click(object sender, EventArgs e)
{
 // This retrieves all messages in the queue, processes them and deletes them 
 System.Messaging.Message[] messages = mq.GetAllMessages();
 foreach (System.Messaging.Message m in messages)
 {
  // Need to read the messages with a formatter
  m.Formatter = new XmlMessageFormatter(new String[] { "System.String,mscorlib" });
  richTextBox1.AppendText(m.Body.ToString());
 }
 mq.Purge();
}

Notice we need to apply a formatter when reading data out from the queue.

Wednesday, June 17, 2015

Learning JavaScript the hard way: 1 - dont minify in beta

Being a seasoned vet with C# i find the world of javascript rather sensible, although there are a few pitfalls. One difference is the use of minified files. Since javascript is parsed, rather than compiled there is a great push to make the source as small as possible, thus allowing for faster loading sites.

One way of achieving this would be to write javascript the same way C++ devs write their code; with truncated and unreadable variable names, and without any comments except the ever so loved "\\change this".

The good news is that javascript devs are not C++ autists, and the prefered solution is a fair bit more sane.

The common practice is called minifying. And it consists of parsing the source files thru a program that changes out every var with a short-as-possible name, and removes all unneded whitespace and comments. This makes the code unreadable for sane humans, but saves space.

 Below is an example of code minified using http://jscompress.com/

This is a normal un-minified javascript function (388 bytes)
This is the same function minified (188 bytes)
But back to the problems: Being new to javascript i just downloaded the minified versions of all my libs (angularJS, jQuery etc.) and this lead to problems during debugging, as all the error messages were less than readable.

Switching out the minified files with the large uncompressed ones made things alot easier.

Friday, June 12, 2015

WCF on IIS: configure permissions

I modified my WCF service to get/set data from a SQL database, in order to make it a usefull service. And after adding the functions i needed i debugged it and everything looked fine. But then upon uploading it to my IIS server i was unable to get access.

The problem was inadequate permissions, and so i started down a long road of error checking.

First off all i checked these two off my list:

  • Newcomer advice 1: Install WCF support for IIS
  • Newcomer advice 2: Add the service as an application in IIS Manager


Having done those the first step i had to do was changing the permissions to use the ApplicationPool:
After doing this i was allowed to view my site, or at least the non descriptive error messages it gave me.


The second step i did was change my web.config a little, so i could get descriptive error messages:

Now I could see there was something wrong with my SQL permissions, as IIS APPPOOL\ASP.NET v4.5 was denied access. So next step was to open SQL Management Studio and add this name as a user:


After adding the user, and setting my table 'arbeidslog' as the default for the user i added the permission 'db_owner' on the User Mapping dialog. (Security -> Logins -> IIS APPPOOL\ASP.NET v4.5)

And that was it, Service is now spitting JSON from my database just like it's supposed to.

Wednesday, June 10, 2015

An example of a WCF web service that returns JSON


Currently developing a project in javascript, and at some point or another that means getting recieving some data from the server. Doing this properly, and for cross platform support means writing a service that can push JSON data.

VisualStudio has a nice template setup for WCF and ASMX services, but they push XML by default.
Some modification is needed for JSON, and also some web.config changes should be made to allow for cross domain interaction.

A sample project is uploaded here (zipped):
https://drive.google.com/file/d/0B6AihF9gdNcnWHEzZkZtNWVpUXM/view?usp=sharing

Sunday, March 29, 2015

Goal Seek

Goal Seek is a rather usefull function in MS Excel, but it's also one i had not used since Office 2010. And when the need presented itself just recently i spent a few minutes finding it. So here is a reference for myself; this is where you find Goal Seek in Excel:


Monday, February 16, 2015

Delete a specific autocomplete entry in Chrome

You might have used a site in the past that moved to a new domain, or you might just have a really awkward search history. There are good reasons for removing your autocomplete entries, and you might want to do so without deleting your entire search history.

And you dont have too either, just mark the bothersome entry and press SHIFT + DELETE to remove it.

An excelent example is the site kickass.so that recently moved back to it's .to domain due to some legal issues. It's so stressing to reach the wrong url when you just want to download an old linux distro in a hurry!


Thursday, January 29, 2015

Ardunno? Getting a fake Arduino Nano to work

An Arduino is a wonderfull thing, and i encourage everyone to support the project by buying one legit one. There are however also some cheap clones for sale on ebay like this one:


It's a NANO DCCduino, and it's pretty much an exact copy of the original Arduino Nano. I bought this online about a year ago for real cheap. I then forgot all about it untill now when my other Arduinos are occupied in other project and i just felt like testing the new servo i got in the mail today.

There were however a real issue with this knockoff. Unlike real Aduinos that show up in device manager as an "Arduino" this clone looked like this, and i was not able to upload my sketches:



Now the reason for this is that these chips dont use the FTDI chip as the regular Arduinos do. They in stead use CH340G for interfacing thru USB. And as such this requires a different driver set.
In one way this is a good thing, considering the recent FTDI anti-pirate trickery.

The CH340G driver is available for download from:
http://www.5v.ru/ch340g.htm

And a mirror for the installer here:
https://drive.google.com/file/d/0B6AihF9gdNcnSGtkVFYzM080NUE/view?usp=sharing



Friday, January 16, 2015

Win + PrtScreen


  • Win + PrtScreen 
This key combo saves a screenshot to User/Pictures/Screenshots

I didn't even know...

Tuesday, January 13, 2015

Testing Windows 10 - Virtual desktops

Windows 10 is now out as a tech preview (for free) and im currently running it as my main OS, and have done so now for a couple of weeks. I will post a few things i've noticed as i get the time, first off:






  • Virtual desktops (sort off)
If you have used linux you probably know about virtual desktops, or if you have owned a ATI card with hydra vision (back in 2013 or so).
Now they have tried to adopt this into Windows but it's not the way you might know it from linux with totally separate desktops. This is more a way of minimizing/restoring apps in bulk (nothing disapears from the taskbar).

When running linux a few years ago i found this feature neat. But it didn't really improve my workflow, it rather just made my mess less visible and gradually hugging more and more ram in the background. This solution might be better in that regards, as everything stays on the taskbar so nothing is forgotten.

I've not yet been using this feature a whole lot but i like the idea.



Monday, January 12, 2015

Android not liking my certificates

At my local college you need to install and use a certificate for access to the WiFi network. This is a quite common thing, and is really no problem setting up. However when upgrading my phone's OS i ran into an issue with this annoing warning message:


Telling me that the certificate might allow strangers to snoop on my internet activity, while in fact the oposite should be true. Anyways the message is highly annoying, and pops up at every reboot.

Now the solution for this is to simply move this user installed certificate from the "user installed" - folder over to the "system installed" -folder. Since Android doesn't throw this warning for the system certs. This solution requires root.


Using a file manager with root access (I use Root Explorer) go to:
/data/misc/keychain/cacerts-added/


This is where you will find your user certs. Copy it over to this folder:
/system/etc/security/cacerts/


And you will no longer be bothered with this annoyance in the future :)