Skip to content

Instantly share code, notes, and snippets.

View agraves's full-sized avatar

Aaron Graves agraves

  • New York, NY
View GitHub Profile
@agraves
agraves / download_images_chrome.js
Created October 23, 2024 21:06
download_images_chrome.js
// Function to check if element is visible in viewport
const isVisible = (elem) => {
const rect = elem.getBoundingClientRect();
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
);
};
[
{
"first_name": "Emma",
"last_name": "Johnson",
"full_name": "Emma Johnson",
"email": "emma.johnson@example.com",
"encrypted_password": "a8a3db3d3c0a2a2",
"reset_password_token": "t9a0e4f8a4e4",
"confirm_token": "d8b8c7c6f5e4d3c",
"age": 28,
@agraves
agraves / pages_controller_test.rb
Created October 9, 2012 21:13
Minitest controller test with clearance
require 'test_helper'
describe PagesController do
before{ sign_in }
subject{ PagesController.new }
%w{some_page another_page}.each do |page|
describe "rendering the #{page} page" do
it 'should render successfully' do
# implicit
class ErrorReporter
def active?
Rails.environment.production?
end
end
Rails.environment.stub :production?, true do
assert ErrorReporter.active?
end
@agraves
agraves / gist:8605608
Created January 24, 2014 20:24
Tea starter kit
Tea Strainer - 9$ - https://www.harney.com/permanent-tea-filters.html
Black Tea - 6.25$/4oz - https://www.harney.com/irish-breakfast-tea.html
Green Tea - 12$/4oz - https://www.harney.com/japanese-sencha.html
Brew the Green for ~2 minutes in less than boiling water, no milk, maybe a little sugar. As for the black tea, 4 minutes, boiling water, milk & sugar.
@agraves
agraves / gist:5086657
Last active December 14, 2015 12:28
Gemfile
ruby '1.9.3'
def local_group(*g, &block)
on_heroku = (ENV['HOME'].gsub('/','') == 'app')
if on_heroku
group(:test, &block)
else
group(*g, &block)
end
@agraves
agraves / gist:4772621
Created February 12, 2013 19:30
Trying to write platform-independent case-insensitive email search (without wildcards). Is this really the best way to do this?
email = 'you@yours.com'.gsub('%', '')
users = User.arel_table
User.find_by_sql(
users.
project(:id).
where(users[:email].matches email).
to_sql
).first
@agraves
agraves / user_search.rb
Created February 11, 2013 03:05
UserSearch refactor
class UserSearch
def self.search(term, topic_id = nil)
scope = User.scoped
if topic_id
scope = scope.joins("
LEFT JOIN (
SELECT DISTINCT(posts.user_id)
FROM posts
WHERE topic_id = #{topic_id.to_i}
1.9.3p327 :048 > t = User.new
=> #<User id: nil, name: nil, some_bool: nil, created_at: nil, updated_at: nil>
1.9.3p327 :049 > t.some_bool = 'a string'
=> "a string"
1.9.3p327 :050 > t.some_bool
=> false
class ImplementMongo < ActiveRecord::Migration
def change
create_table :mongo do |t|
t.string :key
t.text :value
end
end
end