Skip to content

Instantly share code, notes, and snippets.

View jrallison's full-sized avatar

John Allison jrallison

View GitHub Profile
jQuery("#pages ul li").hover(function(){
jQuery(this).stop(true).animate({
marginTop: "10px"
}, 250);
}, function(){
jQuery(this).stop(true).animate({
marginTop: "0px"
}, 250);
});
def first_n_primes(n)
return [] if n <= 0
@primes ||= [2]
x = @primes.last + 1
until @primes.length >= n
prime = true
@primes.each do |p|
Nameserver trace for challenge.gov:
Looking for who is responsible for root zone and followed d.root-servers.net.
Looking for who is responsible for gov and followed f.usadotgov.net.
Looking for who is responsible for challenge.gov and followed a.ns.zerigo.net.
Nameservers for challenge.gov:
c.ns.zerigo.net returned (SERVFAIL)
a.ns.zerigo.net returned (SERVFAIL)
var image = new Image();
image.src = url;
image.onload = function() {
// Display image
};
@jrallison
jrallison / parameterized_cache.html.erb
Created January 20, 2011 19:22
Easily mix dynamic content with fragment caching
<% @somethings.each do |something| %>
<%= cache("somethings:#{something.id}", :time => something.created_at) do %>
<div class="something">
<%= render "somethings/expensive_calculation" %>
<!-- time.strftime(...) calculated dynamically every time -->
<p class="timestamp"><%= time.strftime("%B %d, %Y") %></p>
</div>
<% end %>
<% end %>
# Model
class Model < ActiveRecord::Base
default_scope where(:hidden => false)
def hide!
update_attributes!(:hidden => true)
end
end
@jrallison
jrallison / gist:977391
Created May 17, 2011 21:02
Everything you need to know about rollout

1) Rollout configuration is in models

/web/models/lib/models/config/rollout.rb

$rollout = Rollout.new(REDIS)

$rollout.define_group(:admin) do |user|
  user.admin?
end
@jrallison
jrallison / gist:1264762
Created October 5, 2011 15:40
Mixpanel server events
# In controllers
mixpanel("event name")
# Anywhere else
Mixpanel.new(:event => "event name", :id => some_user.id, :ip => ???).track!
# ApplicationController
def mixpanel(event, opts = {})
unless current_user.admin? || masquerading?
opts = {:event => event, :id => current_user.id, :ip => request.remote_ip}.merge(opts)
@jrallison
jrallison / gist:1370496
Created November 16, 2011 16:11
results

EXPLAIN

mysql> explain SELECT * FROM `submissions` WHERE `submissions`.`id` = 5334;
+----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
| id | select_type | table       | type  | possible_keys | key     | key_len | ref   | rows | Extra |
+----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+
|  1 | SIMPLE      | submissions | const | PRIMARY       | PRIMARY | 4       | const |    1 |       | 
+----+-------------+-------------+-------+---------------+---------+---------+-------+------+-------+

1 row in set (0.01 sec)

@jrallison
jrallison / gist:1483238
Created December 15, 2011 22:31
Admin assistant and Rails 3.0.10 issue.
diff --git a/Gemfile b/Gemfile
index 861f72a..e63813d 100644
--- a/Gemfile
+++ b/Gemfile
@@ -5,7 +5,8 @@ gem 'rails', '3.0.10'
# Bundle edge Rails instead:
# gem 'rails', :git => 'git://github.com/rails/rails.git'
-gem 'sqlite3'
+gem 'mysql'