Snippet Repo is a members-only code repository
to share useful code snippets.

Join over 2,000 members! All applications are manually reviewed.

Apply for membership
More and more sites, are using login with Facebook functionality as it offers an easy way for users to login to a site without registering a bunch of their own details. Having this functionality is good as you can request details form users without them having to spend the time filling them out themselves. Here's how to do implement the feature on your site in 6 steps.

**Step 1**
Log into Facebook, go to the [developer apps page](, and click 'Create New App':
![Create new Facebook App](

**Step 2**
Fill in the required fields:
![Fill in Facebook App fields](

0   61

Posted 17 hours ago

var tag = document.createElement('script');
                tag.src = "";
                var firstScriptTag = document.getElementsByTagName('script')[0];
                firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

                var player;
                function onYouTubeIframeAPIReady() {
                player = new YT.Player('player', {
                height: '640',
0   60

Posted 1 day ago

define('ERROR', '<strong>Error:</strong>');

class Mailer {

	private $settings = [];

	public function __construct($array = NULL) {

		$options = ['SMTP', 'SMTP_PORT', 'SEND_FROM', 'TYPE'];
0   59

Posted 3 days ago

"Helllo World".trim() => #HelloWorld

if( typeof(String.prototype.trim) === "undefined") {
   String.prototype.trim = function() {
      return String(this).replace(/^\s+|\s+$/g, '');
0   84

Posted 4 days ago

#banner {
    background: url('./backgroundimage.png') 0 0 repeat;
    -webkit-animation: animate_background 2s linear 0s infinite;
    -moz-animation: animate_background 2s linear 0s infinite;
    -o-animation: animate_background 2s linear 0s infinite;
    animation: animate_background 2s linear 0s infinite;

@-webkit-keyframes animate_background { 
    from { 
0   96

Posted 5 days ago

// Create a button to trigger file input
$('#button_id').click(function() {

	$('#uploader').trigger('click'); // Input ID

// Hidden file input that will trigger function on change
<input type="file" id="uploader" style="display: none" multiple>

$('#uploader').change(function() {
0   61

Posted 3 days ago

function getMeta($url = NULL) {
		if( !$url ) {
			exit("Paramter URL is empty.");

		$dom = new DOMDocument;

0   52

Posted 3 days ago

class DB {

	private static $instance;
	private $MYSQLI;

	private function __construct(array $DBS) {
		$this->MYSQLI = @new mysqli( $DBS['HOST'], $DBS['USERNAME'], $DBS['PASSWORD'], $DBS['DB'] );

		if( mysqli_connect_errno() ) {
0   54

Posted 4 days ago

Example"form", {
     id : "something",
     type : "POST",
     action : "..."
}).attach(); #Attaches to Body or .attach(#/.custom el)

#Element.remove(#/.custom el)
0   52

Posted 4 days ago

On a recent project, I was looking to control the options available in a Django ChoiceField based on another form parameter (passed along with the response object). Here's what worked for me (you can read further info on my blog post [here]( if needed.

# somefile.json
    "key_one": ["", "A", "B", "C", "D"],
0   67

Posted 6 days ago

var eachItem = 4; // someFunction() will work on 1st, 5th, 9th ... element
$('.selector').each(function(i) {
	if(i++ % eachItem === 0) { // to select 4th, 8th etc. elements use ++i instead of i++

If you want to work with, for example, each 4 element width .selector, use this "hack" :)
0   88

Posted 4 days ago

Debounce function:
function debounce (func) {
    var delay = 250;
    var timer = null;
    return function () {
        if (timer !== null) {
            timer = null;
1   82

Posted 1 week ago

Simple css to make body background responsive
background : url(image.jpg) center center no-repeat;
5   92

Posted 1 week ago

Having to make new functions every time you want to query your database in a file can become somewhat inconvenient and distracting. The following 2 functions are all you need for a simple CRUD system using MySQL PDO.

    $db = new PDO('mysql:dbname=database;host=localhost', 'username', 'password');

    function set_data($sql, $vars = null)
        global $db;
0   104

Posted 1 week ago

With the useful help of transform element: we can vertically align whatever we want, even if we don’t know its height.

Just write:

.element {
  position: relative;
  top: 50%;
  -webkit-transform: translateY(-50%);
  -moz-transform: translateY(-50%);
  -ms-transform: translateY(-50%);
14   4805

Posted 3 months ago

// Close Bootstrap Modal.
$('.close, .save, .cancel').on('click', function(e){
    var $this = $(this);
    // get identifier modal window.
    var modal = $'custom');

  // check tag html5 for video and audio.
   if (($('#id-'+modal).prop("tagName") == 'AUDIO') 
0   135

Posted 1 week ago

Lines of code snipped



Hate Ads? Become a Supporter

Recent Achievements
Snippet Repo Badge gertwerks won their first achievement badge 1 day ago
Snippet Repo Badge aeonx won their third achievement badge 3 days ago
Snippet Repo Badge aeonx won their second achievement badge 4 days ago
Snippet Repo Badge aeonx won their first achievement badge 4 days ago
Snippet Repo Badge rmorrissey23 won their second achievement badge 6 days ago