Skip to content

Instantly share code, notes, and snippets.

View rootasjey's full-sized avatar

Jeremie Corpinot rootasjey

View GitHub Profile
@rootasjey
rootasjey / firebase_functions_helper_post_acl.ts
Created October 15, 2022 05:04
An helper function to check user access control when fetching or saving a new file (markdown post) to Firebase Storage using Cloud Function.
/**
* Tells if an user can have access to a project.
* @param {object} params - An object containing a project's id and jwt;
*/
async function checkAccessControl(params: CheckProjectAccessControlParams) {
const {projectId, jwt} = params;
try {
const projectSnapshot = await firestore
.collection("projects")
@rootasjey
rootasjey / firebase_functions_save_post.ts
Last active October 15, 2022 05:06
A function to fetch a markdown post file in Firebase Storage from Cloud Function (old way).
/**
* Save a project content
* (with accessibility check).
*/
export const save = functions
.region(cloudRegions.eu)
.https
.onCall(async (data) => {
const projectId: string = data.projectId;
const jwt: string = data.jwt;
@rootasjey
rootasjey / firebase_functions_fetch_post.ts
Last active October 15, 2022 05:06
Function to fetch a markdown post in Firebase Storage from Cloud Functions (old way)
/**
* Retrieve a project's content in markdown format
* (with accessibility check).
*/
export const fetch = functions
.region(cloudRegions.eu)
.https
.onCall(async (data) => {
const projectId: string = data.projectId;
@rootasjey
rootasjey / Pagination.tsx
Created November 30, 2021 23:06
React pagination component (TypeScript)
import { ReactElement, useState } from 'react'
import classNames from 'classnames'
import Image from 'next/image'
import ArrowRightIcon from '@/public/images/homepage/arrow-right.svg'
type PaginationProps = {
/** Number of pages to display in the pagination. */
pagesCount: number
@rootasjey
rootasjey / Fitbit-weather-companion.js
Last active November 23, 2018 19:08
Fitbit weather companion fetch example
// Companion
// You'll need to add `fitbit-weather` module in your project
import * as weather from '../lib/fitbit-weather/companion';
weather.setup({ provider : weather.Providers.darksky, apiKey : 'apiKey' });
@rootasjey
rootasjey / Fitbit-settings-messaging-app.js
Last active November 23, 2018 19:08
fitbit settings messaging on app
// App
import * as messaging from "messaging";
// Received message containing settings data
messaging.peerSocket.addEventListener("message", function(evt) {
settings[evt.data.key] = evt.data.value;
// Update Immediately weather value when unit changed
if (evt.data.key === 'weatherRefreshTime') {
// do something
@rootasjey
rootasjey / Fitbit-settings-message-companion.js
Last active November 23, 2018 19:09
Fitbit settings companion messaging
// Companion
import * as messaging from "messaging";
sendValue('weatherRefreshTime', time);
function sendValue(key, val) {
if (val) {
sendSettingData({
key: key,
value: JSON.parse(val)
@rootasjey
rootasjey / Fitbit-stettings-storage.js
Last active November 23, 2018 19:09
Retrieve setting data in companion
// Companion
import { settingsStorage } from "settings";
const time = settingsStorage.getItem('weatherRefreshTime');
@rootasjey
rootasjey / Fitbit-permissions.js
Last active November 23, 2018 19:13
Get the next allowed activity's number
// App
import { me } from "appbit";
/**
* Return the next allowed activity's number
*/
export function getNextAllowedActivity(activityNumber) {
const { granted } = me.permissions;
const grantedActivity = granted('access_activity');
@rootasjey
rootasjey / fitbit-layout.js
Last active November 23, 2018 19:14
Example module which places visual elements according to device detection
// App
/**
* Return horizontal icon position.
*/
export function getIconX() {
const hPos = {
Ionic: 290,
Versa: 250,
};