Skip to content

Instantly share code, notes, and snippets.

View plotti's full-sized avatar

Thomas Ebermann plotti

View GitHub Profile
@plotti
plotti / gist:2971911
Created June 22, 2012 10:27
Finding at-connectiosn
def find_at_connections()
values = []
usernames = persons.collect{|p| p.username}
i = 0
persons.each do |person|
t1 = Time.now
i += 1
person.feed_entries.each do |tweet|
#puts "#Analyzing tweet #{tweet.id}"
usernames.each do |tmp_user|
@plotti
plotti / gist:2972028
Created June 22, 2012 10:47
delayed Jobs
# A version that used delayed jobs to split the work among a lot of workers
# Deprecated because the bottleneck was querying the DB
# Same as find all valued connections only trying to make it faster
def find_delayed_at_connections(friend = true, follower = false, category = false)
usernames = persons.collect{|p| p.username}
persons.each do |person|
Delayed::Job.enqueue(AggregateAtConnectionsJob.new(person.id,self.id,usernames))
end
wait_for_jobs("AggregateAtConnectionsJob")
self.return_delayed_at_connections
@plotti
plotti / gist:2972316
Created June 22, 2012 11:56
Delayed Job helper
# Helper method that is used when creating delayed jobs.
def wait_for_jobs(jobname)
continue = true
while continue
found_pending_jobs = 0
Delayed::Job.all.each do |job|
if job.handler.include? jobname
found_pending_jobs += 1
end
if job.attempts >= 4
@plotti
plotti / gist:2972327
Created June 22, 2012 11:57
Searchable feeds
# Indexing the text field with solr
searchable do
text :text
integer :person_id
time :published_at
text :retweeters do
retweet_ids.collect{|retweet| retweet[:id]}
end
end
@plotti
plotti / gist:2972340
Created June 22, 2012 12:00
Solr at search
def find_solr_at_connections
users = {}
persons.each do |person|
users[person.id] = person.username
end
values = []
i = 0
persons.each do |person|
i += 1
t1 = Time.now
@plotti
plotti / gist:2972364
Created June 22, 2012 12:07
Solr results
Person 1 archaeologymag. Time per person: 7.783559.
Person 2 ArchaeologyDN. Time per person: 1.097274.
Person 3 archaeologynews. Time per person: 0.085687.
Person 4 NEAarchaeology. Time per person: 0.184254.
Person 5 CurrentArchaeo. Time per person: 0.116461.
@plotti
plotti / gist:2972459
Created June 22, 2012 12:26
benchmark
require 'benchmark'
puts Benchmark.measure{Project.find(1).find_at_connections}
31.660000 0.540000 32.200000 ( 35.293887)
@plotti
plotti / gist:3182164
Created July 26, 2012 13:55
User interests extraction
require '../config/environment'
interests = {}
rows = FasterCSV.read("#{RAILS_ROOT}/analysis/data/partitions/final_partitions_p100_200_0.2.csv")
rows.each do |row|
interests[row[0]] = {:category => row[1], :count => row[2]}
end
project = Project.last
ids = project.persons.collect{|p| p.twitter_id}
@plotti
plotti / gist:3182197
Created July 26, 2012 14:01
Sample output for zephoria
---
- - tech
- :count: 13
:names:
- - BillGates
- "7"
- - biz
- "23"
- - ev
- "17"
07/08/2014
5:28 pm
The battle is on! Im heutigen #HomeRunjoiz-Fight stehen sich Rap und Rock gegenüber: DritteStock vs. Dirty Sound Magnet! Jetzt auf www.joiz.ch/LIVE mitchatten und mit deiner Stimme im Voting über Sieg oder Niederlage entscheiden!
Photo
Public
0
Organic
0
Paid
0