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

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

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   41

Posted 19 hours ago

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

		$dom = new DOMDocument;

0   37

Posted 20 hours 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   45

Posted 20 hours ago

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

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

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

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

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

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]( if needed.

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

Posted 3 days ago

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

Posted 5 days ago

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

Posted 4 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.

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

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

Posted 5 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']=='') {
    define('WP_SITEURL', 'http://
0   66

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](

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

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

Posted 4 days ago

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

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

Posted 5 days ago

		//Hide before the fade
		$j('div#sidebar li').hide();
		 * Side Navigation fade in loop
		function outer(){
			var a = 0;
			function inner(){
				if(a===$j('div#sidebar li').length){return;}
0   85

Posted 5 days ago

Lines of code snipped



Hate Ads? Become a Supporter

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