Skip to content

Instantly share code, notes, and snippets.

View ethagnawl's full-sized avatar
🐢

Pete Doherty ethagnawl

🐢
View GitHub Profile
var times = {
Schedule: {
"2014-09-26T00:00:00": [1,23],
"2014-09-27T00:00:00": [9,14]
}
};
function formatHour(hour) {
return hour > 12 ?
@ethagnawl
ethagnawl / gist:4f21692fa2ea2664cb85
Created October 7, 2014 16:17
Angular Watcher Count
// ripped directly from http://www.airpair.com/angularjs/posts/top-10-mistakes-angularjs-developers-make
(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); })();
@ethagnawl
ethagnawl / gist:dc3b2c5e64d9270928bc
Last active August 29, 2015 14:07
Populate Wildcards
# if you're interested, you can follow the conversation around how to make `populate_wildcards`
# more idiomatic on /r/ruby:
# https://www.reddit.com/r/ruby/comments/2iyzab/is_there_a_more_idiomatic_andor_functional_way_to/
# my initial approach
def populate_wildcards(a,b)
a.merge(b) { |key, left, right|
if left.is_a? Hash
populate_wildcards(left, right)
@ethagnawl
ethagnawl / gist:b08ed48ec25984f49f0d
Created October 16, 2014 00:14
Rails 4 Mute Generators
# from http://blog.crowdint.com/2013/06/14/testing-rails-with-minitest.html
# config/initializers/generators.rb
Rails.application.config.generators do |g|
g.helper false
g.assets false
g.view_specs false
end
@ethagnawl
ethagnawl / gist:1ef5205a8cc45d8dc9de
Created October 17, 2014 20:56
allow absolutely positioned element to overflow parent with overflow hidden and position relative
# see http://jsfiddle.net/xfgh6yew/
#outer-0 {
/*
separating `position:relative` from `overflow: hidden`
allows the `position: absolute` overflow to happen
*/
position: relative;
}
@ethagnawl
ethagnawl / gist:0cadc3c3f82782b6ffed
Last active August 29, 2015 14:08
Watch Angular Factory/Service Value (via getter)
function watchFactoryValue(localValue, factoryGetter) {
$scope.$watch(factoryGetter, function () {
localValue = factoryGetter();
});
};
@ethagnawl
ethagnawl / get_nested_hash_keys.rb
Last active August 29, 2015 14:08
Get nested hash keys
def get_nested_hash_keys(hash)
# there must be a more clever way to do this using reduce/inject...
hash.map { |key, value|
if value.is_a? Hash
[key, get_nested_hash_keys(value)]
else
key
end
}.flatten.sort
@ethagnawl
ethagnawl / gist:6b5ab370c33fd7dcce73
Created November 17, 2014 23:12
Find current NPM dependency versions
require 'json'
package = File.open 'package.json', 'r'
json = JSON.parse package.read()
deps = json['dependencies'].keys
versions = deps.map { |dep| `npm list --depth=0 | grep #{dep}` }.map { |version| version.split(/.?\s(.+)/)[1] }
$(document).ready(function(){
countdown();
setInterval(countdown, 1000);
function countdown () {
var now = moment(), // get the current moment
// May 28, 2013 @ 12:00AM
then = moment([2013, 4, 28]),
// get the difference from now to then in ms
ms = then.diff(now, 'milliseconds', true);
// If you need years, uncomment this line and make sure you add it to the concatonated phrase
@ethagnawl
ethagnawl / directives_without_specs.rb
Created December 17, 2014 15:34
Find directives without specs
# assumes some.directive.js/some.directive.spec.js naming convention
directives = (`find . -name *.directive.js`).split(/\r\n|\n/)
directive_specs = (`find . -name *.directive.spec.js`).split(/\r\n|\n/).map { |directive| directive.gsub(/\.spec/, '') }
directives_without_specs = directives - directive_specs
puts directives_without_specs