Time / Date Recognition with jQuery - javascript

I was wondering if anyone has any ideas, or has stumbled upon a script that will recognize portions of dates and times in any given field of text.
For instance, this sentence right here was being typed at 4:24pm and I suspect I will finish it at about 4:25 or so.. perhaps even later on the 19th.
I would like to be able to make a live listener that will pick out those times above (or guess) and surround them in a link to say... /calendar/events/create/TIMESTAMP
I expect regex could be used to find certain indicators like : or th, or anything like that and take a guess at the rest pending the current time..
Macs do this in mail and icalendar.. pretty cool. Thoughts or ideas would be greatly appreciated!

Have a look at date.js library which supports wide variety of formats.
Even with this library you will need to:
Preprocess the text (like removing dots at the end of sentences, removing whitespaces, ..)
Filter out false positives (it can parse th as thursday, say as saturday, etc).
Create algorithm for effective scanning of the text.
Map the found times/dates back to the text, etc.
So there is still a lot of work to do.
To see a very ineffective demonstration of the parsing have a look HERE.

Related

How to parse through a table to gather tide value at a certain time of day

I have been having some quiet days at work and schools out but I wanted to play around with javascript. I'm trying to figure out regular expressions and such. I may be starting out too complicated, I am not too sure.
How hard is it to parse through a table like so (http://gyazo.com/6dc7292f1113201fcc4fe8b5b9e79d7a) and gather the tides for each time of day? For example get the time of 01:45 and see the tide in m is 2.6.
I just want to know the basics of how to grab that variable. Of course tides change from day to day but for now I just want to practice on a static variable.
Thanks, and hopefully this makes sense! I am at the last 2 hours of my 10 hour work day lol!
That's not what Regular Expressions (shortened to Regex) is normally used for. Regex is to pattern match. like how to read a number if a user entered (808)854-3432 or 808-854-3442. I mean theoretically you could regex but it'd probably be 10000x more complicated then is worth it just to grab one table cell value. ideally you would want to grab the table body and then go through a tr and grab the td corresponding to the cell and parse the time. But looking at that sample table, you won't be having a lot of regular tables for "each time of day". It would go a long way to maybe show some work or what you formulated. I would also recommend code academy, khan academy or any other number of JS tutorials to start, if you haven't already.

Availability Calendar jQuery(?)

First of all I'm very thankful for any input. I'm not asking you to do this for me, I would just like to know your thoughts on the best way to approach this project. Please see the image below:
Apologies for it being in German, the important translations are as follows:
verfügbar = available
bereits reserviert = already reserved
Uhrzeit = time slot
aktuelle Woche = this week
and Mo, Di, Mi etc. are shortenings of the days of the week.
I'll quickly explain what it should do, because the picture doesn't really explain everything. It's basically displaying when "someone" is available throughout the day. The data would be pulled as JSON and displayed dynamically for each user and list two weeks. The week we're on, and the future week.
Anyway, I would literally just like to have your opinions on the best way of going about this. My initial thought was: Unix timestamps, find the time difference and convert that into pixels to use as a height for each div. But then it struck me that I wouldn't be able to find out where the div should start. (Maybe it starts at 10:00 like on the picture, how would I determine that)
I thought about doing this in canvas, however have very little experience of Canvas so I avoided that. Shout if you would recommend it though. I'm looking for the ideal solution.
Just to know what to learn would be a big help for me, and any input will be gratefully taken on board!
Thank you for your time,
Peter
Edit: Sorry I forgot to mention those things, thanks for pointing that out:
Reserved time data will also be pulled, the user can decide whether they are available or unavailable during that period of time. I'm not really sure how complicated it would be to have two bars on the same day. For example: unavailable from 06:00 to 12:00, but available from 12:00 to 18:00. So I'm avoiding that for the time being.
Time intervals are 15 mins. For each 15 mins 9px should/could be added to the height.
Thanks for your replies.
you could do it within a <table> and clever css styling... each <td> is 15 minutes and 9px height. the first and the last ones contain start / end time.
I had some similar requirements and solved it with tables and css after I checked out the demo of http://www.project-open.org/ where they used tables sometimes to display calendar / milestone data. Also, the Google Calendar uses tables: https://www.google.com/calendar/
This jquery-plugin might be worth looking at
https://github.com/themouette/jquery-week-calendar
looks like it uses a combination of table(s) and divs to do the layout

Is processing.js a good option to implement this idea?

I've been gathering ideas for my personal project in CSS/JavaScript/XHTML.
The idea is to replicate this:
And so far I have this (I know it's far away from what I need, but just playing around)
http://jsfiddle.net/dburelax/XY8CA/9/
I was wondering if http:// processingjs.org/exhibition/ is my best choice to get this done in javascript? Thanks
P.S: I have no idea how to make the character move within the tiles any suggestions are welcome :)
I'd say light years away. But don't take it as sarcasm; let me explain.
What I see when I look at the gif is an engine that supports block "primitives".
Because, you see, every time he hovers a tile with the pointer it gets decorated with a white border.
In your case, you just have two images:
A map background
A gif of sprites for the character (without his back or sideway, but let's just forget that for now).
With these two in order to achieve the block highlighting you should always calculate offset, and apply image filters on the background with the border decoration (and shadows and what not). Then, when moving outside the box remove decoration the last window.
After that what do you do if you change box size? Recalibrate all offsets? What if you have boxes/bocks (I'll call them interchangeably now) in mixed sizes?
In game engines particularly you have primitives such as boxes, where you can detect collisions and either allow passage or not from the colliding box (a character is a box as well). Think how this would be practical if you for example had "fog of war" and allowed vision only in adjacent boxes.
It's not just about processing.js, which may or may not be helpful to you, but there are key bindings, character movement, character orientation to be thought about first.
I don't know about you, but I wouldn't be able to encode all that information in Javascript objects and still have it performant. Not with current Javascript engines, at least.
While your hobby project is a fun idea, there is much much more you have to learn first to be able to pull this off.
In the case I have offended, take but this and all is mended -- The Goblin
If this is in the scope of learning programming, while having a project to keep you motivated; then go for it (use the path I've deemed hard), learn first how to move images on the HTML5 canvas and when having actual code problems come back.

Find links to images in HTML (incl. outside of common tags/attributes)

I'd like to find (using javascript) all of the references to image links on an HTML page. Since I'm also looking for image references that may not be displayed, or are in unknown attribute types, simply looking for image tags or src's etc. isn't enough. As such, I haven't yet found a simple method using an html parser to do this.
Having looked through the stackoverflow threads, I don't want to lose my soul by employing the dark method of matching that dare not speak its name - I hesitate to mention it here, lest I draw down the fury of those who hate using regu1#r_expre$$i0n$ for such a purpose. But I haven't found the right method yet either.
I know that all links that look like images links are not, and vice versa, but that's OK. I don't need complete coverage, just the widest possible without sacrificing speed. so I'm guessing that following all the links is too intensive, and restricting myself to links that 'look' like images will be just fine.
Anthony was right, regex worked just fine for my purpose here.

Jquery append using multiline

I have been working on a project that dynamically creates a javascript file using ASP.NET which is called from another site.
This jquery javascript file appends a div and fills it with a rather large HTML segment and in order to do that I need to turn the segment into a string like so:
$(document).ready(function(){
var html = "Giving this magazine such a lofty epithet may seem a bit presumptuous, but for a non scientifically trained outsider this magazine offers a fresh and challenging look at the fast paced world of science that doesn't shy away from humor and the use of terms and ideas that may require its readers to go online and define a term. And in some cases it may inspire the reader to pick up a book on science by such greats as Hawking and Greene in order to better grasp some of the concepts dealing with time, space and atoms. This magazine isn't dumbed down. It includes well placed and efficient illustrations to help explain some of the more abstract points. It is not designed in the way popular magazinea are, in so much as they only touch upon a topic in the simplest manner and then move on before the audience is lost. Yet this magazine keeps the attention of the reader by combining explanatory notes that help people with no background knowledge have some grasp of the topic and by using humor and well written articles to clearly make their points. <br />For a magazine with a serious and well researched list of topics having small cartoons the likes of the New Yorker shows how comfortable this magazine is with itself. From the moment I picked up this magazine for the first time I felt like every word I read mattered and was worth my time to read. (Not true of many other magazines) American Scientist may not have the audience of Discover or National Geographic, nor is it as accessible as said titles, but for those with a true interest in science willing to challenge themselves and commit to real learning this magazine may be a perfect fit. At $4.95 it is certainly worth it to pick a copy on the news stand and try it out."
$("#divname").append(html);
});
As you can see the segment will be pretty large and I have no way of knowing how big as it is generated dynamically from my database depending on the reviewID which is defined by the user in their request.
The html to be inserted into the div is a list of reviews and is generated using asp.net MVC by a repeater which loops through a list. (if that helps give you an idea of what I am doing).
Is there any way to turn this large segment into one string which can be inserted into the append script?
Thank You
Cross domain jquery json
http://docs.jquery.com/Release:jQuery_1.2/Ajax#Cross-Domain_getJSON_.28using_JSONP.29
Some ideas:
You can replace new lines with spaces and create a huge line. There shouldn't be a problem with it.
Use string concatenation. Split the string and lines and do:
var html = line1 +
line2 +
...
linen;
Make an Ajax call to fill the div:
$("#divname").load(service_url);
You need to create a service that will return the string.
In my opinion the 3rd option is better than the other ones.
Correct me if i'm wrong but i think everything between the starting and ending quotation marks would be considered part of that string no matter how many lines it has. Unless your string has got any quotation marks in itself, in which case it'll be better to do the equivalent of php's addslashes() function in ASP on your string, which should add a \ before all the " marks in the string.
Another idea can be to use Json to encode/decode the string.
i don't see what's wrong with just generating one big-ass long single-line string and appending it just like you are doing. period. done. Fancier isn't going to gain you anything.
Hide it else where on the page and populate the div with it when you need it?

Categories