Skip to content

Instantly share code, notes, and snippets.

View mstruve's full-sized avatar
🦄

Molly Struve mstruve

🦄
View GitHub Profile
@mstruve
mstruve / educations_controller.rb
Created August 24, 2012 21:48
Two Examples of methods that parse data from LinkedIn in order to get the Job and Education information for a user.
def linkedin
@user=current_user
client = LinkedIn::Client.new("API Key", "Secret Key")
client.authorize_from_access(current_user.link_token, current_user.link_secret)
#breakdown LinkedIn Hash into pieces in order to obtain data
@profile = client.profile
@school = client.profile(:fields => %w(educations))
@schools = @school.educations.all.map{|t| t}
@mstruve
mstruve / api.rb
Last active August 29, 2015 14:23
before do
client = Client.active.find_by(token: headers["Auth-Token"])
error!('Unauthorized. Invalid token.', 401) unless client
error!('Unauthorized action.', 403) unless client.user_authorization_required? && User.new(headers["X-Grpn-Email"]).authorized_action?(request.request_method)
end
@mstruve
mstruve / redis.rb
Created November 16, 2018 19:48
Redis Readonly Console
if ENV['REDIS_ACCESS_MODE'] == 'readonly'
class Redis
class Client
WRITE_COMMANDS = ::Rails.cache.data.command.map { |a| a[0] if a[2].include?('write') }.compact.to_set.freeze
def process(commands)
if commands.flatten.any? { |c| WRITE_COMMANDS.include?(c.to_s) }
raise NotImplementedError, "REDIS_ACCESS_MODE is set to 'readonly', disallowing writes"
end
@mstruve
mstruve / yay.rb
Created May 21, 2019 16:52
2016 Molly
respond_to do |format|
format.json { render :json => { :success => true, :message => 'yay' } }
end
@mstruve
mstruve / heap_dump_worker.rb
Created June 16, 2021 19:52
HeapDumpWorker
require 'objspace'
class HeapDumpWorker
include Sidekiq::Worker
sidekiq_options queue: :medium_priority
def perform(filename)
File.open(filename, 'w') do |f|
ObjectSpace.dump_all(output: f, full: true)