Skip to content

Instantly share code, notes, and snippets.

@cesarandreu
cesarandreu / debounce.js
Created January 30, 2014 21:37
Native debouncing for AngularJS
'use strict';
angular.module('debounce').factory('debounce', function($timeout, $q) {
return function(func, wait, immediate) {
var timeout;
var deferred = $q.defer();
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
@cesarandreu
cesarandreu / example.html
Last active August 29, 2015 13:55
Lets you set anchor tags that cause a full page reload instead of letting ngRoute handle the page-change
<!-- This link will be handled by ngRoute -->
<a href="/angularpage">AngularJS Link</a>
<!-- With directive, this link will cause a full page load and may be handled by your server -->
<a href="/railspage" trd-external>Rails Link</a>
<!-- Manually, this link will cause a full page load and may be handled by your server -->
<a href="/railspage" target="_self">Rails Link</a>
'use strict';
angular.module('debounce').factory('debounce', function($timeout, $q) {
return function(func, wait, immediate) {
var timeout;
var deferred = $q.defer();
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
// 1. How to check if one array has all elements of another?
var importedEmails = ['john@doe.com', 'janet@doe.com'],
existingEmails = ['john@doe.com', 'janet@doe.com', 'fred@mercury.com'];
if(!_.difference(importedEmails, existingEmails).length) console.log('already imported')
// > already imported
// **********************************************************
// 2. How to find what elements are common to two arrays?

Keybase proof

I hereby claim:

  • I am cesarandreu on github.
  • I am cesarandreu (https://keybase.io/cesarandreu) on keybase.
  • I have a public key whose fingerprint is 6D79 23DA 74B6 5C5C 1D91 0AC6 F99C 5388 AD58 560B

To claim this, I am signing this object:

{
"node": true,
"browser": true,
"esnext": true,
"bitwise": false,
"camelcase": false,
"curly": true,
"eqeqeq": true,
"immed": true,
"indent": 2,
angular.module('myApp3', [])
.run(function ($templateCache) {
$templateCache.put('myDirective1.html', '<div class="foo"> {{ msg }} </div>');
$templateCache.put('myDirective2.html', '<div class="bar"> {{ msg }} </div>');
})
.service('$myDirective', function () {
return function (messageFunction) {
function defaultMessageFunction (message) {
return 'Our message is: ' + message;
@cesarandreu
cesarandreu / command
Last active August 29, 2015 13:57
co-busboy will stay stuck waiting if you POST an empty form
curl -X POST http://localhost:9000/
'use strict';
/* this is placed in the root of your project */
module.exports = {
scripts: [
'lib/foo1.js',
'lib/*.js',
'src/*.js'
]
@cesarandreu
cesarandreu / gulp_alias.sh
Last active August 29, 2015 14:03
Alias for running gulp with harmony flag
# Good reminder that sometimes we overthink things
# First I tried this, obviously it doesn't work because it gets evaluated when you run the command
# alias gulp='node --harmony $(which gulp)'
# Then I tried this, which works but is sorta long...
# alias gulp='node --harmony $(for x ($(which -a gulp)); do; if [ -e $x ]; then echo $x; break; fi; done)'
#
# Expanded:
# for x ($(which -a gulp))