Jump to content

JeremyCanada26

Members
  • Posts

    55
  • Joined

  • Last visited

    Never

Posts posted by JeremyCanada26

  1. I'd like to know if there is a way to detect a head instead of the more specifc face. Maybe cut out the rest and be left with a transparent .png of just the head, that would be cool if it's possible.

  2. function checkIfSuppliedImageDataIsValid()
    {
    //first, check that the byte_array isset, then make sure it's not empty, then make sure it contains valid image data
    if(isset($this->byte_array) && !empty($this->byte_array) && imagecreatefromstring($this->byte_array))
    {
    	//passed in byte array is good
    	return true;
    } else
    {
    	//missing or invalid
    	return false;
    }
    }
    

     

    The above function is what i'm settling for, although I also see there might be another way to do it manually but I'm not technical enough to know how.

     

    The first eight bytes of a PNG file always contain the following (decimal) values: 137 80 78 71 13 10 26 10

     

    Taken from the png RFC page, http://www.faqs.org/rfcs/rfc2083.html, section, 3.1. PNG file signature

     

  3. I'm trying to regex match a search phrase that can be any letter or number and be either one word or more than one word, also between 2 and 100 in length.

     

    function checkSearchPhrase()
    {
    	if(isset($_POST['sp']))
    	{
    		//matches any single word or more
    		if(preg_match("/^[A-Za-z0-9]{1,100}$/", $_POST['sp']) == 1)
    		{
    			return trim($_POST['sp']);
    		} else
    		{
    			return false;
    		}
    	} else
    	{
    		return false;
    	}
    }
    

  4. I'm interested to know how other people keep track of time and also how they display time correctly back to the users. I'm using a third party API that I can tie into that actually gives me the userID of a user, their full name and the timezone for that user. After checking a few users data, this is an example data of what I'm working with.

     

    userID: 234213412

    first_name: foo

    last_name: bar

    timezone: -6

     

    Basically when a user visits my web app, I create a new account for them and store the above data. Currently, I'm just fetching the result from time() and converting it into MySQL DateTime format and storing that into my database.

     

    //get the current time as an integer
    $php_timestamp = time();
    //formats the time according to MySQL DateTime type
    $this->mysql_formatted_time = date('Y-m-d H:i:s', $php_timestamp);
    

     

    I would think the current way that I'm doing this is not very good because there is a possibility that I could introduce load balancing servers into the mix and they might not be located in the same region. Also, I would have no idea how to factor the time and modify it according to the timezone value.(in my above example, -6)

     

    Can anyone help me decide what method I should use to keep all of my servers timestamps in sync and how to display the time to the end user so that it looks correct to them?

  5. Yes, I'm running ubuntu 10.4 and using a LAMP setup. I came across an apache module designed specifically for limiting requests by IP address and it detects hammering and eventually forwards the IP out to the firewall. However, this solution reportedly works very well on a single machine only.

     

    In my development setup, it also would work very well since i'm using a single machine. However, When I launch, I'll be switching to 2 servers in a load balancing setup and probably scale upward from there as needed and so the triggering mechanism doesn't work very well with that kind of setup.

     

     

  6. I have a web app that uses an API that I wrote to communicate with my MySQL database that was written in PHP. Currently, each user of the API is required to authenticate before using the API with a username/password. Every API request is logged into a Requests_History table which stores the API request type, the timestamp and the userId of the requester.

     

    How can I easily stop hammering of the API via too many requests in a given time period?

     

    1. first violation within 24 hours, 2 minute ban

    2. second violation within 24 hours, 10 minute ban

    3. second violation within 24 hours, 1 hour ban

  7. This is my first time really working with more than 1 or two tables in a mysql database and I'd like to know what is the best way to go about querying my data so that i'm doing it in at least a somewhat efficient manner that the way I am currently doing it. First I will list my Tables and pastebin the Table creation code so you can get an idea of what I'm working with.

     

    Graff_Users, Drawings, Drawings_Stamps, Stamps, Packages

     

    Ok, those are the tables, the Graff_Users is the main table. The way I've got things setup is that I first do a query on the Graff_Users table for any uid that I want to lookup data for. Then, based on whether the artist column is equal to 1 will determine if there are Drawings to fetch, at least that is how I've been doing it and I dont feel like redesigning something that works so well for me right now.

     

    so everything is fine when artist=0 or null or anything but 1. But my trouble starts if artist=1, then I have to query a whole lot of data here, let me explain it.

     

    Ok, if artist=1, currently, I query the Drawings table to find any drawings where the house_owner_id is equal to the uid of the User. This leads me to a list of Drawings rows. Next, I check which of those rows has stamps_used=1 for each Drawing and gather up a list of id's of the Drawings that have that set to 1. Once I have the list of id's of the Drawings, I query the Drawings_Stamps table for rows where the drawings_id is equal to any of those id's. Then once I have that, I use the stamp_id's from those and do another query on the Stamps table to get all of the stamps matching those id's. Then each Stamp also contains an author_id so I gather those id's up and do another query back on the Graff_Users table to get the first_name,last_name and picture.

     

    Once I have all of that data in various array throughout my script, i create a new array and start putting the pieces back togather from the various arrays until I am left with an array that looks like this one here(JSON used for visualization here)

     

    {
        "request_type": 1,
        "target_uid": "1234567",
        "data": {
            "id": "277",
            "uid": "1234567",
            "first_name": "Jeremy",
            "last_name": "Canada",
            "picture": "http://www.pictures.com/mypic.png",
            "signed_up": "2010-10-29 03:47:09",
            "selected_house": "10",
            "mp3": "1",
            "emblem_id": "2",
            "artistData": [
                {
                    "id": "210",
                    "artist_id": "1234567",
                    "house_owner_id": "1234567",
                    "anonymous": null,
                    "stamps_used": "1",
                    "timestamp": "2010-09-23 00:52:42",
                    "note": "wanna dance?",
                    "first_name": "Jeremy",
                    "last_name": "Canada",
                    "picture": "http://blahblah.com/picture.png",
                    "stampsArray": [
                        {
                            "id": "250",
                            "name": "",
                            "author_id": "654321",
                            "created": "2010-09-23 23:40:22",
                            "keywords_id": null,
                            "packages_id": "27",
                            "public": "1",
                            "package_category_id": "0",
                            "filename": "drawingitems\/663231980_1285285221_445643.png",
                            "number_of_users": "0",
                            "description": "just another stamp my friend",
                            "rating": "0",
                            "thumbs_up": "0",
                            "thumbs_down": "0",
                            "first_name": "Cat Man",
                            "last_name": "Blues",
                            "picture": "http:\/\/pic.com\/_q.jpg",
                            "packageData": {
                                "id": "27",
                                "name": "Circles Of cool",
                                "description": null,
                                "total_stamps": "6",
                                "number_of_users": "0",
                                "rating": "0",
                                "thumbs_up": "0",
                                "thumbs_down": "0"
                            }
                        },
                        {
                            "id": "249",
                            "name": "",
                            "author_id": "1680999989",
                            "created": "2010-09-23 23:38:28",
                            "keywords_id": null,
                            "packages_id": "26",
                            "public": "1",
                            "package_category_id": "0",
                            "filename": "drawingitems\/663231980_1285285108_441450.png",
                            "number_of_users": "0",
                            "description": null,
                            "rating": "0",
                            "thumbs_up": "0",
                            "thumbs_down": "0",
                            "first_name": "Raymond",
                            "last_name": "Coldstar",
                            "picture": null,
                            "packageData": {
                                "id": "26",
                                "name": "The nice pics pack",
                                "description": "description of the package would go here",
                                "total_stamps": "123",
                                "number_of_users": "234",
                                "rating": "3",
                                "thumbs_up": "2",
                                "thumbs_down": "7"
                            }
                        }
                    ]
                },
                {
                    "id": "212",
                    "artist_id": "4",
                    "house_owner_id": "1234567",
                    "anonymous": "0",
                    "stamps_used": "1",
                    "timestamp": "2010-07-09 03:45:59",
                    "note": "shake it baby",
                    "stampsArray": [
                        {
                            "id": "248",
                            "name": "flying stick man 1",
                            "author_id": "663231980",
                            "created": "2010-09-23 23:37:08",
                            "keywords_id": "6",
                            "packages_id": "26",
                            "public": "1",
                            "package_category_id": "0",
                            "filename": "drawingitems\/663231980_1285285027_288422.png",
                            "number_of_users": "1200",
                            "description": "stamp description would go here",
                            "rating": "6734",
                            "thumbs_up": "18",
                            "thumbs_down": "22",
                            "first_name": "Gary",
                            "last_name": "Hoss",
                            "picture": "http:\/\/profiles.com\/63231980_1168_q.jpg",
                            "packageData": {
                                "id": "26",
                                "name": "The nice pics pack",
                                "description": "description of the package would go here",
                                "total_stamps": "6546345",
                                "number_of_users": "234",
                                "rating": "3",
                                "thumbs_up": "2",
                                "thumbs_down": "7"
                            }
                        },
                        {
                            "id": "249",
                            "name": "",
                            "author_id": "1680999989",
                            "created": "2010-09-23 23:38:28",
                            "keywords_id": null,
                            "packages_id": "26",
                            "public": "1",
                            "package_category_id": "0",
                            "filename": "drawingitems\/663231980_1285285108_441450.png",
                            "number_of_users": "0",
                            "description": null,
                            "rating": "0",
                            "thumbs_up": "0",
                            "thumbs_down": "0",
                            "first_name": "Raymond",
                            "last_name": "Blues Brutha",
                            "picture": null,
                            "packageData": {
                                "id": "26",
                                "name": "The nice pics pack",
                                "description": "description of the package would go here",
                                "total_stamps": "6543534",
                                "number_of_users": "234",
                                "rating": "3",
                                "thumbs_up": "2",
                                "thumbs_down": "7"
                            }
                        }
                    ]
                },
                {
                    "id": "221",
                    "artist_id": "663231980",
                    "house_owner_id": "1234567",
                    "anonymous": null,
                    "stamps_used": null,
                    "timestamp": "2010-09-13 07:35:25",
                    "note": "hi jeremy",
                    "first_name": "Coolio",
                    "last_name": "Stars",
                    "picture": "http:\/\/nowhere.com\/1980_1168_q.jpg"
                },
                {
                    "id": "227",
                    "artist_id": "4321",
                    "house_owner_id": "1234567",
                    "anonymous": null,
                    "stamps_used": null,
                    "timestamp": "2010-09-24 01:24:19",
                    "note": ""
                }
            ]
        }
    }
    

  8. I have an integer that I'd like to validate to ensure that it is a valid number between 1 and 99999999999999999999(20 digits).

     

    I'm thinking about using the following, but I'm not sure what the max range is on the FILTER_VALIDATE_INT options.

     

    return filter_var($_REQUEST['r'], FILTER_VALIDATE_INT, array("options" => array("min_range"=>1, "max_range"=>99999999999999999999)));

×
×
  • Create New...

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.