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/...?
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
I don't want to output anything via fprintf,but only the result of "Error in pcap_findalldevs: %s\n", errbuf,what's the function for that?
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?
Hi all,
I have a set of data that contains garbled text fields because of encoding errors during many import/exports from one database to another. Most of the errors were caused by converting UTF-8 to ISO-8859-1. Strangely enough, the errors are not consistent: the word 'München' appears as 'München' in some place and as 'MÜnchen'.
Is there a trick in SQL server to correct this kind of crap? The first thing that I can think of is to exploit the COLLATE clause, so that ü is interpreted as ü, but I don't exactly know how. If it isn't possible to make it in the DB level, do you know any tool that helps for a bulk correction? (no manual find/replace tool, but a tool that guesses the garbled text somehow and correct them)
I pass text in a gridview cell with a pipe delimiter, for example "4|31.99|3", What I'd like to be able to do is format this text to show as
-------------
| 4 |
|£31.99 / 3%|
-------------
As you can see, I need the 4 to be Bold and be on a line of it's own, the 31.99 to be a currency and the 3 to be a percentage. Can this be done in code-behind using a converter or something?
First we find the MSB of the first integer, and then try to find a region of N contiguous zero bits within the second number which is to the left of the MSB from the first integer.
Here is the C code for my solution:
typedef unsigned int t;
unsigned const t_bits = sizeof(t) * CHAR_BIT;
_Bool test_fit_within_left_of_msb( unsigned width,
t val1,
t val2,
unsigned* offset_result)
{
unsigned offbit = 0;
unsigned msb = 0;
t mask;
t b;
while(val1 >>= 1)
++msb;
while(offbit + width < t_bits - msb)
{
mask = (((t)1 << width) - 1) << (t_bits - width - offbit);
b = val2 & mask;
if (!b)
{
*offset_result = offbit;
return true;
}
if (offbit++) /* this conditional bothers me! */
b <<= offbit - 1;
while(b <<= 1)
offbit++;
}
return false;
}
Aside from faster ways of finding the MSB of the first integer, the commented test for a zero offbit seems a bit extraneous, but necessary to skip the highest bit of type t if it is set.
I have also implemented similar algorithms but working to the right of the MSB of the first number, so they don't require this seemingly extra condition.
How can I get rid of this extra condition, or even, are there far more optimal solutions?
I have a scenario where I have code written against version 1 of a library but I want to ship version 2 of the library instead. The code has shipped and is therefore not changeable. I'm concerned that it might try to access classes or members of the library that existed in v1 but have been removed in v2.
I figured it would be possible to write a tool to do a simple check to see if the code will link against the newer version of the library. I appreciate that the code may still be very broken even if the code links. I am thinking about this from the other side - if the code won't link then I can be sure there is a problem.
As far as I can see, I need to run through the bytecode checking for references, method calls and field accesses to library classes then use reflection to check whether the class/member exists.
I have three-fold question:
(1) Does such a tool exist already?
(2) I have a niggling feeling it is much more complicated that I imagine and that I have missed something major - is that the case?
(3) Do you know of a handy library that would allow me to inspect the bytecode such that I can find the method calls, references etc.?
Thanks!
I need a way to take a list of numbers in string form to a List object.
Here is an example:
string ids = "10\r\n11\r\n12\r\n13\r\n14\r\n15\r\n16\r\n17\r\n18\r\n19";
List<String> idList = new List<String>();
idList.SomeCoolMethodToParseTheText(ids); <------+
|
foreach (string id in idList) |
{ |
// Do stuff with each id. |
} |
|
// This is the Method that I need ----------------+
Is there something in the .net library so that I don't have to write the SomeCoolMethodToParseTheText myself?
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.
Hello Community!
I have an application with different components that are accessible through a viewstack in the main application.
The main application looks like that:
<Application>
<Viewstack>
<myComponent1/>
<myComponent2/>
<myComponent3/>
.
.
.
</Viewstack>
</Application>
In myComponent1, I have a horizontalList where the user can select a product.
In myComponent2, I have 2 containers inside the component. A left container with a larger image of the product selected in myComponent1 and a right container with all characteristics of the product.
Both containers have an embed background image.
When I select a product in myComponent1, the application displays myComponent2. When the component is displayed, I first see the page without the large image of the product, then both containers flickers and the product image is displayed.
How could I avoid this flickering? It's really annoying _<
Thanks in advance for your help =)
Regards.
BS_C3
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,
I'm pretty new to C++ and was looking for a good way to pull the data out of this line.
A sample line that I might need to tokenise is
f 11/65/11 16/70/16 17/69/17
I have a tokenisation method that splits strings into a vector as delimited by a string which may be useful
static void Tokenise(const string& str, vector<string>& tokens, const string& delimiters = " ")
The only way I can think of doing it is to tokenise with " " as a delimiter, remove the first item from the resulting vector, then tokenise each part by itself. Is there a good way to do this all in one?
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?
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 just took an exam where i was asked the following:
Write the function body of each of the methods GenStrLen, InsertChar and StrReverse for the given code bellow. You must take into consideration the following;
How strings are constructed in C++
The string must not overflow
Insertion of character increases its length by 1
An empty string is indicated by StrLen = 0
class Strings {
private:
char str[80];
int StrLen;
public:
// Constructor
Strings() {
StrLen=0;
};
// A function for returning the length of the string 'str'
int GetStrLen(void) {
};
// A function to inser a character 'ch' at the end of the string 'str'
void InsertChar(char ch) {
};
// A function to reverse the content of the string 'str'
void StrReverse(void) {
};
};
The answer I gave was something like this (see bellow). My one of problem is that used many extra variables and that makes me believe am not doing it the best possible way, and the other thing is that is not working....
class Strings {
private:
char str[80];
int StrLen;
int index; // *** Had to add this ***
public:
Strings(){
StrLen=0;
}
int GetStrLen(void){
for (int i=0 ; str[i]!='\0' ; i++)
index++;
return index; // *** Here am getting a weird value, something like 1829584505306 ***
}
void InsertChar(char ch){
str[index] = ch; // *** Not sure if this is correct cuz I was not given int index ***
}
void StrRevrse(void){
GetStrLen();
char revStr[index+1];
for (int i=0 ; str[i]!='\0' ; i++){
for (int r=index ; r>0 ; r--)
revStr[r] = str[i];
}
}
};
I would appreciate if anyone could explain me toughly what is the best way to have answered the question and why. Also how come my professor closes each class function like " }; " i thought that was only used for ending classes and constructors only.
Thanks a lot for your help.
I have a c program below, I would like to send out a 32 bit message in a particular order Eg.0x00000001.
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <stdint.h>
struct test
{
uint16_t a;
uint16_t b;
};
int main(int argc, char const *argv[])
{
char buf[4];
struct test* ptr=(struct test*)buf;
ptr->a=0x0000;
ptr->b=0x0001;
printf("%x %x\n",buf[0],buf[1]); //output is 0 0
printf("%x %x\n",buf[2],buf[3]); //output is 1 0
return 0;
}
Then I test it by print out the values in char array. I got output in the above comments. Shouldn't the output be 0 0 and 0 1? since but[3] is the last byte? Is there anything I missed?
Thanks!
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?
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!
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.
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 ?
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 want to replace the inner_text in all paragraphs in my XHTML document.
I know I can get all text with Nokogiri like this
doc.xpath("//text()")
But I want only operate on text in paragraphs, how I can select all text in paragraphs without affecting eventually existent anchor texts in links ?
#For example : <p>some text <a href="/">This should not be changed</a> another one</a>
var I:Image=new Image();
I.source='C:\\Abc.png';
var H:int=I.height;
H is always Zero!
I am presuming this is because the image hasn't finished reading the png file off the disk yet.
What event can I monitor to know when it's width and height will have the right values?
The 'Complete' event only seems to work for DOWNLOADED images.
The 'Render' event happens EVERY FRAME.
The (undocumented?) 'sourceChanged', happens as soon as source changes, and has the same problem!
What event do I watch that will let me know when the image's width and height properties will have valid values? Or is there some Synchronous version of I.source='xxx.png', that I don't know about?
P.S. Yes, I know I shouldn't use "C:\" in an Air Program. This was just for illustrative purposes, so that you won't suggest I use "Complete", which never even seems to fire when the file indicated by source is local.