Jump to content


Staff Alumni
  • Content Count

  • Joined

  • Last visited

  • Days Won


Everything posted by .josh

  1. ...and you are NOT using a framework like jQuery or Prototype, think long and hard to come up with a very good reason why you are not! In all my years of coding, the only valid reason I have ever seen for not using one of these tools, is because someone is trying to learn it the old fashioned way (but not necessarily actually build websites with it). Or...someone is trying to build their own framework. That's it! IMO there has been no other reason worthy enough to warrant not using jQuery or the like! "It will bloat my website, increase page load time, blahblah" is not a good enough reason! These frameworks are compacted and browsers will cache them! So if you post an AJAX question here and your code and/or question does not involve the use of an existing framework like jQuery, then be prepared for you first response to be something along the lines of "Why aren't you using a framework?" Seriously. It is super easy. Way easier than that code you're trying to post. Save yourself the headache. Get jQuery or similar. DO IT.
  2. .josh

    JS Open Hours

    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..
  3. yeah well I have a feeling that's not what he really wants.
  4. 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.
  5. .josh

    On close browser.

    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.
  6. .josh

    Need help finding right pattern

    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.
  7. 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.
  8. .josh

    Get part of URL and add to specific links

    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.
  9. .josh

    Storing data in a JSON text column

    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
  10. 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,]+$
  11. 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.
  12. .josh

    Require digits, but not necessarily together

    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.
  13. .josh

    Jquery Export to Excel

    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 }); });
  14. .josh

    problem with the text fields

    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)?
  15. Okay I have been inspired by one of steelman's (though it pains me to admit it ) posts to make a game. P.s. - Don't be jealous of the awesomeness of my game name! Okay here's how it works: It's just like those threads on other message boards where everybody contributes to making a story by posting the next sentence/few sentences/paragraph or whatever, except for we are gonna take the script and the next poster adds his/her little piece to it. The code you add doesn't have to really 'conform' to any particular theme or situation or goal or whatever, but it does have to be somehow useable or relavent to the script as a whole. In other words, if you wish to create a new arm for Frankenstein-Code, that's fine and dandy, but it has to be attached to his body, not just some random arm laying there. Also, the script has to be "self-contained." No database stuff. No flatfile stuff. I don't want people to have to go setting up and altering databases all the time, or having to mess with dir structures/permissions/whatever. Also no cookies. And keep it strictly PHP, as in, no adding in javascript or some other such thing. These rules may or may not be relaxed, depending on how this game progresses and what comes of it. Also, it should go without saying, but I'm gonna say it anyways, so that one cannot argue they "didn't know" : No malicious code, no vulgar or pornographic content, etc.. Now, in order to keep the code consistent and not have like 3 different people posting 'at the same time' or something, here's what we're gonna do: If you wanna be the next person to add to the script, make a 'placeholder' post, saying "placeholder" or "I'm next" or "get off my koolaid yo" or something. Then copy the code from the previous post, add your piece to it, and then edit your placeholder post. p.s. - Please use code tags when posting. Also, even though coding styles differ, things like indenting in some way are standard, so do it. Okay so I guess I'll start with the cheezy but fitting: <?php echo "Hello World!"; ?>
  16. .josh

    Programming interview question

    What can I say, some people are just more.. adventurous.. than others.
  17. .josh

    Programming interview question

    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!
  18. .josh

    Programming interview question

    Well you know, I did preface it with:
  19. .josh

    Programming interview question

    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 ) */
  20. 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.
  21. Sorry, this isn't a "Do my homework for me" site.
  22. you can't do this with php. use javascript.
  23. .josh

    Back online.

    The admin are new to their reign, So this IRC thing is a pain. Despite all the docs, persistent flummox, It's enough to drive one insane. .. but seriously, did y'all just try turning it on again? Or is the restart command too arcane? It's really not that hard to maintain..
  24. Always great to hear stuff like this, thanks!

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.