Wednesday, May 2, 2012

C++ PPL nested parallel_for loop and lambda capture clause

I am writing nested parallel_for loops, and I wonder whether syntax for lambda capture clause in nested inner loop is appropriate.



// outer loop
parallel_for(0,p,[&highPPL,&lowPPL,&highOneParam,&lowOneParam, &formulaPPL, &confciInputPPL, &methodPPL, confciInput, formula, p, N, &param, up, down](int i)
{
double min = highOneParam[i];
double max = lowOneParam[i];

formulaPPL.local() = formula;
confciInputPPL.local() = new SolverInput(confciInput);
methodPPL.local() = new MethodNMMS(confciInputPPL.local());

/* other things*/

// inner loop
parallel_for(0,N,[p,i,&confciInputPPL.local()](int k)
{
QString prm;
double *x1Pt = new double[1];
double *x2Pt = new double[1];
confciInputPPL.local().local()=new SolverInput(confciInputPPL.local());

/* other things*/
}
}


I don't trust that I have to set as capture member conciInputPPL.local(), and then call confciInputPPL.local().local() to instanciate a copy of the former.



Thanks and regards.





Force user to logout session PHP

I can't seem to find a straightforward answer to this question. Is there a way in which I can force a logged in user to logout? My login system essentially just relies on a session containing the user's unique ID (which is stored in a mysql database). So essentially just...



if (isset($_SESSION['user_id'])) {
echo "You're logged in!";
} else {
echo "You need to login!";
}


But let's say I want to ban this user, well I can change their status to banned in my database but this won't do anything until the user logs out and attempts to log back in... So, how do I force this user to logout? Preferably without checking every single time they view a page whether or not their status has been switched to "banned" because that seems like unnecessary stress on my server. Any help is appreciated, thank you.





MySql query error near WHERE

My code is



$user_query = '
UPDATE
users
SET
`password`="$password",
`email`="$email",
`position`="$position",
WHERE
`username`=".$uname."';
$user_result = mysql_query($user_query, $connection);
confirm_query($user_result);


When I run this query it gives me a error saying



Database query failed: You have an error in your SQL syntax;
check the manual that corresponds to your MySQL server version for the right syntax to use near
'WHERE `username`=".$uname."' at line 7


Can any body help me on this error. thank you everyone.?





Saving XML files from a dataSet through ASP.NET

Currently I have two code samples, once takes a table from my database, puts it into a DataSet and then saves the DataSet and an XML file to my desktop.



The other code saves a file from a webpage. What I would like to do is combine these two code examples so that I can save my XML file through the internet.



Here are the samples:



SqlDataAdapter adapter = new SqlDataAdapter(query, connectionString);
DataSet questionSet = new DataSet();
adapter.Fill(questionSet, "Questions");

questionSet.WriteXml("../../../../../Users/User/Desktop/MyTest");


This successfully saves my table as an XML document and saves it to my Desktop.



The code sample from the MSDN for saving files through ASP.NET



System.String filename = "myFile.txt";

Response.ContentType = "text/xml";

// initialize the http content-disposition header to
// indicate a file attachment with the default filename
// "myFile.txt"
System.String disHeader = "Attachment; Filename=\"" + filename +
"\"";
Response.AppendHeader("Content-Disposition", disHeader);

// transfer the file byte-by-byte to the response object
System.IO.FileInfo fileToDownload = new
System.IO.FileInfo("C:\\downloadJSP\\DownloadConv\\myFile.txt");
Response.Flush();
Response.WriteFile(fileToDownload.FullName);}


This successfully saves a file through my browser.



As far as I understand it, it seems that .WriteXml creates a the file from the dataSet. Is there a way to throw that file at the other code and tell the browser to download the .WriteXml file instead?



All of this code looks almost like magic to me, but then again, it's .NET, which is known for its pixie dust!





MySQL Error 2002 - Can't connect through socket '/tmp/mysql.sock' on 64-bit, with a botched 32-bit uninstall complicating things

I'm new to Macs/MySQL, and am struggling to get MySQL working. I'm on 64-bit Lion, and first attempted to install the 32-bit MySQL from the command line. I then attempted to remove it and replace it with the 64-bit DMG, but the results of mysql -V indicate the 32-bit may still be around in some form. I get 2002 errors when trying to run MySQL-related commands, but Python's MySQLdb works fine. Below is more information; please let me know how to get this working.



I'm aware that some sort of linking is usually used to resolve the problem, but I can't find an answer that fits my file structure. I will try to be very responsive to asks for more information. Thanks!



bash-3.2$ mysql -V
mysql Ver 14.14 Distrib 5.1.62, for apple-darwin10.3.0 (i386) using readline 5.1

bash-3.2$ mysql
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)

bash-3.2$ mysqld
120501 20:21:42 [Warning] Can't create test file /usr/local/mysql-5.1.62-osx10.6-x86_64/data/MDP-main.lower-test
120501 20:21:42 [Warning] Can't create test file /usr/local/mysql-5.1.62-osx10.6-x86_64/data/MDP-main.lower-test
mysqld: Can't change dir to '/usr/local/mysql-5.1.62-osx10.6-x86_64/data/' (Errcode: 13)
120501 20:21:42 [ERROR] Aborting
120501 20:21:42 [Note] mysqld: Shutdown complete


bash-3.2$ ls /usr/local
MySQL-python-1.2.3 mysql
bin mysql-5.1.62-osx10.6-x86_64
etc share
git


And my bash path:



PATH=$PATH:/usr/local/mysql/bin:/usr/local/mysql-5.1.62-osx10.6-x86_64/bin      
export PATH





Edit 1: In response to the "permissions" suggestion, it doesn't seem to work in current form:



bash-3.2$ chown -R mysql.mysql /usr/local/mysql
chown: mysql.mysql: Invalid argument


In that directory:



bash-3.2$ ls -a /usr/local/mysql
. README include scripts
.. bin lib share
COPYING data man sql-bench
INSTALL-BINARY docs mysql-test support-files




Python Regular Expressions - removing all characters passed a certain character

I have a few regular expressions, for example, that looks like this
98374D90
483D39
3843930D393



Right now I have the python code taking out all characters and keeping integers like so:



ws = 98374D90
clean = re.sub("\D", "", ws)


Which leaves me with 9837490 but what I need it to do is once it reaches the character "D" it drops the D and everything after it so 98374D90 would result in 98374 how would I do this?



Thanks for the help.





how to custom jquery mobile on split button listview to 3 anchors?

I want to custom the jquery mobile on listview split button to 3 links for a list. http://jquerymobile.com/demos/1.1.0/docs/lists/lists-split.html



This is the example what i wanted :



enter image description here



Thanks for help.





How can I implement a swiping/sliding animation between views?

I have a few views between which I want to swipe in an iOS program. Right now, I'm swiping between them using a modal style, with a cross dissolve animation. However, I want to have a swiping/sliding animation like you see on the home screen and such. I have no idea how to code such a transition, and the animation style isn't an available modal transition style. Can anyone give me an example of the code? It doesn't need to be a modal model or anything, I just found that easiest.





Why is the view from my XIB file not being loaded by the UIViewController?

In my app delegate, I have:



- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch.
self.viewController = [[CGMContainerViewController alloc] init];
self.window.rootViewController = self.viewController;
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}


I have an unmodified CGMContainerViewController.h/m and a modified CGMContainerViewController.xib (added a button). The view is linked to the File Owner.



Why is the view from the XIB not showing?





Android, How to get context in C2DMReceiver constructor?

I have a C2DM receiver class that initialises the C2DM sender email in the constructor.
The thing is, I need to get the senders email from a resource string and therefore I need to get the context in the constructor for the receiver



The receiver looks like this



public class C2DMReceiver extends C2DMBaseReceiver {

public C2DMReceiver() {
super(AppConstants.getC2DMSender(this)); // How do I get the context here?
}

@Override
public void onRegistered(Context context, String registrationId)
throws java.io.IOException { ...


The relevant code on the C2DMBaseReceiver



public abstract class C2DMBaseReceiver extends IntentService {
...
private final String senderId;

/**
* The C2DMReceiver class must create a no-arg constructor and pass the
* sender id to be used for registration.
*/
public C2DMBaseReceiver(String senderId) {
// senderId is used as base name for threads, etc.
super(senderId);
this.senderId = senderId;
}
...


It's not really relevant to the question but for background purposes the reason for needing this is that the code is in a library project that is used in many android projects each of which has it's own sender's email address defined in a resource file. The AppConstants class has the job of reading the various resource strings and follows on from my accepted answer for a previous question here Android, Best way to provide app sepcific constants in a library project?



Finally for completeness the AppConstants.getC2DMSender method looks like this



public static String getC2DMSender(Context c){
return c.getResources().getString(uk.co.the_prize_quiz.quiz_template.R.string.c2dm_sender);
}


The specific app that users this library has the responsibility of setting the c2dm_sender variable in an xml resource. So in order to get this variable I need the context



<item type="string" name="c2dm_sender" format="string">app_specific_registered_c2dm@email_address</item>


Because this is set in a resource string the specific app can set this value and the template will use it automatically.





Showing a scrollbar only in Firefox

I'd like to have a scrollbar at the bottom of the div but this CSS works only in Firefox, not Webkit browsers like Safari or Chrome.



div.hoge {
width: 500px;
overflow: auto;
}


I googled and found some pages mentioning you should use overflow-x or -webkit-overflow-scrolling but they didn't work either. Need to use some JSs? Any guesses?





Generators to iterate over a dictionary uniformly in both Python 2 and 3

Is there a way to efficiently iterate over the values/items in a dictionary that works in both Python 2 and Python 3?



In Python 2, I can write



for x in mydict:
for x in mydict.iterkeys():
for x in mydict.viewkeys():
for x in mydict.itervalues():
for x in mydict.viewvalues():
for x in mydict.iteritems():
for x in mydict.viewitems():


and in Python 3, I have the following possibilities:



for x in mydict:
for x in mydict.keys():
for x in mydict.values():
for x in mydict.items():


So, I can iterate over the keys with for x in mydict, and that works in both Python 2 and 3. But is there a way to iterate over values and key-value pairs ('items') that works universally? I need it for writing Python code that can be run in both Python versions.



(On a side note, other obstacles with iterators can be bypassed easily; take for example:



if sys.version_info.major<3:
from itertools import izip as zip, imap as map


However, the dictionary methods cannot be redefined easily like map and zip.)



Any ideas?





getting save as file name in word

In the code below the file name is hard coded, but I want the user to be able to pick it.



I was reading about GetSaveAsFilename but I get an error when using it: "method or member not found".



fileSaveName = Application.GetSaveAsFilename _
(fileFilter:="Excel Files (*.txt), *.txt")


This is written for Word 2010. Am I wrong in thinking GetSaveAsFilename is available in word VBA?



 Sub Macro3()
'
' Macro3 Macro
'
'
ActiveDocument.SaveAs2 FileName:="Questionnaire01-05-20122.txt", _
FileFormat:=wdFormatText, LockComments:=False, Password:="", _
AddToRecentFiles:=True, WritePassword:="", ReadOnlyRecommended:=False, _
EmbedTrueTypeFonts:=False, SaveNativePictureFormat:=False, SaveFormsData _
:=True, SaveAsAOCELetter:=False, Encoding:=1252, InsertLineBreaks:=False, _
AllowSubstitutions:=False, LineEnding:=wdCRLF, CompatibilityMode:=0
End Sub


cheers





How to add Mathjax support to PHPMyAdmin

I use MySQL DBMS for storing my data. I've lot of mathematical data to enter into the database. I guess entering Mathematical data in the form of latex is a best option.(Please feel free to suggest if you think other solutions would be better). We use PHPMyAdmin for data entry into MySQL. Now thing is because we are entering lot of math data. It would be better to see what we are entering. Exactly similar to live preview of math.stackexchange.com. This is where Mathjax comes into picture. Now the big question is how to integrate Mathjax support to PHPMyAdmin?



If you want an example here is the kind of stuff we want to enter into the database:




In first year calculus, we define intervals such as $(u, v)$ and
$(u, \infty)$. Such an interval is a \emph{neighborhood} of $a$ if
$a$ is in the interval. Students should realize that $\infty$ is
only a symbol, not a number. This is important since we soon
introduce concepts such as $\lim_{x \to \infty} f(x)$.



When we introduce the derivative [ \lim_{x \to a} \frac{f(x) -
f(a)}{x - a}, ] we assume that the function is defined and continuous
in a neighborhood of $a$.






How to remove leading and trailing slash (/)?

I am using request.path to return current url in django, it is returning /get/category.



I need it as get/category (without leading and trailing slash). I don't want to use string functions.



Any idea?





Knockout.js - Setting initial values through a rails controller

I've got a rails app in which I want to setup my task object with some default values through rails and have knockout.js use those defaults for the observables.



What currently happens is the default from the rails controller is quickly replaced with a blank from the knockout.js observable command.



Here is my rails controller



def new
@task = Task.new
@task.task_date = Time.now
end


My knockout



Task = ->
@name = ko.observable()
@task_date = ko.observable()


My form



= f.text_field :task_date, "data-bind" => "value: name"
= f.text_field :task_date, "data-bind" => "value: task_date"


Do I have to pass JSON from my controller instead of using the default "render :new"?



Can I use the rails defaults at all?





how to calculate time during mousedown event in jquery?

I am trying to do 2 different functionalities on one button on mousedown - up events.
But its not working as i cant able to detect time on mousedown event.



var flag;  
$("#ClikerButton").mousedown(function(e){
//if mouse pressed more than 2 sec, then
// do func1 and set flag = true;
//else do nothing
}).mouseup(function(e){
//if flag == true, do nothing,
//else do func2;
});




How to Integrate Linkedin,Facebook and Google + in My Rails application?

My Rails version is 2.3.2.



Can any one send me some useful links that can be more effective.





Return After Failed Login Attempt PHP

I Am Developing login Form In PHp
The Form Is As Follows



<form method="post" action="Login.php" id="Log">
<select id="Login" name="Type">
<option value="Sel" selected="selected">Select Login type</option>
<option value="Student">Student</option>
<option value="Faculity">Faculity</option>
</select>
<div id="type">
<p id="Ch">Group Id: &nbsp;<input id="l" name="log" type="text"/></p>
<p id="Pass">Password: &nbsp; <input id="p" name="Pass" type="password" /></p>
<input id="Cond" type="Text" />
<input type="submit" value="Login" />
<p id="Invalid" style="padding-top:.75em; color:#FF0000;">Invalid Login Or Password</p>
</form>


In Post.php I Connect With Database And Check Login And Passwords
I Want To Show The Tag When Password Or Login don't Match In The Same Form Below It Without Any Delay
The Is Hidden At The Beginning And Only Be Shown When Login Or Pasword Is Incorrect
How Can I Achieve This Kindly Tell me I Connect With Database Through PHP





graph contributor empty

I have several projects on github, but in some of them the graph of contributors is empty, even though my .gitconfig has a name and email set up.
https://github.com/jlengrand/batchWaterMarking/graphs/contributors



You can see on main page that I am authored on last commit, as jlengrand
https://github.com/jlengrand/batchWaterMarking



I tried to commit and push once again, with a .gitconfig I am sure about, but it doesn't change anything.



Because of this, masterbranch refuses to take some of my projects into account.



Would you know a way to solve this ?



Thanks !