Heavy metaprogramming ahead...
This is an attempt/experiment at being able to temporarily observe an active record through callbacks.
def a | |
e = Event.order("id DESC") | |
e = e.offset(3) | |
e = e.limit(1) | |
e | |
end | |
a.count |
# Allows you to wrap every class method of your class around some code that | |
# can be run before and/or after every single class methods. | |
# | |
# ==== Example | |
# | |
# class MyClass | |
# | |
# extend MethodWrapper | |
# before_method :i_am_first | |
# after_method :i_am_last |
module Foo | |
class C | |
def bar | |
self.new # I want this to return an object of type Fubar | |
end | |
end | |
end | |
class Fubar |
# Configure colors, if available. | |
if [ -x /usr/bin/tput ] && tput setaf 1 >&/dev/null; then | |
c_reset='\[\e[0m\]' | |
c_user='\[\e[0;32m\]' | |
c_path='\[\e[1;34m\]' | |
c_git_clean='\[\e[0;37m\]' | |
c_git_staged='\[\e[0;32m\]' | |
c_git_unstaged='\[\e[0;31m\]' | |
else | |
c_reset= |
# db/migrate/20121112152734_create_users.rb | |
class CreateUsers < ActiveRecord::Migration | |
def change | |
create_table :users do |t| | |
t.string :name | |
t.integer :groups_count, :default => 0 | |
t.timestamps | |
end | |
end |
I have a controller/action with a helper path like this : | |
new_controller_path(:foo => {:record_type => 'Group', :record_id => group.id}) # This returns /foo/new?foo[record_type]=Group&foo[record_id]=123 which is what I want. | |
# I was hoping one of these two would return the SAME THING as above. | |
new_controller_path(Group.new(:record => group)) # This returns /foo/new but I want same thing as above. | |
new_controller_path(:foo => Group.new(:record => group)) # This returns /foo/new but I want same thing as above. | |
# My ultimate goal was to reduce the length of the helper line a bit. |
# While on master which is up to date. | |
git checkout -b feature9 | |
# <work>, <commit>, <work>, <commit>, ... | |
git fetch origin/master | |
git rebase master | |
git checkout master | |
git pull | |
git rebase feature9 | |
# Oopps, I wanted to do -i | |
git reglog |
+------------+-------------+------------+-------------+------------+ | |
| date | video_views | clip_views | video_plays | clip_plays | | |
+------------+-------------+------------+-------------+------------+ | |
| 2016-09-21 | 9166 | 2237 | 2342 | 1622 | | |
| 2016-09-22 | 63967 | 20235 | 23900 | 15616 | | |
| 2016-09-23 | 184224 | 69347 | 103441 | 51579 | | |
| 2016-09-24 | 62307 | 17288 | 25074 | 12300 | | |
| 2016-09-25 | 27367 | 7250 | 6499 | 5060 | | |
| 2016-09-26 | 51912 | 13901 | 12038 | 10471 | | |
| 2016-09-27 | 61551 | 19965 | 18761 | 15030 | |
This is an implementation similar to setInternal()
but will not start the delay/loop again until the callback has finished (presuming it returned a promise). Im interested to know if there's a better way to do this. I choose this rather than using setInterval()
because I wanted to make sure it would not start over if the callback took longer than the interval time.
The callback function will only be called once an initial delay has passed. It would be simple to add a call to cb()
before calling the loop.
Let me know what you think!