Skip to content

Instantly share code, notes, and snippets.

View scottharvey's full-sized avatar

Scott Harvey scottharvey

View GitHub Profile
@scottharvey
scottharvey / stimulus.md
Last active October 8, 2021 19:57 — forked from mrmartineau/stimulus.md
Stimulus cheatsheet
Dir["#{Rails.root}/app/*/**"].each do |dir|
case File.basename(dir)
when 'assets'
Dir["#{dir}/*"].each do |assets_dir|
Rails.application.config.assets.paths << assets_dir
Dir["#{assets_dir}/*"].each do |asset|
parts = File.basename(asset).split('.')
name = "#{parts.first}.#{parts.second}"
Rails.application.config.assets.precompile += [name]
end
@scottharvey
scottharvey / denormalized_order.rb
Created May 5, 2014 06:38
DSL for FlattenRecord
class DenormalizedOrder
include FlattenRecord::Denormalize
denormalize {
except: [:updated_at],
methods: [:grand_total, :average_price],
include: {
line_items: {
only: [:quantity, :price]
include: [:item]
@scottharvey
scottharvey / script.bash
Last active December 22, 2015 17:09
Installing Anisible on Ubunutu
#!/usr/bin/env bash
# Before running this you will need to you `sudo apt-get install curl`
# Then: `curl -L https://gist.github.com/scottharvey/6504369/raw | bash`
sudo apt-get update
# Install Ansible dependencies
sudo apt-get -y install python-dev python-pip
sudo pip install PyYAML Jinja2 paramiko

Basic server setup

Change default root password on the server

passwd

Update and upgrade all installed apt-get packages

apt-get update

apt-get upgrade

@scottharvey
scottharvey / update.rb
Created May 26, 2013 08:50
Example of an update action when using the Reform gem
def update
@form = ProjectForm.new project: project
if @form.validate(params[:project]) && @form.save && @form.project.save
redirect_to edit_admin_project_path(project)
else
render :edit
end
end
@scottharvey
scottharvey / README.md
Last active December 17, 2015 16:49 — forked from chelsea/README.md

Description

Dashing widget to display a random cute picture from http://reddit.com/r/aww

The display of the widget is heavily based on the Image widget, however it does not prepend the src with 'assets' which allows for external images.

Settings

You can set a placeholder image in the event that reddit is down, or otherwise unresponse. This is set at the top of random_aww.rb as follows:

source "http://rubygems.org"
# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.
group :test do
gem 'combustion'
gem 'sqlite3'
gem 'activerecord'
# This is close but I to pass chat.module("friend") into the anonymous function
do (Friend) ->
Message = chat.module "message"
app = chat.app
@scottharvey
scottharvey / gist:1236411
Created September 23, 2011 00:03
Backbone class functions in Coffeescript
class API extends Backbone.Model
{}
fetchData: ->
// API call here