Skip to content

Instantly share code, notes, and snippets.

View maggiben's full-sized avatar

Benjamin maggiben

  • Frávega
  • Argentina
View GitHub Profile
@maggiben
maggiben / EventEmitter.js
Created August 26, 2021 23:36
Very Basic EventEmitter implementation
/* Very basic EventEmitter class */
class EventEmitter {
constructor() {
this.events = new Map();
}
on(eventname, callback) {
if(this.events.has(eventname)) {
const events = this.events.get(eventname);
events.push(callback);
return this.events.set(eventname, events);
@maggiben
maggiben / readUrl.ts
Created July 7, 2021 20:09
Read URL (transform stream -> promise)
private readUrl(url: string): Promise < string > {
return new Promise((resolve, reject) => {
https.get(url, (response) => {
response.setEncoding('utf8');
let body = '';
response.on('data', (data) => {
body += data;
});
response.on('end', () => {
resolve(body);
@maggiben
maggiben / getSuffix.ts
Created June 9, 2021 16:50
Given a file path get the suffix
private getSuffixByFileName(fsPath: string): string | undefined {
const metadataFileExt = '-meta.xml';
const fileName = path.basename(fsPath);
if (fileName.endsWith(metadataFileExt)) {
return fileName.substring(0, fileName.indexOf('-meta.xml')).split('.').slice(1, 2).pop();
}
return undefined;
}
private getTypeDefinitionByFileName(fsPath: string): MetadataType | undefined {
const fs = require('fs').promises;
const ALLOWED_MUTATIONS = [
'manage_splash',
'create_public_api_credential',
'delete_public_api_credential'
];
const loadSchema = async (file) => {
try {
https://www.youtube.com/watch?v=PSoOFn3wQV4|The Bangles - Eternal Flame
https://www.youtube.com/watch?v=W6hknFigMSI|Bonnie Tyler - Total Eclipse of the Heart
https://www.youtube.com/watch?v=mUg5aEy-8CQ|Glenn Medeiros - Nothing's Gonna Change My Love For You
https://www.youtube.com/watch?v=3wxyN3z9PL4|Starship - Nothing's Gonna Stop Us Now
https://www.youtube.com/watch?v=K1b8AhIsSYQ|Starship - We Built This City
https://www.youtube.com/watch?v=ZvMsp7s78Do|Chesney Hawkes - The One and Only
https://www.youtube.com/watch?v=I_2D8Eo15wE|Ram Jam - Black Betty
https://youtu.be/djV11Xbc914|a-ha - Take On Me
https://www.youtube.com/watch?v=k2C5TjS2sh4|Roxette - It Must Have Been Love
https://www.youtube.com/watch?v=xSZBIs0gs0E|Natalie Imbruglia - Torn
import * as React from 'react';
import {
Icon,
MainSectionLayoutTypes,
MainSectionLayout,
Button
} from 'osp-ui-components';
import { FormattedMessage } from 'react-intl';
@maggiben
maggiben / forrajeria.psc
Created November 28, 2019 21:18
Forrajeria
Funcion suma <- totalFacturado ( facturas )
suma <- 0
Para i<-1 Hasta 5 Con Paso 1 Hacer
suma <- suma + facturas[i, 4]
Fin Para
Fin Funcion
Funcion suma <- totalKilos ( facturas )
suma <- 0
Para i<-1 Hasta 5 Con Paso 1 Hacer
@maggiben
maggiben / capitalizeUnderscore.js
Created November 11, 2019 12:45
Capitalize undescore words
'hello_my_name_is_ben'.replace(/_/g, ' ').replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });
// Hello My Name Is Ben
@maggiben
maggiben / nextRun.js
Last active July 23, 2019 16:08
Given a date and a recurrence rule show the next occurrence
var options = RRule.parseString('FREQ=MONTHLY;INTERVAL=1');
options.dtstart = moment.utc('2019-05-16 12:30:00').toDate();
options.count = 2;
var rule = new RRule(options)
var nextRun = rule.all().slice(-1).pop();
console.log(moment(nextRun).format('YYYY-MM-DD H:mm:ss'));
@maggiben
maggiben / wordify.js
Created July 1, 2019 18:51
replace underscore with spaces and uppercase each word
"animal_brand_name".replace(/_/g, ' ').replace(/(?:^|\s)\S/g, function(a) { return a.toUpperCase(); });