Skip to content

Instantly share code, notes, and snippets.

View felippenardi's full-sized avatar

Felippe Nardi felippenardi

View GitHub Profile
@felippenardi
felippenardi / README.md
Created June 1, 2015 17:56
SVN Statuses Cheatsheet

The common SVN statuses cheatsheet

  • U: Working file was updated
  • G: Changes on the repo were automatically merged into the working copy
  • M: Working copy is modified
  • C: This file conflicts with the version in the repo
  • ?: This file is not under version control
  • !: This file is under version control but is missing or incomplete
  • A: This file will be added to version control (after commit)
  • A+: This file will be moved (after commit)
@felippenardi
felippenardi / running-protractor-with-docker.md
Last active July 19, 2020 04:38
Running Protractor Headless with Docker

Running Protractor Headless with Docker

Setting up Docker

1st Docker: Selenium Webdriver

This docker image is a Selenium Webdriver server where our specs will be directed against. It contains the Firefox and Chrome to run our specs headless. It also provides us VNC access to check what is going on the browser.

$ docker run --rm --net="host" -e VNC_PASSWORD=pancakes elgalu/selenium:v2.45.0-ssh3
@felippenardi
felippenardi / readme.md
Last active February 1, 2024 11:06
Benchmarking AngularJS performance

Benchmarking AngularJS performance

Things to optmize

  • Use one-time-bind on expressions ( {{::value}} )
  • Replace $scope.$apply() with $scope.$digest() whenever possible
  • Move filters to controllers

Measuring Watch list

To get the total watchers on the current page, you can run this script on the browser console:

@felippenardi
felippenardi / vim-with-pathogen.md
Created September 18, 2015 22:09
Using Vim Pathogen with git submodules

Updating all submodules after clonning your vim files

git submodule update --init --recursive

@felippenardi
felippenardi / post-commit
Last active October 20, 2015 01:37
Sending your commits to Rescue Time
#!/bin/sh
#
# An example hook script to log commit messages
# as a 'daily highlight' in RescueTime Premium
#
# See README.md for more information
#
# To enable this hook:
#
# 1. Place this file in .git/hooks and rename to "post-commit".
@felippenardi
felippenardi / bookmarklet.js
Created January 18, 2016 16:39
Pivotal Tracker Branch Naming Generator
javascript: (function ($) {
var storyTitles = [];
var story = $('.story .details').closest('.story').first();
if(story){
var title = story.find('.editor.name').val();
var id = /story_(\d+)/.exec(story.attr('class'))[1];
var storyType = story.find(".story_type .selection").text();
var gitptTitle = id + '-' + title;
var translate = {
"ä": "ae", "ö": "oe", "ü": "ue", "ß": "ss"
@felippenardi
felippenardi / 0_reuse_code.js
Created June 19, 2016 14:06
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console

Testing an Angular $resource factory

This is an example of how to test an Angular Resource created with $resource.

Live Demo

Important take aways:

  • Do not mock $resource. Instead, you can use the resource's methods and assert that it is making the right API call. By doing that you can later change the implementation (for example for replace $resource for Angular Cached Resource) without needing toi go change all previous tests.
  • When intercepting the response of a custom method, do not transform the response string into json yourself. When you use the transformResponse action property of a $resource, you replace the default angular parser that is transforming backend response from string to JSON. It has some logic to ensure that the response is a JSON and can be parsed securely. You can use it by injecting $http into your factory and using `$http.defaults.transformRespon
# Testing an Angular $resource factory
#angular #medium
Learn from live example how to test a $resource factory. What to test? What /not/ to test? When to use $resource? These questions will be answered here.
[DEMO LINK](https://gist.run/?id=38949509eed11e6c1527218385579f80)
Let's start with a brief review.
## What is $resource and when to use it?