I'm creating a config file to hold configuration/properties settings for my project that frequently change, such as file paths. What's the standard name/extension for such a file? (e.g. in Java I've used config.xml, in VB.NET I've used App.config...)
This is confusing as hell, here's the php I'm using:
<?php echo date('H:i D j, F',$j->date); ?>
This is what it gives me:
01:33 Thu 1, January
Which seems fine, until you look at the actual time that is being given ($j-date provides):
2010-06-12 21:12:23
Why is it giving me a January and what am I doing wrong?
One of our web designers is working on a site at the moment and is using HTML5 elements, which she styles up in older browsers using the well documented Html5Shiv;
http://css-tricks.com/html5-innershiv/
She reported some pretty weird behavior today and it looks like this is the cause. Initially it was very confusing, and went something along the lines of;
"The page looks fine, I refresh it looks fine, refresh several times and occasionally it will not apply my styles to the HTML5 elements"
Current best theory is that the shiv is not kicking in quick enough, and the page loads before the new elements have been registered. I was wondering if anyone could suggest a surefire way of including the shiv and making sure it's loaded and been parsed BEFORE the rest of the elements, so they will definitely get styled.
EDIT (more info)
Shiv is being included in the head, directly below the title/meta tags;
<!--[if IE]> <script type="text/javascript" src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script> <![endif]-->
The bit that is being styled is in the footer and is cross-site. Many of the pages will change in size as they're being powered by a CMS that our marketing team will use so I am unable to give an exact page size. All I would say is that if page size is an issue and there is no workaround, can someone let me know as this will mean we basically can't use HTML5 on this project (or at the very least we'll need to add superflous markup such as divs to ensure that the layout doesn't go crazy)
EDIT 2
There is no chance of me posting the code unfortunately - it's only re-creatable under really obscure circumstances and the project is marked "top secret" at the moment :( If nobody knows then I'm guessing it's either a case of "everyone knows it happens but kinda ignores it" or just that it's something else other than the shiv.
I want to parse a java.util.Date from a String. I tried the following code but got unexpected output:
Date getDate() {
Date date = null;
SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd");
try {
date = sdf.parse("Sat May 11");
} catch (ParseException ex) {
Logger.getLogger(URLExtractor.class.getName()).log(Level.SEVERE, null, ex);
return null;
}
return date;
}
When I run the above code, I got the following output:
Mon May 11 00:00:00 IST 1970
I'm having some trouble with GSON, mainly deserializing from JSON to a POJO.
I have the following JSON:
{
"events":
[
{
"event":
{
"id": 628374485,
"title": "Developing for the Windows Phone"
}
},
{
"event":
{
"id": 765432,
"title": "Film Makers Meeting"
}
}
]
}
With the following POJO's ...
public class EventSearchResult {
private List<EventSearchEvent> events;
public List<EventSearchEvent> getEvents() {
return events;
}
}
public class EventSearchEvent {
private int id;
private String title;
public int getId() {
return id;
}
public String getTitle() {
return title;
}
}
... and I'm deserializing with the following code, where json input is the json above
Gson gson = new Gson();
return gson.fromJson(jsonInput, EventSearchResult.class);
However, I cannot get the list of events to populate correctly. The title and id are always null. I'm sure I'm missing something, but I'm not sure what. Any idea?
Thanks
In the attempt to understand why I keep getting the following error
error: 'Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)'
while using the command sudo find / -type s the terminal prompted something like this
find: ‘/proc/31348/task/31348/fd/5’: No such file or directory
find: ‘/proc/31348/task/31348/fdinfo/5’: No such file or directory
find: ‘/proc/31348/fd/5’: No such file or directory
find: ‘/proc/31348/fdinfo/5’: No such file or directory
What does this mean?
My goal is to manipulate the boot-sector in my flashdrive (volume E:)
I am using XP.
I am able to read the boot-sector
FILE *fp_read = fopen("\\\\.\\E:", "rb");
/* Able to proceed to read boot sector */
however i am not able to
open the file to write using fopen in 'wb' mode.
FILE *fp_read = fopen("\\\\.\\E:", "wb");
/* Unable to proceed due to Failed to open file to write.:Permission Denied */
The flash-drive is not in use at the moment of execution.
Hex-editors are able to manipulated boot sector etc,
i believe it possible to do so in c.
Any suggestion or insight to overcome the access problem so as to be able to write?
I'm trying to parse the json grabbed from here. Basically what I do is iterate over the items, sort them, then display them. But I get an error saying data.data.children[i] is undefined.
I can't think why it's doing it though?
var json = 'http://www.reddit.com/reddits/mine/.json';
GM_xmlhttpRequest({
method: "GET",
url: json,
onload: reddits
});
function reddits(response){
var txt = response.responseText;
var data;
var suggested = document.getElementById('suggested-reddits');
if(window.JSON && JSON.parse){
data = JSON.parse(txt);
}
else{
data = eval("("+txt+")");
}
suggested.innerHTML += '<span>reddits you\'re subscribed to </span> <ul id="rsub"></ul>';
GM_addStyle('#rsub{width: 500px;}');
var reddits = new Array();
var rsub = document.getElementById('rsub');
for(i = 0; i <= data.data.children.length; i++){
var r = data.data.children[i].data.display_name;
reddits.push(r);
}
sort(reddits);
for(i = 0; i <= reddits.length; i++){
rsub.innerHTML += '<li><a href="#" onclick="set_sr_name(this); return false">' + reddits[i] + '</a></li>';
}
}
I was just thinking to myself "How exactly is a PHP script executed?" I thought it was parsed first for syntax errors etc, and then interpreted and executed.
However, I don't know why I believe that is correct. I'm probably wrong.
So, how exactly is a PHP file interpreted and executed? What stages does this involve? How do included files fit into the parsing of the script?
This is just to help me get my head around it. I'm interested and can not find a good answer with Google.
Thanks!
I have a string as const char *str = "Hello, this is an example of my string";
How could I get everything after the first comma. So for this instance: this is an example of my string
I was planing to do something like:
// pseudocode
char *a, *b;
loop {
if((a = strchr(l, ',')) == NULL) break;
b++;
// but not sure here
}
printf("%s",a);
Thanks
So I was wondering how would you differentiate ppt, xls and doc files from each other in linux regardless of extensions. I tried 'file' but from the looks of it, all of MSOffice files are categorized under the same file type. Similarly I'm having trouble with docx, xlsx and pptx files, since they're essentially all zip files containing a bunch of xml.
Thank you for your help!
P.S. I also tried a python script importing the magic module, but no go.
I am trying to do something very simple in powershell
Reading the contents of a file
Manipulation some string
Saving the modified test back to the file
function Replace {
$file = Get-Content C:\Path\File.cs
$file | foreach {$_ -replace "document.getElementById", "$"} |out-file -filepath C:\Path\File.cs
}
I have tried Set-Content as well.
I always get unautorized exception. I can see the $file has the file content, error is coming while writing the file.
Any help is appreciated.
Ben
We have to handle user specified date formats in our application. We decided to go with Date.strptime for parsing and validation, which works great, except for how it just ignores any garbage data entered. Here is an irb session demonstrating the issue
ree-1.8.7-2010.01 > require 'date'
=> true
ree-1.8.7-2010.01 > d = Date.strptime '2001-01-01failfailfail', '%Y-%m-%d'
=> #<Date: 4903821/2,0,2299161>
ree-1.8.7-2010.01 > d.to_s
=> "2001-01-01"
what we would like, is behavior more like this
ree-1.8.7-2010.01 > d = Date.strptime '2001failfailfail-01-01', '%Y-%m-%d'
ArgumentError: invalid date
Any suggestions would be appreciated
This is really just a syntax question.
I have a PHP script that parses my WordPress feed and returns the latest posts. I also want my script to parse the # of comments, but the WordPress feed XML object for number of comments has a colon in it (slash:comments). It causes the following error:
Parse error: syntax error, unexpected
':' in ... on line ...
I have tried each of the following without luck:
$xml->slash:comments
$comments = 'slash:comments'
$xml->$comments
$xml->slash.':'.comments
$xml->{slash:comments}
$xml->{'slash:comments'}
How do I parse an object with a colon?
I'm using glob function for a autocompletion function. I'm showing you the problem because it's difficult to explain:
matched = ~/.tcsh
glob(matched, 0, NULL, &pglob);
glob put all matched files in a char ** and when I print it I have:
case[0] = .tcshrc
case[1] =
I should have .tcshrc~ in case[1], but nothing =S, I've seen a flag "GLOB_TILDE" like this "
glob(matched, GLOB_TILDE, NULL, &pglob);
But it doesn't change anything! Can someone help me?
val uninterestingthings = ".".r
val parser = "(?ui)(regexvalue)".r | (uninterestingthings~>parser)
This recursive parser will try to parse "(?ui)(regexvalue)".r until the end of input. Is in scala a way to prohibit parsing when some defined number of characters were consumed by "uninterestingthings" ?
UPD: I have one poor solution:
object NonRecursiveParser extends RegexParsers with PackratParsers{
var max = -1
val maxInput2Consume = 25
def uninteresting:Regex ={
if(max<maxInput2Consume){
max+=1
("."+"{0,"+max.toString+"}").r
}else{
throw new Exception("I am tired")
}
}
lazy val value = "itt".r
def parser:Parser[Any] = (uninteresting~>value)|parser
def parseQuery(input:String) = {
try{
parse(parser, input)
}catch{
case e:Exception =>
}
}
}
Disadvantages:
- not all members are lazy vals so PackratParser will have some time penalty
- constructing regexps on every "uninteresting" method call - time penalty
- using exception to control program - code style and time penalty
I want a lite-weight C++ XML parser/DOM that:
Can take UTF-8 as input, and parse into UTF-16. Maybe it does this directly (ideal!), or perhaps it provides a hook for the conversion (such as taking a custom stream object that does the conversion before parsing).
Offers some XPath support.
I've been looking at RapidXML, the Kranf xmlParser, and pugiXML. The first two of those might permit requirement #1 by way of a hook. The third, pugiXML, supports the #2 requirement. But none of those three fulfill both requirements.
What is the smallest (free) library that can handle both requirements?
Suppose I let the user to write a condition using Javascript, the user can write conditions to perform a test and return true or false. E.g.:
INS>5 || ASTO.valueBetween(10,210)
I want to find which variables are used in the script that the user wrote. I tried to find a way to get the identifier names in Java. The Rhino library didn't help a lot. However I found that via handling exceptions I could get all the identifiers. So this problem is solved.
So everything is great, but there is one little problem. How can I replace these identifiers with a numeric identifier? E.g. INS should be _234 and ASTO should be _331.
INS and ASTO etc are entities in my database. I want to replace them, because the name may change. I could do it using a replace but this isn't easy because:
It should be reversible. E.g. ASTO to _234 and _234 to ASTO again.
Replacing _23 with MPLAH may also replace _234. This could be fixed with regexp somehow.
What if _23 is in a comment section? Rare to happen, but possible /* _23 fdsafd ktl */. It should also be replaced.
What if it is a name of a function? E.g. _32() {}. Also rare, but it shouldn't be replaced.
What if it is enclosed in "" or ''?
I am sure that there are a lot more cases. Any ideas?
Hi,
I would like to do something similar what we do in ASP.NET where we parse through all the rows in a GridView and assign a particular value to a particular cell in a row which has a matching TaskId as the current Id.
This has to happen in a Tick function of a Dispatcher Timer object. Since I have a Start Timer button Column for every row in a GridView. Upon a particular row's Start Timer Button click, I have to start its timer and display in a cell in that row. Similarly there can be multiple timers running in parallel.
For this I need to be able to check the task Id of the particular task and keep updating the cell values with the updated time in all of the tasks that have a Timer Started.
TimeSpan TimeRemaining = somevalue;
string CurrentTaskId = "100";
foreach(GridViewRow row in RadGridView1.Rows) // Here I tried RadGridView1.ChildrenOfType() as well but it has null
{
if( (row.DataContext as Task).TaskId == CurrentTaskId )
row.Cells[2].Content = a.TaskTimeRemaining.ToString();
}
Can someone please let me know how do I get this functionality using the Telerik RadGridView?
Cheers,
Syed.
var records = JSON.parse(JsonString);
for(var x=0;x<records.result.length;x++)
{
var record = records.result[x];
ht_text+="<b><p>"+(x+1)+" "
+record.EMPID+" "
+record.LOCNAME+" "
+record.DEPTNAME+" "
+record.CUSTNAME
+"<br/><br/><div class='slide'>"
+record.REPORT
+"</div></p></b><br/>";
}
The above code works fine when the JsonString contains an array of entities but fails for single entity. result is not identified as an array!
Whats wrong with it?
http://pastebin.com/hgyWw5hd
I have xampp installed, and need to edit my httpd.conf file to add a virtual host block. If I right-click on the file in Nautilus and open with gedit, I can see all the content, but it's read-only.
If I try to open it via terminal, like this:
esther@estherLinuxSony:~$ sudo gedit opt/lampp/etc/extra/httpd-vhosts.conf
It opens the root version of gedit, but there's no content in the file.
How can I edit this file?