Snip2Code is shutting down.
It has been quite a ride, since 2013 when we launched our first prototype: thanks to the effort of you guys we collected more than 3 million snippets!
We are very proud to help all our users to be more efficient in their jobs, and to be the central point to share programming knowledge for everyone.
Our basic service is free, so we always survived on our own resources to give you Snip2Code.
Unfortunately, we are no more in the financial position to sustain this effort, and therefore we are announcing here our permanent shut down,
which will take place on August 1st, 2020.
Please save your private snippets using our backup function in the settings, here.
This will allow us to pay for the servers and the infrastructure. If you want to donate, Contact Us!
Reputation Top 1%
Panagiotis Vagenas
5 Snippets  (161st place)
0 Channels
4 Channels
168 points  (181st place)
Junior Code Generator
Serious Code Generator
Junior Publisher
Serious Publisher
Junior Popular Coder
Serious Popular Coder
Junior Autobiographer
Serious Autobiographer
Senior Autobiographer
Master Autobiographer
Junior Famous Coder
Junior Wise Coder

Recent Snippets See all snippets by pan

public by pan  2857  3  5  0

Export products for PrestaShop 1.6 DB

You can change language id in line 44 to meet your needs
p.id_product AS 'ID', AS 'Active (0/1)', AS 'Name *',
p.price AS 'Price tax excl.',
p.id_tax_rules_group AS 'Tax rules ID',
p.wholesale_price AS 'Wholesale price',
p.on_sale AS 'On sale (0/1)',
p.reference AS 'Reference #',
p.supplier_reference AS 'Supplier reference #', AS 'Supplier', AS 'Manufacturer',
p.ean13 AS 'EAN13',
p.upc AS 'UPC',
GROUP_CONCAT( SEPARATOR ', ') as 'Categories (x,y,z,...)',
p.ecotax AS 'Ecotax',
p.width AS 'Width',
p.height AS 'Height',
p.depth AS 'Depth',
p.weight AS 'Weight',
p.quantity AS 'Quantity',
pl.description_short AS 'Short description',
pl.description AS 'Description',
pl.meta_title AS 'Meta-title',
pl.meta_keywords AS 'Meta-keywords',
pl.meta_description AS 'Meta-description',
pl.link_rewrite AS 'URL rewritten',
pl.available_now AS 'Text when in stock',
pl.available_later AS 'Text when backorder allowed',
p.available_for_order AS 'Available for order',
p.date_add AS 'Product creation date',
p.show_price AS 'Show price',
p.online_only AS 'Available online only',
p.condition AS 'Condition'

FROM ps_product p
INNER JOIN ps_product_lang pl ON p.id_product = pl.id_product
LEFT JOIN ps_supplier sl ON p.id_supplier = sl.id_supplier
LEFT JOIN ps_manufacturer ml ON p.id_manufacturer = ml.id_manufacturer
left join ps_category_product cp on p.id_product = cp.id_product
left join ps_category_lang cl on cp.id_category= cl.id_category

WHERE pl.id_lang = 2 and cl.id_lang = 2

GROUP BY p.id_product;            

public by pan  312735  0  6  4

CSS Regex Selector Extension For jQuery

Using this extension enables regular expresions css selectors in jQuery
 * CSS Regex Selector Extension For jQuery
jQuery.expr[':'].regex = function(elem, index, match) {
   var matchParams = match[3].split(','),
       validLabels = /^(data|css):/,
       attr = {
           method: matchParams[0].match(validLabels) ?
               matchParams[0].split(':')[0] : 'attr',
           property: matchParams.shift().replace(validLabels,'')
       regexFlags = 'ig',
       regex = new RegExp(matchParams.join('').replace(/^\s+|\s+$/g,''), regexFlags);
   return regex.test(jQuery(elem)[attr.method](;

public by pan  245563  2  4  0

Replace all occurrences of a string in DB

Searches and replaces all of occurrences of a string in all tables and all fields of the given Database
* @kudos
header("Content-Type: text/plain");

$host = "localhost";
$username = "root";
$password = "";
$database = "mydatabase";
$string_to_replace  = '';
$new_string = '';

// Connect to database server
mysql_connect($host, $username, $password);

// Select database

// List all tables in database
$sql = "SHOW TABLES FROM ".$database;
$tables_result = mysql_query($sql);

if (!$tables_result) {
    echo "Database error, could not list tables\nMySQL error: " . mysql_error();

echo "In these fields '$string_to_replace' have been replaced with '$new_string'\n\n";
while ($table = mysql_fetch_row($tables_result)) {
    echo "Table: {$table[0]}\n";
    $fields_result = mysql_query("SHOW COLUMNS FROM ".$table[0]);
    if (!$fields_result) {
        echo 'Could not run query: ' . mysql_error();
    if (mysql_num_rows($fields_result) > 0) {
        while ($field = mysql_fetch_assoc($fields_result)) {
            if (stripos($field['Type'], "VARCHAR") !== false || stripos($field['Type'], "TEXT") !== false) {
                echo "  ".$field['Field']."\n";
                $sql = "UPDATE ".$table[0]." SET ".$field['Field']." = replace(".$field['Field'].", '$string_to_replace', '$new_string')";
        echo "\n";


public by pan  2556  1  5  0

Instantiate Date from a mysql datetime string

Adds the ability to Date to instatiate from a mysql datetime string. String should be in format "Y-M-D H:M:S" or "Y-M-D".
     * Instantiate Date from a mysql datetime string
     * @param string mysql_string eg "Y-M-D H:M:S" or "Y-M-D"
     * @returns {Date|null}
     * @kudos
    Date.createFromMysql = function(mysql_string)
        if(typeof mysql_string === 'string')
            var t = mysql_string.split(/[- :]/);

            //when t[3], t[4] and t[5] are missing they defaults to zero
            return new Date(t[0], t[1] - 1, t[2], t[3] || 0, t[4] || 0, t[5] || 0);

        return null;

public by pan  2247  2  5  0

Get a time modified Date obj in JS

Modifies the time and returns a new Date obj based on old Date, interval and offset. This is an mySQL DATE_ADD() JS implementation.
     * Add time to a date
     * @param Date date Original date
     * @param string interval Interval: year|quarter|month|week|day|hour|minute|second
     * @param int units How many? (could be negative)
     * @returns {Date}
     * @kudos
    function dateAdd(date, interval, units) {
        var ret = new Date(date); // original date wont be modified
        switch(interval.toLowerCase()) {
            case 'year'   :  ret.setFullYear(ret.getFullYear() + units);  break;
            case 'quarter':  ret.setMonth(ret.getMonth() + 3*units);  break;
            case 'month'  :  ret.setMonth(ret.getMonth() + units);  break;
            case 'week'   :  ret.setDate(ret.getDate() + 7*units);  break;
            case 'day'    :  ret.setDate(ret.getDate() + units);  break;
            case 'hour'   :  ret.setTime(ret.getTime() + units*3600000);  break;
            case 'minute' :  ret.setTime(ret.getTime() + units*60000);  break;
            case 'second' :  ret.setTime(ret.getTime() + units*1000);  break;
            default       :  ret = undefined;  break;
        return ret;