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.
The StdDraw class provides a basic capability for creating drawings with your programs. It uses a simple graphics model that allows you to create drawings consisting of points, lines, squares, circles, and other geometric shapes in a window on your computer.
I was going through the excellent Algorithms 4th edition text and really wanted to use ruby instead of the default java. The book makes use of the Princeton Standard Libraries to help clarify the code and display useful figures.
The original graphics code uses Java Swing/AWT which works fine with Jruby but not so much with standard ruby. So I started wondering how bad it would be to rewrite it in something MRI friendly. I'm attempting to keep the original interface as much as possible while recreating the logic using the ruby TK gem. The graphics drawing portion works but the library is not yet fully complete. See things to implement
If you need something not yet ported consider using the jruby wrapper gem that lets you call the original java code in Jruby.
Most of the docs taken/modified from the original source
Type the following short program into your editor:
require 'standard_draw_tk'
StdDraw.pen_radius = 0.05
StdDraw.pen_color = StdDraw::BLUE
StdDraw.point(0.5, 0.5)
StdDraw.pen_color = StdDraw::MAGENTA
StdDraw.line(0.2, 0.2, 0.8, 0.2)
StdDraw.run
run it:
ruby examples/example4.rb
Add this line to your application's Gemfile:
gem 'standard_draw_tk'
And then execute:
$ bundle
Or install it yourself as: $ gem install standard_draw_tk
Ruby doesn't contain TK by default anymore. And installing the TK gem requires a bit of manual installation depending on the system. I followed this blog post to get it working on linux.
brew install tcl-tk
echo 'export PATH="/usr/local/opt/tcl-tk/bin:$PATH"' >> ~/.zshrc
wish
to test it installed correctlyrvm install 2.6.5 --enable-shared --enable-pthread --with-tk --with-tcl
gem install tk
should workYou will need to add StdDraw.run
to the end of your programs as shown in the examples. I may change or alias this in the future or maybe find a work around. This deviates from the original Standar Draw lib
You can draw points and line segments with the following methods:
StdDraw.point(x, y)
StdDraw.line(x1, y1, x2, y2)
The x- and y-coordinates must be in the drawing area (between 0 and 1 and by default) or the points and lines will not be visible.
You can draw squares, circles, rectangles, and ellipses using the following methods:
StdDraw.circle(x, y, radius)
StdDraw.ellipse(x, y, semiMajorAxis, semiMinorAxis)
StdDraw.square(x, y, radius)
StdDraw.rectangle(x, y, halfWidth, halfHeight)
All of these methods take as arguments the location and size of the shape. The location is always specified by the x- and y-coordinates of its center. The size of a circle is specified by its radius and the size of an ellipse is specified by the lengths of its semi-major and semi-minor axes. The size of a square or rectangle is specified by its half-width or half-height. The convention for drawing squares and rectangles is parallel to those for drawing circles and ellipses, but may be unexpected to the uninitiated.
The methods above trace outlines of the given shapes. The following methods draw filled versions:
StdDraw.filledCircle(x, y, radius)
StdDraw.filledEllipse(x, y, semiMajorAxis, semiMinorAxis)
StdDraw.filledSquare(x, y, radius)
StdDraw.filledRectangle(x, y, halfWidth, halfHeight)
You can draw circular arcs with the following method:
StdDraw.arc(x, y, radius, angle1, angle2)
The arc is from the circle centered at (x, y) of the specified radius. The arc extends from angle1 to angle2. By convention, the angles are polar (counterclockwise angle from the x-axis) and represented in degrees. For example, StdDraw.arc(0.0, 0.0, 1.0, 0, 90) draws the arc of the unit circle from 3 o'clock (0 degrees) to 12 o'clock (90 degrees).
You can draw polygons with the following methods:
StdDraw.polygon([] x, [] y)
StdDraw.filledPolygon([] x, [] y)
You can use the color constants or any predefined TK Color as a string or symbol as well as hex values
# are all the same
StdDraw.pen_color = StdDraw::BLUE
StdDraw.pen_color = :blue
StdDraw.pen_color = 'blue'
StdDraw.pen_color = '#0000FF'
see the examples directory
After checking out the repo, run bin/setup
to install dependencies. You can also run bin/console
for an interactive prompt that will allow you to experiment.
Bug reports and pull requests are welcome on GitHub at https://github.com/gregors/standard_draw_tk.
The gem is available as open source under the terms of the GNU General Public License, version 3 (GPLv3).
FAQs
Unknown package
We found that standard_draw_tk 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.