Skip to content

Instantly share code, notes, and snippets.

@samatsav
samatsav / Clean URL
Created September 20, 2013 13:48
Rewrite clean URL .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ index.php?q=%{REQUEST_URI} [L]
// SAU ALTA VARIANTA MAI BUNA PT PHP EASE(17.10.2013)
RewriteEngine on
@samatsav
samatsav / Javascript only numeric
Created September 20, 2013 13:51
Allow only numeric input inside text field
document.getElementsByTagName('input')[0].onkeypress = function(e) {
e = e || event
var chr = getChar(e)
if (!isNumeric(chr) && chr !== null) {
return false
}
}
// helper functions
function isNumeric(val) {
@samatsav
samatsav / Cascade delete syntax
Created September 20, 2013 13:53
Cascade delete syntax
ALTER TABLE orders_items ADD FOREIGN KEY (orderID) REFERENCES orders(orderID) ON DELETE CASCADE
@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');
@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 / 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 / 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 / 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 / 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 / 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/