-
Posts
14,780 -
Joined
-
Last visited
-
Days Won
43
Everything posted by .josh
-
So a couple of things. Firstly, sure, there are more "elegant" ways of writing this if "make the shortest amount of code possible" is what you consider "elegant". However, I would argue what is more readable and flexible for yourself and other non/semi-coders in the future would be to have a lookup table of hours, Something along the lines of this (I think I got the hours of operation right, based on your condition): function checkTime() { // array of 7 elements, one for each day of the week var hoursOfOperation = [ // array of 24 elements, one for each hour of the day. // 0 value means closed, 1 value means open [0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0], // sunday - closed all day! [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], // monday - open 9a to 5p [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], // tuesday - open 9a to 5p [0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0], // wednesday - open 9a to 1p [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], // thursday - open 9a to 5p [0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0], // friday - open 9a to 5p [0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0] // saturday - open 10a to 1p ]; var now = new Date(); var messageDiv = document.getElementById('messageDiv'); var dayOfWeek = now.getDay(); var hour = now.getHours(); var status = hoursOfOperation[dayOfWeek][hour] ? 'open' : 'closed'; messageDiv.innerHTML='We are '+status+'!'; messageDiv.className=status; } // end checkTime See, now you can easily update a table for any hour of any day without messing with conditions. Secondly, I should point out to you that since javascript is client-side, the date/time is generated by the user's system clock locally set on their computer. Meaning, what their browser says the date/time is may not accurately reflect your actual hours of operation. Consider someone in Colorado visiting your page, vs. someone in China.. completely different timezone. So, if you want to (more) accurately reflect your actual hours of operation, you will need to include some conversion to your timezone. But even then, this is no guarantee it will be 100%, because visitors can (and often do, particularly kiddies trying to get around time/date based software restrictions ) change their time settings easy enough. Or alter your javascript. So if you really truly want the most accuracy out of all this, you should move this stuff server-side. But there is a snag to that, which is the constant check for current open/close status. Which brings me to my last point: I don't know what your actual site looks like, but is it really necessary to use setInterval to constantly check and update this? Things like setInterval come with a performance penalty, and I have a sneaking suspicion just showing an updated status on every page load will likely be just fine..
-
yeah well I have a feeling that's not what he really wants.
-
You need to restructure your code to use AJAX. Read up on how to submit an AJAX POST request and receive a response to update a div or w/e on the same page. There are a billion tutorials out there for it. Come back with specific questions about it if you get stuck.
-
Literally the only thing I have ever seen popup when I try to close my tab/browser or otherwise navigate from the page that I only _marginally_ consider "okay" (read: barely tolerable) is a warning about losing unsaved changes to something.
-
At face value, this should work for you: preg_match('~^\d+/\d+$~',$subject,$match); if ($match) { // matched, do something } but i have a sneaking suspicion you aren't telling us the whole story/requirements.
-
Some items are already hovered over on page load. Any way to fix this?
.josh replied to imgrooot's topic in Javascript Help
You can try adding something like this. I've seen it more or less work as a bandaid for some: $(document.ready(function() { $('.product-small .show-details').hide(); }); I don't really have an explanation why it happens though. -
Here is a basic example for what you want to do, that will work for the link example you provided: <script> $(document).ready(function(){ $('a').each(function() { var onclick = $(this).attr('onclick')||''; var qs = location.search.replace('?',''); var url=onclick.match(/window\.open\('([^']+)/); if (url&&url[0]) { newUrl = url[0] + ((url[0].indexOf('?')==-1) ? '?' : '&') + qs; $(this).attr('onclick',onclick.replace(url[0],newUrl)); } var href = $(this).attr('href')||''; if (href) { href += ((href.indexOf('?')==-1) ? '?' : '&') + qs; $(this).attr('href',href); } }); }); </script> However, this is generally bad practice, as it can easily break. The better thing to do would be to move all of the onclick code to a callback function and then attach the callback function with a click event handler. That way, you can use a variable instead of hardcoded value and then update the variable instead of trying to scrape onclick like this. sidenote: your trackOutboundLink() function will never fire because of that return false; before it.
-
If you are absolutely, positively, 100% sure you will not ever need to actually do any queries to return data sets based off stuff within there, then it shouldn't be an issue
-
Just a random thought.. I don't know full context so this may or may not be something you can do, but I assume if it's a list of numbers you will split at the comma and loop anyways.. why not just simplify to ^[0-9,]+$
-
To directly answer your question, with regex you can use a negative character class to match anything that is not a quote. You didn't actually post your regex code, so a simple example matching relevant part: preg_match('~<span id="[^"]*">~',$content,$match); However, I agree with kicken about using a DOM parser. Depending on what exactly you are looking to grab, you can sometimes get away with parsing html with regex, but in general, regex alone cannot be used to fully and reliably parse html. Regular expressions (regex) parses regular language types (hence the name), meaning, there is an identifiable pattern to the context. HTML is a context free language, which means it is not regular. In order to reliably parse html, you need a combination of regex, loops, conditions, tokens, etc. basically, all the things that make up a DOM parser, which is exactly why we have DOM parsers.
-
regex engine ignores does not capture groups in zero-width assertions (e.g. your positive lookahead), so there is no performance difference between using (?:[pattern]) vs. ([pattern]) unless you want to count the unmeasurably small amount of time it takes to read (and ignore) a single colon char.
-
Quick glance at the doc link you provided, I would say you just need to set the name config property to document.title Example using step #3 in doc: $("button").click(function(){ $("#table2excel").table2excel({ // exclude CSS class exclude: ".noExl", name: document.title }); });
-
At face value the code above looks okay. If it's working without the 3rd field, my first guess is you don't have a column named "kont" in your database table (e.g. it doesn't exist, not spelled the same, etc.) or maybe it's not the right field type (e.g. you made it a date or int type and it's supposed to be text, or maybe you set it to be a certain length e.g. varchar(10) but attempting to put a 20 char value into it). Do you have error reporting turned on? Are you getting an error(s)?
-
What can I say, some people are just more.. adventurous.. than others.
-
You know how like if a question was something like "write some code to output 1 to 100" and you just put echo "1 to 100"; It's totally not what they really wanted, but technically not wrong. So maybe they say "wow, thanks for wasting our time.." or maybe they say "wow! this dude has a sense of humor, we'll hire him!". I've gotten answers like that from job candidates, and it has indeed influenced me giving them the thumbs up. For example if I could tell from their other answers that they know their shit, then I'm down for seeing answers like this. But if I can tell from their other answers they don't know wtf they are doing.. I'll probably think they really thought that's what the ask was, and I'd facepalm. As someone who is part of the hiring process for devs, I've seen candidates go both ways. Anyways, TL;DR: It wasn't meant to be a serious answer, and I prefaced it as such!
-
Well you know, I did preface it with:
-
or at face value you could could go the "cheap GIGO answer" route, accept input as full string and just sort it: $points = array( 'B-->C', 'A-->B', 'C-->D' ); sort($points); print_r($points); /* output: Array ( [0] => A-->B [1] => B-->C [2] => C-->D ) */ Or with an associative array: <?php $points = array( 'B'=>'C', 'A'=>'B', 'C'=>'D' ); asort($points); print_r($points); /* output: Array ( [A] => B [B] => C [C] => D ) */
-
Why do you care about analytics? Analytics is the next logical step after website development. You just spent all that time and money making your website. Don't you want to know how many people are going to it? Which pages are they actually looking at? Which products are they actually buying? What can you do to improve user experience on your site so that they buy more stuff? I can help you with: Google / Universal Analytics Google Tag Manager Adobe Analytics (SiteCatalyst / Omniture) Adobe Dynamic Tag Manager Lots of other things that involve php or javascript I have been doing Digital/Web Analytics for over 6 years, currently working for a company who works exclusively with enterprise level / high end clients. I'm offering my expertise to the "little fish" / "mom and pops" out there for a nominal fee. PM me or email me at crayonviolent [at] gmail [dot] com.
-
Need help answering college sample exam question
.josh replied to hiimmrwood's topic in Javascript Help
Sorry, this isn't a "Do my homework for me" site. -
A million dollor Guru ! Where is he ?
.josh replied to ajoo's topic in PHPFreaks.com Website Feedback
he went that way ---> -
a) Let me remind you that you are responding to a post that was posted several years ago, when this stuff was a much bigger issue. b) I work in the web analytics industry. I look at web stats all day long. And I talk to corporations all day long about those numbers vs. their web sites and the user experience (UX) of their sites. What I see is the exact opposite of your thoughts about webmasters still striving to cater to <IE8. I have been fighting for clients to ditch IE6/7/8 support for years and they are only just now starting to come around since earlier this year, only because of Microsoft ending support for it. So the ball is rolling, yes, but I'm sorry, I disagree with the notions that web devs are in a place where they can just completely forget about supporting it. If you don't believe people are still catering to IE6/7 then I don't believe you have much experience dealing with corporations, and possibly even clients in general. I don't doubt for a second there are plenty of random no-name sites and even some "cutting edge" sites that are "with the times" and cater to younger crowds. And of course it's easy for people to upgrade. And of course there's no reason for them not to. But the stats show that there's still a fair chunk of people that don't, and nobody wants to throw away potential revenue, even if it's 1% of users. Also, I'm not saying there isn't a non-jQuery or non-framework solution for things. That's just silly. All I'm saying is when you have a complex site doing complex things, and having to deal with making sure it works for the widest audience possible, you will more often than not save yourself a lot of time by using a framework like jQuery. Look, I'm done arguing with you about this. As I mentioned in a previous post, I used to be hardcore on the other side of the fence, absolutely shunning frameworks as extra bloat used by people who can't be bothered to learn "real" javascript. I know exactly where you're coming from because I've been there, so I know there's little point in trying to argue with you about it.
-
Frank, that's not a fully cross-browser compatible version of ajax for <IE8. Most people still strive to support IE6 and IE7, even though Microsoft stopped officially supporting those versions (and IE8) earlier this year (April 2014 - XP no longer supported, so by extension <IE9 no longer supported). Also sidenote: you gave a simple example of what to do with the response. That example isn't cross-browser compatible either. And in reality, most people use ajax in conjunction with more complex code, from event handlers to selectors, notwithstanding applying previous stuff to whatever dynamically generated content is likely to come from the ajax call. All of that stuff must be applied in a cross-browser compatible way.
-
GENERAL RULES AND GUIDELINES FOR POSTING This forum is not meant to be a formal freelance service system. It is available for those who wish to seek out services or work from other people, as a courtesy to the members of the phpfreaks community. phpfreaks.com does not specialize in freelance services. This forum is an informal mechanism, as a courtesy to the community. We have no formal mechanism in place (like escrow) to guarantee payment, refund, work done, etc... phpfreaks.com shall not be held responsible for any losses you incur. we have never and continue to not act as any kind of mediator or verification/compensation source for people/organizations who use those forums. We will not be held responsible/liable for any damages, loss, etc. that occur from use of those forums. If you hire someone and they rip you off, don't come crying to us. If someone hires you and they rip you off, don't come crying to us. Those forums are a convenience. If you want something more official that offers guarantees, go to a real freelance site! If you have any questions regarding the freelance forum, feel free to ask them here. RULES: WHERE TO POST:If you want to offer your services, post in the Service Offerings sub-forum.If you want to offer a job or position of employment, post in the Job Offerings sub-forum. People looking for work: DO NOT post your 'resume' in job posting threads. You must directly contact the person you wish to reply to. The only reason replies are allowed is to ask for clarification/details about the job. Failure to adhere to this rule will result in all kinds of things, like you getting banned, or us disallowing replies. People offering work: DO NOT make more than one thread for a specific job. You may make a new thread if it's a different job, but if you are just wanting to tweak the job specifications, edit/reply to your original post. GUIDELINES:When posting in the freelancing forum it's important that you provide a way for users to contact you. They will not be able to reply to your topics so they need a way to contact you privately, and separately from the PHP Freaks website. This can be using emails or any type of instant messaging service (MSN, Gtalk, AIM, Jabber, etc.) or however you see fit.Unless you're an experienced coder and are looking for an extra set of hands, don't assume the job you want done is something "quick" or "easy" or "shouldn't take too long" etc... maybe it is, maybe it isn't. That's like going to a mechanic and telling him you expect him to be done in 2 hours when you have no idea how to fix a car. The best way to get a feel for how long something should take, is to get multiple quotes. Don't expect to get a response from coders if you're offering like $20 for someone to build you xyz site. Do some research and find out what the going rate for sites, particular aspects of sites, scripts, hourly rates, etc.. whatever fits your needs. You may indeed find people willing to do something super cheap, but as with everything else in life, you get what you pay for. The moral of the story is this: Just because one person quotes $20 to build xyz.com from the ground up, or charges $2.15/hr, doesn't mean everybody else is way overcharging. You get what you pay for. Don't expect feedback from posting "You'll get x% of profits once income starts pouring in" deals. Use some common sense: if the coder has to wait until you start making money off his work, what does he need you for? You get what you pay for. Don't expect feedback from posting jobs as 'non-paid' or 'for free'. Would you expect someone to build you a house or fix your car for free? You might get lucky and find some altruistic coder, but more than likely, you won't. You get what you pay for. Even if you do get responses from posts like the above ones mentioned, more than likely the quality is going to be cheap. Cheap as in not a good deal, messy and poor coding, lack of communication, shady dealings, etc.. You get what you pay for. Make sure you know what you want, before looking for someone. Don't assume any part of your project or need, no matter how big or small, goes without saying. Because it doesn't. And I guarantee you you'll end up fighting with the coder about it.Though details vary from coder to coder, yes, it is normal to have to pay some kind of % up front for work you want done. It may sometimes be hard, but it is possible to recover or minimize monetary losses, should a deal go awry. It is not possible to recover work done. That is why the burden of payment is on the client. There are lots of sites/systems you can go through to protect yourself from potential fallouts. One thing you can do is search through the user's posts here. Just click on their name and at the bottom of their profile click the "show last posts of this person" link. This can be a useful research tool for getting a feel for the person's skill level. For instance, if you see their post claiming to have 10 years of php experience doing everything under the sun, but check their post history and see that they recently asked a bunch of really simple questions, chances are they are lying about their skills. Edit history: June 8 2017: Job postings need to include a way for users to contact the poster that does not involve the PHP Freaks forums: replies are discouraged and private messages are only enabled for established users.
-
It was not my intention (nor do I think I implied it) to say you're stupid if you don't use a framework. I said do yourself a favor and make your life easier. Also, I am not "just another soldier" in the "we use frameworks" army. I actually actively resisted and opposed frameworks for a very long time. I too made arguments such as "If people learn jQuery, they won't learn the core language and therefore they will be weak." But the bottom line is that there's always going to be a certain amount of coding involved to keep things cross-browser compatible. And after several years of developing and maintaining my own baked framework (because that is essentially what you wind up with), I came to the realization that there's a whole lot of people out there much smarter than me who are dedicated to maintaining frameworks such as jQuery, vs. just myself, and on my very best of days my code will look very similar to theirs anyways. In short, I came to the realization that it was a waste of my time trying to develop and maintain my own baked framework, because my coding career does not revolve around that framework. Now, I still agree with the notion that one should take the time to learn javascript without frameworks, before diving into using them. I still absolutely agree with the dangers of not properly learning the nuances of javascript if you don't. And the same can be said for any language and framework. But if you've reached that level of expertise, all you are doing is holding yourself back by dedicating time and effort to maintaining your own baked solution. There's basically no compelling argument to do it, unless you are looking to distribute it and focus solely on it. Literally thousands of sites and coders out there developing, testing and submitting feedback etc. to a framework will always do it better than you, one person, trying to basically do the same thing on your own. And for what? Bragging rights? If I'm "just another.." then tell me, what makes you think rolling your own is better? I honestly want to know, because as I said, I did start on your side of the fence. Anyways, I also agree that there's little point in using it if you're only going to use like 1 tiny piece of it. I suppose I will concede that maybe I should amend the OP to weigh the options. But thing is, 9/10 times I see people not using a framework for stuff like AJAX.. turns out the site they are working on is already using a framework. This certainly comes up a lot more for freelancers and coders working in agencies who work with many clients on many sites and it's constantly new sites/clients in the door, vs. some coder working as web dev for a single company. Point being that if you get hired by a client to do some work on their site, it is better to evaluate what they already have going on there and use what's already there, than to just start throwing your own stuff into the mix. If you want to talk about unnecessary bloat, well that's a prime example right there. P.s. - telling me to "keep it civil" right after you've thrown out a "you're just another.." statement.. classy.