2014-10-06

Changing shortcuts in 'Save As'-dialog

I usually restructure my folders on hard drive a bit to keep documents in separate paths depending on project, and usually they don't exist in "my document"-folder. Which makes it a hassle whenever I want to save a document into that folder since the default "save as"-dialog only contains predefined links.

So, today I decided to find out how to work around this, and turns out it is possible, you just need to do some registry magic.

Here's how:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies
Create a new key named 'comdlg32'
Create a new key in that key named 'Placesbar'

Create a new string named 'Place0' and type folder (MyComputer)
Create a new string named 'Place1' and type folder (E:\[Work]\[proj_x])
Create a new string named 'Place2' and type folder (MyDocuments)

(for clarity, this is where all the strings are located: HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Policies\comdlg32\Placesbar\...)

Other pre-defined shortcuts of interest:
  • MyDocuments
  • MyPictures
  • MyMusic
  • MyFavorites
  • Desktop
  • ProgramFiles
  • Recent
Victory!

2013-10-23

Setting up a WAMP-server (and how I got through all the issues)

So, I was in need of accessing a file through LAN in order to get my console to download a file from somewhere (and it only accepts URLs). So I thought that would be an easy fix with the help of a web-server through WAMP, since I had used that earlier without any issues.

Turns out some things have changed so here is my walkthrough (long wall of text with tons of steps) of what I experienced and how I solved the issues that arose, in case someone is running into same issue or if I need to do this again:

  1. Download & install latest WAMP-server for Win64 (as of today, that is: (64 BITS & PHP 5.4) 2.4)
  2. Launch wamp-server, LMB on icon and press "Put Online" and test "localhost" in browser (no response)
  3. Turns out port 80 is being used by skype, try to kill skype and try again (make sure it is working)
  4. Change port of wampserver to use 8080
    1. WAMP-icon/LMB/apache/httpd.conf
      1. Change "Listen 80" to "Listen 8080"
      2. Change ServerName-line to "ServerName localhost:8080"
      3. Restart Service
  5. Test again with http://localhost:8080/ (make sure it is working)
  6. Now next part, accessing a folder on server
    1. create a file in wamp-www-folder "c:\tools\wamp\www\temp\foobar.txt"
    2. should be able to navigate to it by typing "localhost:8080/temp/" in browser
  7. And finally, access the file through an IP-address (so you can access it from other device on your network)
    1. WindowsKey/cmd.exe/
      1. ipconfig <enter> (my ip is 10.20.201.75)
      2. Enter that IP into browser such as http://10.20.201.75:8080/temp/
        1. For me this resulted in an error with "you do not have permission to view this folder"
        2. Go into WAMP-icon/LMB/apache/httpd.conf
        3. Change <Directory "c:/tools/wamp/www"> ... </Directory> into:
          <Directory "c:/Tools/Wamp/www">
              Options Indexes FollowSymLinks MultiViews
              AllowOverride All
              Require all granted
          </Directory>
        4. (Basically it seems like all Allow-lines was changed in Apache 2.4 and thus they should be replaced by the Require all granted-line)
        5. At this point all should be working after a restart, but it wasn't for me, the apache-service stopped responding WAMP-icon/LMB/apache/service/"could not start service even after clicking on it several times) and there were no logs in apache_error.log.
          1. Windows-key/cmd/
          2. cd "C:\Tools\wamp\bin\apache\Apache2.4.4\bin\"
          3. httpd -t (will check configs to see if there is an error in a file, turns out I had an error in httpd.conf-file on a specific line which was reported by this command)
          4. Fixed issue in file and restarted service, working as intended
          5. You can also open TaskManager (ctrl+shift+escape)
            1. Services/wampapache and check status, for me it was stopped, which lead me to use the "httpd -t"-command
  8. Good Game - I win (finally able to download a file through console from a http-address)


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 :)