Skip to content

Instantly share code, notes, and snippets.

def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
data = row.to_hash
Plan.create(title: data['Title'])
steps = data['Steps'].split(/\d/).reject(&:empty?)
steps.map! { |s| s.gsub(/^\.\s+/, '') }
.map! { |s| s.gsub(/\n|:/, '') }
.map! { |s| s.split(/Expected Result/) }
.each { |s| Step.create(description: s[0], result: s[1]) }
end
@beaugaines
beaugaines / hamlizr.sh
Created March 4, 2015 19:17
Hamlize ERB views
#!/bin/bash
######## Global Vars
proceed=true
######## Functions
function check_gem() {
local gem_name=$1
local gem_version=$(gem list | grep $gem_name)
if [[ "$gem_version" == *"$gem_name"* ]]; then
@beaugaines
beaugaines / software_not_engineering.md
Created December 16, 2014 03:21
Software is not engineering

The source

Why writing software is not like engineering

Terence Parr (author of ANTLR parser generator etc...)

This article popped up on reddit and news.ycombinator.com.

While my talent lies in software, my graduate studies were in computer engineering (designing and building digital computers). One observation always struck me: computer engineering seemed more straightforward than computer science (building software). There are a set of engineering design rules to follow and engineering projects are much more likely to work out than software projects. Yes, there are some spectacular engineering failures but, empirically, reliable and useful software is more difficult to pull off. To illustrate my point, consider the amazing space probes we send throughout the solar system. The spacecraft themselves work extremely well, often living long past their design lifetimes. Their control software, on the other hand, has to be constantly tweaked an

true and false vs. "truthy" and "falsey" (or "falsy") in Ruby, Python, and JavaScript

Many programming languages, including Ruby, have native boolean (true and false) data types. In Ruby they're called true and false. In Python, for example, they're written as True and False. But oftentimes we want to use a non-boolean value (integers, strings, arrays, etc.) in a boolean context (if statement, &&, ||, etc.).

This outlines how this works in Ruby, with some basic examples from Python and JavaScript, too. The idea is much more general than any of these specific languages, though. It's really a question of how the people designing a programming language wants booleans and conditionals to work.

If you want to use or share this material, please see the license file, below.

Update

@beaugaines
beaugaines / array_methods.rb
Last active September 30, 2015 04:09
Array methods
# Array definition
def new_array(a,b,c,d)
[a,b,c,d]
# or:
# Array.new << a << b << c << d
# but you would never do that...
end
def first_and_last(a)
"Knowledge has one more, and a more fundamental, relation to the
problem of love. The basic need to fuse with another person so as to
transcend the prison of one’s separateness is closely related to
another specifically human desire, that to know the “secret of man.”
While life in its merely biological aspects is a miracle and a secret,
man in his human aspects is an unfathomable secret to himself—and to
his fellow man. We know ourselves, and yet even with all the efforts
we may make, we do not know ourselves. We know our fellow man, and
yet we do not know him, because we are a thing, and our fellow man is
not a thing. The further we reach into the depth of our being, or
class AddHstoreExtension < ActiveRecord::Migration
def up
execute 'CREATE EXTENSION hstore'
end
def down
execute 'DROP EXTENSION hstore'
end
end
@beaugaines
beaugaines / edit.html.erb
Created April 10, 2014 03:22
User edit form
<!-- app/views/devise/registrations/edit.html.erb -->
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<div class="row">
<div class="col-md-8">
<h3>Change email or password</h3>
<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :patch }) do |f| %>
<%= devise_error_messages! %>
<div class="form-group">
def add_item (item, list)
# nb: no need to return list explicitly; the << operator - which
# is a method in the Array class - returns the Array itself.
list << item unless list.include?(item)
# list
# also, no need for this else statement
# else
#list
#end
# git
alias gmv='git remote -v'
alias m='git add .;git commit -m' # ex: "m New Feature"
alias ga='git add .'
alias gl='git pull'
alias gp='git push'
alias gd='git diff'
alias gdd='git diff HEAD HEAD^1'
alias gco='git checkout'
alias gb='git branch'