Programming

Maximum Memory by Windows Services Configuration (BlackViper Settings)

Maximum Memory by Windows Services Configuration (BlackViper Settings)

There are a lot of tips and tricks on how to optimize your system memory. One of the main ways to get the most out of your system is to configure the “Windows Services”, essentially tasks and programs that windows starts and stops in the background. These services are needed by other programs, changing this configuration can result in that some programs cannot start or behave in a strange manner. If you mess around with the services, you could disable your access to the internet and its a pain to figure out which service you accidentally stopped that should have been running.

There are only two situations in which you should configure the services

  1. You are desperate and want to optimize a very old pc without having to buy new ram
  2. You are a gamer and want the speediest most lightweight computer

Service Configurations

Fortunately smart people have already played around with various configurations. BlackViper provides on his website a list of “tweaked”, “safe” and “default” settings. However the table on his website is interesting, but not very useful. If you would want to apply these settings you would have to open up “services.msc” and apply each setting manually.

Thankfully I found a way to convert the table into a powershell script.

  1. Head over to his site  http://www.blackviper.com/service-configurations/
  2. Go to your Version of Windows
  3. Use the websites Copy function and save the tap separated table into a textfile
  4. Execute following python code in the same folder

Alternatively you can download the resulting Powershell Scripts for Windows7SP1:  Win7SP1 – BlackViperPowerShell

Note: During the execution of the script errors appear for services that are not installed on your system – just ignore them.

Results

To consistently measure the memory usage I did a clean install of Win 7SP1 on a VirtualBox.

  • Default  39 Processes using  600MB Ram
  • “Safe Configuration”:  29 Processes using 500MB.

While the safe configuration ‘saves’ you 100MB of Memory. The amount of effort of testing if all your programs are still running correctly etc. Does not make a lot of sense – especially when typically you are anyway have 8GB+ RAM in Computers these days.

Image:

Posted by happyneal in Hardware, Python, Windows, 0 comments
Forcing IE 10 to render pages as IE 10

Forcing IE 10 to render pages as IE 10

Web Design designed by Simple Icons from the thenounproject.com

Now isn’t that a silly title, sadly it’s one of those things I never thought I would have to deal with. Especially as Internet Explorers market-share is down to 8.8% in June. And seriously people switch to something that supports most of the web standard.

As a matter of fact Internet Explorer 10 defaults to render Webpages with its built in Compatibility Mode (IE 7) when displaying Intranet Websites.

Basically the thinking behind it is, we have an Advanced Browser (mostly) capable of rendering HTML5 Websites, but our Corporate Partners are so backwards that they are still running age-old Websites that possibly could be displayed incorrectly. In matter of fact they call this stupid Feature “Smart Defaults“.

Now as a HTML5 developer you would think, well yeah whatever I’ll just add a meta-tag to the <head></head>

<meta http-equiv="X-UA-Compatible" content="IE=edge">

Well IE 10 looks at it and says “That can’t be right, I am in the intranet, and we don’t have cool HTML 5 sites here! I better render this in compatibility mode!!!”

So the only way to force Internet Explorer to do the right thing is to actually modify the settings of your webserver to add the exact same meta information to the HTTP Response object; Only then IE 10 will say, ok fine ill render it with my weird IE 10 render engine.

You can verify this using the Chrome Developer Tools

  1. Open Chrome, Press F12 to view the Development Tools
  2. Switch to the tab ‘Network’
  3. Navigate to the specific Page
  4. Verify that in the Get Request, the response Header “X-UA-Compatible: IE=10” or “IE=edge”Chrome-IE10-Header
Posted by happyneal in Web Technologies, 0 comments
Java: Multiple Functions and one ErrorHandler

Java: Multiple Functions and one ErrorHandler

Y2K Bug by Cards Against Humanity from The Noun Project

Let’s say you have function fooA() and function fooB() both functions are very similar and throw similar errors.

 public static void fooA(){
         try{
             throw new FileNotFoundException();
         }
         catch (Exception e){
             exceptionHandler(e);
         }
     }

     public static void fooB(){
         try{
             throw new FileNotFoundException();
         }
         catch (Exception e){
             exceptionHandler(e);
         }
     }
 

If you have the possibility to avoid duplicating code you could write a single Error handler and pass the Error to the Error handling function. However you still want to be able to distinguish between different types of Exception and for logging purposes you should mention which function actually caused Exception. The easiest way to figure the Method name is to use e.getStackTrace()[0].getMethodName();
Alternatively you can pass the method name to the Errorhandlerfunction. To do that you can figure out the method name via:

 String methodName = Thread.currentThread().getStackTrace()[1].getMethodName();
 

To determine the various Exceptions there are two possibilities:

Method 1: Use instanceof

The downside to this method is that it is not as readable and identifiable as ErrorHandling function. (However this depends on personal preferences)

     public static void exceptionHandler(Exception e){
         if (e instanceof FileNotFoundException){
             System.out.println(e + " " + e.getStackTrace()[0].getMethodName());
         } else if (e instanceof Exception) {
             System.out.println(e.getStackTrace()[0].getMethodName());
         }
     }
 

Method 2: re-throw the Error

Well you are still throwing around with errors, but it is clearly identifiable as Error handler.

  public static void exceptionHandler(Exception e){
         try {
             throw e;
         }
         catch (FileNotFoundException e){
             System.out.println(e + " " + e.getStackTrace()[0].getMethodName());
         }
         catch(Exception e) {
             System.out.println(e.getStackTrace()[0].getMethodName());
         }
     }
 
Posted by happyneal in Programming, 0 comments
Google App Engine: Import CSV to Datastore

Google App Engine: Import CSV to Datastore

Processing CSV Data with the Google App Engine is a two step process.
First you need to upload the data and store it in the blobstore.
Then you retrieve the file and process the information and save it to the Datastore(Database).
You can process the csv data with the standard python tools from the csv module, however instead of parsing a file you must parse a BlobReader.

Posted by happyneal in Python, Web Technologies, 6 comments
Aptana / Eclipse: Set up Git Repository (Github, Bitbucket)

Aptana / Eclipse: Set up Git Repository (Github, Bitbucket)

If you code for yourself or with a team you should be using a code repository. However getting started you need a dedicated server, installation etc. or you take the more convenient route and use one of the many repository providers.

Step 1: Get a Repository

For small teams you can get free Repositories. The two most popular providers are:

  • Github.com: Allows you to host as many open source projects as you like. (private projects cost a monthly fee)
  • Bitbucket.com: Allows a small team to host private projects. (As the team gets bigger you got to pay a monthly fee)

Larger teams, hopefully have the budget to pay for these awesome services.

Step 2: Set up your SSH key

Eclipse and Aptana Studio have Git already integrated. Git uses an encrypted connection to transmit data. You need to provide a SSH keypair.

Check for existing SSH keys

  1. Go to the directory “C:\Users\<username>\.ssh”
  2. Check if the files “id_rsa” and “id_rsa.pub” exist

Generate new SSH keys

If the two files already exist, you can skip this step.

  1. Open git-bash.bat (either by using windows search or navigate to C:\Users\%USRNAME%\Documents\Aptana Studio 3 Workspace\.metadata\.plugins\com.aptana.portablegit.win32\git-bash.bat)
  2. Enter the following command using your correct email-address.
    ssh-keygen -t rsa -C "name@email.com"
  3. For the first question, just press enter.
    Generating public/private rsa key pair.
    # Enter file in which to save the key (/c/Users/you/.ssh/id_rsa):
    
  4. Now enter a passphrase for your key (Password Generator) and confirm the password

Add SSH key to Repository

  1. Go to the directory “C:\Users\<username>\.ssh”
  2. Open the file ‘id_rsa.pub’ in a texteditor
  3. Copy the entire contents to the Clipboard (Ctrl-C)
  4. Open a web browser and login to github.com or bitbucket.com
    • (Github) Click on the “Edit my profile” button on the top right
    • (Bitbucket) Click on your Avatar > “Manage Account”
  5. On the left side navigate to “SSH Keys”
  6. Click “Add SSH key”
  7. Give the key a title (like username with the computer name) and paste the key into the form

Test Connection

  1. Open git-bash.bat
  2. Use the command
    • (Github) ssh git@github.com
    • (Bitbucket) ssh git@bitbucket.com

If everything went well you will get a message like:

Hi username! You’ve successfully authenticated, but GitHub does not provide shell access.

Note: At first I had difficulties to establish a connection. If you are having problems, check if the keys are in the right directory and have the proper names id_rsa and id_rsa.pub.

Source/Further information: Github – https://help.github.com/articles/generating-ssh-keys

Step 3: Set up Aptana/Eclipse

The initial setup is now complete you can now use Eclipse/Aptana to access your Repository.

New/Existing Project

To start using git create or use an existing project.

  1. In the Project Manager, Right-click on the project and select Team > Share Project…Screenshot - 11_19_2013 , 8_43_54 AM
  2. Select the Project, click Create and then Finish.Screenshot - 11_19_2013 , 8_45_51 AM

You now have a local git repository. You now can “Push” the repository to github/bitbucket.

  1. First create a Repository on the website and copy the address of the repository
  2. In the Project Manager, Right-click on the project and select Team > Remotes > Add RemoteScreenshot - 11_19_2013 , 8_52_00 AM
  3. Give the remote a name and paste the address of the repository
  4. Finally push your initial commit with Team > Push

Retrieve from Repository

If you already have a Project stored in your repository and want to retrieve it.

  1. Go to File > Import 
  2. Select Git > Git Repository as New ProjectScreenshot - 11_19_2013 , 8_31_50 AM
  3. Enter the URI of your repository:
    • (Github) git@github.com:<username>/<repository>
    • (Bitbucket) git@bitbucket.com:<username>/<repository>

Use your Repository

Here are some tips on using the repository (well they are based on my experience using SVN, but the same principles apply):

Commit as often as possible

The beauty of subversioning is that you can figure out step by step what parts of your code created the error. When working in a team, always make sure that the entire code is correct and valid and still be compiled/executed.

Write proper commit messages

Always comment what you are currently committing. It helps to rollback to a specific point, and it is a documentation of your work.

Regular updates

When working in a team regularly check that you have the newest version of the code available by doing a “Pull”.

Best Practices

A lot of experts have articles on how to use git effectively in a team. Read up on them and see if they are suitable for your team.  Check out this article about Git Best practices.

Posted by happyneal in Programming, 8 comments
PySide: QPushbutton Text below Icon

PySide: QPushbutton Text below Icon

Apparently using a QPushbutton with a Icon does not work. As alternative I am going to use a QToolbutton.

import sys
from PySide.QtCore import *
from PySide.QtGui import *

class Widget(QWidget):
    
    def __init__(self, parent= None):
        super(Widget, self).__init__()
        
        layout = QVBoxLayout(self)
        
        #QToolButton
        btn = QToolButton()
        btn.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
        btn.setText("test")
        btn.setIcon(btn.style().standardIcon(QStyle.SP_DirIcon))
        btn.setIconSize(QSize(54,54))
        
        layout.addWidget(btn)
        
        self.setLayout(layout)
        
        
if __name__ == '__main__':
    app = QApplication(sys.argv)
    
    dialog = Widget()
    dialog.show()

    app.exec_()
Posted by happyneal in Python, 0 comments