Skip to content

Instantly share code, notes, and snippets.

View bludnic's full-sized avatar
:electron:
Developing open-source 🌐

bludnic

:electron:
Developing open-source 🌐
View GitHub Profile
@bludnic
bludnic / directions.js
Created April 4, 2017 13:39 — forked from levymetal/directions.js
Tutorial on how to calculate driving distance using Google maps API, full post available @ http://christianvarga.com/how-to-calculate-driving-distance-between-2-locations-with-google-maps-api/
var directionsService = new google.maps.DirectionsService();
var request = {
origin : 'Melbourne VIC', // a city, full address, landmark etc
destination : 'Sydney NSW',
travelMode : google.maps.DirectionsTravelMode.DRIVING
};
directionsService.route(request, function(response, status) {
if ( status == google.maps.DirectionsStatus.OK ) {
@bludnic
bludnic / app.scss
Created September 9, 2017 17:59
Custom icons for ion-tabs
/** Custom Icons **/
ion-icon {
&[class*="ci-"] {
// Instead of using the font-based icons
// We're applying SVG masks
mask-size: contain;
mask-position: 50% 50%;
mask-repeat: no-repeat;
background: currentColor;
width: 1em;
@bludnic
bludnic / post.component.ts
Created September 17, 2017 14:34
cordova-facebook-ads Native Banner
ionViewDidEnter(){
this.initFacebookAds();
};
ionViewDidLeave(){
if (!this.platform.is('cordova')) return;
FacebookAds.removeNativeAd('112713919406063_117179372292851');
};
initFacebookAds() {
@bludnic
bludnic / node-folder-structure-options.md
Created December 31, 2017 05:53 — forked from lancejpollard/node-folder-structure-options.md
What is your folder-structure preference for a large-scale Node.js project?

What is your folder-structure preference for a large-scale Node.js project?

0: Starting from Rails

This is the reference point. All the other options are based off this.

|-- app
|   |-- controllers
|   |   |-- admin
@bludnic
bludnic / i18n.js
Last active January 24, 2018 13:46
Mongoose i18n plugin
const mongoose = require('mongoose');
const mapObject = (Obj) => {
if (Array.isArray(Obj)) {
} else if(typeof Obj === 'object') {
} else {
}
const isArray = (str) => {
console.log('str', str);
if (str.indexOf('[].') > -1) {
const split = str.split('[].')
console.log('split', split);
return {
name: split[0],
value: split[1]
}
}
@bludnic
bludnic / i18n.js
Created January 25, 2018 22:36
Multilingual schema mongoose plugin
import mongoose from 'mongoose'
import traverse from 'traverse'
const bodyToLocalized = (body, fields, lang = 'en') => {
fields.forEach(field => {
if (field in body) {
body[field + '.' + lang] = body[field]
delete body[field]
}
})
@bludnic
bludnic / tour.js
Created January 25, 2018 22:37
Koa.js router example
import Router from 'koa-router'
import Tour from './../models/tour'
import TourController from './../controllers/tour'
import setLang from './../middleware/setLang'
import { toLocalized, toLocalized2, bodyToLocalized, localizedToBody } from './../helpers/i18n'
const router = new Router()
/*
https://medium.com/@zurfyx/building-a-scalable-node-js-express-app-1be1a7134cfd
https://medium.com/@xoor/building-a-node-js-rest-api-7-request-validation-43c144300d06
@bludnic
bludnic / .eslintrc.json
Created February 15, 2018 13:00 — forked from leny/.eslintrc.json
ESLint config file for node.js + ES6 projects.
{
"env": {
"node": true,
"es6": true
},
"ecmaFeatures": {
"arrowFunctions": true,
"blockBindings": true,
"classes": true,
"defaultParameters": true,