Skip to content

Instantly share code, notes, and snippets.

View iirving's full-sized avatar
💭
Looking for the next Thing

Ian irving iirving

💭
Looking for the next Thing
View GitHub Profile
@iirving
iirving / add ajax style loading image to any form
Created August 16, 2010 19:03
as per Adding a “loading” image to (just about) any form on submit, with jQquery
<script language="javascript" type="text/javascript">
$("form").submit(function() {
if ($('#loading_image').length == 0) { //is the image on the form yet?
// add it just before the submit button
$(':submit').before('<img src="/images/ajax-loader.gif" style="display: none;" alt="loading" id="loading_image">')
}
$('#loading_image').show(); // show the animated image
$(':submit',this).attr('disabled','disabled'); // disable double submits
return true; // allow regular form submission
});
@iirving
iirving / Initialize max value in Fat Controller
Created August 23, 2010 20:54
as per Initialize max value in Ruby on Rails ActiveRecord, automagically
class ItemController < ApplicationController
....
# GET /items/new
# GET /items/new.xml
def new
@item= Item.new
@item.display_order = get_new_item_display_order
respond_to do |format|
format.html # new.html.erb
@iirving
iirving / Initialize max value in Fat Model, the local way
Created August 23, 2010 21:44
as per Initialize max value in Ruby on Rails ActiveRecord, automagically
class Item < ActiveRecord::Base
validates_presence_of :display_order
validates_uniqueness_of :display_order
...
def after_initialize
if self.display_order.nil? then #if the section is new (created) and sequence order has no value
item_display_order_max_value = Item.maximum('display_order')
item_display_order_max_value = 0 if item_display_order_max_value.nil?
self.display_order = item_display_order_max_value + 1
end
@iirving
iirving / Initialize max value the Server Way in a Fat Model, the server way
Created August 23, 2010 23:14
as per Initialize max value in Ruby on Rails ActiveRecord, automagically
class Item < ActiveRecord::Base
validates_presence_of :display_order
validates_uniqueness_of :display_order
...
def after_initialize
if self.display_order.nil? then #if the section is new (created) and sequence order has no value
if $item_display_order_max_value.nil? then
$item_display_order_max_value = Item.maximum('display_order')
$item_display_order_max_value = 0 if item_display_order_max_value.nil?
$item_display_order_max_value += 1
@iirving
iirving / Initialize max value the Server Way in a Fat Model, the server way, revised
Created August 25, 2010 21:14
as per Initialize max value in Ruby on Rails ActiveRecord, automagically
def after_initialize
if self.new_record? then
if $item_sequence_order_max_value.nil? ||
( (!$item_display_order_max_dateTime.nil? )&& ( ( (Time.now - $item_display_order_max_dateTime).to_i ) > ( 10 *60 ) )) then
$item_display_order_max_value = self.class.maximum('display_order')
$item_display_order_max_value = 0 if $page_display_order_max_value.nil?
end
$item_display_order_max_dateTime = Time.now
$item_display_order_max_value += 1
self.display_order = $item_display_order_max_value
@iirving
iirving / Initialize max value the Server Way in a Fat Model, the server way, revised with lots of AutoMagic
Created August 26, 2010 19:59
as per Initialize max value in Ruby on Rails ActiveRecord, automagically
def after_initialize
if self.new_record? then
key = self.class.to_s
max_initialize_value_field = 'display_order'
$max_initialize_value = Hash.new() if !(defined? $max_initialize_value)
$max_initialize__value_dateTime = Hash.new() if !(defined? $max_initialize__value_dateTime)
if ( $max_initialize_value[key].nil? ) || ( ( !$max_initialize__value_dateTime[key].nil? )&&
( ( (Time.now - $max_initialize__value_dateTime[key]).to_i ) > ( 10 *60 ) )) then
max_initialize_value = self.class.maximum(max_initialize_value_field)
max_initialize_value = 0 if max_initialize_value.nil?

Development Contract Killer

A fork of the popular open-source contract for web designers and developers by Stuff & Nonsense, reworded for developers


Between us [company name] and you [customer name]

Keybase proof

I hereby claim:

  • I am iirving on github.
  • I am iani (https://keybase.io/iani) on keybase.
  • I have a public key whose fingerprint is 7175 EE5A 7C92 B04F 0D07 2170 9B7D 4399 20F1 EEA1

To claim this, I am signing this object:

@iirving
iirving / Light.js
Created April 15, 2016 20:00
light observers
import Ember from 'ember';
export default Ember.Object.extend( {
isOn: false,
color: 'yellow',
age: null,
description: Ember.computed('isOn', function() {
return'The bulb is '+ this.get('color') + ' and the light is set to ' + this.get('isOn');
}),
@iirving
iirving / app.js
Created April 19, 2016 18:51
bindings
import Ember from 'ember';
//import Resolver from 'ember/resolver';
//import loadInitializers from 'ember/load-initializers';
import config from './config/environment';
import teacher from './teacher';
import student from './student';
import myName from './myName';
import user from './user';