def Singleton(cls): def delegate(*args, **keyargs): if hasattr(cls, 'instance') == False: cls.instance = cls(*args, **keyargs) return cls.instance return delegate @Singleton class test: def __init__(self): self.attr = 'aaa' print('init test') if __name__ == '__main__': a = test() b = test() print(a,b,a==b) print(a.attr, b.attr) a.attr = 'bbb' print(a.attr, b.attr) b.attr = 'ccc' print(a.attr, b.attr)
2011年7月27日星期三
Singleton implementation in Python
2011年7月21日星期四
Extract metadata from xbox360 GOD directory
I have many xbox306 game and I want to share some to my friends (Note: I use XBR system).
But I can't get game name from the directory.
Fortunately there a file in game folder whose name is GUID, we can extract game name and game icon from that file.
The game name is at position 1041, there are 2 pictures at the metadata file, 5914 and 22298.
I cann't get other metadata from this file, anyone who knowes please send me an email.
Here is the program I wrote in python to extract metadata from GOD directory.
How to use:
1. Extract the zip file.
2. Modify main.py (4th and 5th line)
4. Open gamelist.html in the output folder to see the game list.
But I can't get game name from the directory.
Fortunately there a file in game folder whose name is GUID, we can extract game name and game icon from that file.
The game name is at position 1041, there are 2 pictures at the metadata file, 5914 and 22298.
I cann't get other metadata from this file, anyone who knowes please send me an email.
Here is the program I wrote in python to extract metadata from GOD directory.
How to use:
1. Extract the zip file.
2. Modify main.py (4th and 5th line)
sourceFolder = r'............\xbox360' outpath = r'.........\out'3. run metaExtractor.exe
4. Open gamelist.html in the output folder to see the game list.
Oralce Sum function in livelink
Found a big bug in livelink.
When excute oracle aggregate function SUM, livelink always truncate the value.
See this SQL
The solution is (for livelink) convert decimal to string
When excute oracle aggregate function SUM, livelink always truncate the value.
See this SQL
select sum(v) from ( select 1.01 v from dual union select 1.05 v from dual )pl/sql give 2.06 but livelink give 2.
The solution is (for livelink) convert decimal to string
select to_char(sum(v)) from ( select 1.01 v from dual union select 1.05 v from dual )It is very strange, isn't it?
2011年7月20日星期三
The dropdownl list default value issu in IE of jqGrid cell eding
The dropdownlist in jqGrid cell edit has an issue in IE.
Let's see what happens
In jqGrid js file
Here is the problem. We can add key "value" to exclude array.
Now the functions reads
Let's see what happens
In jqGrid js file
var oSv = options.value; } else if (typeof options.value === 'object') { var oSv = options.value; for ( var key in oSv) { if (oSv.hasOwnProperty(key ) ){ ov = document.createElement("option"); ov.setAttribute("role","option"); ov.value = key; ov.innerHTML = oSv[key]; // this line set option to be selected and the selectedIndex is correct if (!msl && ( $.trim(key) == $.trim(vl) || $.trim(oSv[key]) == $.trim(vl)) ) { ov.selected ="selected"; } if (msl && ($.inArray($.trim(oSv[key]),ovm)>-1 || $.inArray($.trim(key),ovm)>-1)) { ov.selected ="selected"; } elem.appendChild(ov); } } } // before this line the selectedIndex is correct setAttributes(elem, options); // but after this line the selectedIndex is incorrectThe problem must be setAttributes(elem, options);
function setAttributes(elm, atr) { var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr']; $.each(atr, function(key, value){ if($.inArray(key, exclude) === -1) { $(elm).attr(key,value); } }); if(!atr.hasOwnProperty('id')) { $(elm).attr('id', $.jgrid.randId()); }Notice this line
$(elm).attr(key,value);The key is "value" and the value is "{RMB:'RMB', USD:'USD', EUR:'EUR', AUD: 'AUD', GBP:'GBP', SGD: 'SGD'}"
Here is the problem. We can add key "value" to exclude array.
Now the functions reads
function setAttributes(elm, atr) { var exclude = ['dataInit','dataEvents','dataUrl', 'buildSelect','sopt', 'searchhidden', 'defaultValue', 'attr']; $.each(atr, function(key, value){ if($.inArray(key, exclude) === -1) { $(elm).attr(key,value); } }); if(!atr.hasOwnProperty('id')) { $(elm).attr('id', $.jgrid.randId()); }It works well now.
订阅:
博文 (Atom)