Skip to content

Instantly share code, notes, and snippets.

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

Ashley Engelund weedySeaDragon

🏠
Working from home
View GitHub Profile
@weedySeaDragon
weedySeaDragon / array_arrays_as_table.rb [ruby] [arrays]
Last active December 23, 2019 21:01
Format an Array of Arrays as a table
#--------------------------
#
# @class ArrayArraysAsTable
#
# @desc Responsibility: Creates a string with an Array of Arrays of Strings and/or Numbers
# formatted as a Table.
# BASED ON print_table FROM THOR: bundler/vendor/thor/lib/thor/shell/basic.rb
#
# I needed a way to easily view an array of arrays as a decently formatted table.
# The code in Thor had the basic methods. I refactored and renamed some things,
@weedySeaDragon
weedySeaDragon / jinja2-namespace-columns-ex.py
Created October 23, 2018 20:54
python, jinja2: Example of namespace and more in a jinja2 template. Written in python so it can be easily run.
# You can use the following in a python console/workspace to see examples of:
# - jinja namespace() (reference a variable in the outer scope (loop))
# - passing a value into a template (use a dictionary with each entry = "variable_name": variable_value
# - slice() jinja filter (can be used to split a list into columns
#
# You can also just run this .py file.
#
# @since 2018-10-23
# @author Ashley Engelund [email protected] < weedySeaDragon @ github >
@weedySeaDragon
weedySeaDragon / ruby_read_file_in_chunks.rb
Last active October 11, 2017 23:00
Ruby: Don't read a file into memory all at once. Read it n lines at a time. (spoiler: Use enumerators!)
# (still working on the comments / descriptions for this)
# When you don't want to read an entire file into memory at once, you can use Enumerators to read it in 1 part at a time.
#
# An Enumerator is really like someone that keeps track of a _where you are_ in a collection of things,
# and knows how to do a few things related to the current location, like:
# - give me one thing at a time, a.k.a. ".each"
# - go to the next thing, a.k.a. ".next"
# - get the next thing, but don't actually move your location forward to it, a.k.a. ".peek"
# - tell me how many things there are, a.k.a. ".size"
@weedySeaDragon
weedySeaDragon / paperclip-size-validation-errors-example.rb
Created February 10, 2017 21:07
Paperclip file size validation error messsages - a little readme comment and example
# This is a file used in the SHF-project that uses the paperclip gem.
# I wrote a big comment that explains using error messages for (paperclip) size validation.
class UploadedFile < ApplicationRecord
belongs_to :membership_application
has_attached_file :actual_file
validates_attachment :actual_file, content_type: {content_type: ['image/jpeg',
@weedySeaDragon
weedySeaDragon / rspec-shared-context-examples-optional.rb
Last active February 11, 2022 00:23
Using shared_context and shared_examples in Rspec with optional arguments. Answer to SO 24872199
#-------------------------- #
#
# @author Ashley Engelund ([email protected] weedySeaDragon @ github)
# @date 1/13/17
#
# @desc This is my answer to the Stack Overflow (SO) question:
# How can I use a default method to create something in a shared_example,
# sometimes overriding it with some other method and parameters for it?
#
# @see http://stackoverflow.com/questions/24872199/rspec-with-reusable-method-for-shared-examples-context
@weedySeaDragon
weedySeaDragon / README.md
Created October 27, 2016 04:27 — forked from jxson/README.md
README.md template

Synopsis

At the top of the file there should be a short introduction and/ or overview that explains what the project is. This description should match descriptions added for package managers (Gemspec, package.json, etc.)

Code Example

Show what the library does as concisely as possible, developers should be able to figure out how your project solves their problem by looking at the code example. Make sure the API you are showing off is obvious, and that your code is short and concise.

Motivation

@weedySeaDragon
weedySeaDragon / rake_examples.rake
Last active October 13, 2022 19:48
Rake examples - passing arguments to a rake task, calling one rake task from another, and more
# Also @see https://www.viget.com/articles/protip-passing-parameters-to-your-rake-tasks for
# examples using dependents and default values for arguments (see the updates at the end)
# Avdi Grimm's rake tutorial is really helpful. His section on FileLists:
# @see http://www.virtuouscode.com/2014/04/22/rake-part-2-file-lists/
# Rails:
# * to get access to Rails models, etc, your task must depend on the :environment task
# ex: task :my_task => :environment do ....
.bs-header
.container
= render_breadcrumbs :builder => ::BootstrapBreadcrumbsBuilder
# Guide
# Configure the essential configurations below and do the following:
#
# Repository Creation:
# cap deploy:repository:create
# git add .
# git commit -am "initial commit"
# git push origin master
#
# Initial Deployment:
#!/usr/bin/env ruby
#
# Originally written by http://redartisan.com/tags/csv
# Added and minor changes by Gavin Laking
# Rewritten by Andrew Bennett for Ruby 1.9
#
# Usage: ruby csv_to_fixture.rb file.csv [--json]
#
# "id","name","mime_type","extensions","icon_url"
# "1","unknown","unknown/unknown","||","/images/icon/file_unknown.gif"