I've recently knocked up a server/client app for Windows & Android that allows one to send a file from Windows to an android phone over a socket connection.
It works great for a single file but trying to send multiple files over in a single stream is causing me problems. I've also realised that aside from the binary data, I will need to send messages over the socket to indicate error states and other application messages. I have little experience with network programming and and wondering what is the best way forward.
Basically the C# server side of the app just goes into a listening state and uses Socket.SendFile to transmit the file. On Android I use the standard Java Socket.getInputStream() to receive the file. That works great for a single file transfer, but how should I handle multiple files and error/messaging information? Do I need to use a different socket for each file? Should I be using a higher level framework to handle this or can I send everything over the single socket? Any other suggestions for frameworks or learning materials?
I am writing an abstract matrix class (and some concrete subclasses) for use on very differing hardwares/architectures, etc. and I want to write a row and column type that provides a transparent reference to the rows and columns of the matrix.
However, I want to tune for performance, so I'd like this class to be essentially a compiler construct. In other words, I'm willing to sacrifice some dev time to making the overhead of these classes as small as possible.
I assume all (small) methods would want to be virtual? Keep the structure small? Any other suggestions?
Question:
The prime factors of 13195 are 5, 7, 13 and 29.
What is the largest prime factor of the number 600851475143?
I found this one pretty easy, but running the file took an extremely long time, it's been going on for a while and the highest number I've got to is 716151937.
Here is my code, am I just going to have a wait or is there an error in my code?
//User made class
public class Three
{
public static boolean checkPrime(long p)
{
long i;
boolean prime = false;
for(i = 2;i<p/2;i++)
{
if(p%i==0)
{
prime = true;
break;
}
}
return prime;
}
}
//Note: This is a separate file
public class ThreeMain
{
public static void main(String[] args)
{
long comp = 600851475143L;
boolean prime;
long i;
for(i=2;i<comp/2;i++)
{
if(comp%i==0)
{
prime = Three.checkPrime(i);
if(prime==true)
{
System.out.println(i);
}
}
}
}
}
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 :)
This is probably a really simple question, but how do I go about getting the right offset of an element in jQuery?
I can do:
$("#whatever").offset().left;
and it is valid.
But it seems that:
$("#whatever").offset().right
is undefined.
So how does one accomplish this in jQuery?
Thanks!!
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
Hi,
I have a problem with JQuery Context Menu ( link text ) and iframe.
If i use it inside, the context menu is naturaly shown inside. But it will be partialy shown.
I am searching how to resolve it.
Please note that the context menu only appear when i click on specific iframe's elements.
thanks :)
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?
//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'd like everything to function correctly, except when it's mobile, the entire site will used a set of specific templates.
Also, I'd like to autodetect if it's mobile. If so, then use that set of templates throughout the entire site.
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 have a class User and a class History. History has 'User' property, and User has 'Histories' property. So there's a database relationship.
But when I create a new User history class and set UserID property, I can't access the 'User' property.
var history = new History { UserID = 1 };
// history.User = null ???
How can I get the user?
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 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?
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.
Suppose I have this:
<select id="myselect">
<option rel="a">1</option>
<option rel="b">2</option>
<select>
How do I use JQuery so that onchange $("#myselect"), I alert the "rel" part of the option (not 1 or 2)
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)
Is there anyway to remove a character from a given position?
Let's say my word is:
PANCAKES
And I want to remove the 2nd letter (in this case, 'A'), so i want PNCAKES as my return.
Translate doesnt work for this.
Replace doesnt work for this.
Regex is damn complicated...
Ideas?