Skip to content

Instantly share code, notes, and snippets.

View mikeymicrophone's full-sized avatar

Mike Schwab mikeymicrophone

View GitHub Profile
@mikeymicrophone
mikeymicrophone / find_or_fabricate.rb
Created August 12, 2018 14:12
These methods allow you to probabilistically reuse data rather than making a fresh record every single time you fabricate.
def find_or_fabricate model, attrs = {}
model_klass = model.to_s.camelize.constantize
if model_klass.where(attrs).count == 0 || die_roll(model_klass.where(attrs).count % 5)
Fabricate model, attrs
else
model_klass.where(attrs).offset(rand(model_klass.where(attrs).count)).first
end
end
def die_roll faces = 6
@mikeymicrophone
mikeymicrophone / matched-bank.html
Created January 16, 2017 23:33
help debug double-binding of fdicCertificateNumber as selectedBankCert on line 22
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/paper-button/paper-button.html">
<link rel="import" href="shared-styles.html">
<dom-module id="matched-bank">
<template>
<style include="shared-styles">
</style>
<div class="matchedBank">
<span>[[displayedBank.name]]</span>
@mikeymicrophone
mikeymicrophone / bankdata-ajax.html
Last active January 5, 2017 20:01
I'm curious how I would extend iron-ajax in Polymer - what element should I put in the template to show how I'm overriding it?
<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="../bower_components/iron-ajax/iron-ajax.html">
<dom-module id="bankdata-ajax">
<template>
<iron-ajax
id="request_courier"
url="[[url]]"
handle-as="json"
last-response="{{resultingData}}">
</iron-ajax>
@mikeymicrophone
mikeymicrophone / application_controller.rb
Created August 15, 2014 15:28
trying to execute __FILE__ on a different file using inheritance and callbacks in Ruby 1.8.7
class ApplicationController
#logs of code omitted
before_filter :define_file_locator
def define_file_locator
self.class.send :define_method, :log_file_location, lambda {
instance_eval 'Rails.logger.info "File location: #{__FILE__}"'
}
log_file_location
@mikeymicrophone
mikeymicrophone / genre_leader.pseudo
Created March 12, 2014 04:34
pseudo code for finding the artist who has released into/within the most genres
artists = all artists
for each artist
grab all tracks by artist
grab all genres for tracks
count number of unique genres
note the number of genres for the artist
start with the first artist
compare her number of genres with the number of genres for the second artist
whoever has more is the leader
@mikeymicrophone
mikeymicrophone / gist:2485002
Created April 25, 2012 00:51
steps in feature development: comment on notes, tag notes
Commenting on notes:
- generate comments scaffold (controller, model, migration, views)
- add comment link and comment form spot to comment partial
- tell CommentsController#new to respond to JS requests
- create new.js.erb partial for comments controller
@mikeymicrophone
mikeymicrophone / 20120115192726_picture_has_photo_file.rb
Created January 22, 2012 01:49
using carrierwave (for uploading files)
class UsersHaveAvatar < ActiveRecord::Migration
def up
add_column :users, :avatar, :string
end
def down
remove_column :users, :avatar
end
end
A Rails app has a few top-level folders that serve different purposes. This might vary from app to app, but most apps use this basic structure pretty faithfully.
app
This folder is where most of your code goes. It has folders for your controllers (navigation logic), models (business logic), and views (display templates). Sometimes developers create extra folders in here for objects like mailers and observers. In Rails 3.1, an assets folder joined this group. The assets folder contains files that get compiled into javascript code, stylesheets, and images. These asset files are written in Ruby-like languages, but the rest of the code in the app folder is Ruby.
config
This folder has files that run when your app starts, including environment.rb and database.yml. They control decisions about how the app works in different scenarios (examples: which email account should be used for outgoing messages? which database should be used for data stored by this server?). The config folder also contains credent
These are the steps you will probably need to take, to get a new Rails app running.
1. install Rails
2. create a new Rails app
3. navigate into the root directory of your app
4. generate a scaffold
@mikeymicrophone
mikeymicrophone / terminal output
Created January 18, 2012 15:48
the process of setting up, editing, and deploying the community_pics app
First, download GitHub for Mac (or install git).
http://mac.github.com
Then, go to the community_pics repository page and click "Clone in Mac"
http://github.com/schwabsauce/community_pics
Open a Terminal window and move into the community_pics directory
$ cd Documents/community_pics
Then run bundle and rake db:migrate.