Skip to content

Instantly share code, notes, and snippets.

View mornir's full-sized avatar
🎮
Gaming

Jérôme Pott mornir

🎮
Gaming
View GitHub Profile
@mornir
mornir / 0_reuse_code.js
Last active September 11, 2016 17:18
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@mornir
mornir / google-auth-functions.js
Created June 21, 2017 17:57 — forked from elon-gs/google-auth-functions.js
Google Functions code for generating Google Auth tokens
// Code to write Google API Oauth tokens to Firebase database
const FUNCTIONS_CLIENT_ID = functions.config().googleapi.client_id;
const FUNCTIONS_SECRET_KEY = functions.config().googleapi.client_secret;
const FUNCTIONS_REDIRECT = '{YOUR_FUNCTIONS_SUBDOMAIN}.cloudfunctions.net/OauthCallback';
// TODO: use firebase functions:config:set to configure your Google API client ID and secret
// Also update FUNCTIONS_REDIRECT
const googleAuth = require('google-auth-library');
@mornir
mornir / trigger-to-google-sheet.js
Created June 21, 2017 17:57 — forked from elon-gs/trigger-to-google-sheet.js
Trigger function that copies new data in FB database to Google Sheet
// Trigger function copies new data in FB database to Google Sheet
const FUNCTIONS_CLIENT_ID = functions.config().googleapi.client_id;
const FUNCTIONS_SECRET_KEY = functions.config().googleapi.client_secret;
const FUNCTIONS_REDIRECT = '{YOUR_FUNCTIONS_SUBDOMAIN}.cloudfunctions.net/OauthCallback';
// TODO: use firebase functions:config:set to configure your Google API client ID and secret
// Also update FUNCTIONS_REDIRECT
const googleAuth = require('google-auth-library');
const google = require('googleapis');
@mornir
mornir / array_iteration_thoughts.md
Created July 2, 2017 17:26 — forked from ljharb/array_iteration_thoughts.md
Array iteration methods summarized

While attempting to explain JavaScript's reduce method on arrays, conceptually, I came up with the following - hopefully it's helpful; happy to tweak it if anyone has suggestions.

Intro

JavaScript Arrays have lots of built in methods on their prototype. Some of them mutate - ie, they change the underlying array in-place. Luckily, most of them do not - they instead return an entirely distinct array. Since arrays are conceptually a contiguous list of items, it helps code clarity and maintainability a lot to be able to operate on them in a "functional" way. (I'll also insist on referring to an array as a "list" - although in some languages, List is a native data type, in JS and this post, I'm referring to the concept. Everywhere I use the word "list" you can assume I'm talking about a JS Array) This means, to perform a single operation on the list as a whole ("atomically"), and to return a new list - thus making it much simpler to think about both the old list and the new one, what they contain, and

@mornir
mornir / string_parse.js
Created July 16, 2017 08:56
String parsing using array destructuring
const pathUrl = "c:/alex/mesdocument";
const [server, user, directory] = pathUrl.split("/");
@mornir
mornir / auth-demo.js
Created July 16, 2017 14:21
Authentification demo with VueFire
// Initialize Firebase
firebase.database.enableLogging(false) // toggle on for debug (it's noisy)
var db = firebase.initializeApp({
apiKey: "AIzaSyDSdRWUWjx55Yf9_SCaW23_HTGhUrvE6qw",
authDomain: "vuefire-auth-example.firebaseapp.com",
databaseURL: "https://vuefire-auth-example.firebaseio.com",
storageBucket: "vuefire-auth-example.appspot.com",
messagingSenderId: "925981907667"
}).database();
@mornir
mornir / fetch_json.js
Last active December 13, 2017 17:28 — forked from msmfsd/es7-async-await.js
Javascript fetch JSON with ES7 Async Await
async function fetchAsync () {
// await response of fetch call
const response = await fetch('https://api.github.com');
// only proceed once promise is resolved
const data = await response.json();
// only proceed once second promise is resolved
return data;
}
// more concise
@mornir
mornir / Code.gs
Created December 21, 2017 20:05 — forked from CodingDoug/README.md
Copying Data from a Google Sheet into Firebase Realtime Database in real time via Apps Script
// Copyright 2017 Google LLC.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
@mornir
mornir / README.md
Created December 21, 2017 20:06 — forked from CodingDoug/README.md
Copying data from Firebase Realtime Database to a Google Sheet in real time via Cloud Functions
@mornir
mornir / Async_Await_Error_Handling.js
Created December 23, 2017 07:14
Async Await Error Handling
function catchErrors(fn) {
return function (...args) {
return fn(...args).catch((err) => {
console.error('Ohhhh nooo!!!!!');
console.error(err);
});
}
}
const catchError = (fn) => (...params) => fn(...params).catch(e => console.error(e))