2013-07-11

Consume CPU / create CPU load

As usual I found myself in need of something and after searching for a solution I stumbled upon something really interesting that I thought might be worth sharing or at least keep there for myself to read next time I'm in need of it.

This time around I wanted to see what happened to an application when it was under super heavy load (100% CPU).

Turns out the easiest solution to achieve that was to run a console command that comes with windows (at least I think it does? It exists on my machine at least; win7, but it might have arrived in some SDK that I have downloaded).

The program is called consume.exe and can be found in c:\Program Files (x86)\Microsoft SDKs\Windows\v7.0a\Bin\x64 (the last part might vary it seems).

What this does is that it gives you the ability to hog system resources for x amount of seconds.

If that doesn't give you what you needed you might find more information in regards to hogging resources on this StackExchange-url.

2013-06-08

Productivity and workflow improvements in a Windows environment

Today I decided that I should focus on improving my workflow by teaching myself some windows keyboard short keys similar to Win+E, Win+D, Win+R.

On Microsoft's support site they have a pretty updated and complete version of what keyboard shortcuts that exists and what they do and it taught me a couple of cool tricks. The most amazing one is definitely WIN + arrow keys.

What these macros do is that they resize/realign the current active window in many different ways. Left and Right aligns the window to the screen(s) and makes it possible to get items that are outside of displays to be moved into view again (OH BOY, FINALLY!!!). This also makes it easier to align windows next to one other since the window when moved snaps to the edges of the display. The Up and Down buttons are used to maximize/restore/minimize the current active window. Here I have only found use for Maximize/Restore-functionality.

Two other cool thing that I didn't know about prior to today is that:

  • alt+ print screen screen captures only current active window to clipboard
  • win+[1-9] starts/activates the program in the respective "pinned to taskbar"-slot
What I really was searching for today though, is functionality to minimize the current active window. It turns out that this was pretty easy by pressing alt+space+n/m (depending on OS-language). Unfortunately this wasn't really what I wanted and hence the search continued. 

And it didn't take long before I ran into an amazing program called AutoHotkey which makes it possible to pretty much rebind any input in Windows to do whatever you want. And it can also generate other keypresses/mousepresses for you depending on what you tell it to do.

It took me a while to get into the syntax and flow of the program but after just an hour I got it to do a much better minimize functionality than what was offered by stock windows. 

My version of minimize stores last minimized window and any additional click during a certain timeframe on that shortkey will restore the last minimized window. Next thing to use AutoHotkey for, is to make it generate boilerplate code for me whenever pressed :) (Also, I made win+c start calculator by writing #c:: Run calc.exe).

Link to AutoHotkey and here's the code to minimize/restore a window:


#SingleInstance force

time_before_reset := 1000
title := "foobar"
press_counter := 0

#m::
if press_counter = 0
{
WinGetTitle, title, A
WinMinimize,%title%
;MsgBox Minimizing %title%
press_counter := 1
SetTimer, reset_state, %time_before_reset%
return
} else {
;MsgBox Maximizing %title%
WinRestore, %title%
Gosub, reset_state
return
}

reset_state:
SetTimer, reset_state, off
press_counter := 0
return

2013-04-20

Proper event handling in a system

This will be another short post in regards to previously mentioned system about how a system should be structured for proper event handling...

I ran into next big issue, where multiple parts of the system listens to the same update events but where we need one system to be updated first and then the next one.

I really can't find a GOOD way to solve this issue from code. I can find multiple ways to solve it, but none really seems good enough. The usual and easiest way I guess would be that there will be "system wide commands" that is handled by a controller or similar and that that functions in turn calls public functions on other objects or triggers new commands that the model/view listens to.

However, I don't really like that system due to either a lot of public functions or all the issues with trying to debug a flow.

I have really come to like the idea of having a "visual schematic/flow view" where you traverse nodes and then put all synchronization and commands in that place instead of in code. Makes it easier to understand flows and easier to understand where one flow should stop and the next should start etc...

Might have to redo some things on my hobby projet... :o

2013-04-11

Useful VS shortcuts


alt + mouse drag - creates a "selectable box" that you can use to mark certain parts of vertically aligned items such as replace all "int" in a specific line or whatever
shift + alt + enter - fullscreen coding window (remove all crap windows when you don't need them)
ctrl + k + k - bookmark
ctrl + k + n - goto next bookmark
ctrl + / [or '] - command box where you can write stuff like >of melee to quick open file
ctrl + ] [or å] - goto matching brace
ctrl + shift + ] [or å] - select everything between matching brace
Ctrl + F10 - run to cursor when debugging
Ctrl + W - select current word

ctrl + shift + r - record temporary macro
ctrl + shift + p - run temporary macro
Ctrl + K + S - surround selected code with...
Ctrl + Shift + u - Make uppercase
Ctrl + u - Make lowercase

Issue with my event solution...

This will be a short update mostly as a note to self on why it is bad to use events or something with a strong connection between classes in a solution with garbage collections.

Basically, I have some home brewn event system based around

  • Singleton Controller
  • Event/Command with id[string]
  • Registering interest on controller with ( id[string], cb[Function/Delegate])
And then I would add connection between classes similar to this:
            Controller.instance.registerInterest("id_1", onSpawnParticles);
            Controller.instance.registerInterest("id_2", onReloadDatabase);

Now, due to the issue of the callback being a function, whenever I want to delete something that registered their interest at Controller I would have to manually remove all connections or else GC will always find connections to that class...

I probably should have done this solution with the help of Observer-pattern so I only get one callback and thus only have to do one "unregister" call for each class that falls out of scope... Much easier :o)

Ah well, good thing to learn the hard way :)

2013-04-01

How I finally got PS3 Media Server to work again

After many curse words I finally managed to find out why my PS3 could not find my PS3 Media Server (PS3MS).

This is the background for my scenario:

  • Running Windows 7 64-bit
  • In PS3MS traces, this text is shown : Access granted to /192.168.1.132 (my ps3 ip)
  • On PS3, I see Windows Media Server but no PS3MS
  • When I turn off windows firewall they find eachother
  • Turning it back on and looking at the pfirewall.log file (C:\windows\system32\logfiles\firewall\) with every log setting enabled I see that TCP-connections to port 5001 are dropped
  • After a lot of guessing. googling and bruteforce attempts, it turns out that those drops are due to calls to "javaw.exe".
Solution:
For me it was inbound connections that were dropped. When looking at inbound rules for Windows Firewall advanced settings.

I had all the regular things enabled (java.exe, PS3 Media server.exe and what not...)

I had the following items as blocked on my inbound rules:
TCP C:\program files (x86)\java\jre6\bin\javaw.exe
UDP C:\program files (x86)\java\jre6\bin\javaw.exe

I enabled those applications for port 5001 on the interface "Local Area Network" and I finally got a connection.

Also, make sure that C:\windows\syswow64\java.exe is enabled.

Me guessing on why this happens:
As I understand it, it seems like the issue is that PS3 Media Server is using the java binaries to handle network communication. Thus even if PS3MS is allowed communication through firewall the communication will still be dropped. Worst part is that all of this information and all this blocking is hidden for the user making it close to impossible to understand why something was blocked...

2013-03-12

Change language in SimCity

So, I got a bit sad after installing SimCity and I found out that I got it in Swedish.

I contacted Origin and they said that there is no way to change the localization/language setting. Well, turns out there is, but it requires some manual work (been working for me at least). I sat down with a colleague and started looking for localization settings and we found the following stuff...

We basically wanted to go from Swedish to English and this is how we did it...


  1. Insert disc containing data (you will need to get the dll-files from somewhere and I wont publish it)
  2. open up SimCity.zip (found on disc) in winrar or some other program
    1. copy the wanted GDFBinary_*.dll file to your "origin games\simcity" folder (gameFolder)
    2. in zip file, navigate to SimCityData\Locale\
      1. copy appropriate language folder into gameFolder\SimCity\Locale
      2. copy same language folder into gameFolder\SimCityData\Locale
    3. in zip file, navigate to SimCityRecovery\Locale\
      1. copy appropriate language folder into gameFolder\SimCityRecovery\Locale
  3. enter 'regedit' through start menu\run
    1. navigate to HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Maxis\SimCity
      1. change GDFBinary to your wanted dll-file (E:\games\SimCity\GDFBinary_en_US.dll)
      2. change locale to wanted language en_US

Enjoy!