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
0   31

Posted 22 hours ago

    function list_all_images($path)
        $array = array();
        $finfo = finfo_open(FILEINFO_MIME_TYPE);
        $files = new RecursiveIteratorIterator(
            new RecursiveDirectoryIterator($path),
0   62

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](, and click 'Create New App':
![Create new Facebook App](

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

0   128

Posted 5 days 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   77

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   72

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

"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

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   4838

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   117

Posted 1 week ago

Debounce function:
function debounce (func) {
    var delay = 250;
    var timer = null;
    return function () {
        if (timer !== null) {
            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]( 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;

0   59

Posted 1 week ago

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

Posted 1 week ago

Example"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.

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

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

Posted 1 week ago

Lines of code snipped



Hate Ads? Become a Supporter

Recent Achievements
Snippet Repo Badge volvox won their second achievement badge 22 hours ago
Snippet Repo Badge gertwerks won their first achievement badge 5 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