Skip to content

Instantly share code, notes, and snippets.

@samatsav
samatsav / 0_reuse_code.js
Created August 29, 2014 07:49
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@samatsav
samatsav / ro_slugs.php
Created October 21, 2013 13:31
Inlocuieste diacriticele cu caractere compatibile ASCII. (@@todo: inainte de a folosii functia, a se scoate din $map conversiile in plus)
function ro_slugs($cuvant) {
$slug = trim(strtolower(stripslashes($cuvant)));
$map = array(
'/à|á|å|â|ă|â|Â|Ă|ă/i' => 'a',
'/è|é|ê|ẽ|ë/i' => 'e',
'/ì|í|î|î|Î|Î/i' => 'i',
'/ò|ó|ô|ø/i' => 'o',
'/ù|ú|ů|û/i' => 'u',
'/ș|ș|ş|Ș|Ș|Ş/i'=>'s',
@samatsav
samatsav / 'indexOf' method for IE
Created October 21, 2013 12:52
functia indexOf --- pt versiunile IE < 8.0 (lipseste)
if (!Array.prototype.indexOf)
{
Array.prototype.indexOf = function(elt /*, from*/)
{
var len = this.length >>> 0;
var from = Number(arguments[1]) || 0;
from = (from < 0) ? Math.ceil(from) : Math.floor(from);
if (from < 0)
from += len;
@samatsav
samatsav / Object Oriented Javascript + Conflicts tip
Created October 21, 2013 11:15
Object Oriented Javascript + Conflicts tip
http://enterprisejquery.com/2010/10/how-good-c-habits-can-encourage-bad-javascript-habits-part-1/
@samatsav
samatsav / Default Image Rewrite
Created September 25, 2013 20:44
Rewrite all images not found to a default image
RewriteEngine on
RewriteCond %{REQUEST_URI} \.(jpg|jpeg|gif|png)$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .*$ /DEFAULTIMAGE.png [L]
@samatsav
samatsav / Create a user for a database.sql
Created September 24, 2013 14:49
Add a new user to a MySQL database from the command line
mysql -u root -p
/* Then enter your password and hit enter. Now we want to create a database which our new user will have privileges on. If you already have a database you can skip this step. */;
mysql > create database new_database;
/* Now with our new database in place called new_database we can move on and set up a user for this schema. */;
mysql > grant usage on *.* to new_database_user@localhost identified by 'user_password';
@samatsav
samatsav / json2.js
Created September 24, 2013 14:39
Includes JSON for browsers that don't support it.. Ex: JSON.parse(response) nu merge in IE 7 ca pute
/*
json2.js
2012-10-08
Public Domain.
NO WARRANTY EXPRESSED OR IMPLIED. USE AT YOUR OWN RISK.
See http://www.JSON.org/js.html
@samatsav
samatsav / Object Size
Created September 20, 2013 14:13
Object prototype function to easily return it's properties number. A.k.a object size
Object.Size = function(obj) {
var size = 0, key;
for (key in obj) {
if (obj.hasOwnProperty(key)) size++;
}
return size;
};
@samatsav
samatsav / Class file
Created September 20, 2013 13:57
Convert PHP arrays to XLS
<?php
/*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
@samatsav
samatsav / PHP Error display
Created September 20, 2013 13:55
Overwrite display error setting (display all errors)
error_reporting(E_ALL);
ini_set('display_errors', '1');