dimanche 31 août 2014

Snap render list in Hamlet


Vote count:

0




Given this little project I'm using to learn Haskell, I would like to move my request handler's code generation to a Hamlet template, but am unsure how to pass things around.


My current code generates the following error when lines are uncommented, which is the first blocker:



Couldn't match expected type String -> String' with actual typeString' In the return type of a call of renderHtml' Probable cause:renderHtml' is applied to too many arguments In the expression: renderHtml ($ (shamletFile "fileList.hamlet")) In an equation for `myTemplate': myTemplate = renderHtml ($ (shamletFile "fileList.hamlet"))



Code:



site :: Snap ()
site =
ifTop (writeBS "hello world") <|>
route [ ("foo", writeBS "ba"),
("view_root_json_files", listRootFilesHandler)
] <|>
dir "static" (serveDirectory ".")

--myTemplate :: String -> String
--myTemplate = renderHtml ( $(shamletFile "fileList.hamlet") )

toText :: [FilePath] -> Text
toText = foldMap (flip snoc '\n' . pack)

listRootFilesHandler :: Snap ()
listRootFilesHandler = do
filenames <- liftIO $ getDirectoryContents "data"
let filtered_filenames = filter (not . isPrefixOf ".") filenames
writeText $ toText filtered_filenames


asked 46 secs ago







Snap render list in Hamlet

I'm learning IntroToCS using Java and something went wrong


Vote count:

0




import java.awt.Rectangle;


public class IONS {



public static void main(String[] args) {
Rectangle x = new Rectangle(10, 20);
int width = x.width();
System.out.println(width);

}


}


ERROR: The method width() is undefined for the type Rectangle IONS.java


There is an error in line 7 while compiling, where am I going wrong ?



asked 21 secs ago







I'm learning IntroToCS using Java and something went wrong

Do not show icon on the cake


Vote count:

0




echo $html->link('', array('controller'=>'deals','action'=>'deals_print_setting','deal_id' => $deal['Deal']['id'], 'city' => $city_slug,'filter_id' => $id ,'ext' => 'csv'), array('class'=>'fancybox', 'data-fancybox-type'=>'ajax'));



asked 1 min ago







Do not show icon on the cake

Image Target Vufroria Sample example


Vote count:

0




i want to make my own object of tracker like in Image Target example i want to replace the Teapot by another 3D shape , the problem is i can't understand the code very well! here is the Code: Teapot Class: have two Functions: setVerts() and setIndices() with alot of indices and vertices numbers


and the ImageTargetRender is:



// The renderer class for the ImageTargets sample.
public class ImageTargetRenderer implements GLSurfaceView.Renderer
{
private static final String LOGTAG = "ImageTargetRenderer";

private SampleApplicationSession vuforiaAppSession;
private ImageTargets mActivity;

private Vector<Texture> mTextures;

private int shaderProgramID;

private int vertexHandle;

private int normalHandle;

private int textureCoordHandle;

private int mvpMatrixHandle;

private int texSampler2DHandle;

private Teapot mTeapot;

private float kBuildingScale = 12.0f;
private SampleApplication3DModel mBuildingsModel;

private Renderer mRenderer;

boolean mIsActive = false;

private static final float OBJECT_SCALE_FLOAT = 3.0f;


public ImageTargetRenderer(ImageTargets activity,
SampleApplicationSession session)
{
mActivity = activity;
vuforiaAppSession = session;
}


// Called to draw the current frame.
@Override
public void onDrawFrame(GL10 gl)
{
if (!mIsActive)
return;

// Call our function to render content
renderFrame();
}


// Called when the surface is created or recreated.
@Override
public void onSurfaceCreated(GL10 gl, EGLConfig config)
{
Log.d(LOGTAG, "GLRenderer.onSurfaceCreated");

initRendering();

// Call Vuforia function to (re)initialize rendering after first use
// or after OpenGL ES context was lost (e.g. after onPause/onResume):
vuforiaAppSession.onSurfaceCreated();
}


// Called when the surface changed size.
@Override
public void onSurfaceChanged(GL10 gl, int width, int height)
{
Log.d(LOGTAG, "GLRenderer.onSurfaceChanged");

// Call Vuforia function to handle render surface size changes:
vuforiaAppSession.onSurfaceChanged(width, height);
}


// Function for initializing the renderer.
private void initRendering()
{
mTeapot = new Teapot();

mRenderer = Renderer.getInstance();

GLES20.glClearColor(0.0f, 0.0f, 0.0f, Vuforia.requiresAlpha() ? 0.0f
: 1.0f);

for (Texture t : mTextures)
{
GLES20.glGenTextures(1, t.mTextureID, 0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, t.mTextureID[0]);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
GLES20.glTexParameterf(GLES20.GL_TEXTURE_2D,
GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA,
t.mWidth, t.mHeight, 0, GLES20.GL_RGBA,
GLES20.GL_UNSIGNED_BYTE, t.mData);
}

shaderProgramID = SampleUtils.createProgramFromShaderSrc(
CubeShaders.CUBE_MESH_VERTEX_SHADER,
CubeShaders.CUBE_MESH_FRAGMENT_SHADER);

vertexHandle = GLES20.glGetAttribLocation(shaderProgramID,
"vertexPosition");
normalHandle = GLES20.glGetAttribLocation(shaderProgramID,
"vertexNormal");
textureCoordHandle = GLES20.glGetAttribLocation(shaderProgramID,
"vertexTexCoord");
mvpMatrixHandle = GLES20.glGetUniformLocation(shaderProgramID,
"modelViewProjectionMatrix");
texSampler2DHandle = GLES20.glGetUniformLocation(shaderProgramID,
"texSampler2D");

try
{
mBuildingsModel = new SampleApplication3DModel();
mBuildingsModel.loadModel(mActivity.getResources().getAssets(),
"ImageTargets/Buildings.txt");
} catch (IOException e)
{
Log.e(LOGTAG, "Unable to load buildings");
}

// Hide the Loading Dialog
mActivity.loadingDialogHandler
.sendEmptyMessage(LoadingDialogHandler.HIDE_LOADING_DIALOG);

}


// The render function.
private void renderFrame()
{
GLES20.glClear(GLES20.GL_COLOR_BUFFER_BIT | GLES20.GL_DEPTH_BUFFER_BIT);

State state = mRenderer.begin();
mRenderer.drawVideoBackground();

GLES20.glEnable(GLES20.GL_DEPTH_TEST);

// handle face culling, we need to detect if we are using reflection
// to determine the direction of the culling
GLES20.glEnable(GLES20.GL_CULL_FACE);
GLES20.glCullFace(GLES20.GL_BACK);
if (Renderer.getInstance().getVideoBackgroundConfig().getReflection() == VIDEO_BACKGROUND_REFLECTION.VIDEO_BACKGROUND_REFLECTION_ON)
GLES20.glFrontFace(GLES20.GL_CW); // Front camera
else
GLES20.glFrontFace(GLES20.GL_CCW); // Back camera

// did we find any trackables this frame?
for (int tIdx = 0; tIdx < state.getNumTrackableResults(); tIdx++)
{
TrackableResult result = state.getTrackableResult(tIdx);
Trackable trackable = result.getTrackable();
printUserData(trackable);
Matrix44F modelViewMatrix_Vuforia = Tool
.convertPose2GLMatrix(result.getPose());
float[] modelViewMatrix = modelViewMatrix_Vuforia.getData();

int textureIndex = trackable.getName().equalsIgnoreCase("stones") ? 0
: 1;
textureIndex = trackable.getName().equalsIgnoreCase("tarmac") ? 2
: textureIndex;

// deal with the modelview and projection matrices
float[] modelViewProjection = new float[16];

if (!mActivity.isExtendedTrackingActive())
{
Matrix.translateM(modelViewMatrix, 0, 0.0f, 0.0f,
OBJECT_SCALE_FLOAT);
Matrix.scaleM(modelViewMatrix, 0, OBJECT_SCALE_FLOAT,
OBJECT_SCALE_FLOAT, OBJECT_SCALE_FLOAT);
} else
{
Matrix.rotateM(modelViewMatrix, 0, 90.0f, 1.0f, 0, 0);
Matrix.scaleM(modelViewMatrix, 0, kBuildingScale,
kBuildingScale, kBuildingScale);
}

Matrix.multiplyMM(modelViewProjection, 0, vuforiaAppSession
.getProjectionMatrix().getData(), 0, modelViewMatrix, 0);

// activate the shader program and bind the vertex/normal/tex coords
GLES20.glUseProgram(shaderProgramID);

if (!mActivity.isExtendedTrackingActive())
{
GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
false, 0, mTeapot.getVertices());
GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
false, 0, mTeapot.getNormals());
GLES20.glVertexAttribPointer(textureCoordHandle, 2,
GLES20.GL_FLOAT, false, 0, mTeapot.getTexCoords());

GLES20.glEnableVertexAttribArray(vertexHandle);
GLES20.glEnableVertexAttribArray(normalHandle);
GLES20.glEnableVertexAttribArray(textureCoordHandle);

// activate texture 0, bind it, and pass to shader
GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
mTextures.get(textureIndex).mTextureID[0]);
GLES20.glUniform1i(texSampler2DHandle, 0);

// pass the model view matrix to the shader
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,
modelViewProjection, 0);

// finally draw the teapot
GLES20.glDrawElements(GLES20.GL_TRIANGLES,
mTeapot.getNumObjectIndex(), GLES20.GL_UNSIGNED_SHORT,
mTeapot.getIndices());

// disable the enabled arrays
GLES20.glDisableVertexAttribArray(vertexHandle);
GLES20.glDisableVertexAttribArray(normalHandle);
GLES20.glDisableVertexAttribArray(textureCoordHandle);
} else
{
GLES20.glDisable(GLES20.GL_CULL_FACE);
GLES20.glVertexAttribPointer(vertexHandle, 3, GLES20.GL_FLOAT,
false, 0, mBuildingsModel.getVertices());
GLES20.glVertexAttribPointer(normalHandle, 3, GLES20.GL_FLOAT,
false, 0, mBuildingsModel.getNormals());
GLES20.glVertexAttribPointer(textureCoordHandle, 2,
GLES20.GL_FLOAT, false, 0, mBuildingsModel.getTexCoords());

GLES20.glEnableVertexAttribArray(vertexHandle);
GLES20.glEnableVertexAttribArray(normalHandle);
GLES20.glEnableVertexAttribArray(textureCoordHandle);

GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
GLES20.glBindTexture(GLES20.GL_TEXTURE_2D,
mTextures.get(3).mTextureID[0]);
GLES20.glUniformMatrix4fv(mvpMatrixHandle, 1, false,
modelViewProjection, 0);
GLES20.glUniform1i(texSampler2DHandle, 0);
GLES20.glDrawArrays(GLES20.GL_TRIANGLES, 0,
mBuildingsModel.getNumObjectVertex());

SampleUtils.checkGLError("Renderer DrawBuildings");
}

SampleUtils.checkGLError("Render Frame");

}

GLES20.glDisable(GLES20.GL_DEPTH_TEST);

mRenderer.end();
}


private void printUserData(Trackable trackable)
{
String userData = (String) trackable.getUserData();
Log.d(LOGTAG, "UserData:Retreived User Data \"" + userData + "\"");
}


public void setTextures(Vector<Texture> textures)
{
mTextures = textures;

}

}


buiding.xml is another file with diffrent numbers of vertices and indices i'm Confused about the numbers in Building.xml and in setVertx() .setindcises() plz help.



asked 54 secs ago







Image Target Vufroria Sample example

form validation in PHP using preg_match


Vote count:

0




Hi I am trying to validate a simple HTML form. Here is my HTML code-



<HTML>
<body>
<form method="get" action="password.php">
User ID<input type="text" name="user" id="user" required/><br/>
Password<input type="password" name="pass" id="pass" required/><br/>
<input type="submit" value"Login Here">
</form>
</body>
</html>


The password must contain only digits. My password.php is-



<?php
$name=$_GET['user'];
$pass=$_GET['pass'];

$strlen1= strlen($name);
$strlen2= strlen($pass);

$regex= "/^[789][0-9]{9}$/"; // my password should contain digits only.

if($strlen1==0 | $strlen2==0)
{
echo 'Username or password field is empty'.'<br/>';
}

else if($name==$pass)
{
echo 'Go for a better password'.'<br/>';
}

else if(!preg_match($regex,$pass))
{
echo 'password is invalid'.'<br/>';
}

else
{
echo 'You have successfully logged in'.'<br/>';
}

?>


On running the script even when I enter the valid password like-"123456" the message says- "password is invalid". Please let me know the mistake in above code. Thanks!!!



asked 1 min ago







form validation in PHP using preg_match

how to stream output as it happens C#


Vote count:

0




I got this code from microsoft support site and it allows you to run a external process from your application it give output after the execution of program but i would like to stream output as it happens on screen how do i do it?



using System;
using System.Diagnostics;
using System.IO;

namespace Way_Back_Downloader
{

internal class RunWget
{
internal static string Run(string exeName, string argsLine, int timeoutSeconds)
{
StreamReader outputStream = StreamReader.Null;
string output = "";
bool success = false;

try
{
Process newProcess = new Process();
newProcess.StartInfo.FileName = exeName;
newProcess.StartInfo.Arguments = argsLine;
newProcess.StartInfo.UseShellExecute = false;
newProcess.StartInfo.CreateNoWindow = true;
newProcess.StartInfo.RedirectStandardOutput = true;
newProcess.Start();



if (0 == timeoutSeconds)
{
outputStream = newProcess.StandardOutput;
output = outputStream.ReadToEnd();

newProcess.WaitForExit();
}
else
{
success = newProcess.WaitForExit(timeoutSeconds * 1000);

if (success)
{
outputStream = newProcess.StandardOutput;
output = outputStream.ReadToEnd();
}

else
{
output = "Timed out at " + timeoutSeconds + " seconds waiting for " + exeName + " to exit.";
}

}
}
catch (Exception exception)
{
throw (new Exception("An error occurred running " + exeName + ".", exception));
}
finally
{
outputStream.Close();
}
return "\t" + output;
}
}
}


asked 9 secs ago







how to stream output as it happens C#

Rotate around alternate axis


Vote count:

0




I am struggling with bitmap rotations. I wish to rotate a graphic around an alternate axis but I can only ever get it to rotate around the center point no matter what I do, putting in postTranlate. preTranslate, set Translate in any order doesnt work I have also tried the postRotate(45,0,0) but it always rotates around the center. Code below taken of internet what would I do to alter its rotation point, the code below uses the launcher icon which is square I am using a long thin graphic like an arrow. Thanks



// Rotate image to 45 degrees.

public void RotateImage(){
ImageView image;
Bitmap bMap;
Matrix matrix;

//Get ImageView from layout xml file
image = (ImageView) findViewById(R.id.imageView1);

//Decode Image using Bitmap factory.
bMap = BitmapFactory.decodeResource(getResources(), R.drawable.ic_launcher);

//Create object of new Matrix.
matrix = new Matrix();

//set image rotation value to 45 degrees in matrix.
matrix.postRotate(45);

//Create bitmap with new values.
Bitmap bMapRotate = Bitmap.createBitmap(bMap, 0, 0,
bMap.getWidth(), bMap.getHeight(), matrix, true);

//put rotated image in ImageView.
image.setImageBitmap(bMapRotate);
}


asked 28 secs ago







Rotate around alternate axis