Skip to content

Instantly share code, notes, and snippets.

View akinsgre's full-sized avatar

Greg Akins akinsgre

View GitHub Profile
# check that user is logged in
def require_user
logger.info "Require User"
if current_user.nil?
session[:link_back] = request.url
redirect_to login_path
false
end
end
def require_user_no_linkback
# check that user is logged in
def require_user
if current_user.nil?
session[:link_back] = request.url
redirect_to login_path
false
end
end
@akinsgre
akinsgre / index.html.erb
Created February 24, 2012 20:25
Example of sortable "portlets" and saving position
<h1>MenuItems#index</h1>
<style>
.column { width: 170px; float: left; padding-bottom: 100px; }
.portlet { margin: 0 1em 1em 0; }
.portlet-header { margin: 0.3em; padding-bottom: 4px; padding-left: 0.2em; }
.portlet-header .ui-icon { float: right; }
.portlet-content { padding: 0.4em; }
.ui-sortable-placeholder { border: 1px dotted black; visibility: visible !important; height: 50px !important; }
#starting at line 243
def feeds_into_timescales(feeds)
# convert timescale (minutes) into seconds
seconds = params[:timescale].to_i * 60
# get floored time ranges
logger.info "Original Start time is " + feeds.first.created_at.to_s
logger.info "Original End time is " + feeds.last.created_at.to_s
start_time = get_floored_time(feeds.first.created_at, seconds)
end_time = get_floored_time(feeds.last.created_at, seconds)
logger.info "start_time = " + start_time.to_s + " & end_time is " + end_time.to_s
class ContactMethod < ActiveRecord::Base
validates_presence_of :name
def self.select_options
descendants.map { |c| c.to_s }.sort
end
end
class Phone < ContactMethod
end
@akinsgre
akinsgre / form_for.rb
Created December 8, 2011 14:29
Problems with Rails form_for tag
#This form "should" create a new contact and a new group_contact record. What I really
# want to do is to add an existing contact to a group. But can't figure out
# how to build a form_for that will let me do that.
#
# If I were creating my own form, I'd just put the group_id in a hidden field and let
# the user pick a contact from a select. Then I'd post to a groups_controller
# to add the contact to group.contacts.
#
# I'm just not seeing how to do that in a form_for
#
@akinsgre
akinsgre / gist:1405687
Created November 29, 2011 17:46
Trouble getting routes & link_to working
routes.rb
=================
resources :groups do
member do
post 'join'
put 'add_contact'
end
end
When I do "bundle exec rake routes" I get "add_contact_group" -> /groups/:id/add_contact
@akinsgre
akinsgre / test.rb
Created September 2, 2011 13:38
JSON generation
#ruby 1.9.2
require 'json'
class Item
def initialize(name, description )
@name = name
@description = description
end
def to_json(*a)
{"name" => @name, "description" => @description}.to_json(*a)
@akinsgre
akinsgre / Thing.java
Created August 19, 2011 14:49
Java object for DynaTree
public class Thing {
private String title ;
private List<Thing> children ;
public Thing(String title) { this.title = thing );
// getters and settors accordingly
}
List<Thing> things = new ArrayList<Thing>() ;
things.add(new Thing("One"));
@akinsgre
akinsgre / test.html
Created August 19, 2011 13:34
Assigning click events to dynamically loaded content.
<html>
<head>
<script src="javascripts/jquery-1.6.2.js" type="text/javascript" ></script>
<script type="text/javascript">
$(function() {
$('input').click(function(event) {
alert("This worked ..." + event.type);
});
$("#content").html("<input type='button' value='Loaded later'/>");
});