Wednesday, April 11, 2012

Uncompress gzip compressed http response

I'm using php's file_get_contents() function to do a HTTP request. To save bandwidth I decided to add the "Accept-Encoding: gzip" header using stream_context_create().

Obviously, file_get_contents() outputs a gzip encoded string so I'm using gzuncompress() to decode the encoded string but I get an error with data passed as argument.

[...] PHP Warning: gzuncompress(): data error in /path/to/phpscript.php on line 26

I know there is another function able to decompress gzipped data gzdecode() but it isn't included in my PHP version (maybe it is only available on SVN).

I know that cUrl decodes gzip stream on the fly (without any problem) but someone suggested me to use file_get_contents() instead of cUrl.

Do you know any other way to decompress gzipped data in PHP or why gzuncompress() outputs a Warning? It is absurd that gzuncompress() doesn't work as expected.

The problem is certainly about PHP: the HTTP request is made to Tumblr API that give a well-encoded response.

SharePoint BDC Model NULL Structure

I crawle database at FAST Search Server for SharePoint 2010. When incremental crawl is running, it is getting the following error for some records. After the first error, SharePoint takes the same errors from every subsequent incremental crawle.

SharePoint Log:

04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1A04 Business Connectivity Services Business Data ca7e Verbose Instantiating Type 'System.String'.
04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1A04 Business Connectivity Services Business Data ca7j Verbose Recursively instantiating Type 'System.String' at a nest level of '0'.

04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x0580 SharePoint Server Search Connector Framework e64y Verbose Getting the contents of entity instance with ID Microsoft.BusinessData.Runtime.Identity

04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1A04 Business Connectivity Services Business Data ca7l Verbose Found primitive default value ''; returning that instead of instantiating at a nest level of '0'.

04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1A04 Business Connectivity Services Business Data ca7f Verbose Completely instantiated Type 'System.String'.

04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1594 Business Connectivity Services Business Data bix3 Medium Closed connection to Db: FASTDB
04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1594 SharePoint Server Search FilterDaemon fld1 High Fltrdmn: failure reading ACL. Error 0x8004fd11 [fltrdaemon.cxx:2681] d:\office\source\search\native\mssdmn\fltrdaemon.cxx

04/10/2012 18:56:12.21 mssdmn.exe (0x11C8) 0x1594 SharePoint Server Search FilterDaemon e4ye High FLTRDMN: Errorinfo is "LobSystem (External System) returned a null structure which is incompatible with the associated metadata." [fltrsink.cxx:553] d:\office\source\search\native\mssdmn\fltrsink.cxx

After the first error, every incremental crawle takes same Error which is seen the following crawle history log table .

  1. Crawle Log:

    • Crawle Type : Full

    • Successes     : 284310

    • Warnings    : 0

    • Errors          : 0

  2. Crawle Log:

    • Crawle Type : Incremental

    • Successes     : 25375

    • Warnings    : 0

    • Errors          : 0

  3. Crawle Log:

    • Crawle Type : Full

    • Successes     : 20270

    • Warnings    : 0

    • Errors          : 70

  4. Crawle Log:

    • Crawle Type : Incremental

    • Successes     : 12650

    • Warnings    : 0

    • Errors          : 70

  5. Crawle Log:

    • Crawle Type : Incremental

    • Successes     : 26450

    • Warnings    : 0

    • Errors          : 70

    it continues like this.

How can i solve this problem.

Thanks for your attention.

bash extended globs :: rm all *.jpg files except two particular ones

Can I use Bash extended glob patterns to implement logical 'AND' ? Say I have a folder of jpg files and I want to rm all except A.jpg and B.jpg. How would I do that without trying tricks like remaming the files temporarily and so on ? I guess the general theme is how one can combine logical expressions and negations in Bash extended globs.

Retrieve the contents of DataSource form the ComboBox

I have a combobox that I bind with a list of objects with three properties, int a, int b, string x. When bound I set DataTextField to x and DataValue Field to a. What I want to do is get the value of b in the codebehind after the collection has been bound to the list. I do not want to use viewstate. Can I possibly use reflection? something like this?

var dataSource = ddlTest.GetDataSource();
 var newDataSource = dataSource.GetType().GetProperty("_dataSource", BindingFlags.NonPublic | BindingFlags.Instance);


I'm not sure about this, but you might be able to add b as a custom attribute to the ListItem. Try something like this and see if it works:
var table = new DataTable("TableName"); 
//bind the dropdown to the result set
dropDownList.DataSource = table;
//iterate through the datasource and add custom attributes for each item in the list
table.AsEnumerable().ToList().ForEach(r => 
    dropDownList.Items.FindByValue(r.Field<int>("a").ToString()).Attributes["data-field"] = r.Field<int>("b").ToString());    
If you'd prefer to use a regular foreach loop:
foreach (DataRow row in table.Rows)
    var item = dropDownList.FindByValue(row.Field<int>("a").ToString());
    if (item != null)
        item.Attributes["data-value"] = row.Field<int>("b").ToString();
If adding custom attributes doesn't work and you don't want to use ViewState, you might have to store both a and b in the value field, separated by a delimeter. This can be a pain because you'll have to parse the items to get the values, but given your requirements that might be the best option if the custom attributes don't work.

Advance Python Scheduler and SQLAlchemyJobStore

I am using sqlalchemy job store in APS . Jobs are added too cron using the function add_cron_job. But no entry is made in database table. Pls help me out: following is the code

import time
import logging
from threading import Timer
from threading import Lock
from gadgetplatform.classes.utils.utilities import import_module
from apscheduler.scheduler import Scheduler

from apscheduler.jobstores.sqlalchemy_store import SQLAlchemyJobStore

class SchedulerManager(object):
_instance = None
_initialised = False
lock = Lock()
log = logging.getLogger(__name__)

def __new__(cls):

if not cls._instance or not cls._initialised:
if not cls._instance:"creating instance")
cls._instance = super(SchedulerManager, cls).__new__(cls)
cls._initialised = True
cls._instance.init()"instance created")
cls.lock.release()"lock released")"returning instance")
return cls._instance

def init(self):
self.sched.add_jobstore(SQLAlchemyJobStore('mysql://root@localhost/mygola?charset=utf8&use_unicode=0'), 'apschedulerJobs')

def addToCron(self,source,time):"called to add schedular")

time = time.split(' ')


self.sched.add_cron_job(func, year=yr, month=mnth, day=d, hour=h, minute=m)
self.jobDict.append(source)"added with the time")

def removeFromCron(self,source):

def start(self):
self.sched.start()"Schedular Started")

def stop(self):

def getRunningJobs(self):
return self.jobDict

def convertStringToFunction(self,source):
strArr = source.rsplit('.',1)
mod = import_module(strArr[0])
func = getattr(mod, strArr[1])
return func