Skip to content

Instantly share code, notes, and snippets.

@nicovalencia
nicovalencia / onerror.js
Last active August 29, 2015 13:58
Chrome dev tools source map auto-linking for unhandled Q.js rejection stack traces
var q = require('q');
if (debug) {
q.onerror = function(err) {
console.log(err); // auto-links source map refs in stack trace
};
}
somePromiseThatThrowsAnError
.then(function() { /* do stuff */ })
# Use to proxy commands through a proxy server:
Host your_destination_name
HostName your.destination
ProxyCommand ssh -i ~/.ssh/your_key -A -q your_user@your.proxy nc -q0 your.destination 22
ForwardAgent yes
(function () { var root = $(document.getElementsByTagName('body')); var watchers = []; var f = function (element) { if (element.data().hasOwnProperty('$scope')) { angular.forEach(element.data().$scope.$$watchers, function (watcher) { watchers.push(watcher); }); } angular.forEach(element.children(), function (childElement) { f($(childElement)); }); }; f(root); console.log(watchers.length); })();
/*
* Example directory/file structure:
*
* app
* |-- components/
* | -- user-profile/
* | |-- user-profile.js
* | |-- user-profile-directives.js
* | -- user-profile-services.js
* -- main.js
@nicovalencia
nicovalencia / injector.js
Created October 31, 2014 17:38
injector angular
function createInjector(modulesToLoad) {
var INSTANTIATING = {},
providerSuffix = 'Provider',
path = [],
loadedModules = new HashMap(),
providerCache = {
$provide: {
provider: supportObject(provider),
factory: supportObject(factory),
service: supportObject(service),
@nicovalencia
nicovalencia / http-backend-decorator.js
Last active August 29, 2015 14:10
Add global timeout to Angular $http
/**
* @monkeypatch
* $http gives us no way to add a global timeout default. This is critical
* for triggering the YOUR_FAULT_TOLERANCE module to handle timeouts after
* a reasonable amount of time:
*
* @upgrade instructions
* Ensure that arguments[x] is overriding the timeout property of the
* $httpBackend provider's constructor.
*
var items = [{
content: 'hotdog 1'
}, {
content: 'hotdog 2'
}, {
content: 'hotdog 3'
}, {
content: 'hotdog 4'
}, {
content: 'hotdog 5'
class RestrictPrecisionOnExistingMetrics < ActiveRecord::Migration
def up
ActiveRecord::Base.record_timestamps = false
begin
AnswersMetric.find_each(&:save)
MetricValue.find_each(&:save)
ensure
ActiveRecord::Base.record_timestamps = true
define([
'angular'
], function(angular) {
'use strict';
angular.module('common.pagination', [])
/**
* @ngdoc service
namespace :move_eei_content do
PROGRAM_IDS = [ 595, 596, 597, 598, 599, 600, 601, 602, 603, 613, 614, 615, 616, 617, 618, 849, 855, 856, 619, 620, 621, 622, 623, 625, 626, 627, 656, 628, 629, 630, 631, 632, 633, 634, 859, 882, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 624, 651, 652, 653, 654, 655, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667 ]
CIVIC_CHARACTER_FORMATION_ID = 32
desc 'moves selected eei programs to civic character formation champion'
task :run => :environment do
Tree.where(id: PROGRAM_IDS).each do |tree|
puts "Moving #{tree.title}..."