In Silverlight 4, an extension property called StringFormat is added to display formatting display. There are some predefined formats available. In this article we will see some of them.
I spend WAY to much time fumbling around because vim doesn't handle closing braces like most IDEs do. Here's what I want to happen:
type this:
if( whatever )
{ <CR>
where <CR> mean hit the enter key
and get this:
if( whatever )
{
|
}
where | is the position of the cursor. It's what Eclipse does. It's what Visual Studio does. And it's what I want Vim to do.
I've seen a few plugins, tried a few, and none of them seem to give me this behavior. Surely I can't be the first programmer to want this.
I have this regexp:
/(.*)(([0-9]([^a-zA-Z])*){7,}[0-9])(.*)/.
Given the following values
0654535263
065453-.-5263
065asd4535263
Expected Results
06****
06****
06****
Actual Results
0654535263
06****
065asd4535263
It does not match the last row because of the letters (I want to match from 0-3 letters) and it matches only last occurence (in the second row in example, it skips first row).
I have a method in Java that concatenates 2 Strings. It currently works correctly, but I think it can be written better.
public static String concat(String str1, String str2) {
String rVal = null;
if (str1 != null || str2 != null) {
rVal = "";
if (str1 != null) {
rVal += str1;
}
if (str2 != null) {
rVal += str2;
}
}
return rVal;
}
Here are some of the requirements:
If both str1 and str2 are null, the method returns null
If either str1 or str2 is null, it will just return the not null String
If str1 and str2 are not null, it will concatenate them
It never adds "null" to the result
Can anyone do this with less code?
This has to be pretty simple, but I'd like to parse the current URL and execute conditional code depending on whether the user is on the /sitemap/ directory.
So for example, if the site is example.com, and if the request is example.com/sitemap/.
Then I want to execute conditional code in that case. I'm using wordpress so I'm not sure if there is a built-in function that gets this...
A pure PHP solution is fine.
I'm considering how to do automatic bug tracking and as part of that I'm wondering what is available to match source code line numbers (or more accurate numbers mapped from instruction pointers via something like addr2line) in one version of a program to the same line in another. (Assume everything is in some kind of source control and is available to my code)
The simplest approach would be to use a diff tool/lib on the files and do some math on the line number spans, however this has some limitations:
It doesn't handle cross file motion.
It might not play well with lines that get changed
It doesn't look at the information available in the intermediate versions.
It provides no way to manually patch up lines when the diff tool gets things wrong.
It's kinda clunky
Before I start diving into developing something better:
What already exists to do this?
What features do similar system have that I've not thought of?
I've worked with jQuery over the years. However, recently, I've found myself getting deeper into the JavaScript language. Recently, I've heard about "truthy" and falsey values. However, I don't fully understand them. Currently, I have some code that looks like this:
var fields = options.fields || ['id', 'query'];
I need to identify if fields is null, undefined, or has a length of 0. I know the long way is to do:
if ((fields === null) || (fields === undefined) || (fields.length === 0)) {
...
}
My question is, is the following the same:
if (!fields) {
...
}
Thank you!
I'm way out of my league here...
I have a mapping table (table1) to assign particular values (value) to a whole number (map_nu). My second table (table2), is a collection of averages (avg)
(I couldn't figure out how to properly make a markdown table, please feel free to edit!)
table1: table2:
(value)(Map_nu) (avg)
---- -----
1 1 1.111
1.045 2 1.2
1.09 3 1.33333
1.135 4 1
1.18 5 1.389
1.225 6 1.42
1.27 7 1.07
1.315 8
1.36 9
1.405 10
I need to find a way to match the averages from table2 to the closest value in table1. It only need to match to the 2 digit past the decimal, so I've added the Truncated function
SELECT map_nu
FROM `table1`
JOIN table2 ON TRUNCATE(table1.value,2)=TRUNCATE(table2.avg,2)
I still miss the values that don't match the averages exactly. Is there a way to pick the nearest truncated value?
Thanks!
Let's say I have a string in an RTL language such as Arabic with some English chucked in:
string s = "Test:?????;?????;?????;a;b"
Notice there are semicolons in the string. When I use the Split command like string[] spl = s.Split(';');, then some of the strings are saved in reverse order. This is what happens:
??Test:?????
?????
?????
a
b
The above is out of order compared to the original. Instead, I expect to get this:
?Test:
?????
?????
?????
a
b
I'm prepared to write my own split function. However, the chars in the string also parse in reverse order, so I'm back to square one. I just want to go through each character as it's shown on the screen.
Hello
I have two histograms.
int Hist1[10] = {1,4,3,5,2,5,4,6,3,2};
int Hist1[10] = {1,4,3,15,12,15,4,6,3,2};
Hist1's distribution is of type multi-modal;
Hist2's distribution is of type uni-modal with single prominent peak.
My questions are
Is there any way that i could determine the type of distribution programmatically?
How to quantify whether these two histograms are similar/dissimilar?
Thanks
Hello,
I am a regex idiot and never found a good tutorial (links welcome, as well as a pointer to an interactive VS2010 integrated editor).
I need to parse strings in the following form:
[a/b]:c/d
a, b: double with "." as possible separator. CAN be empty
c: double with "." as separator
d: integer, positive
I.e. valid strings are:
[/]:0.25/2
[-0.5/0.5]:0.05/2
[/0.1]:0.05/2
;) Anyone can help?
Thanks
Hi,
Presently I'm using two regx:
ABC.*1EFG
ABC.*2HIJ
to retrieve Line 1 and Line 2 from a text file. Is there a better single regex, so that both the lines(L1 and L2) from below can be matched.
Line 1: ABCanystring1EFGanystring
Line 2: ABCanystring2HIJanystring
Line 3: ABCanystring2LMNanystring
.
.
.
Line n
Thanks you in advance,
Su
I'm considering how to do automatic bug tracking and as part of that I'm wondering what is available to match source code line numbers (or more accurate numbers mapped from instruction pointers via something like addr2line) in one version of a program to the same line in another. (Assume everything is in some kind of source control and is available to my code)
The simplest approach would be to use a diff tool/lib on the files and do some math on the line number spans, however this has some limitations:
It doesn't handle cross file motion.
It might not play well with lines that get changed
It doesn't look at the information available in the intermediate versions.
It provides no way to manually patch up lines when the diff tool gets things wrong.
It's kinda clunky
Before I start diving into developing something better:
What already exists to do this?
What features do similar system have that I've not thought of?
I have the following text file:
...
"somewords MYWORD";123123123123
"someother MYWORDOTHER";456456456456
"somedifferent MYWORDDIFFERENT";789789789
...
i need to match the word MYWORD, MYWORDOTHER, MYWORDDIFFERENT and then substitute the space before this word with ";".
Someone can figure out a regex?
I have done something like that:
+[^ ][^ ][^ ][^ ][^ ][^ ][^ ]";
but this works only with a specific word lenght. I need to modify to get any word of any leght.
Any help?
Thank you.
Hi,
How can I take a line like this:
Digital Presentation (10:45), (11:30), 12:00, 12:40, 13:20, 14:00, 14:40, 15:20, 16:00, 16:40, 17:20, 18:00, 18:40, 19:20, 20:00, 20:40, 21:20, 22:00, 22:40, 23:10, 23:40.
And match all the 24 hour times so I can convert to a more human readable format using date()?
Also I want to match times in the 24:00-24:59 range too
Thanks!
I have two tables in my database, one contains a list of items with other information on these items. The other table is contains a list of photographs of these items.
The items table gives each item a unique identifier,which is used in the photographs table to identifier which item has been photographed.
I need to output a list of items that are not linked to a photograph in the second table. Any ideas on how I can do this?
I have a user dao
@Entity
@Table(name="EBIGUSERTIM")
public class EbigUser {
private String id;
private Integer source;
private String entryscheme;
private String fullName;
private String email;
private Long flags;
private String status;
private String createdBy;
private Date createdStamp;
private String modifiedBy;
private Date modifiedStamp;
@Id
@Column(name="ID")
public String getId() {
return id;
}
public void setId(String id) {
this.id = id;
}
@Id
@Column(name="SOURCE")
public Integer getSource() {
return source;
}
public void setSource(Integer source) {
this.source = source;
}
@Column(name="ENTRYSCHEME")
public String getEntryscheme() {
return entryscheme;
}
public void setEntryscheme(String entryscheme) {
this.entryscheme = entryscheme;
}
@Column(name="FULLNAME")
public String getFullName() {
return fullName;
}
public void setFullName(String fullName) {
this.fullName = fullName;
}
@Column(name="EMAIL")
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
@Column(name="FLAGS")
public Long getFlags() {
return flags;
}
public void setFlags(Long flags) {
this.flags = flags;
}
@Column(name="STATUS")
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
@Column(name="CREATEDBY")
public String getCreatedBy() {
return createdBy;
}
public void setCreatedBy(String createdBy) {
this.createdBy = createdBy;
}
@Column(name="CREATEDSTAMP")
public Date getCreatedStamp() {
return createdStamp;
}
public void setCreatedStamp(Date createdStamp) {
this.createdStamp = createdStamp;
}
@Column(name="MODIFIEDBY")
public String getModifiedBy() {
return modifiedBy;
}
public void setModifiedBy(String modifiedBy) {
this.modifiedBy = modifiedBy;
}
@Column(name="MODIFIEDSTAMP")
public Date getModifiedStamp() {
return modifiedStamp;
}
public void setModifiedStamp(Date modifiedStamp) {
this.modifiedStamp = modifiedStamp;
}
i am selecting 2 rows out of the db. The sql works
select * from ebigusertim where id='blah'.
It returns 2 distinct rows. When i query the data using hibernate, it appears that the object memory is not being allocated for each entry in the list. Thus, i get 2 entries in the list with the same object.
Criteria userCriteria = session.createCriteria(EbigUser.class);
userCriteria.add(Restrictions.eq("id", id));
userlist = userCriteria.list();
I have anywhere from 5 to 10 generic list in an ASP.NET VB.NET web app. I would like to write a method to pass them all into, and return only the elements they all have in common.
I'm looking for some ideas how to accomplish this the easiest and cleanest way possible.
Write a function, called constrainedMatchPair which takes three arguments: a tuple representing starting points for the first substring, a tuple representing starting points for the second substring, and the length of the first substring. The function should return a tuple of all members (call it n) of the first tuple for which there is an element in the second tuple (call it k) such that n+m+1 = k, where m is the length of the first substring. Complete the definition
def constrainedMatchPair(firstMatch,secondMatch,length):
I have a SQL problem that I've come up against routinely, and normally just solved w/ a nested query. I'm hoping someone can suggest a more elegant solution.
It often happens that I need to select a result set for a user, conditioned upon it being the most recent, or the most sizeable or whatever.
For example: Their complete list of pages created, but I only want the most recent name they applied to a page. It so happens that the database contains many entries for each page, and only the most recent one is desired.
I've been using a nested select like:
SELECT pg.customName, pg.id
FROM (
select id, max(createdAt) as mostRecent
from pages
where userId = @UserId
GROUP BY id
) as MostRecentPages
JOIN pages pg
ON pg.id = MostRecentPages.id
AND pg.createdAt = MostRecentPages.mostRecent
Is there a better syntax to perform this selection?
Hi,
I have two tables table1 and table2, i need to write a select query which will list me the columns that exist in both the tables.(mysql)
I need to do for different tables (2 at a time)
Is this possible?
I tried using INFORMATION_SCHEMA.COLUMNS but am not able to get it right.
Hello,
i need a HTML to parse:
<span>some text<span><span><span>text</span></span></span></span>
I need to remove unnecessary <span> occurrences, so that output is:
<span>some text<span>text</span></span>
I wrote a regex, which does this once:
/<SPAN>[^<]*<\/SPAN>/i
How to make this work same number of times on both <span> and </span>?
Hi i encountered this problem whereby when i initialized my String[], there seems to be a null in the String[] before i do anything. How do i initialized the String[] to be completely empty,i.e. without the null at the start?
The output for the following code is:
nullABC
nullABC
nullABC
nullABC
nullABC
public static void main(String[] args){
String[] inputArr = new String[5];
for (int i = 0; i< inputArr.length; i++){
inputArr[i] += "ABC";
}
for (int i = 0; i< inputArr.length; i++){
System.out.println(inputArr[i]);
}
}
}