Skip to content

Instantly share code, notes, and snippets.

View michelepatrassi's full-sized avatar
🌊
I’m the maker of ClubUp!, tech writer on Medium and startup addicted.

Michele michelepatrassi

🌊
I’m the maker of ClubUp!, tech writer on Medium and startup addicted.
View GitHub Profile
@michelepatrassi
michelepatrassi / gist:7e922900ea409d966f9a082ddceb5762
Created March 16, 2021 19:32
Format object to array of objects
const tags = {
Advertising: "Advertising",
Architecture: "Architecture",
Aviation: "Aviation",
Banking: "Banking",
Business: "Business",
Construction: "Construction",
Design: "Design",
Economics: "Economics",
Engineering: "Engineering",
@michelepatrassi
michelepatrassi / daily-planning-example.txt
Last active April 6, 2020 13:28
Daily planning example
1/04/2020
8:30 - study nestJS
9:30 - team call
-> remember wrap to wrap up project task
10 - break
10:15 - deploy with cloud66 using docker compose, find out how to connect frontend with backend
-> deployment went fine, had to define custom file!
@michelepatrassi
michelepatrassi / server.ts
Last active February 5, 2023 13:56
Angular Universal Server Side Rendering battle tested server.ts and webpack.server.config.js files 🦁(includes Firebase, FirebaseUI, Angular i18n and log rotation)
import { RESPONSE, REQUEST } from '@nguniversal/express-engine/tokens';
import { renderModuleFactory } from '@angular/platform-server';
// These are important and needed before anything else
import 'zone.js/dist/zone-node';
import 'reflect-metadata';
import { enableProdMode, ValueProvider, FactoryProvider } from '@angular/core';
// Import module map for lazy loading
import {provideModuleMap} from '@nguniversal/module-map-ngfactory-loader';
import { registerLocaleData } from '@angular/common';
@michelepatrassi
michelepatrassi / uri-split.js
Created November 25, 2019 10:22
Helper to get path and name from file URI
getPathAndFileName(fileUri: string): { path: string; name: string } => {
const splittedUri = fileUri.split('/').filter(x => x);
const path = `${splittedUri.slice(0, -1).join('/')}/`;
const name = splittedUri.slice(-1).join();
return { path, name };
}
@michelepatrassi
michelepatrassi / mutation-observer.ts
Created October 17, 2019 08:21
Angular MutationObserver
Component code
....
ngAfterViewInit() {
const config = { attributes: false, childList: true, subtree: true };
this.messageTreeObserver = new MutationObserver((mutationList, observer) => {
for (const mutation of mutationList) {
if (mutation.type === 'childList') {
// Do action here!
}
}
@michelepatrassi
michelepatrassi / base64.js
Last active September 26, 2019 11:06
How to create base64 string and get it back in NodeJS
# Buffer is a default Nodejs global object
const initialString = 'michelepatrassi';
const token = Buffer.from(initialString).toString('base64');
# want to get it back?
const welcomeBack = Buffer.from(token, 'base64').toString('ascii');
if (initialString === welcomeBack) {
console.log('all good!');
@michelepatrassi
michelepatrassi / index.js
Created September 17, 2019 11:44 — forked from akexorcist/index.js
Axios post method requesting with x-www-form-urlencoded content type
const axios = require('axios')
const qs = require('querystring')
...
const requestBody = {
name: 'Akexorcist',
age: '28',
position: 'Android Developer',
description: 'birthdate=25-12-1989&favourite=coding%20coding%20and%20coding&company=Nextzy%20Technologies&website=http://www.akexorcist.com/',
@michelepatrassi
michelepatrassi / updated-server.ts
Last active June 14, 2022 07:47
Angular universal SSR requestAnimationFrame
// add this code to your server.ts
// implementation credits: https://gist.github.com/paulirish/1579671
global['requestAnimationFrame'] = function(callback, element) {
let lastTime = 0;
const currTime = new Date().getTime();
const timeToCall = Math.max(0, 16 - (currTime - lastTime));
const id = setTimeout(function() { callback(currTime + timeToCall); },
timeToCall);
lastTime = currTime + timeToCall;
@michelepatrassi
michelepatrassi / cfcron-add-update-config.js
Created September 6, 2019 09:37
Cloud function add update with config variables
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import MailchimpApi = require('mailchimp-api-v3');
import md5 = require('crypto-js/md5');
const CRON_SCHEDULE = '* * * * *';
export const cronMailchimp = functions.region('europe-west1').pubsub
.schedule(CRON_SCHEDULE).onRun(async context => {
const { audience, apikey } = functions.config().mailchimp;
@michelepatrassi
michelepatrassi / cfcron-add-update.js
Last active September 5, 2019 10:30
Cloud Function cron, add and update mailchimp contact
import * as functions from 'firebase-functions';
import * as admin from 'firebase-admin';
import MailchimpApi = require('mailchimp-api-v3');
import md5 = require('crypto-js/md5');
const CRON_SCHEDULE = '* * * * *';
const API_KEY = 'YOUR_API_KEY';
const AUDIENCE_ID = 'YOUR_AUDIENCE_ID';
export const cronMailchimp = functions.region('europe-west1').pubsub