Relative time with moment.js but with one day granularity

I am using moment.js to display dates in a readable format. What I want is to display them relatively to current time (1 day ago, 2 weeks ago and so on). In documentation, I found that I have to use fromnow(), but I do not care about minutes, seconds and hours. So instead of 6 […]

Show javascript Alert without blocking javascript

On page load, I am starting a timer to check if session is expired. I am checking expiry by making ajax call to a page. I need to display alert 5 minutes before expiry and redirect to default page after expiry. Here is my code: function startSessionCheckTimer() { setInterval(checkSessionExpiry, 60000); } function checkSessionExpiry() { $.ajax({ […]

Javascript alert: block if message contains certain word?

I have a webapp that makes calls to a database. Every once in a while, we get a javascript alert dialog that says that the transaction was deadlocked. Honestly, we don’t care if that happens because it’s not an interactive app…it just displays data based on a timer and if it misses it this time, […]

Get LinkedIn share count JSONP

Using the LinkedIn API, I want to get the share count for an URL. https://www.linkedin.com/countserv/count/share?url=http://www.linkedin.com&format=json But this gives me an error because of Same-Origin Policy. I want to use JSONP to then get the data, but I am stuck there. $.getJSON(“https://www.linkedin.com/countserv/count/share?url=https://www.linkedin.com&format=jsonp&callback=myCallback”, function(data) { elem.find(“.count”).html(data.count); }); I still get the Same-Origin Policy error and no data […]

meteor-useraccounts and alanning meteor-roles – Check role on sign-in

Is it possible to check users role on Sign in, and than if user is in role “admin” to display one page, and if is it in role “basic-user” to display another page ( go to another route).

Form action value difference in prop and attr

Here is a simple form: <form action=”hello”> </form> If I use var action = $(‘form’).attr(‘action’); I get the correct value, “hello”. But if I use var action = $(‘form’).prop(‘action’); I get http://localhost/hello What’s up with that? I read that I should use prop() instead of of attr() but here it returns incorrect value

Sails js Error in file Upload

I have a form which have a input type file with name “uploadfile”. No error occurs while a file is selected and form is submitted. But having this error while I don’t select a file and submit the form. ` if(req.file(‘uploadfile’)._files.length>0){ var ques_file = req.file(‘uploadfile’); console.log(‘here’); ques_file.upload({ saveAs: function(file, cb) { cb(null, file.filename); }, dirname: […]

AngularJS : Watch scope value of a injected service changed in one directive from another directive

Consider the following scenario. There are two directives which is independent of each other and I want to share the scope between these two directives. Since they are not nested, I cant use a controller in the directives to share the scope. So I have created a service and injected the service to both of […]

Is it possible to extend the range of a regex meta character?

I am working with js (javascript) regex literal expressions but I guess the answer applies to all regex in some form. I simply want to know if it is possible to do this: /\w+[more characters]/g (please disregard the incorrect expression, it is for illustration only) or are we locked in the finality of the meaning […]

When using canvg to convert Highchart SVG into PNG, all text appears twice – how to solve?

Here’s my (truncated) example SVG image (made with Highcharts, http://www.highcharts.com/ ) – when I render that onto a canvas (with canvg (https://github.com/gabelerner/canvg and code adapted from here: https://stackoverflow.com/a/8997520/2067690) all text in the resulting PNG is duplicated, meaning that it’s output double, one piece of text immediately followed by the same text once again. How can […]