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.
Golden Section Search for javascript. (a line search technique used to minimize or maximize the output a function, also known as `argmax`).
A line search technique to help you find the minimum or maximum of a function. I've adapted the version from wikipedia to support async functions as well as synchronous ones :)
npm install gss
The arguments are a bit bad, but here's how you'd use it:
gss(asyncFunctionToMinimize, lowerBound, middleNumber, upperBound, precision, callback(err, min))
asyncFunctionToMinimize(x, cb)
: takes one argument, x
, for which you are finding the argmax, and a callback that it calls when finished. It should call its callback like this: cb(null, result)
.lowerBound
: a number you think makes a lower bound to the solutionmiddleNumber
: any number between the upper and lower boundsupperBound
: a number you think makes an upper bound to the solutioncallback(err, min)
: a function to receive the results of the line searchThe synchronous version takes a function that returns the result, and when it finishes it returns the result, so you don't need a callback. See the example below.
var gss = require('gss').gss
// f(x) = x^2
var f = function(x, cb) { cb(null, Math.pow(x, 2)); }
gss(f, -10, -7, 1, Math.sqrt(1e-10), function(err, min) {
//
// Now we have the min!
//
console.log(min, 'this should be prettty close to zero.');
});
Sync example (you bad bad noder ;):
var gssSync = require('gss').gssSync
var f = function(x) { return Math.pow(x, 2); } // f(x) = x^2
var min = gssSync(_.memoize(f), -100, -50, 100, Math.sqrt(1e-10))
console.log(min, 'should be pretty darn close to zero.');
I recommend you use _.memoize
to make the minimization go as quickly as possible. If you'd like to maximize instead, have your function multiply by -1 before returning.
middleNumber
, to simplify APIFAQs
Golden Section Search for javascript. (a line search technique used to minimize or maximize the output a function, also known as `argmax`).
We found that gss 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.