Skip to content

Instantly share code, notes, and snippets.

View gndelia's full-sized avatar
:shipit:
Working from home

Gonzalo D'Elia gndelia

:shipit:
Working from home
View GitHub Profile
@gndelia
gndelia / solution.js
Created August 3, 2020 23:16
cassidoo newsletter problem solution
function charNumSort(array) {
return array
.map((word) => ({ word, characters: new Set(word.toLowerCase().split('')) }))
.sort((a, b) => {
if (a.characters.size === b.characters.size) {
return b.word.length - a.word.length
}
return a.characters.size - b.characters.size
})
.map(({ word }) => word)
@gndelia
gndelia / flatten.js
Created May 10, 2019 04:40
Implementation of Flatten Array for interview
const expect = require('chai').expect;
// Implementation of flatten(array)
function flatten(array) {
// early return if it is not an array or if empty
if (!array || !Array.isArray(array)) {
return;
}
return array.reduce((flattened, element) => {
return flattened.concat(Array.isArray(element) ? flatten(element) : [element]);
@gndelia
gndelia / post-hostStorage.js
Last active November 5, 2018 02:11
v1 of uploading file and storing them in the host
const storage = require('./hostStorage');
app.post('/upload', async (req, res) => {
try {
await storage.store(req.files.file);
res.sendStatus(200);
}
catch(err) {
res.sendStatus(500);
}
});
@gndelia
gndelia / hostStoragev1.js
Created November 2, 2018 00:04
First version of host storaging
const baseStorageFolder = './storage';
const store = file => {
const filePath = `${baseStorageFolder}/${file.name}`;
return new Promise((res, rej) => file.mv(filePath, err => {
if (err) {
rej();
return;
}
res();
}));
@gndelia
gndelia / server.js
Last active November 5, 2018 02:33
frontend basic server to statically serve our app - starting point
let http = require('http');
const url = require('url');
let fs = require('fs');
const PORT=8000;
http.createServer((req, res) => {
let requestUrl = url.parse(req.url);
res.writeHead(200);
let stream = fs.createReadStream(__dirname + (requestUrl.pathname === '/' ? '/index.html' : requestUrl.pathname));
@gndelia
gndelia / index.js
Last active November 5, 2018 02:42
starting point for index.js - upload examples
const backendPort = 8001;
const instance = axios.create({ baseURL: `http://localhost:${backendPort}` });
async function upload(e) {
let files = this.files;
let formData = new FormData();
formData.append('file', files[0]);
const configuration = { headers: { 'content-type': 'multipart/form-data' } };
let response = await instance.post('/upload', formData, configuration);
alert('upload done!');
@gndelia
gndelia / basic-frontend-server.js
Last active November 1, 2018 23:22
nodejs basic server for frontend upload
const express = require('express');
const app = express();
const http = require('http').Server(app);
const fileUpload = require('express-fileupload');
const cors = require('cors');
app.use(fileUpload());
app.use(cors());
const backendPort = 8001;
@gndelia
gndelia / front-upload.html
Last active November 1, 2018 23:23
Basic html page for upload example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<title>My uploading page</title>
</head>
<body>
<fieldset>
<legend>Avatar section</legend>
<div>
@gndelia
gndelia / gist:c27c89b4949d46a50a9bc1282a30b725
Created May 29, 2017 21:12
.jshintrc example for quadion
{
"undef": true,
"unused": true,
"curly": true,
"indent": 4,
"devel": true,
"browser": true,
"worker": true,
"jasmine": true,
"globals": {
@gndelia
gndelia / .jscsrc
Created May 29, 2017 20:58
.jscsrc example for quadion
{
"disallowCommaBeforeLineBreak": null,
"disallowDanglingUnderscores": null,
"disallowEmptyBlocks": true,
"disallowImplicitTypeConversion": [ "string" ],
"disallowKeywordsOnNewLine": [ ],
"disallowKeywords": [ "with" ],
"disallowMixedSpacesAndTabs": true,
"disallowMultipleLineBreaks": true,
"disallowMultipleLineStrings": true,