Thursday, 3 October 2013

Cakephp get data from another model

Cakephp get data from another model

I'm developing an e-commerce website. I have 2 tables - Customers & Shipping
Field in Customers - id, name, address, city, postal & country Field in
Shipping - id, address, city, postal & country
The process flow, after the customer click checkout button, they need to
fill up shipping form (shipping - add.ctp).
But in add.ctp, i also want to show address from table customer. So, I can
put check button - Use this address as shipping address.
Anyone can help how the controller & add.ctp looks like? Thank You.

Wednesday, 2 October 2013

Find maximum value of a continuous function at a specific resolution

Find maximum value of a continuous function at a specific resolution

Imagine having a function that is continuous over a range [0.0,n]. Are
there any algorithms to find the maximum value of the function given a
minimum step size s more quickly than simple iteration? The simple
iteration is straightforward to program but the time complexity grows when
n / s is large.
double maxValue = 0;
double maxValueX = 0;
double s = 0.1 * n;
for (double x = 0.0; x <= n; x += s)
{
double value = someFunction(x);
if(value > maxValue) {
maxValue = value;
maxValueX = x;
}
}
I have tried this approach which is much quicker, but don't know if it
will get stuck on local maximums.
double min = 0;
double max = n;
int steps = 10;
increment = (max - min) / steps;
while (increment > s)
{
double maxValue = 0;
double maxValueX = X;
for (double x= min; x <= max; x+= increment)
{
double value = someFunction(x);
if(value > maxValue) {
maxValue = value;
maxValueX = x;
}
}
min = Math.Max(maxValueX - increment, 0.0);
max = Math.Min(maxValueX + increment, n);
increment = (max - min) / steps;
}

How to identify unbound variables for auto-including of modules using Template Haskell?

How to identify unbound variables for auto-including of modules using
Template Haskell?

Is it possible to use Template Haskell to pre-analyze a code, searching
for undefined symbols and including them, if they are defined elsewhere?
I.E, simulating Eclipse's auto-include for Java programs (except not
actually altering the source)?

alpha blending in opengl es not working

alpha blending in opengl es not working

I'm trying to vary the transparency of a texture drawn onto a quad, the
code below works fine except the alpha set with glColor4f has no effect.
What are the possible reasons for this? Is it likely to be a gl setting
somewhere else in the program?

glEnable(GL_BLEND);
glBlendFunc(GL_SRC_COLOR, GL_ONE_MINUS_SRC_ALPHA);
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, textureId);
glColor4f(1.0f, 1.0f, 1.0f, 0.3f);
glVertexAttribPointer(vertexHandle, 3, GL_FLOAT, GL_FALSE, 0, quadVertices);
glVertexAttribPointer(normalHandle, 3, GL_FLOAT, GL_FALSE, 0, quadNormals);
glVertexAttribPointer(textureCoordHandle, 2, GL_FLOAT, GL_FALSE, 0,
quadTexCoords);
glEnableVertexAttribArray(vertexHandle);
glEnableVertexAttribArray(normalHandle);
glEnableVertexAttribArray(textureCoordHandle);
glUniformMatrix4fv(mvpMatrixHandle, 1, GL_FALSE,
(GLfloat*)&modelViewProjectionButton.data[0] );
glDrawElements(GL_TRIANGLES, NUM_QUAD_INDEX, GL_UNSIGNED_SHORT, quadIndices);
glDisableVertexAttribArray(vertexHandle);
glDisableVertexAttribArray(normalHandle);
glDisableVertexAttribArray(textureCoordHandle);

Visual Studio Toolbox - close toolbox

Visual Studio Toolbox - close toolbox

I wonder if ther is a way of confirming selection of a tool from MS VS
Toolbox / close toolbox. The opposite of:
ctrl+w .. ctrl+x
and
ctrl + alt + x
What I find really annoying is when I have to add an association between
two entities in model designer, and the one that I want to start with is
hidden behind toolbox.
If so, I have to use e.g. scrollbar to make toolbox loose focus.
Is there a way to confirm that I want to use selected control and hide the
toolbox?
(like shift+esc in VS6) ?

Tuesday, 1 October 2013

Import updating CSV into SQL Server

Import updating CSV into SQL Server

I'm looking for a simple solution (beginner to SQL) to allow the import of
data from my .csv file to my SQL DB.
I have a third party program that is updating my .csv file every 30
seconds and I want to put that updating information into my SQL DB. I
tried the importing & exporting wizard but it didn't work due to the .csv
file being utilized by the other third party program.
Getting the information into the SQL DB doesn't need to be in real time it
could just retrieve all the information when opening a saved sql query
file.
Thank you!

Using c dynamic link library in javascript program

Using c dynamic link library in javascript program

I want to use c dll in my javascript code.
Is that possible to do that using node ?
Thanks!