Skip to content

Instantly share code, notes, and snippets.

View baruchvlz's full-sized avatar
🎮
What's happening?

Baruch Velez baruchvlz

🎮
What's happening?
View GitHub Profile
@baruchvlz
baruchvlz / map_to_model.ts
Last active September 24, 2019 17:05
fix: better FormModelValue.value type
interface FormModelValue<V = string | number | boolean | undefined | null> {
value: V;
error: boolean;
}
type MapToModel<T> = {
[P in keyof T]: FormModelValue<T[P]>
}
interface Form<M> {
@baruchvlz
baruchvlz / .eslintrc.js
Last active March 19, 2019 10:46
commonly used eslint rules
module.exports = {
"env": {
"browser": true,
"es6": true,
"node": true,
"jest/globals": true
},
"parser": "babel-eslint",
"extends": ["eslint:recommended"],
"parserOptions": {
@baruchvlz
baruchvlz / fetch-interceptors.ts
Created February 8, 2019 13:07
basic interceptor for fetch. assumes your routes are proxy through `/api-`
interface Interceptors {
request: { [k: string]: (...args: any[]) => any };
response: { [k: string]: (response: Response) => any };
}
class Interceptor {
protected requestCount: number = 0;
protected interceptors: Interceptors = {
request: {},
response: {},
export function fetchJSON(url: string, method: API_METHODS, data?: any): Promise<any> {
return fetch(url, {
method,
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then((res: any) => {
if (res.status >= 400) {
/**
Simple automation for Docker deployment with different environment files. Essentially end result
is to pass a enviroment when calling the file so that the correct compose file is copied into
the root directory.
*/
(function() {
'use strict';
// imports
const process = require('process');
const fs = require('fs');
div(id="breadcrumbs")
span(ng-repeat="breadcrumb in breadcrumbs")
#[button(ui-sref="{{breadcrumb.path}}", class="link") {{breadcrumb.name}}]/
@baruchvlz
baruchvlz / generateKey.js
Created April 4, 2016 23:06
MongoDB unique key generator.
/**
* generateKey ( Because I don't like to use `_id` )
* Generates a unique key
* @param Model -> Object
* @param Property Name (I.E. `clientId`) -> String
* @return Key -> String
**/
export function generateKey(model, propName) {
// Algorythm for Key
const keyAlgo = () => {
@baruchvlz
baruchvlz / mongoCrudHelper-ES6.js
Created March 30, 2016 15:20
Simple CRUD Helper to be used with MongoDB. Uses `q`
import q from 'q'
/*******************************************************************************
Create
*******************************************************************************/
export function crudCreate ( model, body ){
let dfd = q.defer()
new model(body).save()
.then(result => {
return dfd.resolve(result)
@baruchvlz
baruchvlz / trimResponseES6.js
Last active March 24, 2016 18:36
Simple Helper function to trim properties from MongoDB responses.
import _ from 'lodash'
/**
* Trim Response function
* Trim Object with given keys in Array
* @param obj || array of objects
* @param array
* @return obj
**/