Skip to content

Instantly share code, notes, and snippets.

View rjswenson's full-sized avatar

Robin S. Healey rjswenson

  • Internet Superhighway
  • USA
View GitHub Profile
<td><%= button_to 'Approve', post_comment_path(comment, comment: { approved: true }), method: :put, class: "btn" %></td>
@rjswenson
rjswenson / my_computer.js
Created November 13, 2013 01:14
Basic Javascript for a constructor function, toString(), and variable. Day 1.
function Computer(name, brand, year, color) {
this.name = name;
this.brand = brand;
this.year = year;
this.color = color;
};
Computer.prototype.toString = function () {
return "The computer is a(n) " + this.brand +
" made in " + this.year + ". " +
@rjswenson
rjswenson / gist:7535024
Created November 18, 2013 20:48
Jasmine Javascript testing for encoder
var encoder = {
setMessage: function() {
this.message = document.getElementById('message').value;
},
getPassword: function() {
this.password = prompt("Enter your Decoder Password: ");
},
setUrl: function() {
totalURL = document.URL + "?" +
encodeURI(this.encrypt());
@rjswenson
rjswenson / gist:7901901
Created December 10, 2013 22:53
Blog ideas:
1. Unicorn: The joys of multithreading and performance gains from heroku and unicorn. I will discuss the threaded approach vs the traditional heroku setup. I will also discuss pitfalls including managing each thread and forcing them to quit or close when idle.
2. Postgres Locally: Why one should set up PG locally (ie for debug issues), my cautionary tale, and the actual process updated and also including how to uninstall and reinstall.
3. Media queries continued: I would like to go into detail in taking a 2 column layout and forming it into a one column form for easier viewing.
4. Big O notation explained: A quick overview of big0 and why we need to use and understand it. Add relevent types including sort styles and other basic algorythm notations.
5. Preparing for a boot camp: Code School, the Rails tutorial, where to find ruby sample problems. Fizzbuzz. How to get ready.
@rjswenson
rjswenson / Q1.rb
Last active January 2, 2016 06:09
My responses to Elastic Suite questions.
# Q1: Given this scenario, how would you go about returning the answer of life anytime the method answer_to_life is called?
# https://gist.github.com/7e676b9a9e6c9d47c319
# The cleanest way to have all classes you mentioned (which of course are objects) possess the same method is to find a common
# superclass they share, from which they inherit. Since we are dealing with a miriad of Classes (NilClass, String, FixNum) they
# all share the superclass of 'Class' so I modified it to contain the method.
class Object
def answer_to_life
42
@rjswenson
rjswenson / Rakefile.rake
Created January 27, 2014 18:10
Rakefile ready for tests
# Make sure you require rake and then create a new
# 'task' called 'test'. Then you can run rake test
# and it add libs, test, look for the pattern of _test,
# and run. Finally, make test default for rake, so
# now you just need to type 'rake' to run it.
require 'rake'
require 'rake/testtask'
require File.expand_path('../config/application', __FILE__)
@rjswenson
rjswenson / user_counts.rb
Last active August 29, 2015 13:59
Spyder Monthly Stats per user
# GOAL: CustomCatalogs, Whiteboards Printed, Orders Created, Orders Submitted BY User PER Month
(1..12).each do |num|
printed_cc = PrintJob::CustomCatalog.where(:updated_at.gte => num.months.ago.beginning_of_month, :updated_at.lte => (num-1).months.ago.beginning_of_month)
printed_orders = PrintJob::Document.where(:updated_at.gte => num.months.ago.beginning_of_month, :updated_at.lte => (num-1).months.ago.beginning_of_month)
printed_whiteboards = PrintJob::Whiteboard.where(:updated_at.gte => (num.months.ago).beginning_of_month, :updated_at.lte => (num-1).months.ago.beginning_of_month )
arr = {}
printed_cc.each do |cc|
next if cc.author.nil?
@rjswenson
rjswenson / sftp_file_pulling.rb
Created April 30, 2014 21:04
A method to pull data conditionally from an external ftp. Checks modified time vs local file before uploading new version.
def elastic_sftp
local_files = Dir.glob(File.join(Rails.root, 'data', 'data', "**/*")).map {|f| f.split("data/data/")[1] }
@sftp = Net::SFTP.start('sftp.vfc.com', ENV['VFC_USERNAME'], :password => ENV['VFC_PASSWORD']) do |sftp|
sftp.dir.glob(File.join("#{@sftp_directory}", 'Elastic' , 'Data'), "**/*.txt").each do |file|
if local_files.include?(file.name.downcase)
if Time.at(file.attributes.mtime) > File.mtime(File.join(Rails.root, 'data', 'data', file.name.downcase))
sftp.download!(File.join("#{@sftp_directory}", 'Elastic' , 'Data', file.name),
File.join(Rails.root, 'data', 'data', file.name.downcase))
p "#{file.name} is out of date and has been downloaded."
# Assets are images that need no resampling, fonts, etc, that
# are used for the site. Examples are catalog landing pages,
# carousel images, etc.
class Asset
include Mongoid::Document
include Mongoid::Paperclip
field :type
field :catalog_key
field :category
@rjswenson
rjswenson / leading_variation_desc.rb
Created October 10, 2014 23:24
Failure to lead
@pdf.formatted_text_box variation_description(variations.first),
width: 1.625.in,
align: :center,
size: 6,
at: [@pdf.bounds.left, @pdf.bounds.top - 2.6.in]
def variation_description(variation)
[
{ text: "#{variation.code}\n"},