Skip to content

Instantly share code, notes, and snippets.

@joesavak
joesavak / presidentrun.rb
Created January 10, 2012 22:55
how to run for president
#gotta be insane to do this, and american and 35 or older
if self.sane || !self.american || self.age < 35
exit(1)
end
#assumes all affairs will become public by the time the election is over
affair-factor = (all_affairs - repented_affairs) * -1
#if your religion isn't that of our founding fathers- you have problems.
if self.religion == public.perceived_founding_father_religion
@joesavak
joesavak / deploy.rb
Created June 21, 2011 17:40
sunspot bounce in deploy.rb
set somevars, "foobar"
namespace :deploy do
task :default do
update
someother_task
reindex_solr
end
task :reindex_solr do
@joesavak
joesavak / sunspot.yml
Created June 21, 2011 17:37
test_sunspot.yml
qa:
solr:
hostname: localhost
port: 8982
log_level: INFO
master_solr:
hostname: masterserver.mydomain.com
port: 8982
log_level: INFO
auto_commit_after_request: true
function postToLinkedIn(comment) {
IN.API.Raw("people/~/current-status")
.method("PUT")
.body(JSON.stringify(comment))
.result(handleLIResults)
.error(handleLIErrors);
};
function handleLIErrors(error) {
@joesavak
joesavak / renderupdateliscript.rb
Created June 3, 2011 18:44
renderupdateliscript
postcomment = "blah blah must be < 140. Oh and # are probably a good idea to use in here".
liscript = liscript +%&postToLinkedIn("&+postcomment+%&");&
render :update do |page|
if !liscript.blank?
page << liscript
end
#other page updates here
end
def saveliuid
user = current_user
liuid = params[:liuid]
liname = params[:liname]
user.li_uid = liuid
user.li_name = liname
user.save!
respond_to do |format|
format.js do
<script type="text/javascript" src="http://platform.linkedin.com/in.js">
api_key: <%=@liapp %>
authorize: true
onLoad: onLinkedInLoad
</script>
<script type="text/javascript">
function onLinkedInLoad() {
IN.Event.on(IN, "auth", onLinkedInAuth);
$('#usingstoredLI').hide();
@joesavak
joesavak / linkedinfields.rb
Created June 3, 2011 17:39
LinkedIn fields
class AddLiuidToUsers < ActiveRecord::Migration
def self.up
add_column :users, :li_uid, :string
add_column :users, :li_name, :string
end
def self.down
remove_column :users, :li_uid
remove_column :users, :li_name
end
begin
@graph = Koala::Facebook::GraphAPI.new(user.fbaccess)
str = "hello fb world"
link = HOSTURL+"/comments/"+id #hostURL is an env variable for us
returnstr = @graph.put_wall_post(str,{:name=>"linkName",:link=>link})
rescue
#eventually we'll have more logic here, but we basically turn it off for now (no more posts if failure)
user.fbaccess = nil
user.fbusername = nil
user.fb_uid = nil
@joesavak
joesavak / savefbuid.rb
Created May 20, 2011 20:09
savefbuid.rb
def savefbuid
user = current_user
fbuid = params[:fbuid]
fbaccess = params[:fbaccess]
user.fb_uid = fbuid
user.fbaccess = fbaccess
@graph = Koala::Facebook::GraphAPI.new(fbaccess)