working on it ...

Filters

Explore Public Snippets

Sort by

Found 122k snippets

    public by Tech_JA modified Oct 26, 2017  39  0  3  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  51  0  3  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 electron modified Oct 18, 2017  101  0  3  0

    es6 async function

    template for async function es6 javascript js
    async function GetData() {
    	const resp = await axios.get('/url')
    	console.log(resp)
    }
    
    GetaData()

    public by szmerek modified Sep 6, 2017  263  4  5  0

    OnClick without setting an attribute of the link

    //<div id="dog" >Woow woow</div>
    
    
        (function() {
            document.getElementById("dog").onclick = function() { 
                alert('fuf fuf'); 
            };
        })();																								

    public by tttttttttt modified Aug 30, 2017  83  1  1  0

    ttttttttttttttttt

    tttt
    // ==UserScript==
    // @name         MicroScatter Cheater Script
    // @namespace    http://qsysmine.tk/
    // @version      0.1
    // @description  Press C on microscatter to win
    // @author       qsysmine
    // @match        https://quizlet.com/*/microscatter
    // @grant        none
    // ==/UserScript==
    
    (function() {
        var $ = window.jQuery;
        var cheat = function() {
            var ids = [];
            var checkhasid = function(id) {
                for(var i in ids) {
                    if(ids[i] == id) {
                        return true;
                    }
                }
                return false;
            };
            $('.cell').each(function(index){
    
                if(checkhasid($(this).attr("data-id"))) $('[data-id="' + $(this).attr("data-id") + '"]').trigger("click")
                if(!checkhasid($(this).attr("data-id"))) ids.push($(this).attr("data-id"));
    
            });
        };
        var z = 0;
        $('*').keyup(function(e) {
            if(e.keyCode == 67 && z == 0) {z = 1; cheat();}
        });
    })();
    
    

    public by tttttttttt modified Aug 30, 2017  83  0  1  0

    ttttttttttt

    ttttttttttttttt
    // ==UserScript==
    // @name         MicroScatter Cheater Script
    // @namespace    http://qsysmine.tk/
    // @version      0.1
    // @description  Press C on microscatter to win
    // @author       qsysmine
    // @match        https://quizlet.com/*/microscatter
    // @grant        none
    // ==/UserScript==
    
    (function() {
        var $ = window.jQuery;
        var cheat = function() {
            var ids = [];
            var checkhasid = function(id) {
                for(var i in ids) {
                    if(ids[i] == id) {
                        return true;
                    }
                }
                return false;
            };
            $('.cell').each(function(index){
    
                if(checkhasid($(this).attr("data-id"))) $('[data-id="' + $(this).attr("data-id") + '"]').trigger("click")
                if(!checkhasid($(this).attr("data-id"))) ids.push($(this).attr("data-id"));
    
            });
        };
        var z = 0;
        $('*').keyup(function(e) {
            if(e.keyCode == 67 && z === 0) {z = 1; cheat();}
        });
    })();
    
    

    public by szmerek modified Aug 20, 2017  162  0  3  0

    Remove part of a string before specified character

    //remove string before '&' if want to include character '&' then 'indexOf("&") + 0'
    var str = "black&white";
    str = str.substring(str.indexOf("&") + 1);
    
    //or use regex
    var str = "black&white";
    str = /&(.+)/.exec(str)[1];
    
    // or use .split() and .pop() 
    var str = "black&white";
    str = str.split("&").pop();						

    public by szmerek modified Aug 20, 2017  143  1  3  0

    Check whether a string matches a regex

    //RegExp allows to inject variable values into the regex string
    var str = "sample1";
    var re = new RegExp("^([a-z0-9]{5,})$");
    if (re.test(str)) {
        console.log("valid");
    } else {
        console.log("invalid");
    }					

    public by szmerek modified Aug 20, 2017  141  0  4  0

    Hide element(s) by class

    Some examples for hiding the class.
    //Ex 
    //<div class="appBanner">appbanner</div> 
    
    document.getElementsByClassName('appBanner')[0].style.visibility = 'hidden';
    
    //change the style rules of all elements matching the class
    
    [].forEach.call(document.querySelectorAll('.appBanner'), function (el) {
      el.style.visibility = 'hidden';
    });
    
    //If for...of is available then use
    
    for (let el of document.querySelectorAll('.appBanner')) el.style.visibility = 'hidden';
    
    //And the other one
    
    Array.filter( document.getElementsByClassName('appBanner'), function(elem){ elem.style.visibility = 'hidden'; });
    
    //and the last one
    
    var appBanners = document.getElementsByClassName('appBanner'), i;
    
    for (i = 0; i < appBanners.length; i += 1) {
        appBanners[i].style.display = 'none';
    }																								

    public by sunole modified Aug 5, 2017  107  0  2  0

    test javascript one

    // Enter here the actual content of the snippet.			
    var aaaa =5;
    • Public Snippets
    • Channels Snippets