Peter DeMartini

  1. How to force remove locked items from trash (Mac OS X)

    Recently I have had a folder in my trash that would not go away even after I emptied it. So I decided to do some simple command line to force delete the file. 

    Step 1:

    • Open up Terminal in Applications/Utilities
    • Type “sudo rm -rf ” - with a space afterwards and don’t press enter

    Step 2:

    • Open up Trash on the Dock, then drag the folder or file to Terminal Window

    Step 3:

    • Go to the Terminal Window, you should see “sudo rm -rf /path/to/.Trash/folder”
    • Press enter
    • Enter in admin password

    Now you are done. The folder should have disappeared from your trash.

    1 month ago  /  1 note

  2. Get page load time in jQuery

    Have you ever wondered how to get that nifty little page load time on the bottom of your page? This is all about bragging rights. You want a quick website so why not show everyone. Anyways, here is the good stuff.

    http://codepad.co/s/585338

    1 month ago  /  3 notes

  3. euvoltologo:

Fight Club as Code.

    euvoltologo:

    Fight Club as Code.

    (via berumen)

    1 month ago  /  23 notes  /  Source: euvoltologo

  4. Developer and Designer?

    Someone told me once you can’t be a designer and a developer. I didn’t believe him. I thought you could do it all. I was actually wrong. It is like being a doctor and an artist. You can only specialize in one. Although you could be a designer and developer. You should only focus on one field and excel at it. For me I picked developer and it was the best the decision of my life. What about you, designer or developer?

    1 month ago  /  0 notes

  5. Global Sessions with Redis Bug Fix

    I recently ran into an issue on my node server where the sessions were all the same across website. For example, if someone logged in, then everybody who accesses the site would be logged in as that user.  My sessions were being stored by redis — because that is an efficient way of storing key:value pairs.

    Anyways, the problem was that redis (on my server) wasn’t properly configured. So logged into redis-cli and ran the “SHUTDOWN” command. Logged out of redis-cli. Copied the redis.conf template, from the source code folder for redis, to /etc/ using this command cp /path/to/redis.conf /etc/redis.conf . After that was copied over, I ran this command: redis-server /etc/redis.conf .That fixed the global session problem.

    2 months ago  /  0 notes

  6. Advanced Twitter Streaming API Concepts in PHP

    Twitter’s Streaming API Documentation is pretty slim for advanced uses. Sure they give you some of the bare the concepts and examples but when it comes time to actually build yourself a scalable application you can find yourself stuck with an inefficient product. I am not going to give you code examples but more discuss certain concepts that will help you succeed.

    First of all, these concepts can differ per application and may not apply directly to yours. From my experience, I have discovered three concepts when building an effective application using Twitter’s Streaming API.

    Use System Daemons:

    First note that you don’t want the Streaming API being run directly in your Web Application. Cron Jobs work great for scheduled tasks but not for handing a constant stream. In my case I ended up using System_Daemons. They work pretty well and fairly easy to set up in a UNIX environment.

    Get out of being Rate Limited:

    Option 1: Apply and become a Twitter Partner.

    Option 2: If you are wondering how to track more than 400 keywords without becoming a twitter partner. Use your application to authorize more twitter users and use those auth tokens for each 400 or (399 to be safe) keywords being tracked.

    Storing Tweets Rapidly:

    This concept is directly related to speed and redundancy. First of all if you are tracking a lot of keywords, users, or whatever you may be doing. Twitter is going to be sending those to your application in great abundance and rapidly. In one of my applications we were getting in 1000 tweets a second. Now the key is to handle that amount of data is not to process every tweet right when you get them in. You want to save the tweets coming in as fast as possible and insure that they will be processed and that involves just doing one thing, saving them into a database or file.

    In a previous app I was building we were using MongoDB and that worked great. Basically just converted the tweet coming in, into an array and then inserting the array directly into the MongoDB. This was fast and worked great.

    Once the tweets are queued you want to processes them. To really benefit from Twitter’s Streaming API, you want to process the tweets in the queue as fast as you can. If you can keep the queue count at zero, then you are golden.

    Using a queue helps you prevent your application from losing tweets and creates an efficient way for processing tweets.

    Conclusion:

    Planning is key. Think about how you are going to integrate Twitter’s Streaming API. Write clean and efficient code. Speed and redundancy is key.

    Notes:

    Last but definitely not least, use Phirehose for ease of use.

    If you have any questions or need any help on a project send me a message, I am available for hire.

    2 months ago  /  1 note

  7. Javascript Convert First Letter In Each Word to Uppercase

    Title says it. Just a simple javascript that converts the first letter in each word to uppercase. Enjoy.

    http://codepad.co/s/cd4066

    function capFirst(string){ 
    var newString = '';
    string = string.toLowerCase();
    strings = string.split(' ');
    for(var i = 0; i < strings.length; i++){
    newString = newString + ' ' + strings[i].charAt(0).toUpperCase() + strings[i].slice(1);
    }
    return newString;
    }

    2 months ago  /  1 note

  8. Array Conversion Helper for PHP

    So today I decided to create a class that does several things. All of which are related to arrays. Here is a list of what this class can be used for:

    1. Converting an Object to an Array
    2. Converting an Array to an Object
    3. Converting an Array (keys and values) to lower case
    4. Converting an Array (keys) to lower case
    5. Converting an Array (values) to lower case
    6. Converting an Array (keys and values) to upper case
    7. Converting an Array (keys) to upper case
    8. Converting an Array (values) to upper case
    
    <?php 
    
    //Converts objects to arrays, arrays to objects, array strings to lower case, and array strings to upper case 
    //Works with Multi-Demensional arrays and objects
    
    class arrayConverter {
    	
    	//Converts objects to arrays
    	//pass an array to this function
    	function object_2_array($object){
    		$array = array(); 
        	foreach ($object as $key => $value) { 
            	if (is_array($value) || is_object($value)) { 
                	$array[$key] = $this->object_2_array($value); 
            	} else { 
                	$array[$key] = $value; 
                }
       	 	} 
       	 	return $array; 
    	}
    	
    	//Converts array to object
    	//pass an array to this function
    	function array_2_object($array){
    		if(!is_array($array)){
    			return $array;
    		}
    		
    		$object = new stdClass();
    		
    		if(is_array($array) && !empty($array)){
    			foreach($array as $key => $value){
    				if(is_array($value)){
    					$object->$key = $this->array_2_object($value);
    				}else{
    					$object->$key = $value;
    				}
    			}
    			return $object;
    		}else{
    			return false;
    		}
    	}
    	
    	//Convert array keys and values to lower case
    	//Works with objects and arrays
    	function array_to_lower($array){
    		if(is_object($array)){
    			$array = $this->object_2_array($array);
    			$convertBackToObject = true;
    		}else{
    			$convertBackToObject = false;
    		}
    		
    		$newArray = array();
    		
    		foreach($array as $key => $value){
    			$key = strtolower($key);
    			if(is_array($value)){
    				$newArray[$key] = $this->array_to_lower($value);
    			}else{
    				$newArray[$key] = strtolower($value);
    			}
    		}
    		
    		if($convertBackToObject){
    			return $this->array_2_object($newArray);
    		}else{
    			return $newArray;
    		}
    	}
    
    	
    	//Convert array keys to lower
    	//Works with objects and arrays
    	function array_keys_to_lower($array){
    		if(is_object($array)){
    			$array = $this->object_2_array($array);
    			$convertBackToObject = true;
    		}else{
    			$convertBackToObject = false;
    		}
    		
    		$newArray = array();
    		
    		foreach($array as $key => $value){
    			$key = strtolower($key);
    			if(is_array($value)){
    				$newArray[$key] = $this->array_keys_to_lower($value);
    			}else{
    				$newArray[$key] = $value;
    			}
    			
    			$newArray[$key] = $value;
    		}
    		
    		if($convertBackToObject){
    			return $this->array_2_object($newArray);
    		}else{
    			return $newArray;
    		}
    	}
    	
    	//Convert array values to lower case
    	//Works with objects and arrays
    	function array_values_to_lower($array){
    		if(is_object($array)){
    			$array = $this->object_2_array($array);
    			$convertBackToObject = true;
    		}else{
    			$convertBackToObject = false;
    		}
    		
    		$newArray = array();
    		
    		foreach($array as $key => $value){
    			if(is_array($value)){
    				$newArray[$key] = $this->array_values_to_lower($value);
    			}else{
    				$newArray[$key] = strtolower($value);
    			}
    		}
    		
    		if($convertBackToObject){
    			return $this->array_2_object($newArray);
    		}else{
    			return $newArray;
    		}
    	}
    	
    	
    	//Convert array keys and values to lower case
    	//Works with objects and arrays
    	function array_to_upper($array){
    		if(is_object($array)){
    			$array = $this->object_2_array($array);
    			$convertBackToObject = true;
    		}else{
    			$convertBackToObject = false;
    		}
    		
    		$newArray = array();
    		
    		foreach($array as $key => $value){
    			$key = strtoupper($key);
    			if(is_array($value)){
    				$newArray[$key] = $this->array_to_upper($value);
    			}else{
    				$newArray[$key] = strtoupper($value);
    			}
    		}
    		
    		if($convertBackToObject){
    			return $this->array_2_object($newArray);
    		}else{
    			return $newArray;
    		}
    	}
    
    	
    	//Convert array keys to lower
    	//Works with objects and arrays
    	function array_keys_to_upper($array){
    		if(is_object($array)){
    			$array = $this->object_2_array($array);
    			$convertBackToObject = true;
    		}else{
    			$convertBackToObject = false;
    		}
    		
    		$newArray = array();
    		
    		foreach($array as $key => $value){
    			$key = strtoupper($key);
    			if(is_array($value)){
    				$newArray[$key] = $this->array_keys_to_upper($value);
    			}else{
    				$newArray[$key] = $value;
    			}
    			
    			$newArray[$key] = $value;
    		}
    		
    		if($convertBackToObject){
    			return $this->array_2_object($newArray);
    		}else{
    			return $newArray;
    		}
    	}
    	
    	//Convert array values to lower case
    	//Works with objects and arrays
    	function array_values_to_upper($array){
    		if(is_object($array)){
    			$array = $this->object_2_array($array);
    			$convertBackToObject = true;
    		}else{
    			$convertBackToObject = false;
    		}
    		
    		$newArray = array();
    		
    		foreach($array as $key => $value){
    			if(is_array($value)){
    				$newArray[$key] = $this->array_values_to_upper($value);
    			}else{
    				$newArray[$key] = strtoupper($value);
    			}
    		}
    		
    		if($convertBackToObject){
    			return $this->array_2_object($newArray);
    		}else{
    			return $newArray;
    		}
    	}
    
    }
    ?>
    
    

    2 months ago  /  2 notes

  9. FindAndModify Query for Mongo in PHP

    If anyone has ever wondered what the quickest way to find a document and at the same time remove the document from that collection with MongoDB and PHP. This is the solution you need:

     <?php $found = $coll->command(array('findandmodify' => '', 'query' => array('name' => 'superman'), 'sort' => array('created' => -1),'limit' => 1, 'remove' => true)); ?> 

    The documentation for this can be found here on the mongodb site.

    4 months ago  /  21 notes