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.
Want a progress bar that's going to stay put and yet leave you satisfied?
Look no further. With no artificial flavors (dependencies), entirely organic ingredients (ServingSeconds actually came out of original code for PBAndJ), and no GMOs (all Ruby objects are left unharmed), PBAndJ is a progress bar you can feel good about giving to your kids. And your Ruby projects.
$ gem install pb_and_j
$ gem 'pb_and_j'
$ require 'pb_and_j'
Basic usage would go something like this:
NOTE: tick
will call start
if it has not already been invoked.
count = things.count # Assume an array of Thing objects
bar = PBAndJ::ProgressBar.new('things', count) # description and total count
bar.start # set the start time and print initial status
things.each do |thing|
# do something with things
bar.tick # automatically increase the counter and displays the updated progress bar
end
bar.stop # prints the current status and then a line feed
In the case that you do not wish to update for every iteration,
tick
also accepts the current index as a parameter:
count = things.count # Assume an array of Thing objects
bar = PBAndJ::ProgressBar.new('things', count) # description and total count
bar.start # set the start time and print initial status
things.each_with_index do |thing, i|
# do something with things
bar.tick i + 1 if i % 100 == 0 # only update the progress bar every 100th iteration
end
bar.stop # prints the current status and then a line feed
And for the really crazy stuff,
tick
also accepts the time that you expect it to complete
and uses that for the expected completion time,
as well as the expected elapsed time:
count = things.count # Assume an array of Thing objects
bar = PBAndJ::ProgressBar.new('things', count) # description and total count
bar.start # set the start time and print initial status
things.each_with_index do |thing, i|
# do something with things
time = my_crazy_non_linear_completion_time_calculation
bar.tick i + 1, time # tell PBAndJ when the process is expected to complete.
end
bar.stop # prints the current status and then a line feed
The full parameters for initialization are:
PBAndJ::ProgressBar.new label, count, pad: 0, width: 80, show: true, stream: STDOUT
label
(required)
count
(required)
pad
width
show
stream
Multiple progress bars may be managed by using ANSI codes:
is = 3
js = 50
ibar = PBAndJ::ProgressBar.new('i', is)
ibar.start
ibar.stop
is.times do |i|
jbar = PBAndJ::ProgressBar.new('j', js)
jbar.start
js.times do |j|
jbar.tick
sleep 0.1
end
jbar.stop # outputs a line break
print "\e[A" * 2 # move up 2 lines
ibar.tick
ibar.stop
sleep 1
end
If you want to use the output in some other way,
set show
to false and simply use #message
:
count = things.count # Assume an array of Thing objects
bar = PBAndJ::ProgressBar.new('things', count, show: false)
things.each_with_index do |thing, i|
# do something with things
bar.tick # does not print anything out
print "\r" + bar.message # this is essentially what PBAndJ does when show is true
end
bar.stop # only necessary if you wish to see a message after everything is complete
FAQs
Unknown package
We found that pb_and_j 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.