Skip to content

Instantly share code, notes, and snippets.

Property.all.each do |property|
property.activity_logs.each do |activity_log|
iterations = activity_log.activity_log_iterations.order('iteration_time desc')
iterations.each_with_index do |iteration, index|
next_iteration = iterations[index+1]
if next_iteration.present?
iteration.update_column(:end_date, next_iteration.iteration_time)
end
end
end
@dubilla
dubilla / activity_log_iteration_set_end_date.rb
Created February 9, 2014 16:34
activity_log_iteration_set_duration_in_days.rb
ActivityLogIteration.latest.where('end_date is null').find_each do |iteration|
iteration.set_duration_in_days_until_today
iteration.save
end
@dubilla
dubilla / _space_fields.html.haml
Created March 7, 2014 22:52
nested_form unique id
- object_id = f.object_name.gsub(/[^0-9]+/,'') || f.options[:child_index]
@dubilla
dubilla / property-spaces-ctrl.js.coffee
Created March 7, 2014 23:42
jQuery to Angular tie-up
$document.on 'nested:fieldAdded and:again', (event) ->
$scope.$apply ->
$compile(event.field)($scope)
true
true
@dubilla
dubilla / gist:11191245
Created April 22, 2014 19:24
Ellipsis on Text Overflow
I narrowed it down:
1. The element on the right must be in the DOM before the element on the left, and have float: right
2. The element on the left must have display: block, float: none, white-space: nowrap, overflow: hidden, text-overflow: ellipsis
= f.input :space_condition, collection: ['raw', 'pre-existing', 'pre-built', 'white box', 'core and shell'], label_method: :capitalize, label: "Space condition", :input_html => {:id => "space_condition_{{$index}}", :'ng-model' => 'space.space_condition', :'ng-init' => 'space.space_condition=""'}
describe 'Deal Term Display', ->
HTML = '<div deal-terms></div>'
scope = elem = DealTerm = null
beforeEach ->
inject ($compile, $rootScope, _DealTerm_) ->
DealTerm = _DealTerm_
scope = $rootScope.$new()
scope.log = deal_terms: []
scope.showthis = true
@dubilla
dubilla / gist:252e4c8d03b9db87a909
Created August 25, 2014 15:38
.git/hooks/pre-push
#!/usr/bin/env ruby
# Read this blog to know more about this script.
#
# http://blog.bigbinary.com/2013/09/19/do-not-allow-force-pusht-to-master.html
class PrePushHandler
def handle
reject if pushing_to_master? && forced_push?
# Player 1 plays 0s
# Player 2 plays 1s
if item.even?
box[move] = 'X'
elsif item.odd?
box[move] = '0'
end
# Did player 1 win?
if item.odd? and item > 3 and player_winner?(box, '0')
@dubilla
dubilla / gist:4c98e30ea6619533a338
Created March 31, 2015 20:47
Git Branches Command
alias branches="git for-each-ref --sort=-committerdate refs/heads/ --format='%1B[0;32m%(authorname)%09%1B[0;36m(%(committerdate:relative))%09%1B[0;33m%(refname:short)%09%1B[m% (subject)' --count 10 | tail -r | column -t -s $'\t'"