How to Link a Facebook App with a Fan Page

According to the Facebook developer documentation, you can link a Facebook app with a fan page by following these steps:

  1. Set your page category to “App Page” (found under “Brands & Products”).
  2. Set the title of the app and the page to the same title.
  3. Go to your App and select “App Details”
  4. Under “Contact Info” you will find “App Page”. There you will be able to create a new page or if all went well, select your page from a list.

That’s it! Very simple.

Download Google’s Free SEO eBook (PDF)

For many people, SEO is all about optimizing your website to show up well on google’s search results. There are a lot of people in the world who have a strategy and a recipe for how to accomplish that.

Well, Google might know a thing or two about how to do good search engine optimization.

Here’s the link to the PDF of Google’s SEO eBook.

Download the PDF above to start learning top notch SEO techniques, straight from the horse’s mouth.

Javascript Simple Page Redirect

Pure javascript works well for performing a page redirect, don’t both using jQuery or other libraries for this.

How to create a simple Page Redirect in Javascript

// similar behavior as an HTTP redirect
window.location.replace("http://stackoverflow.com");

// similar behavior as clicking on a link
window.location.href = "http://stackoverflow.com";

location.replace is better than location.href – here’s why

window.location.replace is better than using window.location.href =, because replace() does not put the originating page in the session history, meaning the user won’t get stuck in a never-ending back-button fiasco. If you want to simulate someone clicking on a link, use location.href. If you want to simulate an HTTP redirect, use location.replace.

Source: StackOverflow

Javascript How to Check if Element is Hidden

Checking for element visibility in javascript and jquery is easy. Follow these instructions to learn how.

Checking if Element is Hidden with Javascript (Plain)

function isRendered(domObj) {
    if ((domObj.nodeType != 1) || (domObj == document.body)) {
        return true;
    }
    if (domObj.currentStyle && domObj.currentStyle["display"] != "none" && domObj.currentStyle["visibility"] != "hidden") {
        return isRendered(domObj.parentNode);
    } else if (window.getComputedStyle) {
        var cs = document.defaultView.getComputedStyle(domObj, null);
        if (cs.getPropertyValue("display") != "none" && cs.getPropertyValue("visibility") != "hidden") {
            return isRendered(domObj.parentNode);
        }
    }
    return false;
}

Checking if Element is Hidden with Javascrpt (jQuery)

$(element).is(":visible"); 

Source: StackOverflow

Setup Docker Mongo and Import CSV Data

Setting up docker MongoDB and importing CSV is easy. Just follow these steps.

How to Setup Docker Mongo

  1. I’m assuming you’ve already got Docker installed on your system. if you don’t, do that first.
  2. For the following steps, do not actually run the command until the instruction says so. This is going through the building of the command for your own information.
  3. to get docker mongo from the MongoDB main docker repository, refer to the following:
    docker run --name mongo -d mongo
  4. We will add exposure to both the mongodb connector plugin port, 27017, and the web interface port, 28017, which requires the –httpinterface flag.
    docker run --name mongo -p 27017:27017 -p 28017:28017 --httpinterface
  5. Now we add a mount to a local volume, so you can have local access to the data files created by mongo. Also, just to be nice to the filesystem, we’ll enable smallfiles mode.
    docker run --name mongo -p 27017:27017 -p 28017:28017 -v /my/own/datadir:/data/db -d mongo --httpinterface --smallfiles
  6. Now, also, lets mount the directory on your local system where your CSV data file lives:
    docker run --name mongo -p 27017:27017 -p 28017:28017 -v /my/own/datadir:/data/db -v /path/to/sample/data/file:/data/seeds -d mongo --httpinterface --smallfiles
  7. Finally, hit enter, and run the command from step 6

Go inside the running Docker Mongo instance so you can import data

sudo docker exec -i -t mongo bash

Now, you’re inside the Docker instance and you have a command line waiting for input.

Run in the import of your CSV Data

mongoimport --db someDatabaseName --collection someCollectionName --type csv --headerline --file /data/seeds/yourfile.csv

Note: the –db name and the –collection name provided doesn’t need to already exist. They will be automatically created upon execution of the import command

How Many Pages Should a Large Sitemap Have?

Sitemaps are easy when you’re using a small wordpress site. But when you have 100,000s of pages, sitemaps become their own project. Here’s what you need to know for sitemapping very large websites.

Q: How big can my Sitemap be?

Sitemaps should be no larger than 10MB (10,485,760 bytes) and can contain a maximum of 50,000 URLs. These limits help to ensure that your web server does not get bogged down serving very large files. This means that if your site contains more than 50,000 URLs or your Sitemap is bigger than 10MB, you must create multiple Sitemap files and use a Sitemap index file. You should use a Sitemap index file even if you have a small site but plan on growing beyond 50,000 URLs or a file size of 10MB. A Sitemap index file can include up to 1,000 Sitemaps and must not exceed 10MB (10,485,760 bytes). You can also use gzip to compress your Sitemaps.

Q: My site has tens of millions of URLs; can I somehow submit only those that have changed recently?

You can list the URLs that change frequently in a small number of Sitemaps and then use the lastmod tag in your Sitemap index file to identify those Sitemap files. Search engines can then incrementally crawl only the changed Sitemaps.

Q: What data format must the sitemap be?

Acceptable sitemap data types are XML, RSS, Line delimited text, mRSS, and Atom 1.0.

Source: Google Support

Q: What are nested sitemaps and what is the benefit of using nested sitemaps?

In the example above, the asterisk next to the name is indicating that the sitemap file is an index, not a sitemap as mentioned above. Sitemap indices are sitemaps to point to other sitemaps. This what makes your life easier and more structured. If you loaded each section of your site as a separate sitemap, that’s fine, but rather annoying to page through on webmaster tools. If you were to use indices, you could drill down and see more detail in specific areas. Let me show you.

How sitemap indices help:

  1. Indicate where indexation issues are.
  2. Allow an overview look (the numbers for sitemap.xml) all the way down to specific areas. Great for reports!
  3. Show the search engines what your site structure is supposed to be.
  4. Identify possible duplicate content. (Have a section for doll shoes and doll boots? Those might cause duplicate content if they share products and their URLs are different)

Source: https://moz.com/blog/multiple-xml-sitemaps-increased-indexation-and-traffic

Javascript Matching a string to an Array of Regex Expressions

If you want to check if a string matches any of an array of regexes and return true in the first encountered match, do the following:

var regexes = [/a/,/b/,/c/];
for(var i = 0; i<regexes.length; i++) {
  var regex = regexes[i];
  if( str.match( x[i] ) ) {
    console.log("regex:", regex, "matching: true");
  } else {
    console.log("regex:", regex, "matching: false");
  }
}

Mongoose.js find with regex

When consuming MongoDB with mongoose helper functions like find() in NodeJS, it is easy to filter with a regular expression.

The end result will be similar to using a  “LIKE” query in SQL.

How to use regex with the Find function

var name = 'Peter';
model.findOne({name: new RegExp('^'+name+'$', "i")}, function(err, doc) {
  //Do your action here..
});

Doing this essentially queries mongodb with this regular expression: /Peter/i

For simpler regular expressions not requiring the passage of a dynamic variable, you can use a regex expression straight into the find filter object:

model.find({'name' : /stuff/i}, function(err, docs){
    cb(docs);
});

Source: StackOverflow

Record Audio in Swift with AVAudioRecorder

Recording audio in Swift is easy. Just follow these steps to record a new audio snippet and save it in the phone.

Steps to record audio with Swift

  1. Implement an AVAudioSession
  2. Set the audiosession’s category to AVAudioSessionCategoryPlayAndRecord
  3. Set the audiosession’s active state to true
  4. Get the documents directory and set a path to the new recording file that will be created. Create a NSURL type variable with that path.
  5. Create a settings object to be passed into the recorded. (see example below)
  6. Create an AVAudioRecorder, and record with it’s .record() method.

Record Audio in Swift 2.0 Example

func record() {
    //init
    let audioSession:AVAudioSession = AVAudioSession.sharedInstance()

    //ask for permission
    if (audioSession.respondsToSelector("requestRecordPermission:")) {
        AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
            if granted {
                print("granted")

                //set category and activate recorder session
                try! audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
                try! audioSession.setActive(true)


                //get documnets directory
                let documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
                let fullPath = documentsDirectory.stringByAppendingPathComponent("voiceRecording.caf")
                let url = NSURL.fileURLWithPath(fullPath)

                //create AnyObject of settings
                let settings: [String : AnyObject] = [
                    AVFormatIDKey:Int(kAudioFormatAppleIMA4), //Int required in Swift2
                    AVSampleRateKey:44100.0,
                    AVNumberOfChannelsKey:2,
                    AVEncoderBitRateKey:12800,
                    AVLinearPCMBitDepthKey:16,
                    AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue
                ]

                //record
                try! self.audioRecorder = AVAudioRecorder(URL: url, settings: settings)

            } else{
                print("not granted")
            }
        })
    }

}

Record Audio in Swift 1.0 Example

//declare instance variable 
var audioRecorder:AVAudioRecorder!


func record(){

    var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
    audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
    audioSession.setActive(true, error: nil)

    var documents: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory,  NSSearchPathDomainMask.UserDomainMask, true)[0]
    var str =  documents.stringByAppendingPathComponent("recordTest.caf")
    var url = NSURL.fileURLWithPath(str as String)

    var recordSettings = [AVFormatIDKey:kAudioFormatAppleIMA4,
        AVSampleRateKey:44100.0,
        AVNumberOfChannelsKey:2,AVEncoderBitRateKey:12800,
        AVLinearPCMBitDepthKey:16,
        AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue

    ]

    println("url : \(url)")
    var error: NSError?

    audioRecorder = AVAudioRecorder(URL:url, settings: recordSettings, error: &error)
    if let e = error {
        println(e.localizedDescription)
    } else {

        audioRecorder.record()
    }


}

Recording Audio in Swift 2

Recording audio in Swift is easy. Just follow these steps to record a new audio snippet and save it in the phone.

Steps to record audio with Swift 2

  1. Implement an AVAudioSession
  2. Set the audiosession’s category to AVAudioSessionCategoryPlayAndRecord
  3. Set the audiosession’s active state to true
  4. Get the documents directory and set a path to the new recording file that will be created. Create a NSURL type variable with that path.
  5. Create a settings object to be passed into the recorded. (see example below)
  6. Create an AVAudioRecorder, and record with it’s .record() method.

Record Audio in Swift 2.0 Example

func record() {
    //init
    let audioSession:AVAudioSession = AVAudioSession.sharedInstance()

    //ask for permission
    if (audioSession.respondsToSelector("requestRecordPermission:")) {
        AVAudioSession.sharedInstance().requestRecordPermission({(granted: Bool)-> Void in
            if granted {
                print("granted")

                //set category and activate recorder session
                try! audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord)
                try! audioSession.setActive(true)


                //get documnets directory
                let documentsDirectory = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)[0]
                let fullPath = documentsDirectory.stringByAppendingPathComponent("voiceRecording.caf")
                let url = NSURL.fileURLWithPath(fullPath)

                //create AnyObject of settings
                let settings: [String : AnyObject] = [
                    AVFormatIDKey:Int(kAudioFormatAppleIMA4), //Int required in Swift2
                    AVSampleRateKey:44100.0,
                    AVNumberOfChannelsKey:2,
                    AVEncoderBitRateKey:12800,
                    AVLinearPCMBitDepthKey:16,
                    AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue
                ]

                //record
                try! self.audioRecorder = AVAudioRecorder(URL: url, settings: settings)

            } else{
                print("not granted")
            }
        })
    }

}

Record Audio in Swift 1.0 Example

//declare instance variable 
var audioRecorder:AVAudioRecorder!


func record(){

    var audioSession:AVAudioSession = AVAudioSession.sharedInstance()
    audioSession.setCategory(AVAudioSessionCategoryPlayAndRecord, error: nil)
    audioSession.setActive(true, error: nil)

    var documents: AnyObject = NSSearchPathForDirectoriesInDomains( NSSearchPathDirectory.DocumentDirectory,  NSSearchPathDomainMask.UserDomainMask, true)[0]
    var str =  documents.stringByAppendingPathComponent("recordTest.caf")
    var url = NSURL.fileURLWithPath(str as String)

    var recordSettings = [AVFormatIDKey:kAudioFormatAppleIMA4,
        AVSampleRateKey:44100.0,
        AVNumberOfChannelsKey:2,AVEncoderBitRateKey:12800,
        AVLinearPCMBitDepthKey:16,
        AVEncoderAudioQualityKey:AVAudioQuality.Max.rawValue

    ]

    println("url : \(url)")
    var error: NSError?

    audioRecorder = AVAudioRecorder(URL:url, settings: recordSettings, error: &error)
    if let e = error {
        println(e.localizedDescription)
    } else {

        audioRecorder.record()
    }


}