working on it ...

Filters

Explore Public Snippets

Sort by

Found 6 snippets

    public by Tech_JA modified Oct 26, 2017  398  1  5  0

    sqlite-sync.js

    
    var sqlite = require('sqlite-sync'); //requiring 
     
    //Connecting - if the file does not exist it will be created 
    sqlite.connect('test/test.db'); 
     
    //Creating table - you can run any command 
    sqlite.run("CREATE TABLE COMPANYS(ID  INTEGER PRIMARY KEY AUTOINCREMENT, NAME TEXT NOT NULL);");
     
    //Inserting - this function can be sync to, look the wiki 
    sqlite.insert("COMPANYS",{NAME:"My COMPANY"}, function(inserid){
    	console.log(inserid);
    });
     
    //Updating - returns the number of rows modified - can be async too 
    var rows_modified = sqlite.update("COMPANYS",{NAME:"TESTING UPDATE"},{ID:1});
     
    //Create your function 
    function test(a,b){
    	return a+b;
    }
     
    //Add your function to connection 
    sqlite.create_function(test);
     
    // Use your function in the SQL 
    console.log(sqlite.run("SELECT ID, test(NAME, ' Inc') as NAME FROM COMPANYS"));
     
    // Closing connection  
    sqlite.close();
    
    					

    public by Tech_JA modified Oct 26, 2017  384  1  5  0

    Get the current date and time

    Get the current date and time
    var datetime = "";
    
    function getdate() {
        var currentdate = new Date();
        datetime = currentdate.getFullYear();
        datetime += "/";
        if (currentdate.getMonth() < 10) {
            datetime += "0" + currentdate.getMonth();
        } else {
            datetime = currentdate.getMonth();
        }
        datetime += "/";
        if (currentdate.getDate() < 10) {
            datetime += "0" + currentdate.getDate();
        } else {
            datetime += currentdate.getDate();
        }
        datetime += " ";
        if (currentdate.getHours() < 10) {
            datetime += " " + currentdate.getHours();
        } else {
            datetime += currentdate.getHours();
        }
        datetime += ":";
        if (currentdate.getMinutes() < 10) {
            datetime += "0" + currentdate.getMinutes();
        } else {
            datetime += currentdate.getMinutes();
        }
        datetime += ":";
        if (currentdate.getSeconds() < 10) {
            datetime += "0" + currentdate.getSeconds();
        } else {
            datetime += currentdate.getSeconds();
        }
    }
    
    getdate();
    console.log("data e hora actuais: " + datetime);						

    public by Tech_JA modified Jan 30, 2017  3314  3  5  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  2933  2  5  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  1818  9  5  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  2012  7  5  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();
        }
    });                   

    List Complete ( 6 snippets total )

    • Public Snippets
    • Channels Snippets