# -*- 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
Highlight
2012-06-28
Fixing Python 2.6+ to run Python 3 code:
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:
Install and use gconf-editor to change the Nautilus desktop visible icon settings.
#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.
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:\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:
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:
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
2012-03-02
Resizing a vmdk disk image using Oracle VM VirtualBox 4
My work PC has a small disk, thus i made a 4 GB virtual machine. After getting an external harddrive, it turned out to be hard to resize. I spent too much time to find a solution there, so i'm noting all steps here:
First power off the VMs that use the vmdk.
>"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" clonehd -format vdi "I:\VMs\X_dev\X-disk1.vmdk" "I:\VMs\X_dev\X-disk1.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'vdi'. UUID: [...]
>"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" modifyhd --resize 16000 "I:\VMs\X_dev\X-disk1.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
First power off the VMs that use the vmdk.
>"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" clonehd -format vdi "I:\VMs\X_dev\X-disk1.vmdk" "I:\VMs\X_dev\X-disk1.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'vdi'. UUID: [...]
>"C:\Program Files\Oracle\VirtualBox\vboxmanage.exe" modifyhd --resize 16000 "I:\VMs\X_dev\X-disk1.vdi"
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
2012-02-23
Setting & getting web browser cookies
Details here.
Client-side JavaScript/ ECMAScript:
Server-side Java in JSP using Liferay:
Client-side JavaScript/ ECMAScript:
function createCookie(name, value, days){ if (days){ var date = new Date() date.setTime(date.getTime()+(days*24*60*60*1000)) var expires = "; expires="+date.toGMTString() } else var expires = "" document.cookie = name+"="+encodeURIComponent(value)+expires+"; path=/" } createCookie("best_location", "/this folder; it's short + great!", 3650)
Server-side Java in JSP using Liferay:
<%@page import="com.liferay.portal.kernel.util.HtmlUtil" %> <%@page import="java.net.URLDecoder" %> <% Cookie cookies[] = request.getCookies(); if (cookies != null){ for (Cookie cookie : cookies){ if (cookie.getName().equals("best_location")) out.print("Best location: " + HtmlUtil.escape(URLDecoder.decode(cookie.getValue()))); } } %>
Labels:
browser,
cookie,
cookies,
decoding,
ECMAScript,
encoding,
escape,
escaping,
java,
javascript,
jsp,
Liferay
Subscribe to:
Posts (Atom)