Skip to content

Instantly share code, notes, and snippets.

View akinsgre's full-sized avatar

Greg Akins akinsgre

View GitHub Profile
#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
@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; }
# 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
# 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
<div id="channel_info">
<div style="clear:both"/>
<div id="dialog0" class="column" > </div>
<div id="dialog1" class="column" > </div>
</div>
<div style="clear:both"></div>
@akinsgre
akinsgre / controller.rb
Created March 13, 2012 14:29
Problem with ActiveRecord save/update
def update
@channel = Channel.find(params[:channel_id])
@status = 0
# check permissions
if @channel.user_id == current_user.id
# save data
@channel.options1 = params[:options]
logger.debug "Channel changes " + @channel.changes.to_s
if @channel.save
@akinsgre
akinsgre / output.txt
Created July 27, 2012 12:26
Helper methods not called synchronously
Started GET "/plugins/1" for 127.0.0.1 at 2012-07-27 08:12:13 -0400
Processing by PluginsController#show as HTML
Parameters: {"id"=>"1"}
Plugin Load (0.1ms) SELECT `plugins`.* FROM `plugins` WHERE `plugins`.`id` = 1 LIMIT 1
Rendered plugins/show.html.erb (0.3ms)
Completed 200 OK in 110ms (Views: 2.2ms | ActiveRecord: 0.1ms)
Private User
@akinsgre
akinsgre / plugin.rb
Created July 30, 2012 12:45
Dependent delete on relate_to_details
class Plugin < ActiveRecord::Base
belongs_to :user
has_one :plugin_window_detail, :dependent => :delete
def private?
private_flag?
end
end
@akinsgre
akinsgre / controller.rb
Created September 13, 2012 15:17
Type error
def update
@channel = current_user.channels.find(params[:id])
# make sure channel isn't social
#render :text => '' and return if @channel.social
if params["channel"]["video_type"].blank? && !params["channel"]["video_id"].blank?
@channel.errors.add(:base, t(:channel_video_type_blank))
end
if @channel.errors.count <= 0
puts "########## Params #{params.inspect}"
@channel.save_tags(params[:tags][:name])
@akinsgre
akinsgre / config.txt
Created November 8, 2012 14:30
Example of setting maxmemory.. confusing for me.
$ ./redis-cli
redis> set x 10
OK
redis> config set maxmemory 200
OK
redis> set y 20
(error) ERR command not allowed when used memory > 'maxmemory'
redis> config set maxmemory 0
OK
redis> set y 20