I'm writing a code generator which produces Scala output.
I need to emulate a ternary operator in such a way that the tokens leading up to '?' remain intact.
e.g. convert the expression c ? p : q to c something. The simple if(c) p else q fails my criteria, as it requires putting if( before c.
My first attempt (still using c/p/q as above) is
c match { case(true) = p; case _ = q }
another option I found was:
class ternary(val g: Boolean = Any) { def |: (b:Boolean) = g(b) }
implicit def autoTernary (g: Boolean = Any): ternary = new ternary(g)
which allows me to write:
c |: { b: Boolean = if(b) p else q }
I like the overall look of the second option, but is there a way to make it less verbose?
Thanks
In my web.config I have the following:
<customErrors mode="RemoteOnly" defaultRedirect="/error.aspx"/>
When an error occurs, the user is redirected to /error.aspx?aspxerrorpath=/somepage where I can get user's name, name of the page, date, but... I can't get the error message!
I can get it via the OnException method, but then I won't be able to get the name of the page which is very important for me.
How can I get both the page and the error message?
<td valign="center" colspan="2">
<a href="" class="table_desc" >
<span class="desc_info_butt"></span>
</a>
text here
</td>
.desc_info_butt{
background:url(Description_Button.png) top left no-repeat;
height:16px;
width:16px;
display:block;
}
For some reason, the image and text appear on two different lines!~
I'm having trouble translating a subroutine from Perl to PHP (I'm new to Perl).
The entire subroutine is as follows:
sub find_all_subsets {
if (1 == scalar (@_)) {return [@_]}
else {
my @all_subsets = () ;
my $last_item = pop (@_) ;
my @first_subsets = find_all_subsets (@_) ;
foreach my $subset (@first_subsets) {
push (@all_subsets, $subset) ;
my @ext_subset = @{$subset} ;
push (@ext_subset, $last_item) ;
push (@all_subsets, [@ext_subset]) ;
}
push (@all_subsets, [$last_item]) ;
return (@all_subsets) ;
}
}
My problem is that I really don't quite understand the Perl syntax, so I'm having trouble writing these @{$subset}, [@ext_subset] and [$last_item] in PHP.
Thanks and sorry if the question is stupid.
Hi:
In one of my window form, I created an instance of a class to do some works in the background. I wanted to capture the debug messages in that class and displayed in the textbox in the window form. Here is what I did:
class A //window form class
{
public void startBackGroundTask()
{
B backGroundTask = new B(this);
}
public void updateTextBox(string data)
{
if (data != null)
{
if (this.Textbox.InvokeRequired)
{
appendUIDelegate updateDelegate = new appendUIDelegate(updateUI);
try
{
this.Invoke(updateDelegate, data);
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
}
else
{
updateUI(data);
}
}
}
private void updateUI(string data)
{
if (this.Textbox.InvokeRequired)
{
this.Textbox.Invoke(new appendUIDelegate(this.updateUI), data);
}
else
{
//update the text box
this.Textbox.AppendText(data);
this.Textbox.AppendText(Environment.NewLine);
}
}
private delegate void appendUIDelegate(string data);
}
class B // background task
{
A curUI;
public b( A UI)
{
curUI = UI;
}
private void test()
{
//do some works here then log the debug message to UI.
curUI.updateTextBox("message);
}
}
I keep getting a null reference exception after
this.Invoke(updateDelegate, data);
is called.
I know passing "this" as a parameter is strange. But I want to send the debug message to
my window form.
Please help.
Thanks
I have a very big table with a lot of rows, every row has stats for every user for certain days. And obviously I don't have any stats for future. So to update the stats I use
UPDATE Stats SET Visits=@val WHERE ... a lot of conditions ... AND Date=@Today
But what if the row doesn't exist? I'd have to use
INSERT INTO Stats (...) VALUES (Visits=@val, ..., Date=@Today)
How can I check if the row exists or not? Is there any way different from doing the COUNT(*)?
If I fill the table with empty cells, it'd take hundreds of thousands of rows taking megabytes and storing no data.
This is my first time building a responsive site, and as I tailor the CSS for the iPhone I'm running into a problem. The styles all apply correctly, the text changes size and the wrapper changes widths. The problem is the iPhone browser still opens up at a huge width, see the screenshot:
I'm using
@media all and (max-device-width: 480px) {}
to set the specific iPhone css. body {width:;} doesn't work.
Thanks for the help :)
My Zend application is going to get an command line php script that should email reports. There generation depends on Zend_View, Zend_Layout and is currently already working fine in the web interface.
How can I reuse this whole MVC functionality in the command line?
Should I add a new controller CommandLineController and call this somehow from the commandline?
How can I kick of such a Controller manually, without having a HTTP request?
I'm an html noob and I just wanted to know if it's possible to make a text box in which you could type a website and when you click submit it will load the website in the iframe of your choice.
Usually I would have a table field called ID on auto increment. That way I could order using this field etc.
However I have no control over the structure of a table, and wondered how to get the results in reverse order to default.
I'm currently using
$q = mysql_query("SELECT * FROM ServerChat LIMIT 15");
However like I said there is no field I can order on, so is there a way to tell mysql to reverse the order it gets the results? I.e last row to first row instead of the default.
I like using LINQ to SQL. The only problem is that I don't like the default way of updating tables.
Let's say I have the following table with the following columns:
ID (primary key), value1, value2, value3, value4, value5
When I need to update something I call
UPDATE ... WHERE ID=@id
LINQ to SQL call
UPDATE ... WHERE ID=@id and value1=@value1 and value2=@value2 and value3=@value3 and value4=@value4 and value5=@value5
I can override this behavior by adding
UpdateCheck=UpdateCheck.Never
to every column, but with every update of the DataContext class with the GUI, this will be erased. Is there any way to tell LINQ to use this way of updating data?
Is there a simple :) and efficient way or reading very large number of rows sequentially using Zend_Db?
Basically I need to process entire table, row by row. Table is large, primary key sequence is not guaranteed(i.e. not an autoincrement, but is UNSIGNED INT).
What's the best way to approach this?
Environment: PHP 5.2, Zend Framework 1.10, MySQL 5.1
I get this message at runtime of ASP.NET 2 page :
The page 'MyFolder/blabla.aspx' cannot use the user control 'MyFolder/MyControl.ascx', because it is registered in web.config and lives in the same directory as the page.
Of course I can separate them to 2 different folders and thus solve the problem, but the question is :
WTF !?!?! Why I can't put them in the same folder ?!
Why can't they all .. get along !?! :)
Thanks
Basically, what I want to do is to be notified whenever a specific method has been called. I was hoping I could accomplish this using Reflection, but my attempts haven't gotten me anywhere yet, so I'm hoping that perhaps somebody else with the same need has accomplished this before and can enlighten me.
I figured using MethodInfo was the way to go, but like I said, I found nothing there that could help me accomplish what I wanted to do. Any suggestions, hints or solutions would be greatly appreciated.
i had string like this in javascript
var str = "This is my test string is Ingrédients";
the substring "Ingrédients" can be also as "Ingredients"
how to get the index of substring "Ingrédients" from the above string
by applying regular expression ( Ingr[ée]dients )
//API
class Node
class Person extends Node
object Finder
{
def find[T <: Node](name: String): T = doFind(name).asInstanceOf[T]
}
//Call site (correct)
val person = find[Person]("joe")
//Call site (dies with a ClassCast inside b/c inferred type is Nothing)
val person = find("joe")
In the code above the client site "forgot" to specify the type parameter, as the API writer I want that to mean "just return Node". Is there any way to define a generic method (not a class) to achieve this (or equivalent). Note: using a manifest inside the implementation to do the cast if (manifest != scala.reflect.Manifest.Nothing) won't compile ... I have a nagging feeling that some Scala Wizard knows how to use Predef.<:< for this :-)
Ideas ?
I have a C# security/monitoring application that I need to have running no matter what. However, I can not remove privileges or restrict access to parts of the OS (Windows).
I thought of having a protection service running which monitors continuously if an application is running, and starts it back up when the application is killed somehow, while the application monitors the protection service and starts the service if the service is killed. To my knowledge you can't simultaneously kill multiple processes at the same time.
Any better idea to guarantee that an application is always running?
in R , when i use "print", i can see all the values, but how can i save this as a vector
for example, in for loop,
for (i in 1:10), i want the value of A , when i= 1,2,3,4..... but if i use the x=A, it only have the final value of A which is the value when i = 10. so , how can i save the vaule in print(A)