Skip to content

Instantly share code, notes, and snippets.

View mrgenixus's full-sized avatar

Benjamin West mrgenixus

View GitHub Profile
#consider using a 'formatter' collaborator and then using:
delegate :min_yardage, to: :formatter, prefix: formatted
# so that `formatted_min_yardage` returns the formatted value.
#A formatter might be a. PORO with a block passed to new line:
def formatter
@formatter = ModelFormatter.new(self) do
include ActionView/Helpers::NumberHelper
@mrgenixus
mrgenixus / errors_concern.rb
Created May 17, 2023 23:42
Generalized controller error handling
module ErrorHandling
def respond_with_errors(error: nil, resource: nil, status: 422, **options)
add_error(:base, error) if error.present?
self.errors = resource.errors if resource&.errors&.is_a? ActiveModel::Errors
render json {
error: errors.full_messages.to_sentence,
errors: errors,
full_errors: errors.full_messages,
success: false,
@mrgenixus
mrgenixus / Apple Signing.md
Created May 17, 2023 19:33
Apple Signing

The Apple Signing setup process (including Visual Studio Code)

For Development

Signing

App Developer Account

Your apple id must be registered as an app developer on the account. In order to give your user access to profiles and certificates, your account must have the developer-level credential, at a minimum. This will allow you to create a development certificate on your machine and upload it as well as download any relevant profiles

@mrgenixus
mrgenixus / response_json.rb
Created September 4, 2022 15:54
response_json.rb
# REF https://ruby-doc.org/stdlib-2.1.3/libdoc/json/rdoc/JSON.html#method-i-parse
module RequestJSONHelpers
def response_json
JSON.parse(response.body, object_class: HashWithIndifferentAccess)
end
end
@mrgenixus
mrgenixus / NOTES.md
Last active September 6, 2022 21:39
reducer-helpers

Expectations:

  • All Actions will use payload for values that would be in the body of a corresponding HTTP Post.
  • Actions will provide meta information as action.meta ... which a reducer can/will store as a property of an individual record
  • Values that might appear in a query string, such as id will be included in the action as top-level properties (id, post_id, comment_id, etc);
@mrgenixus
mrgenixus / plan.md
Created October 18, 2021 16:22
How to rails new

Approaches

  • Monorepo - 2 codebases: Rails (API) + Webpacker, React Runtime, no React on Rails

    • Complex deployment, Simplified test-writing, complex test-running
    • Full separation of behaviors
    • Mirrors PTE
    • Some tight-coupling allowed in deployment
    • could be easily converted to Capacitor app
    • could be built for native mobile api access
  • Multirepo (not allowed in this case) - Above +

class Component extends React.Component {
onScroll(event) {
this.scrollPosition = getScrollPosition(event);
if (this.scrolling) return;
this.scrolling = true;
const processLongOperation = (beginPosition) => {
longOperation(beginPosition, (completionState) => {
this.setState(completionState, () => {
//rendered
@mrgenixus
mrgenixus / args.rb
Last active August 30, 2019 02:11
arguments in ruby
def func a, c, d
puts "a: " + a.to_s
puts "c: " + c.to_s
puts "d: " + d.to_s
end
def func2 *args
puts args.to_s
end
@mrgenixus
mrgenixus / classes.js
Created March 7, 2018 23:09
es6 classes
function ParentWidget(properties) {
Object.assign(this, properties);
}
function farewell() {
console.log('Goodbye Cruel ' + this.name);
}
ParentWidget.prototype.farewell = farewell;
export function stub(obj, method, callback=_.noop, { as:name, returns }) {
beforeEach(function() {
const stub = this.sinon.stub(obj, 'method', (...args) => {
callback.call(this, ...args);
});
if (returns) stub.returns(returns);
if (name) _.set(this, name, stub);
});