Skip to content

Instantly share code, notes, and snippets.

Avatar

Scott Meves stereoscott

View GitHub Profile
View gist:51d5bc0b6299beb4b5a7
gem 'activerecord', '4.1.5'
require 'active_record'
require 'minitest/autorun'
require 'logger'
ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: ':memory:')
ActiveRecord::Base.logger = Logger.new(STDOUT)
ActiveRecord::Schema.define do
View crash_report.txt
Process: GitX [88336]
Path: /Applications/GitX.app/Contents/MacOS/GitX
Identifier: net.phere.GitX
Version: 0.15.1962 dev (0.15.1962)
Code Type: X86-64 (Native)
Parent Process: ??? [1]
Responsible: GitX [88336]
User ID: 501
Date/Time: 2014-11-03 03:31:53.855 -0500
@stereoscott
stereoscott / random_text.sql
Created Jun 22, 2014
PostgreSQL random text function
View random_text.sql
-- http://www.postgresql.org/message-id/bddc86150908200534p14723ac2vd1ef223af095d822@mail.gmail.com
CREATE OR REPLACE FUNCTION
random_text(INTEGER)
RETURNS TEXT
LANGUAGE SQL
AS $$
SELECT array_to_string(array(
SELECT SUBSTRING('23456789abcdefghjkmnpqrstuvwxyz'
FROM floor(random()*31)::int+1 FOR 1)
@stereoscott
stereoscott / copy_attachments.rb
Created Apr 6, 2014
Paperclip Copy Attachments
View copy_attachments.rb
module Paperclip
module CopyAttachments
def copy_attachments_from(source_obj, source_bucket = nil, destination_bucket = nil)
self.class.attachment_definitions.keys.each do |attachment_name|
source_attachment = source_obj.send(attachment_name)
next if source_attachment.blank?
destination_attachment = self.send(attachment_name)
connection = destination_attachment.send(:connection)
@stereoscott
stereoscott / active_admin_extensions.rb
Created Jan 12, 2014
Sample ActiveRecord model that uses paperclip to upload a csv report to s3
View active_admin_extensions.rb
module ActiveAdmin
module Reports
module DSL
def enable_reports
action_item only: :index do
link_to("Download", {action: :report, params: params}, {method: :post, data: { confirm: "Are you sure you want to generate this report?"}})
end
collection_action :report, method: :post do
@stereoscott
stereoscott / active_admin.rb
Last active Mar 15, 2020
Stream CSV exports in ActiveAdmin in Rails 4
View active_admin.rb
# if you want to monkey patch every controller, put this in initializers/active_admin.rb
ActiveAdmin::ResourceController.class_eval do
include ActiveAdmin::CSVStream
end
View gist:5623005
PROMPT='%{$fg_bold[red]%}➜ %{$fg_bold[green]%}%p %{$fg[cyan]%}%c %{$fg_bold[blue]%}$(git_prompt_info)%{$fg_bold[blue]%} % %{$reset_color%}'
ZSH_THEME_GIT_PROMPT_PREFIX="[%{$fg[red]%}"
ZSH_THEME_GIT_PROMPT_SUFFIX="%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_DIRTY="%{$fg[blue]%}] %{$fg[yellow]%}✗%{$reset_color%}"
ZSH_THEME_GIT_PROMPT_CLEAN="%{$fg[blue]%}]"
View gist:5620415
/* Modernizr 2.6.2 (Custom Build) | MIT & BSD
* Build: http://modernizr.com/download/#-cssanimations-csstransforms3d-shiv-mq-cssclasses-teststyles-testprop-testallprops-prefixes-domprefixes-load
*/
;window.Modernizr=function(a,b,c){function A(a){j.cssText=a}function B(a,b){return A(m.join(a+";")+(b||""))}function C(a,b){return typeof a===b}function D(a,b){return!!~(""+a).indexOf(b)}function E(a,b){for(var d in a){var e=a[d];if(!D(e,"-")&&j[e]!==c)return b=="pfx"?e:!0}return!1}function F(a,b,d){for(var e in a){var f=b[a[e]];if(f!==c)return d===!1?a[e]:C(f,"function")?f.bind(d||b):f}return!1}function G(a,b,c){var d=a.charAt(0).toUpperCase()+a.slice(1),e=(a+" "+o.join(d+" ")+d).split(" ");return C(b,"string")||C(b,"undefined")?E(e,b):(e=(a+" "+p.join(d+" ")+d).split(" "),F(e,b,c))}var d="2.6.2",e={},f=!0,g=b.documentElement,h="modernizr",i=b.createElement(h),j=i.style,k,l={}.toString,m=" -webkit- -moz- -o- -ms- ".split(" "),n="Webkit Moz O ms",o=n.split(" "),p=n.toLowerCase().split(" "),q={},r={},s={},t=[],u=t
View gist:5584743
<body class="overview">
<section class="overview-section engage-section">
<h1 class="overview-section-header engage-section-header">xxx</h1>
</section>
<section class="overview-section measure-section">
<h1 class="overview-section-header measure-section-header">xxx</h1>
</section>
</body>
@stereoscott
stereoscott / application_controller.rb
Last active Jan 31, 2021
Returning mobile views from rails, either by using a custom view path ("views_mobile") or by setting a custom request format.
View application_controller.rb
class ApplicationController < ActionController::Base
before_filter :prepend_view_path_if_mobile
def mobile_request?
@mobile_request ||= (request.subdomains.first == domain_prefixes[:mobile])
end
helper_method :mobile_request?
def prepend_view_path_if_mobile
prepend_view_path Rails.root + 'app' + 'views_mobile' if mobile_request?