Thursday, 3 October 2013

Why is the PHP ipc message not in the queue?

Why is the PHP ipc message not in the queue?

In PHP I try to send a message through IPC, and to immediately check if
the message is in the queue. Here is a test code:
$rQueue = msg_get_queue(12345, 0660);
msg_send($rQueue, 0, "test", FALSE, FALSE);
print_r(msg_stat_queue($rQueue));
which prints out the statistics from the given queue, indicating
msg_qnum=0, i.e. no messages in the queue. I expect at least one message
in the queue instead. Where is the problem?

Wednesday, 2 October 2013

open() system call in C with char array as path appending ? to filename

open() system call in C with char array as path appending ? to filename

I am trying to open (and simultaneously create) a file in C, using a
character array as the path name I pass in which is stored within a node
structure. When I do this, it is appending a question mark to the file
name.
The array specifying the file name is defined as follows:
#define MAX_LENGTH 1024
typedef struct node {
...
char input[MAX_LENGTH]; // filename
...
}
When I initially put the program name in the node structure, I use
makeargv and strcpy as follows:
char **strings;
makeargv(s,":",&strings;
strcpy(n->input,strings[2]);
When I open the file, I try to redirect stdin to it as follows:
char **argumentList;
makeargv(nodes[i]->prog," ",&argumentList);
if (strcmp(nodes[i]->input, "stdin") != 0) {
char* input = nodes[i]->input;
int in = open(input, O_RDONLY);
dup2(in, 0);
int cl = close(in);
I am having trouble understanding if it is something to do with the way I
am passing the pathname in, the attempt to redirect to stdin, or something
else, and I'm having trouble figuring out exactly what the problem
is..could anyone point me in the right direction as to why this may be
happening?

how use regex to get from specific point to end of text?

how use regex to get from specific point to end of text?

I want to know what is the proper regular expression for that :
In an action unprecedented during 12 years of war in Afghanistan, the
commandant of the Marine Corps is firing two top generals. See why:
<a onmouseover="LinkshimAsyncLin.swap()>Generals fired over Taliban attack
</a><br/>security.blogs.cnn.com<br/>There were three investigations of the
incident.
I want to do the following :
give me string starting of a tag which contains
onmouseover="LinkshimAsyncLin.swap() in any position at properties area ..
and end with the end of the remain string .. i mean from this a tag to end
of the string
MY TRY :-
i used this pattern :
<a[^>]*?onmouseover\\s*=\\s*['\"]([^'\"]*?)['\"][^>]*?/?>
it got successfully this part <a onmouseover="LinkshimAsyncLin.swap()> i
want to get also all remain tags and text to the end point
Note :
My friends, I know that using regex with html tag is very bad practice and
i already have red that alot but i want that for special case
thank in advance :)

Recursive query with outer joins?

Recursive query with outer joins?

I'm attempting the following query,
DECLARE @EntityType varchar(25)
SET @EntityType = 'Accessory';
WITH Entities (
E_ID, E_Type,
P_ID, P_Name, P_DataType, P_Required, P_OnlyOne,
PV_ID, PV_Value, PV_EntityID, PV_ValueEntityID,
PV_UnitValueID, PV_UnitID, PV_UnitName, PV_UnitDesc, PV_MeasureID,
PV_MeasureName, PV_UnitValue,
PV_SelectionID, PV_DropDownID, PV_DropDownName,
PV_DropDownOptionID, PV_DropDownOptionName, PV_DropDownOptionDesc,
RecursiveLevel
)
AS
(
-- Original Query
SELECT dbo.Entity.ID AS E_ID, dbo.EntityType.Name AS E_Type,
dbo.Property.ID AS P_ID, dbo.Property.Name AS P_Name, DataType.Name AS
P_DataType, Required AS P_Required, OnlyOne AS P_OnlyOne,
dbo.PropertyValue.ID AS PV_ID, dbo.PropertyValue.Value AS PV_Value,
dbo.PropertyValue.EntityID AS PV_EntityID,
dbo.PropertyValue.ValueEntityID AS PV_ValueEntityID,
dbo.UnitValue.ID AS PV_UnitValueID, dbo.UnitOfMeasure.ID AS PV_UnitID,
dbo.UnitOfMeasure.Name AS PV_UnitName, dbo.UnitOfMeasure.Description
AS PV_UnitDesc, dbo.Measure.ID AS PV_MeasureID, dbo.Measure.Name AS
PV_MeasureName, dbo.UnitValue.UnitValue AS PV_UnitValue,
dbo.DropDownSelection.ID AS PV_SelectionID, dbo.DropDown.ID AS
PV_DropDownID, dbo.DropDown.Name AS PV_DropDownName,
dbo.DropDownOption.ID AS PV_DropDownOptionID, dbo.DropDownOption.Name
AS PV_DropDownOptionName, dbo.DropDownOption.Description AS
PV_DropDownOptionDesc,
0 AS RecursiveLevel
FROM dbo.Entity
INNER JOIN dbo.EntityType ON dbo.EntityType.ID = dbo.Entity.TypeID
INNER JOIN dbo.Property ON dbo.Property.EntityTypeID = dbo.Entity.TypeID
INNER JOIN dbo.PropertyValue ON dbo.Property.ID =
dbo.PropertyValue.PropertyID AND dbo.PropertyValue.EntityID =
dbo.Entity.ID
INNER JOIN dbo.DataType ON dbo.DataType.ID = dbo.Property.DataTypeID
LEFT JOIN dbo.UnitValue ON dbo.UnitValue.ID =
dbo.PropertyValue.UnitValueID
LEFT JOIN dbo.UnitOfMeasure ON dbo.UnitOfMeasure.ID =
dbo.UnitValue.UnitOfMeasureID
LEFT JOIN dbo.Measure ON dbo.Measure.ID = dbo.UnitOfMeasure.MeasureID
LEFT JOIN dbo.DropDownSelection ON dbo.DropDownSelection.ID =
dbo.PropertyValue.DropDownSelectedID
LEFT JOIN dbo.DropDownOption ON dbo.DropDownOption.ID =
dbo.DropDownSelection.SelectedOptionID
LEFT JOIN dbo.DropDown ON dbo.DropDown.ID =
dbo.DropDownSelection.DropDownID
WHERE dbo.EntityType.Name = @EntityType
UNION ALL
-- Recursive Query?
SELECT E2.E_ID AS E_ID, dbo.EntityType.Name AS E_Type,
dbo.Property.ID AS P_ID, dbo.Property.Name AS P_Name, DataType.Name AS
P_DataType, Required AS P_Required, OnlyOne AS P_OnlyOne,
dbo.PropertyValue.ID AS PV_ID, dbo.PropertyValue.Value AS PV_Value,
dbo.PropertyValue.EntityID AS PV_EntityID,
dbo.PropertyValue.ValueEntityID AS PV_ValueEntityID,
dbo.UnitValue.ID AS PV_UnitValueID, dbo.UnitOfMeasure.ID AS PV_UnitID,
dbo.UnitOfMeasure.Name AS PV_UnitName, dbo.UnitOfMeasure.Description
AS PV_UnitDesc, dbo.Measure.ID AS PV_MeasureID, dbo.Measure.Name AS
PV_MeasureName, dbo.UnitValue.UnitValue AS PV_UnitValue,
dbo.DropDownSelection.ID AS PV_SelectionID, dbo.DropDown.ID AS
PV_DropDownID, dbo.DropDown.Name AS PV_DropDownName,
dbo.DropDownOption.ID AS PV_DropDownOptionID, dbo.DropDownOption.Name
AS PV_DropDownOptionName, dbo.DropDownOption.Description AS
PV_DropDownOptionDesc,
(RecursiveLevel + 1)
FROM Entities AS E2
INNER JOIN dbo.Entity ON dbo.Entity.ID = E2.PV_ValueEntityID
INNER JOIN dbo.EntityType ON dbo.EntityType.ID = dbo.Entity.TypeID
INNER JOIN dbo.Property ON dbo.Property.EntityTypeID = dbo.Entity.TypeID
INNER JOIN dbo.PropertyValue ON dbo.Property.ID =
dbo.PropertyValue.PropertyID AND dbo.PropertyValue.EntityID = E2.E_ID
INNER JOIN dbo.DataType ON dbo.DataType.ID = dbo.Property.DataTypeID
INNER JOIN dbo.UnitValue ON dbo.UnitValue.ID =
dbo.PropertyValue.UnitValueID
INNER JOIN dbo.UnitOfMeasure ON dbo.UnitOfMeasure.ID =
dbo.UnitValue.UnitOfMeasureID
INNER JOIN dbo.Measure ON dbo.Measure.ID = dbo.UnitOfMeasure.MeasureID
INNER JOIN dbo.DropDownSelection ON dbo.DropDownSelection.ID =
dbo.PropertyValue.DropDownSelectedID
INNER JOIN dbo.DropDownOption ON dbo.DropDownOption.ID =
dbo.DropDownSelection.SelectedOptionID
INNER JOIN dbo.DropDown ON dbo.DropDown.ID =
dbo.DropDownSelection.DropDownID
)
SELECT E_ID, E_Type,
P_ID, P_Name, P_DataType, P_Required, P_OnlyOne,
PV_ID, PV_Value, PV_EntityID, PV_ValueEntityID,
PV_UnitValueID, PV_UnitID, PV_UnitName, PV_UnitDesc, PV_MeasureID,
PV_MeasureName, PV_UnitValue,
PV_SelectionID, PV_DropDownID, PV_DropDownName, PV_DropDownOptionID,
PV_DropDownOptionName, PV_DropDownOptionDesc,
RecursiveLevel
FROM Entities
INNER JOIN [dbo].[Entity] AS dE
ON dE.ID = PV_EntityID
The problem is the second query, the "recursive one" is getting the data I
expect since I can't do the LEFT JOINs like in the first query. (At least
to my understanding).
Is there a way I can accomplish this? (Background info and clarity
available if necessary)

Limit fields to update in Mass Update

Limit fields to update in Mass Update

I use these two codes to select a list of field names to be updated. But I
would rather want to limit the fields for update.The code below returns
all available fields. How can I do this?
// this is the controller code
public List<SelectOption> getFieldTypeOptions() {
// prevent url hacking
if (objs.size()<1) return null;
List<SelectOption> options = new List<SelectOption>();
options.add(new SelectOption('','-None-'));
Schema.DescribeSObjectResult sObj = discoverSObjectType(objs.get(0));
fieldMap = sObj.fields.getMap();
List<String> keys = sortByFieldLabel(fieldMap);
for(String key:keys) {
Schema.DescribeFieldResult d = fieldMap.get(key).getDescribe();
if(d.isAccessible() && d.isUpdateable()) {
if (isSupportedFieldType(d)) {
String label = d.getLabel();
if(d.isCustom()) label += ' (' + key + ')';
options.add(new SelectOption(key, label));
}
}
}
return options;
// This is the VisualForce Page
<apex:selectList id="pickList" size="1" value="{!fieldName}" required="true">
<apex:selectOptions value="{!fieldTypeOptions}"/>

Tuesday, 1 October 2013

jQuery Wrap function Divs but one

jQuery Wrap function Divs but one

How do you wrap every div in jQuery but the div you are in? I assume it is
the wrap function, but not sure how to manipulate it to make it wrap all
but this div.

Facebook image upload with custom post message

Facebook image upload with custom post message

I am currently building an app which generates a custom image with user's
facebook username on it. The username is being collected by one of the
following methods:
Asking user for his Facebook username and doing a graph search and thus
obtaining his username.
Threw Facebook connect which will authorize user to my website and I can
get what I want (with Permissions: publish_stream,user_photos )
In the end, I let user to post the image to his Facebook wall threw a button:
<a href="imageupload.php?filename="abc" >Post this image to facebook</a>
and content of imageupload.php is:
$appId = 'MY_APP_ID';
$appSecret = 'MY_APP_SECRET';
$return_url = 'MY_HOME_URL';
$fbPermissions = 'publish_stream,user_photos';
include_once("inc/facebook.php"); //include facebook api library
//Call Facebook API
$facebook = new Facebook(array(
'appId' => $appId,
'secret' => $appSecret,
'fileUpload' => true,
'cookie' => true
));
$facebook->setFileUploadSupport(true);
//get user
$fbuser = $facebook->getUser();
$access_token = $facebook->getAccessToken();
//get full image path else logout
if(!empty($_GET['filename'])){ $img = 'uploads/'.$_GET['filename'].'.jpg';}
else{
$loginUrl = $facebook->getLoginUrl(array('scope'=>$fbPermissions,
'return_url'=>$return_url));
header('Location: ' . $loginUrl);
}
//variables we are going to post to facebook
$msg_body = array(
'source' => '@' . realpath($img),
'message' => 'I have created this image at '.$return_url
);
if ($fbuser){ //user is logged in to facebook, post our image
try {
$uploadPhoto = $facebook->api('/me/photos', 'POST', $msg_body );
} catch (FacebookApiException $e) {
echo $e->getMessage(); //output any error
}
}else{
$loginUrl =
$facebook->getLoginUrl(array('scope'=>$fbPermissions,'return_url'=>$return_url));
header('Location: ' . $loginUrl);
}
This successfully post my image to Facebook with a "PREDEFINED MESSAGE". I
know I have authorized user, but wouldn't that be counted in a Black Hat
spamming if you are self generating a message on user's wall without
letting him to post the text if he wanted to.
If so, How can I use some dialog box like Facebook Feed (Which I am not
using BTW because it is not the way to post image I suppose) that can
"ethically" send user's photo with a custom message(if this is considered
ethical) to his/her Facebook's wall?

Starting a script with a keypress without an X server

Starting a script with a keypress without an X server

I am looking for a way to bind any sequence of keys to an action that will
run a script. I need to accomplish this on a Ubuntu 12.10 server which
does not have X. I have looked into Upstart however I am unable to find an
event that satisfies my needs.

I am able to call a method w/o passing the required arguments in c++. How come=?iso-8859-1?Q?=3F_=96_stackoverflow.com?=

I am able to call a method w/o passing the required arguments in c++. How
come? – stackoverflow.com

Here is the code... #include "stdafx.h" #include<iostream> using namespace
std; class Base { public: virtual void Display(bool b = false) { ...