Skip to content

Instantly share code, notes, and snippets.

Avatar
🏠
Working from home

Abraham Petrillo abepetrillo

🏠
Working from home
View GitHub Profile
@abepetrillo
abepetrillo / rails_4.2.11.3_test.rb
Last active Sep 2, 2020
Testing bug with instance variables and security patch
View rails_4.2.11.3_test.rb
# 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.
View load_all_controllers_in_routes
Rails.application.routes.routes.map {|r| r.defaults[:controller] }.compact.reject {|r| r.include? 'devise' }.map(&:camelize).constantize
@abepetrillo
abepetrillo / recursive_compression.sh
Created Oct 25, 2017
Compress all images recursivley in a directory
View recursive_compression.sh
find -name '*.png' -print0 | xargs -0 optipng -o7
@abepetrillo
abepetrillo / greenhouse.css
Last active Aug 16, 2017
css-for-greenhouse
View greenhouse.css
.opening {
min-height: 200px;
display: flex;
justify-content: center;
flex-direction: column;
color: red;
}
.opening a {
color: red;
View gist:e85169b964022e1f70e6b6abf8a20dad
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 Apr 20, 2017
Dragon actor comic
View index.html
<!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)">
View gist:91b9a6f61ad9fde864b5f7c002ea493b

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
View minitest_file_upload.rb
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!')
View rspec_test_file_upload.rb
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!'
View persist_posted_file.rb
class DocumentsController < ApplicationController
def create
Document.create(file: params[:file].read)
head :ok
end
end