working on it ...
Explore Public Snippets
Found 129k snippets
public by DinhoPutz 54 0 3 0
Somar valores de um objeto no JavaScript
Soma os campos de mesmo nome nos itens de um objeto
var objeto = [ { valor: 10 }, { valor: 15 } ]; objeto; var somaValores = function (novoObjeto) { // Aqui realiza a soma dos valores da propriedade "valor" dentro do objeto var total2 = novoObjeto.reduce((total, valor) => total + valor.valor, 0); // Resultado da soma console.log( total2 ); } somaValores(objeto);
public by PBMCube 130 0 4 1
Game Box Prototype
command combinations
Description: Quickly create operational games using simple box graphics from Phaser3 shapes (v3.13.x). This test game mechanics for enjoyment. Final Artwork added to game mechanisms, prototypes and mechanics as the final pipeline product phase.
// ============ //Example 4.1: Prototyping Graphics begins // ============ //create a character avatar using the box prototype method player = box({who: this, whereX: 150, whereY: 100,length:32, width:32, color: 0x0000FF,border: 0xFFFFFF}); this.physics.add.existing(player); player.body.velocity.x = 10; //see update function player.body.velocity.y = 50; console.log("Stationary Blue character avatar created as 'player' variable."); // ------------ // OR the direct method using either rectangle or graphics // and set movement velocities. var avatar = this.add.rectangle(100, 100, 32, 32, 0x0000FF).setStrokeStyle(5, 0x3399CC); console.log("Moving Blue character avatar created as 'player' variable."); var graphics = this.add.graphics({ fillStyle: { color: 0xFF0000 } }); graphics.lineStyle(10,0xFF9900,0); graphics.strokeRect(100, 100, 32, 32); //non-controlled movement (usage AI bot; see Chapter 6) graphics.fillRectShape(avatar); this.physics.add.existing(avatar); avatar.body.velocity.x = 50; avatar.body.velocity.y = 10; //non-controlled movement (usage AI bot; see Chapter 6) this.physics.add.existing(graphics); graphics.body.velocity.x = 50; graphics.body.velocity.y = 50; console.log("Moving Red avatar created as 'avatar' variable.\n Movement velocity set."); // ------------ //create an opponent - direct method var monster = this.add.rectangle(180, 60, 32, 32, 0x00FF00).setStrokeStyle(5, 0xFF9900); console.log("Green monster avatar created as 'monster' variable."); //Example 4.1: ends // ============
public by PBMCube 124 0 4 1
Scene Preload an Image
command format: Example:this.load.image("key", "path");
Description:Use this in the scene.preload function. .png are the default images. You can also set the "base URL"
// ============ // Example 3.4: Additional Phaser Properties begins // ============ // remote URL to game assets // Cross-origin resource sharing (CORS) this.load.setCORS = 'anonymous'; // Setting base URL path this.load.setBaseURL('http://makingbrowsergames.com/p3devcourse/_p3demos/imgages/'); // Preload a gfx asset this.load.image("face", "face.png");
public by PBMCube 123 0 4 1
Doors as Buttons
Dungeon doorways should be both clickable and sense collisions.
//Phaser III - clicking on a doorway // ============ // Example 4.6: Doors as Buttons // ============ // Creating door rectangles; review console in this experiment //placed on a wall with 2px extended into the room doorN = this.add.rectangle(35,0,60,18,0x000000) .setInteractive() .setOrigin(0);
public by PBMCube 140 1 4 1
Game Config File
This is a config file example to pass into the Phaser.Game. It is a barebones Phaser3 configuration object
var config = { type: graphics_mode, width: game_width, height: game_height, parent: 'div-tag-name', scene: [nameOfScene] };
public by PBMCube 119 0 4 1
Global Game Object
Assigning a global namespace variable with delegation into Phaser.Game
var game = new Phaser.Game(config);
public by DinhoPutz 141 1 3 0
Monitorar alterações em formulário, exibir alteração, filtro por campo.
Objetivo:
1. Monitorar alterações apenas a parte do formulário contida dentro da DIV "divCheckList".
2. Monitorar alterações apenas os campos que contenham no atributo "for" a palavra (caracteres) "check_".
3. Exibir as alterações em tempo real dentro da div "#parcial".
var selectElem = document.getElementById('divCheckList') // Seção onde se encontra o form, pode ser o ID da div acima dele ou de alguma div dentro do form. selectElem.addEventListener('change', function() { $("#parcial").html(""); $("label").each(function(index, element) { var ele = $(element); var elementos2 = []; algo = ele.attr("for").indexOf("check_"); // aqui filtramos apenas os campos que conteam "check_" no atributo "for", poderia ser ID, Class, placesseholder... if (algo > -1) { variavel = ("#" + ele.attr("for")); elementos2 = [index, ele.html(), ele.attr("for"), $(variavel).val()]; console.log(elementos2); $('#parcial').append("" + elementos2[1] + " - " + elementos2[3] + "\n"); } else null; }); })
{ setUp: function () { this.server = sinon.fakeServer.create(); }, tearDown: function () { this.server.restore(); }, "test should fetch comments from server" : function () { this.server.respondWith("GET", "/some/article/comments.json", [200, { "Content-Type": "application/json" }, '[{ "id": 12, "comment": "Hey there" }]']); var callback = sinon.spy(); myLib.getCommentsFor("/some/article", callback); this.server.respond(); sinon.assert.calledWith(callback, [{ id: 12, comment: "Hey there" }])); } }
public by tomsim 1486 1 6 0
Simple RPC call
Simple function to call RPC (only 1k uncompressed). Use this instead of JQuery. Alternatively, use zepto.min.js from zeptojs.com if you have 26K to spare.
/* Addapted from Paolo Manna git pmanna/mongoose_os_playground browser_rpc_service.js */ var platform = ''; var host = ''; var defCallBack = function(response) { if ((response) && (response.error)) { alert(response.message); } }; // Common call to RPC services on the board function callRPCService(cmd, params, callback) { if (!callback) { callback = defCallBack; } var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { callback(this.response); } }; xhttp.open('POST', 'rpc/' + cmd + '?' + new Date().getTime(), true); xhttp.responseType = 'json'; xhttp.send(JSON.stringify(params)); } // Discover which platform we're using, to enable/disable features function startup() { callRPCService('Config.Get',{}, function(response) { if (response) { platform = response.device.id; console.log('Platform is: ' + platform); var mac_id = (response.device.id.split("_"))[1]; host = mac_id + '.local'; document.getElementById("hostname").innerHTML = host; } }); } // Reboots the microcontroller function rebootDevice() { callRPCService('Sys.Reboot',{delay_ms:500}); }
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();