Skip to content

Instantly share code, notes, and snippets.

@reprah
reprah / rubeque_refactor.rb
Created October 11, 2013 16:55
Rewriting the index action of SolutionsController in Rubeque
# the current index action in SolutionsController (for comparison purposes)
# app/controllers/solutions_controller.rb
def index
@problem = Problem.find(params[:problem_id]) rescue (redirect_to "/" and return)
if !current_user_admin? && (@problem.nil? || [email protected]?(current_user))
redirect_to @problem and return
end
@top_solutions = Solution.where(problem_id: @problem.id, user_id: { "$nin" => [current_user.id] }).
desc(:score).desc(:updated_at).page(params[:page] || 1)
@reprah
reprah / io_nonblock_demo.rb
Created October 5, 2013 17:36
Ruby methods in io/nonblock
#
# Documenting io/nonblock and how the methods (nonblock?, nonblock=, nonblock{}) there behave
#
# server.rb
require 'socket'
TCPServer.open('localhost', 3030) do |server|
while client = server.accept
@reprah
reprah / SHA1.rb
Last active January 16, 2022 06:10 — forked from tstevens/SHA1.rb
#!/usr/bin/ruby
require 'rubygems'
require 'active_support/all'
require 'digest/sha1'
def leftrotate(value, shift)
return ( ((value << shift) | (value >> (32 - shift))) & 0xffffffff)
end
# FIPS 180-2 -- relevant section #'s below
@reprah
reprah / gist:5040180
Created February 26, 2013 17:10
Gist to submit to the Bundler issue tracker. Problems with Bundler after updating from version 1.0.22 to 1.30.
What I'm trying to accomplish:
- Updating Bundler version from 1.0.22 to 1.3.0 so it's compatible with Rails 4,
and then updating to Rails 4.0.0.beta1
Command I ran:
- gem update bundler (successfully installed bundler 1.3.0)
- bundle update rails (to 4.0.0.beta1 in gemfile)
What I expected to happen:
- For the rails gem to be updated