Skip to content

Instantly share code, notes, and snippets.

View welll's full-sized avatar
🏠
Working from home

Wellington Soares welll

🏠
Working from home
View GitHub Profile
@welll
welll / long-list-argument.js
Created March 14, 2017 09:10
AvenueCode - Blog Post
function createProduct(id, name, description, sku, colors, sizes, price, imageURL, thumbnailURL){
//
//
}
@welll
welll / callback-hell-async.js
Created March 14, 2017 08:23
Callback Hell Async/Await
const AWS = require(`aws-sdk`)
const fs = require(`fs`)
const path = require(`path`)
const dir = `./sample-dir`
const bucket = `bucket-name`
const s3bucket = new AWS.S3({params: {Bucket: bucket}})
async function readDirAsync(path) {
@welll
welll / callback-hell.js
Last active March 14, 2017 07:13
AvenueCode - Blog Post
const AWS = require(`aws-sdk`)
const fs = require(`fs`)
const path = require(`path`)
const dir = `./sample-dir`
const bucket = `bucket-name`
const s3bucket = new AWS.S3({params: {Bucket: bucket}})
fs.readdir(dir, (err, files) => {
var dependency1 = require('./dep1');
export.fooBar = dep
@welll
welll / episode.js
Created January 16, 2017 14:35 — forked from mpj/episode.js
Code from the "Dependency Injection Basics" episode of Fun Fun Function
const assert = require('assert')
function getAnimals(fetch, id) {
return fetch('http://api.animalfarmgame.com/animals/' + id)
.then(response => response.json())
.then(data => data.results[0])
}
describe('getAnimals', () => {
it('calls fetch with the correct url', () => {
@welll
welll / aggregate.js
Created November 1, 2016 04:05
Aggregate data from MongoDB with Node.js and mongoose
var mongoose = require('mongoose');
var Schema = mongoose.Schema;
//Database connection
var uristring = 'mongodb://localhost/test';
var mongoOptions = { };
mongoose.connect(uristring, mongoOptions, function (err, res) {
if (err) {
console.log('Error when connecting to: ' + uristring + '. ' + err);
@welll
welll / enum-access.js
Created November 1, 2016 02:48 — forked from bnoguchi/enum-access.js
How to access enumValues in mongoose from a Model or Document
var mongoose = require('./index')
, TempSchema = new mongoose.Schema({
salutation: {type: String, enum: ['Mr.', 'Mrs.', 'Ms.']}
});
var Temp = mongoose.model('Temp', TempSchema);
console.log(Temp.schema.path('salutation').enumValues);
var temp = new Temp();
console.log(temp.schema.path('salutation').enumValues);
@welll
welll / make-animated-gif.js
Created October 13, 2016 14:56 — forked from AVGP/make-animated-gif.js
Uses three.js, three-software-renderer & omggif to render an animated GIF from a Three.js Scene on the server with node.js
var fs = require('fs'),
omggif = require('omggif'),
THREE = require('three'),
SoftwareRenderer = require('three-software-renderer');
// How many frames and how large shall the GIF be?
var NUM_FRAMES = 200, WIDTH = 500, HEIGHT = 500;
// Our scene, camera and renderer and a box to render
var scene = new THREE.Scene(),
@welll
welll / json_with_cpp.cpp
Created July 22, 2016 16:43 — forked from makomweb/json_with_cpp.cpp
Some fun with JSON serialization/deserialization using C++ REST SDK (Codename "Casablanca").
#include <cpprest/json.h>
#include <sstream>
using namespace std;
typedef web::json::value JsonValue;
typedef web::json::value::value_type JsonValueType;
typedef std::wstring String;
typedef std::wstringstream StringStream;
String JsonValueTypeToString(const JsonValueType& type)
@welll
welll / date_conversion.cpp
Created January 28, 2016 11:58 — forked from st-j/date_conversion.cpp
Convert between boost dates and Unix timestamps (time_t)
#include <ctime>
#include <iostream>
#include <boost/date_time/gregorian/gregorian.hpp>
#include <boost/date_time/posix_time/posix_time.hpp>
//==============================================================================
//! Convert date part of Unix timestamp (time_t) to boost date
//!