Skip to content

Instantly share code, notes, and snippets.

View teone's full-sized avatar

Matteo teone

  • Intel
  • San Francisco
View GitHub Profile
@teone
teone / Gruntfile.js
Last active August 29, 2015 14:10
Basic Grunt configuration for compass and livereload
module.exports = function(grunt) {
// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
watch: {
scripts: {
files: ['sass/*.scss'],
tasks: ['compass'],
options: {
@teone
teone / lbdecorators.js
Last active August 29, 2015 14:22
Example, how to cache a request with loopback
'use strict';
angular.module('lbServices')
.config(function($provide) {
// store if a request is being processed
var pending = false;
$provide.decorator('Access_credential', function($delegate, $q, $cacheFactory){
@teone
teone / proxy.js
Created October 29, 2015 15:57
Setup a proxy with gulp and browsersync. Please note that this is not a complete Gulp File, it is just to remember how to set up a proxy.
// please note that this is not a complete Gulp File,
// it is just to remember how to set up a proxy
var httpProxy = require('http-proxy');
var proxy = httpProxy.createProxyServer({
target: 'http://0.0.0.0:9000'
});
proxy.on('error', function(error, req, res) {
@teone
teone / common
Created December 8, 2015 00:17
ConfigParser
[gui]
gui_a=common
gui_b=common
[server]
server_a=common
server_b=common
@teone
teone / index.js
Last active January 31, 2016 02:53
Async Loop With Generators and Promises
'use strict';
// async function (eg: rest call)
const makeRequest = function (endpoint) {
return new Promise(function (resolve, reject) {
resolve(endpoint);
});
}
// generator function
@teone
teone / us.json
Created February 8, 2016 17:04
Us Topo Json
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@teone
teone / filter.js
Created February 8, 2016 21:19
Oder Object By Key Filter
angular.module('myModule', [])
.filter('orderObjectByKey', function(lodash) {
return function(items) {
if(!items){
return;
}
return lodash.reduce(Object.keys(items).reverse(), (list, key) => {
list[key] = items[key];
@teone
teone / toBeSimilar.js
Created February 12, 2016 01:18
Jasmine Custom Matcher - toBeSimilar
// test that numbers are similar with a tolerance of 0.1
var customMatchers = {
toBeSimilar: (util, tester) => {
const tolerance = 0.1;
return {
compare: (actual, expected) => {
return {
@teone
teone / karma.conf.js
Created May 13, 2016 16:37
Test Suites with Karma
// Karma configuration
// this is to load a different suite of test while developing
var testFiles = '*'; // by default load all js files
if(process.argv[4]){
// if a param is specified, read only that file
testFiles = process.argv[4];
}
var wiredep = require('wiredep');
@teone
teone / test.js
Last active April 17, 2020 19:44
Mocking promises in Angular Karma/Jasmine tests
(function () {
'use strict';
describe('The service', () => {
let service, scope;
const resolveValue = 'The value you want to resolve.';
const mock = {
promise: () => {
return {