$q = $_GET['q'];
// Load and parse the XML document
$rss = simplexml_load_file('http://search.twitter.com/search.atom?lang=en&q=$q&rpp=100&page=1');
This returns results containing "$q" instead of results containing the value of $q. Why won't it work?
If I wanted to have a collection that described the (recursive) contents of a root directory, including directories and files, how would I store them? Or do I need to come up with an object that holds:
-Current directory
-Parent directory
-Files in directory
..and slap them all in one big list and manually work out the relationship at runtime from each entries Parent directory.
Given this extension method
public static void Until(this Action action, Func<bool> booleanFunc)
{
while (!booleanFunc())
action();
}
is it possible to turn this
var x = 0;
Action ac = () => x += 1;
ac.Until(() => x == 5);
into something of this sort
var x = 0;
(() => x += 1).Until(() => x == 5);
That is, a one liner?
select @[email protected]('*')
for xml raw,type
Above statement will generate following alert:
Msg 6819, Level 16, State 3, Line 2
The FOR XML clause is not allowed in a ASSIGNMENT statement.
Hello,
I'm looking for a way to use pthread rwlock structure with conditions routines in C++.
I have two questions:
First: How is it possible and if we can't, why ?
Second: Why current POSIX pthread have not implemented this behaviour ?
To understand my purpose, I explain what will be my use: I've a producer-consumer model dealing with one shared array. The consumer will cond_wait when the array is empty, but rdlock when reading some elems. The producer will wrlock when adding(+signal) or removing elems from the array.
The benefit of using rdlock instead of mutex_lock is to improve performance: when using mutex_lock, several readers would block, whereas using rdlock several readers would not block.
I have a little problem:
slideHelpers.total = 4
for (i=1;i <= slideHelpers.total; i++) {
$('<a href="#">' + i + '</a>').bind('click', function(){ alert('go to the ' + i + ' slide')}).appendTo('.slideaccess')
}
the alert gives out 5 what is logic, because when the function click triggers i is actually 5. But i would like to have the same i as in my <a> tag. What is the best way to handle this?
I could put i in the data() of the <a> tag for example but i am sure there is a easier way.
I have three text boxes on the stage id=red, blue, green same as the keys in my
cars Object/Array
public function carsToBox():void
{
var cars:Object={red:"300zx",blue:"Skyline",green:"Supra"};
for(var tempObj:String in cars)
{
tempObj.text= cars[tempObj];//this trows errors
}
}
So I'm thinking "tempObj.text" would equal red.text but I can't stick "tempObj" with ".text" is there a way this can be done?
How would I go about parsing incoming form data where the name changes based on section of site like:
<input type="radio" name="Motorola section" value="Ask a question">
where 'Motorola section may be that, or Verizon section, or Blackberry section, etc.
I do not have any control over changing the existing forms unfortunately, so must find a way to work with what is there.
Basically, I need to be able to grab both the name="" data as well as its coresponding value="" data to be able to populate the email that gets sent properly.
I'm trying to use a dynamically generated fully-qualified table name in sql server 2008. For example, this does not work:
select max([id]) from @dbName+N'.[T1]'
This will give an error like:
Msg 102, Level 15, State 1, Line 73
Incorrect syntax near '+'.
I know that something like this works:
declare @qualifiedTable varchar(200) = @dbName+N'.[T1]'
select max([id]) from @qualifiedTable
But I have to do this LOTS of times so I would really like to do it in line. Is it possible?
I'm in love with the function in Eclipse "assign to field". Basically, when I have
getString();
and I type ctrl-2, Eclipse converts this into
String getString = getString();
Is this possible in VS 2010?
Hi,
I would like to add some debugs for my simple ruby functions and I wrote a function as below,
def debug(&block)
varname = block.call.to_s
puts "#{varname} = #{eval(varname,block)}"
end
debug {:x} #prints x = 5
debug {:y} #prints y = 5
I understand that eval is evil. So I have two questions.
Is there any way to write that debug method without using eval? If NO is there a preferred way to do this?
Is there any way to pass a list of arguments to this method? I would ideally prefer debug {:x, :y. :anynumOfvariables}. I could not quite figure out how to factor that into the debug method (i.e, to take a list of arguments)
So I'm trying to store the "rank" of a user when they log in to a control panel which displays different options depending on the given rank. I used the same method as I did for storing and displaying the username, which is displayed on the top of each page and works just fine. I can't for the life of me figure out why it won't work for the rank value, but I do know that it is not saving it in the session. Here is the bit that's not working;
$username = ($_POST['username']);
$password = hash('sha512', $_POST['password']);
$dbhost = 'mysql:host=¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦;dbname=¦¦¦¦¦¦¦¦¦¦¦';
$dbuser = '¦¦¦¦¦¦¦¦¦¦¦';
$dbpassword = '¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦¦';
try {
$db = new PDO($dbhost, $dbuser, $dbpassword);
$statement = $db->prepare("select password from users where email = :name");
$statement->execute(array(':name' => $username));
$result = $statement->fetch();
$pass = $result[password];
$rank = $result[rank];}
catch(PDOException $e) {echo $e->getMessage();}
if ($password == $pass) {
session_start();
$_SESSION['username'] = $username;
$_SESSION['rank'] = $rank;
header('Location: http://¦¦¦¦¦¦¦¦¦.ca/manage.php');
}
else{
include'../../includes/head.inc';
echo '<h1>Incorrect username or password.</h1>';
include'../../includes/footer.inc';
}
I'm also new to the whole PDO thing, hence why my method of authenticating the password is pretty sketchy.
Let's say we have an empty bathtub. We've lost the plug, so once water is added it will drain away at a constant rate of 2 liters pr. minute. We add water to the tub in increments. 60 liters at 10:51, 30 liters at 11:54 and 50 liters at 13:18.
So, the question is: How can I find out how much water is in the bathtub at any given time?
Hello, heres basically what I need to get done.
I have a jsp page which allows me to add/modify/delete an item.
The items are stored in a database which I have controller classes to access(dont worry bout that part)
When an item gets selected and deleted the id of the item gets sent to the controller to be processed.
The item will not always be deleted if their is a foreign key constraint so I send either a delete=true or delete=false through url back to the jsp page.
I would like to have it so a javascript function gets called displaying an alert saying the item was deleted or the item was not deleted.
can someone please tell me the best way to do this? thank you
I'm often confused by this. I've always been taught to name numbers I use often using variables or constants, but if it reduces the efficiency of the program, should I still do it? Heres an example:
private int CenterText(Font font, PrintPageEventArgs e, string text)
{
int recieptCenter = 125;
int stringLength = Convert.ToInt32(e.Graphics.MeasureString(text, font));
return recieptCenter - stringLength / 2;
}
The above code is using named variables, but runs slower then this code:
private int CenterText(Font font, PrintPageEventArgs e, string text)
{
return 125 - Convert.ToInt32(e.Graphics.MeasureString(text, font) / 2);
}
In this example, the difference in execution time is minimal, but what about in larger blocks of code?
In C# (within the context of T4 template see http://www.olegsych.com/2008/03/how-to-generate-multiple-outputs-from-single-t4-template/) I want to do this
<# String myTemplateVar;
#>
<# if (string.IsNullOrEmpty(myTemplateVar)) {
myTemplateVar= "name";
};
#>
I want to give a value to myTemplateVar if myTemplateVar has not already been setup by an external call from T4 engine in another template which would have this instruction:
CallContext.SetData("myTemplate.myTemplateVar", ExternalTemplateVar);
But I cannot even compile in C# why ? How to fix this ?
Hello All,
I am writing a little install script for some software. All it does is unpack a target tar, and then i want to permanently set some environment variables - principally the location of the unpacked libs and updating $PATH. Do I need to programmatically edit the .bashrc file, adding the appropriate entries to the end for example, or is there another way? What's standard practice?
Thanks
hey there, I'm creating a series of input elements and for some reason their values aren't $_POSTing. Any light shed on the subject would be appreciated!
My current code is as follows:
javascript
Afields = 1;
function addAdultInput() {
if (Afields != 10) {
document.getElementById('adultMembers').innerHTML += "<input type='text' value='' name='adult_members_"+Afields+"' /><br />";
Afields += 1;
} else {
document.getElementById('adultMembers').innerHTML += "Only 10 Adult Member fields allowed.";
document.getElementById('addAdultMember').disabled=true;
}
}
HTML
<form name="form1" method="post" action="">
<tr>
<td class="style12" valign="top">Adult Members' Names:<br /><small>10 Max </small><input id="addAdultMember" type="button" onclick="addAdultInput()" name="add" value="Add Adult" /></td>
<td id="adultMembers">
<span class="erorr">*for paid members only</span><br />
<input type='text' value='' name='adult_members_0' /><br />
</td>
</tr>
<input type="submit" name="Submit" value="Register">
</form>
How would I take a text box value and use it in the query string on submit? I'd like it to start as this,
/News?favorites=True
and end up something like this after the user enters in a search and clicks search.
/News?query=test&favorites=True
The controller action looks like this
public ActionResult Index(string query,bool favorites)
{
//search code
}
This question is something close to what I'd like to do, but I'd like to use the query string and maintain the existing values in the query string.
Thanks.
class CheckStore {
private String displayText;
private boolean state;
private String meaningfulText;
private URL url;
public CheckStore(String text, boolean state) {
this.displayText = text;
this.state = state;
}
:
:
}
As I am initializing only two variables (displayText and state) in the constructor, Will the rest two variables (meaningfulText and url which will have the value null) will require space in memory to store null value.
Q1. I think they will require space. If they will, then how much memory does a null value takes in the memory (like int takes 4 bytes).
Q2. How much space a string takes in memory. I guess it will depend on the length of the string. So how much space a string takes of how much length?
I want to organize my c++ variables and functions in the following way: function prototypes in a header file "stuff.h", function implementation in "stuff.cpp", then say #include "stuff.h" in main.cpp (so I can call functions implemented in stuff.cpp). So far so good. Now I want to declare some variables in stuff.cpp that have global scope (so I can modify the variables in functions implemented in stuff.cpp and main.cpp). This doesn't seem to work. How can I do this?
I have a list of posts and an edit link for each. When clicking edit it goes to a page where I can edit the specific post I clicked on. For this I will have to pull from the db the id of the post.
Would this be the correct way to do it?
<a href="<?php echo site_url("post/edit/$row->id"); ?>">Edit</a>
post is my controller, edit is my function, and $row->id should pull the id of the post.
hi everyone, i have a collection of book object in a hashmap, the book has book_title, book_author, book_year_published, etc. i want to sort them based on the book_title which is a String, in both ascending and descending order, and display them on the screen. i wish someone can help me, i have been doing this for hours and still havent come up with a solution. thanks in advance