2017-07-21

pip install pymssql fails with 'sqlfront.h': No such file or directory

I've tried to install pymssql on Windows using command line:
pip install pymssql

The operation fails with an error:
fatal error C1083: Cannot open include file: 'sqlfront.h': No such file or directory

while looking for a solution, the first results are not really helpful, until you arrive to this helpful one.

In short: I was using python version 3.6, which currently isn't supported with pymssql.
Using python 3.5 instead solves that issue, and the pip install pymssql runs well.

If you're using Anaconda Navigator, it is made even simpler:
In the Environment section, you can add a new environment with your choice of python version. When you're choosing a supported version - 3.5 for example - you will find the pymssql in the packages list and install it from there directly.

2015-01-09

AngularJS Directive: Accessing an DOM element with a dynamic ID in an asynchronous directive

Hi,

This problem was really bothering me for few months. In earlier cases I tried to avoid it, but today I could not hide from it any longer. And the thing is that there was no post on any other place that could solve this matter... So here it goes.

You're writing a directive in AngularJS, and you want to access one of the DOM elements declared within its template.
Usually you do it through the linking function (post section in the compile) or in the directive controller, by injecting and using '$element', as explained here.

But, in my case, I had to access an element using its ID and this ID was dynamic.

So, my template contains:

   
<div>
    <div ng-attr-id="{{ 'something_' + dynamicValue }}"></div>

</div>
     
And my directive contains:

{
    templateURL: 'pathToTempalte',
    scope: {
        dynamicValue: '@'
    },
    link: function(scope, element, attributes) {
        attributes.$observe('dynamicValue', function(value) {
            element.find('#something_' + value);
        });
    }
}

The element.find doesn't work, because nothing is actually compiled and rendered yet here.

The solution, at the moment, is to use ''$timeout".

$timeout, even with '1' as a parameter, will only be executed after everything has been rendered, and outside of the asynchronous scope. Therefore using element.find inside its function, will deliver the expected result:

{
    templateURL: 'pathToTempalte',
    scope: {
        dynamicValue: '@'
    },
    link: function(scope, element, attributes) {
        attributes.$observe('dynamicValue', function(value) {
            $timeout(function() {
                element.find('#something_' + value);
            }, 1);
        });
    }

}

Happy coding

2013-01-18

A guide for modeling a graph database - A lunch with Neo4J chief scientist Jim Webber, London

Since the invention of NOSQL databases, it gets more and more attention from the developer community. One of the remarkable and unique databases exists in this topic of NOSQL is the graph database of NEO4J, an open-source database which stores the data as a Graph.

Modeling a graph database is quite different than modeling the regular RDBMS database, and even from other NOSQL databases such as key-value collections. We got used to identifying the molecularity of the data and save it as the columns, joining similar data together into tables. But since Neo4J is a flexible graph database, this case does not work there.

In order to model the data, we need to identify first the queries that we're about to run on the database. These queries will form the basic logical sentences which are the keys of modeling the database (more about that coming up in a second).

We need to identify where to store each piece of information:
- as a node
- as an edge
- as a property of a node or of an edge

Nodes should store items of information, nouns: Users, Receipts, Comment, Document.
The edges should store relation-items that forms a verb: Created by, Voted By, IS the son of, etc.
Properties are an additional description for either nodes or edges. You should put as a property the data that does not need to be related. if we look at the information as a sentence - the properties are the adjectives.

So, nodes and edges (and properties) should create a logical sentence as part of the modeling:
User A VOTED_YES on Question Q
This sentence creates the model for us:
[User (name=A)] -- VOTED_YES --> [Question (content=Q)]

Where User and Question are nodes. Each of which has properties that describe it (user name, question content/title).
Pay specific attention to VOTED_YES edge.
We could have chosen VOTED (vote_data = 'yes') where we have an edge of VOTED and the content is its property. Why didn't we model it so?

Jim Webber, the chief scientist of NEO4J explains: Performance-wise, it's better to create granularity in the model. So that each of these votes is a unique type of an edge.
And what if we want to collect all the votes for a specific question? We can create an Index for the vote, and easily find all the votes in the index that are pointing to a specific question.

__ to be continued __

2012-08-06

Javascript, animation and easing functions

I recently had to create an animation, which obey to the laws of physics, using javascript and HTML5.

Among the gravity and free falling, one of these animations had to also apply sort of bouncing and elastic laws.

After creating it first with CSS3 and HTML, we realized that most of the Android devices does not support it fully yet. Especially versions prior to Ice Cream Sandwich, such as Android 2.1, 2.2, 2.3 and lower (Froyo and its siblings).

So, I had to transfer everything into HTML5 Canvas, and instead of applying the css-transitions, I had to implements everything alone.

The first website I encountered and would like to highly recommend is Timothee Groleau's easing generator which can be found here:
http://timotheegroleau.com/Flash/experiments/easing_function_generator.htm

Originally made for Flash - but can easily adopted to Javascript HTML5 too.

The output of his generator is basically a function describes a certain movement of an object.
Such movement may be physical movement on either X/Y/Z axis, or even the rotation degree of an object.

The function takes 4 parameters:

t - the current time of the animation (starts with 0 and in every frame has to be increased in 1/num_of_frames_per_second). make sure that if you work in Milliseconds - t has to be that too.

b - the initial parameter (of the x/y/z axis, the rotation degree/radians etc.)

c - the target (of the same x/y/z axis or the rotation degrees)

d - total time for this process - again, like the t, has to be at the same time-unit, and personally - I recommend working with milliseconds.

the output of the function is the current value of your object at the specific t.

as for drawing, especially for 3d objects, there are already-made frameworks that can be used for this purpose such as Three.js and k3d.

one last word - nearly every physical action has a formula to describe it. use the generator to find it instead of too many if's ... :)


2012-01-10

TreePanel generated from TreeStore

Apparently, generating a treePanel from a treeStore is not 'out-of-the-box' like generating a grid or even generating tree from static json in Ext-JS.

In addition, at the moment there are not a many examples out there that explains how it should be done. Most of the examples are using a static JSON (memory). But what if you are using a store with an already-made JSON which you need to customize to be a tree?

listeners to the rescue
The way to make it happen, is to alter the store a bit.
we start by defining a store as usual:


Ext.define('MyTreeStore', {
extend: 'Ext.data.TreeStore',

config: {
someConfig: 0
},

constructor: function (cfg) {
var me = this;

cfg = cfg || {};
me.callParent([Ext.apply({
autoLoad: true,
storeId: 'MyTreeStoreID',
root: {
expanded: true
},
proxy: {
type: 'rest',
url: 'http://website/JsonGenerator.php'
extraParams: {
someCoolConfig: 1
},
reader: {
type: 'json'
},
// Don't want proxy to include these params in request
pageParam: undefined,
startParam: undefined
},
fields: ['JSONField_ID', 'JSONField_NAME'],

// ------------------------------------------------------------------------
// this is the important part:

listeners: {
append: function (thisNode, newChildNode, index, eOpts) {
if (!newChildNode.isRoot()) {
newChildNode.set('leaf', true);
newChildNode.set('text', newChildNode.get('JSONField_NAME'));
}
}
}

// ------------------------------------------------------------------------

}, cfg)]);
}
});

2012-01-01

C#, Entity Framework, WCF and JSON serialization

Ever tried to serialize Entity Framework with WCF?
Have you tried it with the Lazy-Initialization feature?
And how about the Proxy Creation Enabled?

There's a problem of circular reference if one table is referencing another table - which referencing the first one.

We have had a great deal of problems with it. We even tried to consult an external expert of Entity Framework who simply told us it's impossible to serialize it on WCF.
oh darn... :(

We tried many solutions before we gave up:
like that one:
http://geekswithblogs.net/danemorgridge/archive/2010/05/04/entity-framework-4-wcf-amp-lazy-loading-tip.aspx

and that:
http://blogs.microsoft.co.il/blogs/gilf/archive/2011/10/17/avoiding-circular-reference-for-entity-in-json-serialization.aspx

We even used t4templates to create a whole new set of flattened objects (!!!)
But it doesn't really make life easier as one has to load separately each and every object.

But this was not what we were looking for. We needed a solution that finds the spanning tree of a graph and serializing it into JSON.

Eventually the solution unexpectedly arise in the form of the open source JSON Serialization for .NET:
http://json.codeplex.com/

One of the features of this excellent util is to keep track of the objects which were already serialized in order not to re-serialize it again.
I was ready to implement it myself as I found out it already exists - which saved me a lot of time and work.

So, I would like to thank these guys who made this excellent code.

ExtJS 4.0 - Class system, object inheritance and config

Recently we've started using the new Ext-JS 4.0 class system.

one of the obstacles I came across with was using the configuration while making inheritance.

On most of the examples in the web - it works seamlessly perfect.
but what happens when you try to extend an existing object?
for example, 'Ext.panel.Panel' ?

Suddenly - weird stuff happens and it doesn't work any longer.

So for example:
Ext.define('ProductionMap.popup.serverExplorer', {
extend: 'Ext.panel.Panel',

config: {
ParameterConfig: '',
},

constructor: function (cfg) {
this.initConfig(config);
return this;
},

initComponent: function () {
...
}


will give an error.
took me an hour to figure it out - but I found the solution and it's REALLY simple.
It's all about the constructor:
instead of that code, use:

constructor: function (cfg) {
this.initConfig(config);
this.callParent([config]);
return this;
},


and kaboom - works like a charm :)

Liad

pip install pymssql fails with 'sqlfront.h': No such file or directory

I've tried to install pymssql on Windows using command line: pip install pymssql The operation fails with an error: fatal error C108...