Skip to content

Instantly share code, notes, and snippets.

View benkoshy's full-sized avatar

Ben Koshy benkoshy

View GitHub Profile
@benkoshy
benkoshy / overriding.md
Created December 22, 2022 00:50
pagy issue
module QuotesHelper 

  # overrriding this
  # => wrong number of arguments (given 3, expected 2)
  def pagy_url_for(pagy, page)
    page
  end
end
@benkoshy
benkoshy / wrap_modal_in_frame.md
Created December 19, 2022 23:50
Wrap modal + items in a turbo_frame
# psuedo-code

turbo_frame_tag "items", src: items_path do
     <div id="modal">
           <div id="items to paginate>           
            <%== pagy_nav(pagy) %>     
     </div>
end
@benkoshy
benkoshy / ransack_pagy.md
Created December 16, 2022 00:58
example of ransack + pagination
# controller
def index
    @q = Quote.ransack(params[:q])
    @pagy, @quotes = pagy(@q.result(distinct: true))
    
  end

  def search
 index
@benkoshy
benkoshy / Copy of Phlex Tutorial.md
Last active October 25, 2022 21:20
Link to Online version of Phlex Tutorial by Andy Jeffries

Grafted from Andy Jeffries' work.

Phlex tutorial

Introduction

We're going to walk through the two most common scenarios when first using Phlex. The first is to take an existing Rails application, realise you could do with more componentisation and extract part of a view to a Phlex View. The second is to entirely replace the view layer of an application with Phlex Views, to get rid of writing raw HTML and encourage reuse of components structure and styling (particularly when using TailwindCSS for example, which can become very verbose with classes everywhere).

Let's imagine we have a very simple Rails application that shows off a list of books. We've created a simple model called Book and a BookController along with the requisite index.html.erb . For today we'll ignore the more complex aspects of authentication, and editing/deleting the models, etc and just work with that view, as the process is really the same.

@benkoshy
benkoshy / separate end point.md
Last active September 15, 2022 21:13
Solve it without pagy
# really sounds like an X-Y problem
# there are many ways to skin a cat
# what about just using a different end point for the count?
# or a mock object in lieu of pagy

# or just decouple from pagy entirely!!

def index
 @pagy, @results = pagy(query)
@benkoshy
benkoshy / innerHtml example.md
Last active August 12, 2021 19:57
An example: innerHtml - what is destroyed and what is retained?

Consider some html - this is what we want to create:

<div id="start-of-content" class="show-on-focus">
    <p> Setting innerHtml on the #start-of-content element to "" would wipe this msg away </p>   
</div>

(If you're reading this on Github, you can open the dev tools and see the relevant element.)

@benkoshy
benkoshy / zshrc.md
Created May 27, 2021 23:11
My .zshr file

[ -f ~/.fzf.zsh ] && source ~/.fzf.zsh

source ~/Downloads/Programs/fm/fm.zsh

@benkoshy
benkoshy / send-grid-example.md
Last active May 4, 2021 02:58
Example of mail gun using SMTP with a rails application
# production.rb
# mail gun
  config.action_mailer.delivery_method = :smtp
  config.action_mailer.raise_delivery_errors = true
  config.action_mailer.perform_deliveries = true
  config.action_mailer.smtp_settings = { address: "smtp.mailgun.org",
                                         port: 587,
                                         user_name: Chamber.dig!(:smtp_email, :mail_username),
 password: Chamber.dig!(:smtp_email, :mail_password),
@benkoshy
benkoshy / tekla-api-how-to-get-bolt-information-from-a-part.md
Created April 28, 2021 23:03
Tekla Open API - Demonstrates a hello world example of how to get bolt information from a part
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Tekla.Structures.Geometry3d;
using Tekla.Structures.Model;

namespace RopesProject
[!] There was an error while loading `pagy.gemspec`: /home/koshy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/pagy-7c9eb10dd089/lib/pagy/frontend.rb:26: syntax error, unexpected '='
...  def pagy_get_params(params) = params
...                              ^
/home/koshy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/pagy-7c9eb10dd089/lib/pagy/frontend.rb:97: syntax error, unexpected end-of-input, expecting end. Bundler cannot continue.

 #  from /home/koshy/.rbenv/versions/2.6.5/lib/ruby/gems/2.6.0/bundler/gems/pagy-7c9eb10dd089/pagy.gemspec:5
 #  -------------------------------------------
 #  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
 >  require 'pagy'