Highlight

2013-01-09

Repairing slow systems

Recently my old PC became very slow at everything. I looked at the problem areas:

#1. CPU usage

Single-core machines being hogged by rude/buggy software is why i switched to a quadcore i5 for my main machine. CPU usage can be viewed and managed via your Task Manager, accessible on Windows via Ctrl+Alt+Del, Start Task Manager. If you don't want to end a rude process, you can try to lower its priority via the context menu.

If the CPU is automatically underclocked, perhaps dust is blocking airflow that's needed to run at full speed. When cleaning the inside of your PC, always shut off its power and stay grounded by touching the bare metal case to avoid static discharge frying your bits.

#2. RAM usage

When the temporary memory of a PC fills up, operating systems tend to use virtual memory on the hard drive, but the hard drive is orders of magnitude slower than RAM, even an SSD. Besides, writing to an SSD still shortens its lifespan more than writing to magnetic disk. Increase RAM (note the type and size your motherboard supports, and that it will match the slowest chips installed) or decrease program consumption. Note that 32-bit Windows only supports up to 4 GB of RAM and will leave the rest unused.

#3. Storage space

Many programs cache slow data to the hard disk, but when space runs out (Windows warns about this), that becomes impossible, also affecting the virtual memory. Use CCleaner and SpaceSniffer to free up space and consider external drives for archiving. If you're ambitious, perhaps you want to try moving the entire OS to a bigger/faster disk using a boot media with disk imaging/cloning tool.

#4. Storage integrity

Environmental effects like temperature, moisture, and cosmic rays, can corrupt stored data. Modern systems can correct for this, but i've found that can produce terrible lag. Schedule regular (monthly should do) surface sector relocation scans. Ubuntu does this out of the box on startup, but Windows needs a scheduled task that runs a batch file containing
@echo off
echo y|chkdsk c: /r
shutdown -r
as admin. The reboot is required because C: is probably in use.

I solved my old Windows XP system's lag by manually scheduling a sector repair via the C: partition's properties' extra's scan tool in Explorer.

S.M.A.R.T. monitoring tools like SpeedFan and HD Tune can indicate problems with your hard drive.

On a side note: Unlike many tutorials showing only easy Dell installs, i noticed that the Medion MD8818's hard disk drive is fastened by two short screws through the bottom of the tower.

#5. Storage order

Modern (file)systems are less affected by heavy read/write activity, but defragmentation every once in a while can help, except on an SSD (see also #2) as those have neglible seek/read times.

#6. Software updates

Newer software can have bugfixes and improved efficiency. Use your component manufacturer's website (like AMD or NVIDIA for drivers) and/or reputable tool such as FileHippo.com Update Checker (might not check drivers) and Microsoft Update (doesn't check 3rd party software).

#7. Software alternatives

AlternativeTo lists alternatives to many bloated/slow software packages.

2012-06-28

Fixing Python 2.6+ to run Python 3 code:

# -*- coding: utf-8 -*-
from __future__ import print_function
__doc__ = """XLS2DB by Cees Timmerman"""
changelog = """
2012-06-28 v1.0
"""
import glob, locale, os, re, sys, time
#from pyXLSX.xlsx import workbook  # no MergedCells support and fails at Unicode.
from win32com.client import Dispatch  # PyWin32 or ActivePython required. Excel, too.
#from win32com.client.gencache import EnsureDispatch as Dispatch  # Also makes constants available.
#import Image  # PIL to resize images.
import pymysql   # Note: Python 3 doesn't support old db protocol.

print(__doc__)
print(changelog.split("\n")[-2])
print()

if sys.version[:2] == '2.':
 #print("Python 2 sucks at Unicode; use Python 3 to run this.")
 #sys.exit(2)

 # Fix Python 2. We should be running in Python 3, though.
 original_print = print
 def print(*args, **kwargs):
  #original_print("args: " + str(args))
  #original_print("kwargs: " + str(kwargs))
  new_args = []
  for arg in args:
   try:
    new_args.append(arg.encode('ascii', errors='xmlcharrefreplace'))
   except:
    new_args.append(arg)
  original_print(*new_args, **kwargs)
 
 try:
  input = raw_input
  str = unicode
 except: pass

2012-06-21

Filtering a table using jQuery:

$(document).ready(function(){
 $.extend($.expr[':'], {
  'containsi': function(elem, i, match, array){
   return (elem.textContent || elem.innerText || '').toLowerCase().indexOf((match[3] || "").toLowerCase()) >= 0
  }
 })
})
function CT_filterTable(table_id, column_nr, text) {
 table_id = "#"+table_id
 $(table_id+" tr").hide();
 $(table_id+" tr>td:nth-child("+column_nr+"):containsi('"+text.replace("'", "\\'")+"')").parent().show()
}

2012-05-15

Installing Firefox and Flash player on Debian 6 (Squeeze)

Here's what i did after installing the 180 MB CD image in a virtual machine:
#apt-get update
#apt-get upgrade
[ If you don't have a graphical desktop yet, try Gnome's (1.6 GB, though!): ]
# apt-get install gdm gnome-core gnome-terminal
# nano /etc/apt/sources.list
[ Add these two for Firefox and Flash plugin: ]
deb http://packages.linuxmint.com debian import
deb http://ftp.uk.debian.org/debian/ squeeze main contrib non-free
# apt-get update
# apt-get remove iceweasel  [ This will install the dumbed-down Epiphany browser for some reason. ]
# apt-get install firefox
# apt-get install flashplugin-nonfree
Maybe i should try Iceweasel (3.6.15) again as apt-get somehow installed a South African locale of Firefox (12.0). :( I fixed that by installing this and setting general.useragent.locale to "en-US" in about:config and perhaps installing this and/or changing the desktop shortcut to use only "firefox" instead of the opt path and %u.

Install and use gconf-editor to change the Nautilus desktop visible icon settings.

2012-03-27

Quick & easy navigation.

String sql = "select name, address, zip, city, country, phone, url"
+ " from retailer"
+ " where latitude is not null and longitude is not null"
+ " order by pow(lat-lat2, 2) + pow(2 * min(abs(lon-lon2), 360-abs(lon-lon2)), 2) asc limit 10";
stmt = con.prepareStatement(sql);
stmt.setDouble(1, Double.parseDouble(request.getParameter("lat")));
stmt.setDouble(2, Double.parseDouble(request.getParameter("lng")));
Honolulu to Los Angeles and San Fransisco in Python:
>>> lat, long = (21.3069444, -157.8583333)
>>> lat2, lon2 = (34.0522342, -118.2436849)
>>> pow(lat-lat2, 2) + pow(2 * min(abs(lon-lon2), 360-abs(lon-lon2)), 2)
33839.327855007934
>>> lat2, lon2 = (37.7749295, -122.4194155)
>>> pow(lat-lat2, 2) + pow(2 * min(abs(lon-lon2), 360-abs(lon-lon2)), 2)
30952.629658700374
2 * lon is ok for latitude 45 or -45, but 1/cos(radians(lat)) is better.

2012-03-19

Hunting bugs

1. Get Sysinternals Suite.
2. Start Process Explorer and/or Process Monitor.
3. Go to Options, Configure Symbols...

DbgHelp.dll path (version 6.0 or later, not in system32; the version of DbgHelp that ships in Windows has reduced functionality from the other releases-- specifically, it lacks support for Symbol Server and Source Server.):
C:\Windows\system32\dbghelp.dll
C:\Program Files\Debugging Tools for Windows (x64)\dbghelp.dll

Symbols path(s):
SRV*I:\symbols*http://msdl.microsoft.com/download/symbols;SRV*I:\symbols*http://symbols.mozilla.org/firefox

"I:\symbols" is the location of my symbols cache; yours may differ.

2012-03-08

Making Redmine suck less

Problem: Issue importance and status are hard to see.

Solution: Install this theme and add a custom CSS rule to strike-through resolved issues. I might have a Facebook entry with more details, but can't find it.


Problem: Gantt charts should be sorted by start date instead of issue id.

Culprit: C:\Program Files\BitNami Redmine Stack\apps\redmine\lib\redmine\helpers\gantt.rb

Solution:

      # TODO: top level issues should be sorted by start date
      def gantt_issue_compare(x, y, issues)
        # Edit by Cees on 8mar12 by http://www.redmine.org/issues/7335
        [(x.root.start_date or x.start_date or Date.new()), x.root_id, (x.start_date or Date.new()), x.lft] <=> [(y.root.start_date or y.start_date or Date.new()), y.root_id, (y.start_date or Date.new()), y.lft]
        #if x.root_id == y.root_id
        #  x.lft <=> y.lft
        #else
        #  x.root_id <=> y.root_id
        #end
      end


Problem: I don't know how to restart Redmine.

Solution: Choose the applicable one here. If you use Windows and Bitnami with Redmine 1.1.2, save this text as "restart Redmine.bat" and run as Administrator:

net stop redmineMongrel1
net start redmineMongrel1
net stop redmineMongrel2
net start redmineMongrel2
pause