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.
Well since it seems relatively difficult to send the object of a WebControl over JSON using jquery.ajax() I've decided to send the name of the control as a string because I know how to do that. Then I promptly realized that, from a web service, I don't actually know how to search for a control by ID name. Since its a service I can't seem to get Control.FindControl() to work so does anyone have ideas or suggestions? All I'm trying to do is call a databind() on my radcombobox.
Thanks in advance!
For any of you that knows anything about asp.net/rad controls - I'm basically updating a database and want the radcombobox to be in sync with that database again after adding something, before I autoselect what was just added. Other than databind do i have to call anything to refresh that list?
Thanks again!
Hello,
I have a database on a SQL Server 2000 server. This database has a table called "Person" that has a field call "FullName" that is a VARCHAR(100).
I am trying to write a query that will allow me to get all records that have a name. Records that do not have a name have a FullName value of either null or an empty string. How do I get all of the Person records have a FullName? In other words, I want to ignore the records that do not have a FullName. Currently I am trying the following:
SELECT
*
FROM
Person p
WHERE
p.FullName IS NOT NULL AND
LEN(p.FullName) > 0
Thank you
I have code like that:
TEXT_TO_FILTER='I would like to replace this $var to proper value'
var=variable
All I want to get is:
TEXT_AFTER_FILTERED="I'd like to replace this variable to proper value"
So I did:
TEXT_AFTER_FILTERED=`eval echo $TEXT_TO_FILTER`
TEXT_AFTER_FILTERED=`eval echo $(eval echo $TEXT_TO_FILTER)`
Or even more weirder things, but without any effects.
I remember that someday I had similar problem and I did something like that:
cat << EOF > tmp.sh
echo $TEXT_TO_FILTER
EOF
chmod +x tmp.sh
TEXT_AFTER_FILTERED=`. tmp.sh`
But this solution seems to be to much complex.
Have any of You heard about easier solution?
The challenge: The shortest code, by character count, that detects and removes duplicate characters in a String. Removal includes ALL instances of the duplicated character (so if you find 3 n's, all three have to go), and original character order needs to be preserved.
Example Input 1:
nbHHkRvrXbvkn
Example Output 1:
RrX
Example Input 2:
nbHHkRbvnrXbvkn
Example Output 2:
RrX
(the second example removes letters that occur three times; some solutions have failed to account for this)
(This is based on my other question where I needed the fastest way to do this in C#, but I think it makes good Code Golf across languages.)
This script should detect the last portion in the full path, and if it is stackoverflow output ok
$current_url = $_SERVER['REQUEST_URI'];
$current_url_arr = explode('/',$current_url);
$count = count($current_url_arr);
if($current_url_arr[$count-2] == 'stackoverflow'){
echo 'ok';
}
else {
echo 'not ok';
}
Example 1: www.myserver.ext/something/else/stackoverflow/
Output: ok
Example 2: www.myserver.ext/something/else/stackoverflow
Output: not ok
Example 3: www.myserver.ext/something/else/stackoverflow/foo
Output: not ok
I hope that you understand the idea. This script works fine, but I'm wondering if there is any better, elegant way to read last portion of URL?
Hello,
I have a complicated form where I first have to take some _GET parameters and obviously I have to do a mysql_real_escape_string() on them since I look stuff up in the database with them.
Them problem for me is after the initial db lookup. When the user submits a form, I send them along as a _POST request and obviously have to do this mysql_real_escape_string call again just in case someone tries to hack my site with a faked form submission.
Then the problem I have is the arguments are escaped twice and my queries begin to look strange like this:
select field1 , field2 , from my_table where some_id = \'.$lookup_id.\' ...
So the system seems to be adding \' and it is messing me up :)
Also, in my other forms I have not seen such behavior. Any ideas on what may be causing this?
One weird thing is that I tried to send unescaped parameters to the post, and the same problem happens. That is a clue, but not a sufficient one for me. :(
Thanks,
Alex
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.
function FM_log(level, text) {
// caso não seja log total escolhe o que loga
var log = false;
switch (level) {
case "addtoprio()":log = true;
case "alternaTropas()":log = false;
case "sendtroops()":log = false;
defalt: log = false;
}
if ((logTotal == false) && (log == true))
GM_log(horaAtual() + " - "+level+", "+text);
else if (logTotal == true)
GM_log(horaAtual() + " - "+level+", "+text);
}
how to do that switch is a way it works?
line is fgets'd, and running in a while loop with counter n, d is a struct with 2 char arrays, p and q. Basically, in a few words, I want to read a line, separate it into 2 strings, one up until the first space, and the rest of the line. I clean up afterwards (\n from the file becomes \'0'). The code works, but is there a more idiomatic way to do this? What errors am I running into "unknowingly"?
int spc = strcspn(line," ");
strncpy(d[n].p, line, spc);
d[n].p[spc+1]='\0';
int l = strlen(line)-spc;
strncpy(d[n].q, line+spc+1, l);
char* nl = strchr(d[n].q, '\n');
if(nl){
*nl='\0';
}
n++;
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
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 am trying to reuse some of my tiles in a controller which is returning a json response to the client. I would like to return a json response similar to the following format:
{
'success': <true or false>,
'response': <the contents of an apache tile>
}
In my controller I would like to perform logic similar to this pseudocode:
boolean valid = validator.validate(modelObj)
String response = ""
if(valid){
response = successView.render() // im looking for a way to actually accomplish
// this, where the successView is the apache tiles view.
// I would also need to pass a model map to the view somehow.
}else{
response = errorView.render()
}
writeJsonResponse(httpResponse, /* a Map whose json representation looks like the one I described above. */)
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!!
What is the best way to achieve sscanf-like functionality in perl?
I am looking now looking at the sscanf module,
Which is better,
Option-1: Going sscanf way?
Option-2: Regex way? [I am a beginner when it comes to Regex]
Hi,
do you know any good algorithms that match two strings and then return a percentage in how many percent those two strings match?
And are there some, that work with databases too?
What is a better way to program the following SQL:
str_to_date(
concat(convert(D.DAY, CHAR(2)),
'-',
convert(M.MONTH, CHAR(2)),
'-',
convert(M.YEAR, CHAR(4))),
'%e-%m-%Y' ) as AMOUNT_DATE
I want to convert the columns D.DAY, M.MONTH, and M.YEAR to a date field using MySQL. The above works, but seems much more complicated than it needs to be. (If there's an ANSI SQL way to do it, that would be even better.)
Thank you!
I have two Ruby arrays, and I need to see if they have any values in common. I could just loop through each of the values in one array and do include?() on the other, but I'm sure there's a better way. What is it? (The arrays both hold strings.)
Thanks.
In IIS 7.5, I'm trying to rewrite a Url such as /about to /content.asp?p=about, with support for QueryString-s, so if the orginal Url was /about?x=y, it should rewrite to /content.asp?p=about&x=y.
The basic rewriting is now working, but when I'm trying to add a QueryString it doesn't work. Tried both /about?x=y and /about&x=y.
My current rule:
<rule name="RewriteUserFriendlyURL1" stopProcessing="false">
<match url="^([^/]+)/?$" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="content.asp?p={R:1}" />
</rule>
How can I fix this?
Thank you.
Right now I am seeing if a sentence contains a specific word by splitting the sentence into an array and then doing an include to see if it contains the word. Something like:
"This is my awesome sentence.".split(" ").include?('awesome')
But I'm wondering what the fastest way to do this with a phrase is. Like if I wanted to see if the sentence "This is my awesome sentence." contains the phrase "my awesome sentence". I am scraping sentences and comparing a very large number of phrases, so speed is somewhat important.
Hello everybody!
I have one small problem. I have list of types(int,string,..)
ArrayList<Class> typeList;
and I have some input values;
ArrayList<Object> values;
How to cast some value to some type if I know which type from the typeList is the values;
typeList.get(i).cast(values.get(i)); <- this is not working???
Actualy I generate dynamic form in runtime.
With Java reflection I get parameterTypes from methods from some class, I generate form with input fields and then i want to cast the text from the input fields to specific types from the paramterTypes that I got with Java reflection from some class.
Is there any way to evaluate a string expression in XSL?
example:
<myItem id="1">
<validator expression="$someVariable = '3'" />
</myItem>
...
<xsl:variable name="someVariable" select="3" />
<xsl:if test="@expression"> ...
I realize this syntax does not work the way I want it to, but is there any way to store the test expression in a variable and then evaluate the expression?
I need to validate a user input based on condition. i wrote a regular expression to do so, but it's failing not sure why.
Can somebody point where i am making mistake?
Regex AccuracyCodeHexRegex = new Regex(@"^[PTQA]((0|8)[01234567]){2}$");
This is what i am trying to validate(If the string is a subset of these strings then it is valid):
Phh, Thh, Qhh, Ahh where 'h' is a hex digit in the set {00, 80, 01, 81, 02, 82, 03, 83, 04, 84, 05, 85, 06, 86, 07, 87}
Ex: P00 is valid
P20 is not valid