Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Paginator is a simple pagination class that provides a generic interface suitable for use in any Ruby program.
Paginator doesn't make any assumptions as to how data is retrieved; you just have to provide it with the total number of objects and a way to pull a specific set of objects based on the offset and number of objects per page.
In both of these examples I'm using a PER_PAGE
constant (the number of
items per page), but it's merely for labeling purposes.
You could, of course, just pass in the number of items per page directly to the initializer without assigning it somewhere beforehand.
bunch_o_data = (1..60).to_a
pager = Paginator.create(bunch_o_data.size, PER_PAGE) do |offset, per_page|
bunch_o_data[offset,per_page]
end
pager.each do |page|
puts "Page ##{page.number}"
page.each do |item|
puts item
end
end
Nothing changes with Paginator; you just use ActiveRecord from within the block you provide.
A controller action:
def index
@pager = Paginator.create(Foo.count, PER_PAGE) do |offset, per_page|
Foo.limit(per_page).offset(offset)
end
@page = @pager.page(params[:page])
end
In your view:
<% @page.each do |foo| %>
<%# Show something for each item %>
<% end %>
<%= @page.number %>
<%= link_to("Prev", foos_url(page: @page.prev.number)) if @page.prev? %>
<%= link_to("Next", foos_url(page: @page.next.number)) if @page.next? %>
See LICENSE.txt
.
FAQs
Unknown package
We found that paginator demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.