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
['application/annodex',
'application/mp4',
'application/ogg',
'application/vnd.rn-realmedia',
'application/x-matroska',
'video/3gpp',
'video/3gpp2',
'video/annodex',
'video/divx',
0   32

Posted 1 day ago

**Function**
<?php
    function list_all_images($path)
    {
        $array = array();
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path),
            RecursiveIteratorIterator::SELF_FIRST
0   64

Posted 3 days ago

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](https://developers.facebook.com/apps/), and click 'Create New App':
![Create new Facebook App](http://i.imgur.com/W5jlqpo.png)

**Step 2**
Fill in the required fields:
![Fill in Facebook App fields](http://i.imgur.com/tzb9QSV.png)

0   129

Posted 5 days ago

<script>
var tag = document.createElement('script');
                tag.src = "http://www.youtube.com/iframe_api";
                var firstScriptTag = document.getElementsByTagName('script')[0];
                firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

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

Posted 6 days ago

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

class Mailer {

	private $settings = [];

	public function __construct($array = NULL) {

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

Posted 1 week 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   72

Posted 1 week ago

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

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

Posted 1 week ago

116
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   4844

Posted 3 months 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   118

Posted 1 week ago

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

Posted 1 week 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](http://ryancmorrissey.com/blog/2014/04/12/django-dependent-choicefield-options/) if needed.

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

Posted 1 week ago

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

		$dom = new DOMDocument;
		libxml_use_internal_errors(true);

		$dom->loadHTMLFile($url);
0   59

Posted 1 week ago

Simple css to make body background responsive
body{
background : url(image.jpg) center center no-repeat;
background-size:cover;
}
5   105

Posted 1 week ago

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

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

Posted 1 week 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   68

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.

**Functions**
<?php
    $db = new PDO('mysql:dbname=database;host=localhost', 'username', 'password');

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

Posted 1 week ago

Lines of code snipped

16649

LINES OF CODE SNIPPED

Hate Ads? Become a Supporter


Recent Achievements
Snippet Repo Badge volvox won their second achievement badge 1 day ago
Snippet Repo Badge gertwerks won their first achievement badge 6 days ago
Snippet Repo Badge aeonx won their third achievement badge 1 week ago
Snippet Repo Badge aeonx won their second achievement badge 1 week ago
Snippet Repo Badge aeonx won their first achievement badge 1 week ago