Skip to content

Instantly share code, notes, and snippets.

View coderberry's full-sized avatar

Eric Berry coderberry

View GitHub Profile
@coderberry
coderberry / chatgpt-q1.md
Created June 1, 2023 15:06
ChatGPT explains how to avoid using `send`

Prompt

I have a Rails app with two models that are associated:

class Person < ApplicationRecord
  has_many :pets
  has_many :toys
end
@coderberry
coderberry / chrome-cheat-sheet.md
Last active March 10, 2023 13:56
Chrome Canary Console Cheat Sheet
source "https://rubygems.org"
git_source(:github) { |repo| "https://github.com/#{repo}.git" }
ruby "2.7.6"
# Authorization framework for Ruby/Rails application
# [https://github.com/palkan/action_policy]
gem "action_policy", "~> 0.6.4"
# Action Policy integration for GraphQL-Ruby
# Shared collection of (mostly Arel) class-level helpers for working with advanced
# SQL selections.
#
# Source: https://github.com/ManifoldScholar/manifold/blob/84625d40af628646453668be028dabc2aa249516/api/app/models/concerns/arel_helpers.rb#L313
#
# Required rubygem: 'dux'
#
# rubocop:disable Style/CharacterLiteral
# rubocop:disable Style/StringLiterals
# @see https://www.postgresql.org/docs/9.5/static/functions-json.html JSON functions and operators in PostgreSQL
@coderberry
coderberry / github-review-toggle-checkboxes.js
Created December 15, 2022 19:12
Inserts a button that can toggle the "viewed" checkboxes when reviewing a PR on Github.
const url = document.URL;
class ReviewToggle {
insertButton() {
const parentElement = document.querySelector(".pr-review-tools");
let button = document.querySelector('#boost-toggle-checkboxes');
if (!button) {
button = document.createElement("button");
button.id = "boost-toggle-checkboxes";
}
@coderberry
coderberry / locations.rb
Created June 25, 2015 18:34
US States with Google Adwords Location ID
US_STATES = {
'AK' => { name: 'Alaska', location_id: 21132 },
'AL' => { name: 'Alabama', location_id: 21133 },
'AR' => { name: 'Arkansas', location_id: 21135 },
'AS' => { name: 'American Samoa', location_id: 2016 },
'AZ' => { name: 'Arizona', location_id: 21136 },
'CA' => { name: 'California', location_id: 21137 },
'CO' => { name: 'Colorado', location_id: 21138 },
'CT' => { name: 'Connecticut', location_id: 21139 },
'DC' => { name: 'District of Columbia', location_id: 21140 },
@coderberry
coderberry / BCrypt.java
Created October 28, 2010 15:39
BCrypt.java
// Copyright (c) 2006 Damien Miller <djm@mindrot.org>
//
// Permission to use, copy, modify, and distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
@coderberry
coderberry / backbone-websql.js
Created March 14, 2012 04:01
backbone-websql.js
// ====== [UTILS] ======
//function for generating "random" id of objects in DB
function S4() {
return (((1+Math.random())*0x10000)|0).toString(16).substring(1);
}
function guid() {
return (S4()+S4()+"-"+S4()+"-"+S4()+"-"+S4()+"-"+S4()+S4()+S4());
}
@coderberry
coderberry / ci.yml
Created August 14, 2020 16:30
Using GitHub Actions for CI (rspec + rubocop)
name: CI
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
env:
RAILS_ENV: test
### Keybase proof
I hereby claim:
* I am coderberry on github.
* I am coderberry (https://keybase.io/coderberry) on keybase.
* I have a public key ASDxOxY4XXIxGp-zouupDGuL3A-bGhziJZ3e6STSnBQaVwo
To claim this, I am signing this object: