Skip to content

Instantly share code, notes, and snippets.

View netgfx's full-sized avatar
💻
Working...

Michael Dobekidis netgfx

💻
Working...
View GitHub Profile
@netgfx
netgfx / Simple Ajax Login Form.php
Created May 11, 2018 17:20 — forked from cristianstan/Simple Ajax Login Form.php
Wordpress: Simple Ajax Login Form
<?php
//Simple Ajax Login Form
//Source: http://natko.com/wordpress-ajax-login-without-a-plugin-the-right-way/
//html
<form id="login" action="login" method="post">
<h1>Site Login</h1>
<p class="status"></p>
<label for="username">Username</label>
<input id="username" type="text" name="username">
@netgfx
netgfx / gulp-zip-utility
Created June 1, 2018 14:48
Gulp create zip
const gulp = require('gulp');
const zip = require('gulp-zip');
gulp.task('default', () =>
gulp.src(['./states/**', "./libs/**", "./styles/**", "./assets/**", "./config.json", "./fbapp-config.json", "./firebase.json", "./cert.pem",
"./index.html"
], { "base": "." })
.pipe(zip('archive.zip'))
.pipe(gulp.dest('dist'))
);
@netgfx
netgfx / js-crypto-libraries.md
Created June 6, 2018 08:02 — forked from jo/js-crypto-libraries.md
List of JavaScript Crypto libraries.

JavaScript Crypto Libraries

I start with a list and plan to create a comparison table.

WebCryptoAPI

http://www.w3.org/TR/WebCryptoAPI/

This specification describes a JavaScript API for performing basic cryptographic operations in web applications, such as hashing, signature generation and verification, and encryption and decryption. Additionally, it describes an API for applications to generate and/or manage the keying material necessary to perform these operations. Uses for this API range from user or service authentication, document or code signing, and the confidentiality and integrity of communications.

@netgfx
netgfx / medium-snippet-BE-0.js
Last active July 22, 2018 19:22
Medium-snippet-BE-1
// The reference of the collection
const bountyQueueRef = db.collection("bountyQueue");
exports.startMatchmaking = functions.https.onRequest((req, response) => {
var data = req.query.data || req.params.data || req.body.data || '';
var userId = req.query.userId || req.params.userId || req.body.userId || 5000;
let userFBId = data.userFBId;
let tag = data.tag;
var signature = data.signature || "123";
@netgfx
netgfx / cloud-functions-imports.js
Created July 22, 2018 19:21
CloudFunctionsImports
const functions = require('firebase-functions');
const cors = require('cors')({ origin: true });
const admin = require('firebase-admin');
const fetch = require('fetch-base64');
const url = require('url');
const _ = require('lodash');
const cryptonode = require('crypto');
const crypto = require('crypto-js');
const request = require('request');
const schedule = require('node-schedule');
@netgfx
netgfx / medium-snippet-validation.js
Created July 22, 2018 19:23
FB Signature Validation
/**
* Validates FB signature to determine if player actually comes from FB, uses *APP SECRET!*
*
* @param {any} signedRequest
* @returns
*/
function validate(signedRequest) {
try {
var firstpart = signedRequest.split('.')[0];
var replaced = firstpart.replace(/-/g, '+').replace(/_/g, '/');
@netgfx
netgfx / medium-snippet-BE-1.js
Last active August 10, 2019 21:58
medium-snippet-BE-2
exports.findMatch = functions.https.onRequest((req, response) => {
var data = req.query.data || req.params.data || req.body.data || '';
var userId = req.query.userId || req.params.userId || req.body.userId || 5000;
let userFBId = data.userFBId;
let tag = data.tag;
var signature = data.signature || "123";
var isValid = validate(signature);
if (isValid === true) {
@netgfx
netgfx / pending-challenge-1.js
Last active July 27, 2018 07:48
medium-pending-challenge-1
{
matchId: "1947418278602326",
pendingParty: {
id: "1790675644305076",
name: "Mike",
photo: "https://..."
}
}
@netgfx
netgfx / pending-challenge-2.js
Last active July 27, 2018 10:40
medium-pending-challenge-2
/*
data = {
"data": {
"matchId": FBInstant.context.getID() || "123",
"signature": signature,
"opponent": {
id: player_facebook_id,
name: player_facebook_name,
photo: player_facebook_image
}
@netgfx
netgfx / pending-challenge-3.js
Last active July 27, 2018 10:42
medium-pending-challenge-3
var pendingChallenges = [];
FirebaseAPI.db.collection("pendingChallenges").where("pendingParty.id", "==", facebookStuff.userId).get().then(function(pendingChallengesDoc) {
console.log(pendingChallengesDoc, pendingChallengesDoc.size);
if (pendingChallengesDoc.empty === true && pendingChallengesDoc.size > 0) {
if (fn) {
fn(pendingChallenges);
}
} else {
pendingChallengesDoc.forEach(function(item) {