I'm wondering how to set the mouse cursor position under X11? Is it possible at all and if, where do I have to look for appropriate functions? X window system, KDE/Gnome/...?
I am looking to split up multiple lines of text to single them out, for example:
Url/Host:ftp://server.com/1
Login:Admin1
Password:Password1
Url/Host:ftp://server.com/2
Login:Admin2
Password:Password2
Url/Host:ftp://server.com/3
Login:Admin3
Password:Password3
How can I split each section into a different textbox, so that section one would be put into TextBox1.Text on its own:
Url/Host:ftp://server.com/1
Login:Admin1
Password:Password1
Thanks in advance :)!
Hello,
I find myself in need of performing bit-level conversion on variables in PHP. In more detail, I have a bit stream that is read as an integer by hardware, and I need to do some operations on the bits to make it into what its actually supposed to be (a float). I have to do this a few times for different formats, and the functionality I need is
Being able to select and move individual bits in a variable
Being able to cast statically one type of variable to the other (ie. int to float)
I know php natively supports bitwise AND, OR, etc, and shift operations, but I was wondering if:
there may already be a library in php that does this sort of thing
I would be better off with delegating the calculations to some other language
Thanks,
Hi
I have a simple problem, I have an app based on CoreData and I need to change the structure a little. How can I migrate the old structure into the new one. Just adding one attribute will chrash the whole app.
Thanks
I need to determine whether a string (sourceString) contains another string (queryString) and if it does, at what offset.
I'm guessing that NSScanner might do the trick but I don't fully understand the documentation.
Let's say sourceString = @"What's the weather in London today?"
If I set queryString to equal @"What's the weather", I'd like a method that would determine that, in this case, YES (sourceString does contain queryString) and the offset is 0 (i.e. at the start of sourceString).
Any suggestions?
Hey
I have a data layer which is returning lists of classes containing data. I want to display this data in my form in WPF. The data is just properties on the class such as Class.ID, Class.Name, Class.Description (for the sake of example)
How can i create a custom control or template an existing control so that it can be given one of these classes and display its data in a data-bound fashion.
Thanks :)
Hi
I am trying to dump the floating point values from my program to a bin file. Since I can't use any stdlib function, I am thinking of writting it char by char to a big char array which I am dumping in my test application to a file.
It's like
float a=3132.000001;
I will be dumping this to a char array in 4 bytes.
Code example would be:-
if((a < 1.0) && (a > 1.0) || (a > -1.0 && a < 0.0))
a = a*1000000 // 6 bit fraction part.
Can you please help me writting this in a better way.
I need to extract certain bits of a byte and covert the extract bits back to a hex value.
Example (the value of the byte is 0xD2) :
76543210 bit position
11010010 is 0xD2
Bit 0-3 defines the channel which is 0010b is 0x2
Bit 4-5 defines the controller which is 01b is 0x1
Bit 6-7 defines the port which is 11b is 0x3
I somehow need to get from the byte is 0xD2 to channel is 0x2, controller is 0x1, port is 0x3
I googled allot and found the functions pack/unpack, vec and sprintf. But I'm scratching by head how to use the functions to achieve this. Any idea how to achieve this in Perl ?
Now, here is the function header of the function I'm supposed to implement:
/*
* float_from_int - Return bit-level equivalent of expression (float) x
* Result is returned as unsigned int, but
* it is to be interpreted as the bit-level representation of a
* single-precision floating point values.
* Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
* Max ops: 30
* Rating: 4
*/
unsigned float_from_int(int x) {
...
}
We aren't allowed to do float operations, or any kind of casting.
Now I tried to implement the first algorithm given at this site: http://locklessinc.com/articles/i2f/
Here's my code:
unsigned float_from_int(int x) {
// grab sign bit
int xIsNegative = 0;
int absValOfX = x;
if(x < 0){
xIsNegative = 1;
absValOfX = -x;
}
// zero case
if(x == 0){
return 0;
}
//int shiftsNeeded = 0;
/*while(){
shiftsNeeded++;
}*/
unsigned I2F_MAX_BITS = 15;
unsigned I2F_MAX_INPUT = ((1 << I2F_MAX_BITS) - 1);
unsigned I2F_SHIFT = (24 - I2F_MAX_BITS);
unsigned result, i, exponent, fraction;
if ((absValOfX & I2F_MAX_INPUT) == 0)
result = 0;
else {
exponent = 126 + I2F_MAX_BITS;
fraction = (absValOfX & I2F_MAX_INPUT) << I2F_SHIFT;
i = 0;
while(i < I2F_MAX_BITS) {
if (fraction & 0x800000)
break;
else {
fraction = fraction << 1;
exponent = exponent - 1;
}
i++;
}
result = (xIsNegative << 31) | exponent << 23 | (fraction & 0x7fffff);
}
return result;
}
But it didn't work (see test error below):
Test float_from_int(-2147483648[0x80000000]) failed...
...Gives 0[0x0]. Should be -822083584[0xcf000000]
4 4 0 float_times_four
I don't know where to go from here. How should I go about parsing the float from this int?
Scenario: I am maintaining a function which helps with an install - copies files from PathPart1/pending_install/PathPart2/fileName to PathPart1/PathPart2/fileName. It seems that String.Replace() and Path.Combine() do not play well together. The code is below. I added this section:
// The behavior of Path.Combine is weird. See:
// http://stackoverflow.com/questions/53102/why-does-path-combine-not-properly-concatenate-filenames-that-start-with-path-dir
while (strDestFile.StartsWith(@"\"))
{
strDestFile = strDestFile.Substring(1); // Remove any leading backslashes
}
Debug.Assert(!Path.IsPathRooted(strDestFile), "This will make the Path.Combine(,) fail).");
in order to take care of a bug (code is sensitive to a constant @"pending_install\" vs @"pending_install" which I did not like and changed (long story, but there was a good opportunity for constant reuse). Now the whole function:
//You want to uncompress only the files downloaded. Not every file in the dest directory.
private void UncompressFiles()
{
string strSrcDir = _application.Client.TempDir;
ArrayList arrFiles = new ArrayList();
GetAllCompressedFiles(ref arrFiles, strSrcDir);
IEnumerator enumer = arrFiles.GetEnumerator();
while (enumer.MoveNext())
{
string strDestFile = enumer.Current.ToString().Replace(_application.Client.TempDir, String.Empty);
// The behavior of Path.Combine is weird. See:
// http://stackoverflow.com/questions/53102/why-does-path-combine-not-properly-concatenate-filenames-that-start-with-path-dir
while (strDestFile.StartsWith(@"\""))
{
strDestFile = strDestFile.Substring(1); // Remove any leading backslashes
}
Debug.Assert(!Path.IsPathRooted(strDestFile), "This will make the Path.Combine(,) fail).");
strDestFile = Path.Combine(_application.Client.BaseDir, strDestFile);
strDestFile = strDestFile.Replace(Path.GetExtension(strDestFile), String.Empty);
ZSharpLib.ZipExtractor.ExtractZip(enumer.Current.ToString(), strDestFile);
FileUtility.DeleteFile(enumer.Current.ToString());
}
}
Please do not laugh at the use of ArrayList and the way it is being iterated - it was pioneered by a C++ coder during a .Net 1.1 era. I will change it. What I am interested in: what is a better way of replacing PathPart1/pending_install/PathPart2/fileName with PathPart1/PathPart2/fileName within the current code. Note that _application.Client.TempDir is just _application.Client.BaseDir + @"\pending_install". While there are many ways to improve the code, I am mainly concerned with the part which has to do with String.Replace(...) and Path.Combine(,). I do not want to make changes outside of this function. I wish Path.Combine(,) took an optional bool flag, but it does not.
So ... given my constraints, how can I rework this so that it starts to suck less?
I have got a file with following format.
1234, 'US', 'IN',......
324, 'US', 'IN',......
...
...
53434, 'UK', 'XX', ....
...
...
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Here I want to extract only those lines having 'IN' as 2nd keyword. i.e.
253, 'IN', 'UP',....
253, 'IN', 'MH',....
Can any one please tell me a command to grep it.
How can I move an element to the end of the body?
Using jQuery, I want some given element to be moved to the body, preferably to be the last element contained by it.
Imagine the following would be valid:
$('#myElement').moveToTheEndOfTheBody();
Thanks!
I've seen questions to prefix zeros here in SO. But not the other way !!
Can you guys suggest me how to remove the leading zeros in alphanumeric text. Are there any built-in APIs or do I need to write a method to trim the leading zero's?
Example:
01234 converts to 1234
0001234a converts to 1234a
001234-a converts to 1234-a
101234 remains as 101234
2509398 remains as 2509398
123z remains as 123z
000002829839 converts to 2829839
I need to Alter the CODE section of an iphone app from a CODE CAVE at runtime.. but the section is protected and i get a kernel exception, can i change the protection flags somehow?
Hi,
I use CreateFileMapping, but this method was not useful,because only static structure can be shared by this method.
for example this method is good for following structure:
struct MySharedData
{
unsigned char Flag;
int Buff[10];
};
but it's not good for :
struct MySharedData
{
unsigned char Flag;
int *Buff;
};
would be thankful if somebody guide me on this,
Thanks in advance!
How to rotate an image with PHP, any degree, without having the filled space? For instance, if I rotate an image 10 degrees, the image rotates fine but the container around (square) gets filled with black. Is it possible to get rid of this, when for example merging 2 images?
Hello, I'm writing an IRCd. For this topic it doesn't really matter if you know much about IRC. Its a simple code style problem.
Quick overview of the problem:
No message may be longer than 512 characters
If the message is more, it must be broken into pieces
The NAMES reply sends all the nicknames of users on a channel, and quickly grows beyond 512 characters.
I currently concocted this marvelous piece of code, it works perfectly. However, its just not "ruby-like". This piece of code is more what you expect in some piece of C code.
# 11 is the number of all fixed characters combined in the reply
pre_length = 11 + servername.length + mynick.length + channel.name.length
list = [""]
i = 0
channel.nicks.each do |nick, client|
list[i+=1] = "" if list[i].length + nick.length + pre_length > 500
list[i] << "#{channel.mode_char(client)}#{client.nick} "
end
list.each { |l| send_numeric(RPL_NAMREPLY, channel.name, l.strip) }
send_numeric(RPL_ENDOFNAMES, channel.name)
So my question is, any ideas to do this more nicely?
PS. code has been slightly modified to make it easier to understand out-of-context
I have a list of
uids: ['1234','4321','1111']
and I would like to turn this into a single string of:
"uid = '1234' OR uid = '4321' OR uid = '1111'"
What's the most efficient way to do this?
Thanks!
It is supposed to be generally preferable to use a StringBuilder for String concatenation in Java. Is it always the case?
What i mean is :
Is the overhead of creating a StringBuilder object, calling the append() method and finally toString() smaller then concatenating existing Strings with + for 2 Strings already or is it only advisable for more Strings?
If there is such a threshold, what does it depend on (the String length i suppose, but in which way)?
And finally - would you trade the readability and conciseness of the + concatenation for the performance of the StringBuilder in smaller cases like 2, 3, 4 Strings?
Hi all,
This is probably seriously easy to solve for most of you but I cannot solve this simply putting str() around it can I?
I would like to convert this list: ['A','B','C'] into 'A B C'.
Thanks in advance!!
I am adding contact functionality to my program, and I want to save the contact list of each individual user, what is the best solution for this? I am new to XML and databases and I don't know which would be best or if there is a database solution that saves locally. Thanks for the help.
An Employee has an inverse relationship to it's Department and vice versa. The Employee entity has an Relationship called department, and it has a DENY delete rule. Employee shall be deleted. Now: Does DENY actually deny deletion of employee, because department is still referencing a Department? Or does it mean that a Department can't be deleted because an Employee is referencing it?