Skip to content

Instantly share code, notes, and snippets.

😊

Benjamin newbenhd

😊
Block or report user

Report or block newbenhd

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@newbenhd
newbenhd / mongodb.js
Last active Jul 12, 2019
mongodb client wrapper
View mongodb.js
// CRUD operator
const mongodb = require("mongodb");
class dbClient {
constructor() {
this.MongoClient = mongodb.MongoClient;
this.connectionURL = "";
this.client = undefined;
this.error = undefined;
@newbenhd
newbenhd / mapbox.test.js
Created Jul 11, 2019
mapbox service test cases
View mapbox.test.js
const mapbox = require("./mapbox");
const { assert } = require("chai");
describe("--> mapbox module test <--", () => {
describe("forwardGeocoding() test", () => {
it("should have response with default", () => {
mapbox.forwardGeocoding(undefined, undefined, {}, (error, response) => {
// if (error) throw error;
assert.isObject(response, "is not an object?");
});
View async
return new Promise(async (resolve, reject) => {
try {
const depnString = JSON.stringify(this.depn);
await fs.writeFile(path.join(this.dest, this.fileName), depnString);
} catch (err) {
reject(err);
}
});
View index.js
"use strict"
const bodyParser = require('body-parser')
const serveStatic = require('serve-static')
function wrapper = () => {
const locals = {}
return (path, callback) => {
on,
}
}
View auth.js
import config from '../config'
import { User } from '../resources/user/user.model'
import jwt from 'jsonwebtoken'
export const newToken = user => {
return jwt.sign({ id: user.id }, config.secrets.jwt, {
expiresIn: config.secrets.jwtExp
})
}
View test cases
if (typeof module !== 'undefined') {
var JSONParser = require('../src/main.js');
var expect = require('chai').expect;
}
describe('JSON Parser', function() {
describe('Numbers', function() {
it('should work on single-digit', function() {
expect(JSONParser(JSON.stringify(1))).to.eql(1);
View parser
/**
* returns a javascript object from a JSON formatted string
* Example json to javascript object:
* "5" -> 5
* "'hello'" -> 'hello'
* "[]" -> []
* "{}" -> {}
* "["hello"]" -> ['hello']
*
* For more examples, use the JSON.stringify method in the console
@newbenhd
newbenhd / prototype
Created Jun 18, 2019
Prototype Inheritance
View prototype
function createArray() {
this.array = [];
}
createArray.prototype.push = val => {
this.array.push(val);
};
@newbenhd
newbenhd / Censor
Created May 24, 2019
Censor function
View Censor
// 1. Declare a function named censor with no parameter.
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object.
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2.
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2.
// 1-2-2. Else, iterate through censorObject using for...in looop
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key using regex and String.replace method.
// 1-2-2-2. Return str1.
// 1-3. Return getCensor.
function censor() {
@newbenhd
newbenhd / censor.js
Last active May 24, 2019
Censor function
View censor.js
/*
Challenge:
Create a function censor that accepts no arguments. censor will return a function that will accept either two strings, or one string. When two strings are given, the returned function will hold onto the two strings as a pair, for future use. When one string is given, the returned function will return the same string, except all instances of a first string (of a saved pair) will be replaced with the second string (of a saved pair).
*/
// 1. Declare a function named censor with no parameter.
// 1-1. Declare a backpack variable named censorObject, and assign it an empty object.
// 1-2. Declare a function named getCensor with two parameters: a string named str1, a string named str2.
// 1-2-1. use if statement to check if str2 is not undefined. If so, set censorObject's key to str1, and its value to str2.
// 1-2-2. Else, iterate through censorObject using for...in looop
// 1-2-2-1. Check if any of keys' strings found on str1's string. If so, replace the string with the value associated with key
You can’t perform that action at this time.