Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

# using after_save (this works)
class GameObserver < ActiveRecord::Observer
observe :game
def after_save(game)
game.record_win_or_tie
end
end
@ryanchin
ryanchin / gist:5097033
Created March 6, 2013 05:48
def self.update_rank_by klass
def self.update_rank_by klass
rank_class = (klass.name + "Rank").constantize
rank_by_col = "#{klass.name.underscore}_id".to_sym
rank = total_points = rank_by = 0
sum_points_by(rank_class, rank_by_col).find_in_batches do |points|
User.transaction do
points.each do |point|
rank_by_col_val = point.send(rank_by_col)
@ryanchin
ryanchin / gist:5096235
Last active December 14, 2015 13:49
result of self.update_rank after changing game.total_points to points.total_points
def self.update_rank_by klass
rank_class = (klass.name + "Rank").constantize
rank_by_col = "#{klass.name.underscore}_id".to_sym
select_sql = "points.user_id, points.#{rank_by_col},
SUM(points.points) total_points"
rank = total_points = 0
Point.select(select_sql).group(:user_id, rank_by_col).
order("total_points DESC").find_in_batches do |points|
User.transaction do
points.each do |point|
@ryanchin
ryanchin / gist:5073948
Created March 3, 2013 00:47
ps aux results
bitnami@domU-12-31-39-10-49-24:~$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.2 3540 1736 ? Ss Feb28 0:00 /sbin/init
root 2 0.0 0.0 0 0 ? S Feb28 0:00 [kthreadd]
root 3 0.0 0.0 0 0 ? S Feb28 0:06 [ksoftirqd/0]
root 4 0.0 0.0 0 0 ? S Feb28 0:28 [kworker/0:0]
root 5 0.0 0.0 0 0 ? S Feb28 0:00 [kworker/u:0]
root 6 0.0 0.0 0 0 ? S Feb28 0:00 [migration/0]
root 7 0.0 0.0 0 0 ? S Feb28 0:08 [watchdog/0]
root 8 0.0 0.0 0 0 ? S< Feb28 0:00 [cpuset]
@ryanchin
ryanchin / gist:5054673
Created February 28, 2013 06:23
httpd.conf
#
ServerRoot "/opt/bitnami/apache2"
#
# Listen: Allows you to bind Apache to specific IP addresses and/or
# ports, instead of the default. See also the <VirtualHost>
# directive.
#
# Change this to Listen on specific IP addresses as shown below to
# prevent Apache from glomming onto all bound IP addresses.
@ryanchin
ryanchin / passenger error
Created February 27, 2013 17:36
error encountered when I run passenger-install-apache2-module
mkdir -p ext/common/libboost_oxt
g++ -Iext -D_REENTRANT -I/usr/local/include -DHASH_NAMESPACE="__gnu_cxx" -DHASH _NAMESPACE="__gnu_cxx" -DHASH_FUN_H="<hash_fun.h>" -DHAS_ALLOCA_H -DHAS_SFENCE - DHAS_LFENCE -Wall -Wextra -Wno-unused-parameter -Wno-parentheses -Wpointer-arith -Wwrite-strings -Wno-long-long -Wno-missing-field-initializers -g -DPASSENGER_D EBUG -DBOOST_DISABLE_ASSERTS -o ext/common/libboost_oxt/aggregate.o -c ext/commo n/libboost_oxt/aggregate.cpp
In file included from ext/boost/src/pthread/thread.cpp:27:0,
from ext/common/libboost_oxt/aggregate.cpp:6:
ext/boost/src/pthread/timeconv.inl: In function âvoid
@ryanchin
ryanchin / gist:2765790
Created May 22, 2012 00:59
Not Sending via Sendgrid
Sent mail to test@example.com (976ms)
Date: Mon, 21 May 2012 17:46:03 -0700
From: Foo <info@Foo.com>
To: Test <test@example.com>
Message-ID: <4fbae1cd97173_147836a9bc5679f@MININT-4LBRRLS.mail>
Subject: Welcome to Foo, Test!
@ryanchin
ryanchin / gist:2727283
Created May 18, 2012 19:49
page ends with </htm
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><script type="text/javascript">var NREUMQ=NREUMQ||[];NREUMQ.push(["mark","firstbyte",new Date().getTime()]);</script>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="Copyright" content="Copyright (c) 2012 foo" />
<title>bar Dashboard</title>
<link href="/assets/bootstrap-27d6ee163b1ec85218082bd3ffe36e97.css" media="screen" rel="stylesheet" type="text/css" />
<link href="https://ajax.googleapis.com/ajax/libs/jqueryui/1.7.2/themes/redmond/jquery-ui.css" media="screen" rel="stylesheet" type="text/css" />