Jump to content

MrFish

Members
  • Posts

    492
  • Joined

  • Last visited

Everything posted by MrFish

  1. 390 Downloads as of June 2nd. Site up with documentation: http://snoozejs.org/documentation
  2. oh shreyaskudav. You remind me of my younger self. I asked the very same question when I was 12 about booleans on the xgenstudios forums. You can always pass variables. The way programming languages work is that it always interprets the most nested elements first. So when you say- var myVar = "test";getElementById(myVar); It will interpret to getElementById("test"); first. Same with functions. function foo() { return "test";}getElementById(foo()); Interpets to- getElementById("test"); Happy programming!
  3. Javascript is a glue. It's becoming more popular as more than just a browser scripting language but it's always been a glue. You can't JUST lean javascript and do everything you want to do. Learn it along-side your server language (###### if it's nodejs more power to you) and your client language (probably html). But in technology there isn't just one language. You'l end up learning many languages to accomplish your goals.
  4. You should learn javascript, html, and css before you ask this question.
  5. I can't understand your question.
  6. shreyaskudav, You have to understand the difference between "client-side" and "server-side". A client is your computer. You see a web page and you click a button. Only your computer knows you clicked the button until you send it to the server (where your PHP lives). The server handles the request and sends a response. When a response is sent the client updates to reflect that response. Shorts of writing a working client side and serve side example there is probably a lot you need to learn if you don't understand this. Keep writing your game (that's how I learned) but you haven't got the knowledge to write it yet (let alone patients). Javascript sends (using ajax) data to your server. PHP handles the ajax request and sends a response back. AJAX updates the browser so players can see what they've done. Keep on keeping on. Good luck.
  7. This. I assume you're new to js so to do that I'd recommend going inserting new DOM nodes (cleaner imo). var myText = document.createElement("span");myText.innerHTML = "This is a note";document.getElementById("my_container").appendChild(myText); But I'd really recommend AngularJS if you're updating html. It has 2-way binding which means whenever you update a variable the view (your html) will update automatically. And whenever you update an input the controller will update. Save a lot of time and frustration.
  8. For clientHeight it really depends on your bowser. What browser are you using?
  9. I've recently been doing AngularJS work and love how it's organized. I tried to find something similar for NodeJS but after searching I've only found the basics to setup your own framework (like expressjs) but nothing that actually provides a simple modular framework. So I've started to write my own. snooze is a restful framework that is simple and modular. It's focused around building a restful api but not necessarily the nodejs version of something like apache. Every request is handled by a controller, is validated through validators, and is processed by a service. A framework suitable for web/mobile/tablet apps. snooze is released under GPL so please feel free to share, change, and share it. Also share it. Have a look at the examples and post your criticisms. I wrote this simple framework for my projects but I'm excited that it may help others. https://github.com/iamchairs/snooze https://github.com/iamchairs/snooze-stdlib snooze.module('myServer', ['snooze-stdlib']) // inject the snooze-stdlib module .route('get', '/users/:username', { // define the route controller: 'UserCtrl', // what controller should handle this route action: 'getUserByUsername', // what action to perform on this route validator: 'GetUsername' // before processing this action what validation should occur }) .controller('UserCtrl', function(User) { // inject the User service return { getUserByUsername: function(res, options) { User.getUserByUsername(options.query.username).then(function(username) { res.send(200, username); }).fail(function(err) { res.send(500, err); }); } }; }) .service('User', function($q) { // inject the $q service return { getUserByUsername: function() { var deferred = $q.defer(); deferred.resolve('iamchairs'); return deferred.promise; } }; }) .validator('GetUsername', function($validator) { // inject the validator service return function(deferred, req) { if($validator.isLength(req.query.username, 2, 32)) { deferred.resolve(); // resolve (valid request) } else { deferred.reject([400, 'Username must be between 2 and 32 characters']); // reject (invalid request) } } });
  10. Got it down to an average of 6/s per 100 business processed. Here is a list of times taken to process individual businesses. Not very consistent. Oh boy getting 146.963 queries/s average. 0.009335041046140.01928496360780.07202100753780.02311992645260.05278611183170.02507495880130.01462388038640.03662300109860.03207707405090.01911401748660.04484701156620.05123400688170.0286669731140.01086711883540.05897092819210.01087403297420.0009930133819580.00136899948120.09078907966610.0108981132507
  11. Well I've done some indexing and it's helped a lot but it's still behind. I'll post the code that runs the queries and post the queries that are called on each. # Each tag is a string value for Tag in tags: # It first checks if the tag exists in the database. # SELECT * FROM tags WHERE tag_name=%s # tag_name is indexed if self.tagExists(Tag) == False: # If not it will add the tag # INSERT INTO tags (tag_name) VALUES(%s) self.addTag(Tag) # Then it will check if the business has the tag associated to it # SELECT * FROM business_tags WHERE bt_b_id=%s AND bt_tag_id=%s # This method also searches for the business ID and tag ID given teh Business and Tag objects # This can probably be trimmed down if self.businessHasTag(B, Tag) == False: # If the business doesn't have the tag it will associate it # INSERT INTO business_tags (bt_b_id, bt_tag_id) VALUES(%s, %s) # bt_b_id is indexed self.bindBusinessTag(B, Tag) for key in B.getKeys(): # Checks if the business has this key set in the key-value data table # SELECT * FROM business_data WHERE bd_b_id=%s AND bd_key=%s # bd_b_id is indexed if self.businessHasKey(B, key): # If the business has the key it will update it # UPDATE business_data SET bd_value=%s WHERE bd_b_id=%s AND bd_key=%s self.setBusinessKey(B, key, B.get(key)) else: # If the business doesn't have the key it will insert it # INSERT INTO business_data (bd_value, bd_b_id, bd_key) VALUES (%s, %s, %s) self.addBusinessKey(B, key, B.get(key)) I am doing a lot of redundant queries when finding the business Id but this is usually less than a millisecond. I'll clean that bit up a bit. I still don't think it will be enough. I'm thinking I may need to create temporary databases and later merge them.
  12. Yes. Names are strings usually. I wish they'd all name themselves numbers but they didn't.
  13. I have a database of ~100,000 local businesses in my area. I have a few scrapers to pull in more businesses from other locations. I've spent the last few days creating a client-server application in python so I can scale up the amount of scrapers and have all the scraped data feed to one machine. So the client scraps sites and the server records the data. With 100,000 businesses the server can't keep up with even 1 client's scraping! When adding a business what's involved is- The business name and address are checked against the database to prevent duplicates. If no business is found the business is added to the current database of 100,000 businesses. Then tags found for that business (e.i. "pizza", "mexican", "chinese", etc.) are checked against a tags table to see if they exist. If they don't exist in the tags table the tags are added. A tag-to-business association table then records the business ID and the tag ID. Lastly a key-value database for random useful information like "known web address" is queried to see if the keys being added exist, and if they do it updates, if they don't it adds the key-value pair. In this there are a lot of string searches going on so I can see why it would slow down so much. I've considered indexing all of the fields that will be searched but I don't know if that will slow down insert queries. One thing I've considered is to just add all this information without checking and have a cleanup process later to remove duplicate data. Not sure is that would help. Any advice to speed up my databases? I'd like a dozen or so scrapers and not being able to keep up with just one scraper is bad news.
  14. For this type of project I'd recommend Node.js and Websockets. Other than that Ajax is going to be the only way to communicate to the server with javascript. Node.js is a lot more complicated than ajax calls but it's worth looking into. Other than that you should probably only poll with ajax every 5 seconds or so.
  15. You should probably just do this in PHP. <?phpif(!$_COOKIE["foo"]){header("location: login.php");exit();}?> You'l have to check server side anyway.
  16. Oh. Well I didn't know that. Probably a good idea to include that in the tut if it's not already. You should probably just use w, d, s, etc. I've never actually used A-z or any variation of it. Just my opinion.
  17. Not sure what your problem is. It doesn't match brackets. http://jsfiddle.net/RPLUm/ Anything in a bracket says "match these characters". Then you define what characters you want to be matched. If you want to match actual brackets you need to escape the bracket with a backslash ''.
  18. I have a simple testing environment where I want to copy live sites to, do some large site-breaking tests, and push it back to the live copy. Surprisingly we don't have this where I work- it's a bit like the wild wild west here. Anyway I've got a testing environment setup and I'm having trouble getting the virtual hosts setup. I've got test.com working find going to /var/www/vhosts/test.com/httpdocs but I didn't think about what would happen if the site was www.test.com. Some of our sites force the www. in the htaccess for seo purposes so this is going to be a problem. I've been looking at apache virtual hosts and ServerAliases and stuff but I'm having trouble figuring out how to apply it to my situation. I don't want to have to define each virtual host so I've gotten away with adding this one line in my httpd.conf- VirtualDocumentRoot /var/www/vhosts/%0/httpdocs And now I'm stuck here- VirtualDocumentRoot /var/www/vhosts/%0/httpdocs<VirtualHost *:80> ServerAlias *.%0</VirtualHost> Which doesn't make sense and doesn't work of course. How can I create an alias that will accept all domains pointed to it with or without a www.
  19. I never would have thought of that. Thanks!
  20. I really don't know how to describe this problem and I'm not sure if it happens with js through a browser or just Node. So I'm using socket.io to communicate with an app on PhoneGap. I'm writing a simple communication manager to listen for specific events and pass the information to the appropriate class to be handled. I thought the cleanest way to map the event to the function in the communication manager (to then decide where it goes and how to pass it) was create a key-value pair like this- exports.eventMap = { "disconnect":"handleDisconnect", "login_request":"loginRequest",} When a connection is made the socket is sent to the handleConnection method. Like this- var that = this; this.socket.on("connection", function(socket) { that.handleConnection(socket); }); All's good- nothing wrong so far. Now this method will record the socket by it's ID and loop through the event map to assign callbacks with a simple for-in loop exports.handleConnection = function(socket){ var socketID = socket.id; this.socketMap[socketID] = socket; console.log("connection to " + socketID + " made"); var that = this; for(var _event in this.eventMap) { var callback = that.eventMap[_event]; var func = function(data) { that[callback](socket, data); } socket.on(_event, func); }}// Eventsexports.handleDisconnect = function(socket, data){ var socketID = socket.id; console.log("connection to " + socketID + " broke");}exports.loginRequest = function(){ console.log("how did this happen??");} The two events get mapped but to the last function in the eventMap object. So "disconnect" and "login_request" both call loginRequest. I have got a round-about way of fixing this but of course I want to know why this happens. Doesn't make sense to me. exports.handleConnection = function(socket){ var socketID = socket.id; this.socketMap[socketID] = socket; console.log("connection to " + socketID + " made"); var that = this; for(var _event in this.eventMap) { var rand = "_" + Math.round(Math.random() * 1000000); console.log(rand); eval("var " + rand + " = that.eventMap[_event]"); eval("var func = function(data){that["+rand+"](socket, data);}"); socket.on(_event, func); }}
  21. This. If I can elaborate- The reason is because- like html- javascript can be changed by the user after it's sent out. That and there's more than one way to submit a form without a browser. The golden rule is that you can never trust anything coming from a user and your server always needs to validate it. Doesn't matter if it's web or a desktop application. Pretty much everything can be changed on the users computer.
  22. This isn't a php question necessarily but I will be using php so I'll put it here for the lack of anything else. I've got a google map class that prints javascript that displays a google map. I need to add a ground overlay and pins over relative to the size of the ground overlay (so they will need to be overlays as well). I've written a utility that lets you place that map in javascript and place the pins on the static image separately (the interactive pin-image can exist without the map- the map is an add on). My problem is that I don't know how to convert the pixel position of the pins relative to the image to lat/lng coordinates in php. I think it would probably be easier to consider the x, y coordinates as percentages so you don't need to convert the lat/lng back to pixels and then back again to lat/lng. I drew and image of what I need. Excuse my lack of basic geography knowledge. If this isn't the right place to ask this question please move it.
×
×
  • Create New...