Skip to content

Instantly share code, notes, and snippets.

@linusthe3rd
linusthe3rd / gist:705094
Created November 18, 2010 15:08
Example of how to write a refresh method
(function() {
//set up your widget
dojo.declare("MyTable", dijit._Widget, {
/*
* An example of a Refresh method in a widget
*/
refresh: function(){
(function() {
//set up your widget
dojo.declare("MyTable", dijit._Widget, {
postCreate: function(){
this.inherited(arguments);
//initialize your default state...
float x = (float) getLocation().getX() / width;
float y = (float) (height - getLocation().getY()) / height;
float w = (float) getSize().getWidth() / width;
float h = (float) getSize().getHeight() /
float radius = (w < h) ? w : h;
gl.glBegin(GL2.GL_TRIANGLE_FAN);
gl.glVertex2f(x, y);
for(int i = 0; i<360; i+=5){
gl.glVertex2f(x + (float)Math.sin(i) * radius, y + (float)Math.cos(i) * radius);
test "should create camp" do
assert_difference('Camp.count') do
post :create, :camp => {
:name => "Camp Tester",
:uri => "test-camp",
:email_address => "test@test.com",
:address => {
:street_1 => "mccormick rd",
:city => "barrer",
:state => "MA",
class Address < ActiveRecord::Base
belongs_to :addressable, :polymorphic => true
validates :addressable, :presence => true
validates :street_1, :presence => true
validates :city, :presence => true
validates :state, :presence => true, :length => { :minimum => 2 }
validates :zip_code, :presence => true, :zipcode_format => true, :length => { :minimum => 5, :maximum => 10 }
validates :country, :presence => true
end
@linusthe3rd
linusthe3rd / circles.cpp
Created January 30, 2011 18:54
The two methods used to create circles in opengl
/*
* Function that handles the drawing of a circle using the triangle fan
* method. This will create a filled circle.
*
* Params:
* x (GLFloat) - the x position of the center point of the circle
* y (GLFloat) - the y position of the center point of the circle
* radius (GLFloat) - the radius that the painted circle will have
*/
void drawFilledCircle(GLfloat x, GLfloat y, GLfloat radius){
@linusthe3rd
linusthe3rd / gist:828176
Created February 15, 2011 20:26
Attaching an event callback to an iFrame's onload event in IE
/**
* This code comes from JeremyMiller on the following thread:
* http://bytes.com/topic/javascript/answers/510057-iframe-ie-onload-problem#post3402334
*/
eventPush(document.getElementById('frame_id'),'load',function () {myFrameOnloadFunction();});
function eventPush(obj, event, handler) {
if (obj.addEventListener) {
obj.addEventListener(event, handler, false);
} else if (obj.attachEvent) {
def index
query = ''
queryHash = Hash.new
if params[:min_age]
append_to_query(query, 'min_age >= :min_age')
queryHash[:min_age] = params[:min_age]
end
if params[:max_age]
@linusthe3rd
linusthe3rd / programs.rb
Created March 14, 2011 01:39
named scopes I am using
scope :open, lambda {
joins(:program_populations).
where('program_populations.current_population < program_populations.max_population').
group("programs.id")
}
scope :closed, lambda {
joins(:program_populations).
where('program_populations.current_population >= program_populations.max_population').
group("programs.id")
}
SQL (1.2ms) describe `campers_camps`
SQL (1.2ms) describe `campers_camps`
Creating scope :open. Overwriting existing method Program.open.
Creating scope :open. Overwriting existing method Session.open.
Loaded suite functional/camp/programs_controller_test
Started
SQL (0.1ms) BEGIN
SQL (0.7ms) SHOW TABLES
Camp Load (0.5ms) SELECT `camps`.* FROM `camps` WHERE (`camps`.`id` = 665138414) LIMIT 1
Processing by Camp::ProgramsController#index as HTML