Skip to content

Instantly share code, notes, and snippets.

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

Abraham Petrillo abepetrillo

🏠
Working from home
View GitHub Profile
@abepetrillo
abepetrillo / rails_4.2.11.3_test.rb
Last active September 2, 2020 21:32
Testing bug with instance variables and security patch
# frozen_string_literal: true
require "bundler/inline"
gemfile(true) do
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
# Activate the gem you are reporting the issue against.
@abepetrillo
abepetrillo / load_all_controllers_in_routes
Created June 18, 2019 18:26
Clean up your routes file
Rails.application.routes.routes.map {|r| r.defaults[:controller] }.compact.reject {|r| r.include? 'devise' }.map(&:camelize).constantize
@abepetrillo
abepetrillo / recursive_compression.sh
Created October 25, 2017 14:13
Compress all images recursivley in a directory
find -name '*.png' -print0 | xargs -0 optipng -o7
@abepetrillo
abepetrillo / greenhouse.css
Last active August 16, 2017 14:19
css-for-greenhouse
.opening {
min-height: 200px;
display: flex;
justify-content: center;
flex-direction: column;
color: red;
}
.opening a {
color: red;
input = [
'Writing Fast Tests Against Enterprise Rails 60min, Overdoing it in Python 45min',
'Lua for the Masses 30min',
'Ruby Errors from Mismatched Gem Versions 45min',
'Common Ruby Errors 45min',
'Rails for Python Developers lightning',
'Communicating Over Distance 60min',
'Accounting-Driven Development 45min',
'Woah 30min',
'Sit Down and Write 30min',
@abepetrillo
abepetrillo / index.html
Created April 20, 2017 19:15
Dragon actor comic
<!DOCTYPE html>
<meta charset="utf-8">
<link rel="stylesheet" href="http://cmx.io/v/0.1/cmx.css">
<script src="http://cmx.io/v/0.1/cmx.js" charset="utf-8"></script>
<style>.cmx-user-scene4 .cmx-text-border .cmx-path {stroke: orange}</style>
<body>
<div style="max-width:900px; -webkit-transform:rotate(0deg)">
<scene id="scene1">
<label t="translate(0,346)">
@abepetrillo
abepetrillo / gist:91b9a6f61ad9fde864b5f7c002ea493b
Created September 22, 2016 20:22 — forked from chrissimpkins/gist:5bf5686bae86b8129bee
Atom Editor Cheat Sheet (Sweetmeat)

Use these rapid keyboard shortcuts to control the GitHub Atom text editor on Mac OSX.

Key to the Keys

  • ⌘ : Command key
  • ⌃ : Control key
  • ⌫ : Delete key
  • ← : Left arrow key
  • → : Right arrow key
  • ↑ : Up arrow key
require 'test_helper'
class DocumentsControllerTest < ActionController::TestCase
test "Uploading a file" do
file_path = File.join(Rails.root, 'tmp', SecureRandom.uuid)
File.open(file_path, 'w+b') { |f| f.write "A random file used for testing attachments!" }
file = Rack::Test::UploadedFile.new(file_path, 'text/plain')
post :create, {file: file}
assert_response :success
assert_equal(Document.last.file, 'A random file used for testing attachments!')
require 'rails_helper'
describe DocumentsController do
describe '#create' do
it 'persists a file' do
file_path = File.join(Rails.root, 'tmp', SecureRandom.uuid)
File.open(file_path, 'w+b') { |f| f.write "A random file used for testing attachments!" }
file = Rack::Test::UploadedFile.new(file_path, 'text/plain')
post :create, {file: file}
expect(Document.last.file).to eql 'A random file used for testing attachments!'
class DocumentsController < ApplicationController
def create
Document.create(file: params[:file].read)
head :ok
end
end