Skip to content

Instantly share code, notes, and snippets.

View danjohnson3141's full-sized avatar
🏠
Working from home

Dan Johnson danjohnson3141

🏠
Working from home
View GitHub Profile
@danjohnson3141
danjohnson3141 / form.js.coffee
Created September 6, 2016 20:09
Formication
class App.Models.Form extends App.Models.SourceModel
initialize: (@options) ->
@nullToBlank()
@formElements = {}
id: ->
if @get('object').get('id')
"<label class='id-column'>ID: #{@get('object').get('id')}</label>"
label: (attribute, label, html_attributes = '') ->
@danjohnson3141
danjohnson3141 / revcaster.md
Last active April 15, 2016 20:46
Revcaster Code Challenge

Hello Daniel,

Thanks for taking the time to review my code challenge.

I have to admit that all of my interaction with S3 has concerned uploading assets not downloading them.

I've taken a quick stab at your request but, obviously, if this were a real project I'd have some questions.

Since I'm fairly weak at getting things from S3 I've also included a snippet of code from a user profile photo upload I recently created.

@danjohnson3141
danjohnson3141 / relations
Created November 5, 2015 21:22
Strange Relations
module Relations
extend ActiveSupport::Concern
included do
def show_dependents
output = []
dependents.each do |dependent|
output << { dependent.to_s.titleize => self.send(dependent.to_s).size }
end
output
@danjohnson3141
danjohnson3141 / gist:41afb16d239d0892a3cc
Created September 23, 2014 23:34
A CSV Parser (not fully baked yet)
module Parser
extend ActiveSupport::Concern
require 'csv'
def parse_csv(csv_file)
CSV::Converters[:blank_to_nil] = lambda do |field|
field && field.empty? ? nil : field
end
[[ -s "$HOME/.profile" ]] && source "$HOME/.profile" # Load the default .profile
[[ -s "$HOME/.rvm/scripts/rvm" ]] && source "$HOME/.rvm/scripts/rvm" # Load RVM into a shell session *as a function*
alias l='ls -FGlAhp'
alias rake!='rake db:drop && rake db:create'
alias raker!='bin/rake db:migrate RAILS_ENV=test'
function ruby_version() {
rvm current
db:create creates the database for the current env
db:create:all creates the databases for all envs
db:drop drops the database for the current env
db:drop:all drops the databases for all envs
db:migrate runs migrations for the current env that have not run yet
db:migrate:up runs one specific migration
db:migrate:down rolls back one specific migration
db:migrate:status shows current migration status
db:rollback rolls back the last migration
db:forward advances the current schema version to the next one
@danjohnson3141
danjohnson3141 / rspec-1
Created May 21, 2014 22:53
RSpec Request Spec Sample
require 'spec_helper'
describe 'AppSupports' do
before(:all) do
@user = create(:user)
end
it "POST /app_supports; logged in user creates new app_support record" do
post_auth '/app_supports', { app_support: { body: "I need help!!!" } }
@danjohnson3141
danjohnson3141 / to_sentence.php
Created December 13, 2013 15:31
PHP version of Ruby's to_sentence method. Uses option array as param.
/**
* PHP Equivilent to Ruby's to_sentence method.
* Example:
* to_sentence(array('a', 'b')) = a and b
* to_sentence(array('a', 'b', 'c')) = a, b, and c
* @param array() $items array of items to split
* @param array() $options array of options:
* conjunction = conjunction string (default ' and ')
* seperator = seperator string (default ', ')
* conjunctionSeperator = conjunction seperator (default ',')
@danjohnson3141
danjohnson3141 / prettyList()
Last active December 30, 2015 06:59
Like Ruby's to_sentance, this function returns a list separated by commas. Last item will be proceeded by "and". Example: prettyList(('a', 'b')) returns "a and b", prettyList(('a', 'b', 'c')) returns "a, b, and c". Alternate version with option array instead of individual params.
<?php
function prettyList($list)
{
$listCount = sizeOf($list);
if($listCount == 1) {
$listString = $list[0];
}
if($listCount == 2) {