Skip to content

Instantly share code, notes, and snippets.

@eggie5

eggie5/_dsl.rb Secret

Created July 30, 2012 06:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eggie5/e6d46087596987ad480e to your computer and use it in GitHub Desktop.
Save eggie5/e6d46087596987ad480e to your computer and use it in GitHub Desktop.
#Databind model
u=User.new;u.id=1
u.add_friend(10.days.ago,2)
u.add_friend(7.days.ago,3)
u.add_follower(6.days.ago, 4)
u.add_friend(6.days.ago, 23)
u.add_friend(6.days.ago, 33);
u.remove_friend(5.days.ago, 2)
.................
#query model
#get current friends and followers on twitter
friends = u.friends
followers = u.followers
#get friends at time in past
friends=u.friends(at: 30.days.ago)
#find out when someone followed you
followers.sample.timestamp
#find your 'bros' (people who you follow and follow you back)
u.bros
#see all your new followers this month
a = u.followers(at: Time.now.beginning_of_month)
b = u.followers(at: Time.now)
new = b-a
ap u => (SEE BELOW FOR OUTPUT)
This is the output of my structure from the ap gem. How should I persist this? redis, postgres, etc???
It's basically two hashes one for followers and friends. The keys are dates and each key has an array events.
#<User:0x7fe08dd169b8
attr_accessor :followers = #<Timeline:0x7fe08dd16940
attr_reader :hash = {
"2012.07.23" => [
[0] {
:event => :follow,
:follower => 4,
:followee => 1
}
]
},
attr_reader :length = 1
>,
attr_accessor :friends = #<Timeline:0x7fe08dd16990
attr_reader :hash = {
"2012.07.19" => [
[0] {
:event => :follow,
:follower => 1,
:followee => 2
}
],
"2012.07.22" => [
[0] {
:event => :follow,
:follower => 1,
:followee => 3
}
],
"2012.07.23" => [
[0] {
:event => :follow,
:follower => 1,
:followee => 23
},
[1] {
:event => :follow,
:follower => 1,
:followee => 33
}
],
"2012.07.24" => [
[0] {
:event => :unfollow,
:follower => 1,
:followee => 2
}
]
},
attr_reader :length = 5
>,
attr_accessor :id = 1
>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment