working on it ...

Filters

Explore Public Snippets

Sort by

Found 106k snippets

    public by pleabargain modified 8 hours ago  9  2  3  0

    javascript output to console current full date as text

    // Enter here the actual content of the snippet.
    // Array of day names
    let dayNames = new Array("Sunday","Monday","Tuesday","Wednesday",
    				"Thursday","Friday","Saturday");
    
    // Array of month Names
    let monthNames = new Array(
    "January","February","March","April","May","June","July",
    "August","September","October","November","December");
    
    let now = new Date();
    console.log(dayNames[now.getDay()] + ", " +
    monthNames[now.getMonth()] +
    " " + now.getDate() +
    ", " + now.getFullYear());
    //output ~ Sunday, February 19, 2017
    

    public by pleabargain modified yesterday at 3:46:06 PM  7  0  3  0

    add all function arguments together

    function sum(){
    	let result =0;
    	//loop through all of the values in func args
      for (i =0; i < arguments.length;i++){
        //now add them toghether
    		result += arguments[i];	
    	
    	}
    	return result;
    }
    sum(34,34,236,32);

    public by JavierSalazar modified Thursday at 6:26:40 PM  19  1  1  1

    Calculo de Numero base dado un total y un procentaje

    Formula para el calculo de Numero base dado un total y un procentaje. Ejemplo: Si tenemos un monto TOTAL ya con IVA sumado. Si conocemos el porcentaje del IVA podemos obtener un numero base que al aplicarle el porcentaje de IVA y sumarselo, obtenemos el TOTAL
    function calcularMontoBase (Montofinal,iva) {
    var montoBase =0;
    
    montoBase = (Montofinal/((iva/100) + 1));
    return montoBase;
    
    }                        

    public by JavierSalazar modified Tuesday at 7:31:39 PM  18  3  2  0

    Pasar varios datos con ajax (Metodo POST)

    Pasar varios datos con ajax (Metodo POST)y es recibido por archivo php con la variable $_POST
    $.ajax(
    {
            url: "<?=resApi;?>procesarProducto.php",
            type: "post",
            dataType: "html",
            data: ({accion: "transferir",subaccion: "buscarStockSucursal", codigoprod: producto, sucursal: sucursal}),
            cache: false,
    })
        .done(function(res)
        {alert(res);}  

    public by camilordx modified Feb 1, 2017  28  2  1  1

    jquery ajax template

    $.ajax({
        type: 'GET',
        url: location.pathname,
        data: "PARAMETERS",
        success: function (data) {
            console.log(data)
        },
        error: function (xhr, status, error) {
            var err = eval("(" + xhr.responseText + ")");
            alert("Error: " + err.Message);
        },
        beforeSend: function () {
            console.log("start")
        },
        complete: function () {
            console.log("end")
        }
    });            

    public by Tech_JA modified Jan 30, 2017  59  1  4  1

    Log file

    Create a log fle
    var util = require('util');
    
    var writeToLog;
    
    var logFile = fs.createWriteStream('./NomeDoFicheiro.log', { flags: 'a+' });
    
    writeToLog = function () {
        logFile.write( util.format.apply(null, arguments) + '\r\n');
    };
    
    writeToLog("teste");         

    public by Tech_JA modified Jan 30, 2017  54  2  4  1

    Detects if enter key was pressed

    Detects if enter key was pressed
    $(document).keypress(function (e) {
        if (e.which === 13) {
            if (eventEnter === 'addCategory') {
               // alert('You pressed Add Category!');
                categories_add_btn();
            }
            if (eventEnter === 'editCategory') {
                //alert('You pressed Edit Category!');
                categories_edit_btn();
            }
            if (eventEnter === 'addManufacturer') {
                //alert('You pressed Add Manufacturer!');
                manufacturers_add_btn();
            }
            if (eventEnter === 'editManufacturer') {
                //alert('You pressed Edit Manufacturer!');
                manufacturers_edit_btn();
            }
            if (eventEnter === 'addSupplier') {
                //alert('You pressed Add Supplier!');
                suppliers_add_btn();
            }
            if (eventEnter === 'editSupplier') {
                //alert('You pressed Edit Supplier!');
                suppliers_edit_btn();
            }
            if (eventEnter === 'addPart') {
                //alert('You pressed Add Part!');
                parts_add_btn();
            }
            if (eventEnter === 'editPart') {
                //alert('You pressed Edit Part!');
                parts_edit_btn();
            }
        }
    });            

    public by Tech_JA modified Jan 30, 2017  23  1  3  1

    Delay function

    Function to wait xxx ms
    //function to wait xxx ms
    function wait(ms) {
        'use strict';
        var start = new Date().getTime();
        var end = start;
        while (end < start + ms) {
            end = new Date().getTime();
        }
    }
    
    //example for 1s
    wait(1000);           

    public by Tech_JA modified Jan 30, 2017  31  0  3  1

    Create dir if not exists

    Create a dir if not exists with node.js
    var fs = require('fs');
    var myDir = process.env.USERPROFILE + "/.dbparts";
    
    function createDir(path, mode, exception) {
        fs.mkdir(path, mode, function (err) {
            if (err) {
                if (err.code === 'EEXIST') {
                    exception(null); //directory already exists
                } else {
                    exception(err); //unnespect error
                }
            } else {
                exception(null); //directory created with success
            }
        });
    }
    
    /**
     *  Call create program data's directory
     */
    createDir(myDir, '0644', function (err) {
        if (err) { //handle directory creation error
            gui.App.quit();
        }
    });                   

    public by shebin512 modified Nov 29, 2016  1129  4  3  1

    Format date in Arabic .

    Format date in arabic without using the locale functions to avoid numeral conversion.
    // Format date in Arabic
    var date = new Date('2016-12-04');
    var months = ["يناير", "فبراير", "مارس", "إبريل", "مايو", "يونيو",
                  "يوليو", "أغسطس", "سبتمبر", "أكتوبر", "نوفمبر", "ديسمبر"];
    var days =["اﻷحد","اﻷثنين","الثلاثاء","اﻷربعاء","الخميس","الجمعة","السبت"];
    var delDateString = days[date.getDay()]+', '+date.getDate()+' '+months[date.getMonth()]+', '+date.getFullYear();
    
    alert(delDateString); // Outputs اﻷحد, 4 ديسمبر, 2016
    • Public Snippets
    • Channels Snippets