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
Example
"Helllo World".trim() => #HelloWorld

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

Posted 2 days ago

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

class Mailer {

	private $settings = [];

	public function __construct($array = NULL) {

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

Posted 1 day ago

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

		$dom = new DOMDocument;
		libxml_use_internal_errors(true);

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

Posted 1 day 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   49

Posted 1 day ago

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

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

Posted 2 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   43

Posted 2 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   82

Posted 3 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++
		someFunction();
	}
});

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

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

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

Posted 4 days ago

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

Posted 6 days ago

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

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

Posted 6 days ago

This snipped very usable for development and production versions of your wordpress website, using one database (remote)

You need allow external web servers to access your MySQL databases by adding your's domain name or IP to the list of hosts that are able to access databases on your web site (in hosting settings)

if ($_SERVER['REMOTE_ADDR']=='127.0.0.1') {
    define('WP_SITEURL', 'http://
0   67

Posted 1 week ago

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

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

Posted 1 week ago

Default Android animation loads all frames in memory to increase performance. This easily leads to **OutOfMemoryError**s with a large number of frames, specially when using compressed formats like PNG.

The following class attempts to solve this by loading one frame at a time, using in-place loading to minimize the performance hit. I did not write this class, I found it on [StackOverflow](http://stackoverflow.com/a/10993879/105304).

public class AnimationsContainer {
    public int FPS = 30;  // animation FPS

    // single instance procedures
    private static AnimationsContainer mInstance;
0   55

Posted 5 days ago

var truck = function() {
    this.turnLeft = function {
       // turn left
       return this;
    }

    this.turnRight = function {
       // turn right
       return this;
    }
0   70

Posted 5 days ago

Lines of code snipped

16423

LINES OF CODE SNIPPED

Hate Ads? Become a Supporter


Recent Achievements
Snippet Repo Badge aeonx won their third achievement badge 1 day ago
Snippet Repo Badge aeonx won their second achievement badge 2 days ago
Snippet Repo Badge aeonx won their first achievement badge 2 days ago
Snippet Repo Badge rmorrissey23 won their second achievement badge 4 days ago
Snippet Repo Badge digamber won their first achievement badge 5 days ago