Replace exactly string with #rollup/plugin-replace - rollup

I'm trying to replace every exact occurrence of $t with $t_cust but that doesn't seem to work well. Any variables starting with $t like $tada, $todo are also replaced.
Any idea how it would be done?
replace({ preventAssignment: true, '$t': '$t_cust' }),

Related

Parse user input for command arguments into array

I'm making a bot in PHP and I want a better way to parse user input into arguments for later operations.
An example would be a user saying "/addresponse -"test" -"works""
I want this to parse that string into:
$command ["test", "works"];
I have found the PHP command parser but I want the user to be able to use human readable commands rather than typing something like /addresponse?p="test"&r="works"
Right now I have a regex working so the user can type "/addresponse "test" "works"" but there are obvious problems because the user cannot make a response for '"test"' only 'test'
I'd appreciate any help, right now I think I can make a regex to get all text between ' -' but I still don't think this is the best solution.
I just looked into using a regex to find text between ' -"' and while this is better than just between quotes, it doesn't solve the whole problem because it still will break if the input contains ' -"'. A string containing this isn't particularly common but I'd like a solution where almost any input will not break it.
Is this a stupid question? I don't think there is a built in php function for this and it got downvoted with no comment...
I found a partial solution:
function parse_cmd($command) {
$command = explode(' -"', $command);
array_splice($command, 0, 1);
foreach($command as &$element) {
$element = substr($element, 0, strlen($element) -1);
}
return $command;
}
This will split everything after ' -"' and return it as an array

Why am I getting “Too many positionals passed…” in this call to HTTP::Request.new?

I tried six or so variations on this code and excepting hardcoded Strs like GET => … I always got this error. Why? How can I fix it and understand it? Is it a bug in the HTTP::Request code?
Code
#!/usr/bin/env perl6
use HTTP::UserAgent; # Installed today with panda, for HTTP::Request.
HTTP::Request.new( GET => "/this/is/fine" ).WHICH.say;
# First, check that yes, they are there.
say %*ENV<REQUEST_METHOD>, " ", %*ENV<REQUEST_URI>;
# This and single value or slice combination always errors-
HTTP::Request.new( %*ENV<REQUEST_METHOD>, %*ENV<REQUEST_URI> );
Output with invariable error
$ env REQUEST_METHOD=GET REQUEST_URI=/ SOQ.p6
HTTP::Request|140331166709152
GET /
Too many positionals passed; expected 1 argument but got 3
in method new at lib/HTTP/Request.pm6:13
in block <unit> at ./SOQ.p6:11
HTTP::Request is from this package — https://github.com/sergot/http-useragent/ — Thank you!
Try
HTTP::Request.new(|{ %*ENV<REQUEST_METHOD> => %*ENV<REQUEST_URI> });
instead of the more obvious
HTTP::Request.new( %*ENV<REQUEST_METHOD> => %*ENV<REQUEST_URI> );
If the left-hand side of => isn't a literal, we won't bind to a named parameter. Instead, a pair object gets passed as positional argument.
To work around this, we construct an anonymous hash that gets flattened into the argument list via prefix |.
As a bonus, here are some more creative ways to do it:
HTTP::Request.new(|%( %*ENV<REQUEST_METHOD REQUEST_URI> ));
HTTP::Request.new(|[=>] %*ENV<REQUEST_METHOD REQUEST_URI> );

os.execute variables

I have multiple Steam accounts that I want to launch via a single Lua script with the options I specify. I've got pretty much everything sorted, except for launching with the code provided. I have no idea how to "pass" the variable with this format.
function Steam(n, opt1, opt2, opt3)
os.execute[["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam2 D:\Steam\steam.exe -login username password -opt1 -opt2 -opt3"]]
end
I have my usernames and Sandboxes setup so that only the number needs changing (fenriros2, fenriros3, Steam2, Steam3 etc) with the same password.
Basically, I want this;
Steam(3, -tf, -exit, -textmode)
to do;
os.execute[["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam3 D:\Steam\steam.exe -login fenriros3 password -applaunch 440 -textmode"]]
I'll use -exit to close the lua window after it's done.
I realize my code isn't exactly efficient, but that's a worry for a later time. Right now I just need to get it working.
Any help is greatly appreciated, and I apologize if I missed something obvious, I'm still fairly new at Lua.
First obvious one. The [[ ]] delimit a string so all you need to do is to create a variable for the string and replace the contents as needed.
function Steam(n, opt1, opt2, opt3)
-- Set up execute string with placeholders for the parameters.
local strExecute = [["start C:\Program" "Files\Sandboxie\Start.exe /box:Steam{n} D:\Steam\steam.exe -login fenriros{n} password -{opt1} -{opt2} -{opt3}"]]
-- Use gsub to replace the parameters
-- You could just concat the string but I find it easier to work this way.
strExecute = strExecute:gsub('{n}',n)
strExecute = strExecute:gsub('{opt1}',opt1:gsub('%%','%%%%'))
strExecute = strExecute:gsub('{opt2}',opt2:gsub('%%','%%%%'))
strExecute = strExecute:gsub('{opt3}',opt3:gsub('%%','%%%%'))
os.execute(strExecute)
end
Steam(1,'r1','r2','r3')

Querying attributes where value is not yet set

Any of you guys know how to query rally for a set of things where an string attribute value is currently not yet set?
I can’t query for the value equal to an empty string. That doesn’t parse. And I can’t use “null” either. Or rather, I can try “null” and it parses fine but it doesn’t result in finding anything.
query = #rally_api.find(:defect, :fetch =>true,
:project_scope_up => false, :project_scope_down => false,
:workspace => #workspace,
:project => #project) { equals :integration_i_d, "" }
This was followed up by telling the me to substitute "" with nil which didn't work. Null was tried to no success as well. I've tried "null" and null and "". None of them work.
I'm not familiar with our Ruby REST toolkit but directly hitting our WSAPI, you would say (<Field> = null). Notice that there are no quotes around "null".
Also, I'm wondering if the use of contains in your example above is what you wanted. You might want =.
try: { equal :integration_i_d, '""' }
Also, if rally_rest_api seems slow - we're working on something faster here:
http://developer.rallydev.com/help/ruby-rally-api

Check if an existing value is in a database

I was wondering how I would go about checking to see if a table contains a value in a certain column.
I need to check if the column 'e-mail' contains an e-mail someone is trying to register with, and if something exists, do nothing, however, if nothing exists, insert the data into the database.
All I need to do is check if the e-mail column contains the value the user is registering with.
I'm using the RedBeanPHP ORM, I can do this without using it but I need to use that for program guidelines.
I've tried finding them but if they don't exist it returns an error within the redbean PHP file. Here's the error:Fatal error: Call to a member function find() on a non-object in /home/aeterna/www/user/rb.php on line 2433
Here's the code that I'm using when trying this:
function searchDatabase($email) {
return R::findOne('users', 'email LIKE "' . $email . '"');
}
My approach on the function would be
function searchDatabase($email) {
$data = array('email' => $email);
$user = R::findOne('users', 'email LIKE :email, $data);
if (!empty($user)) {
// do stuff here
} // end if
} // end function
It's a bit more clean and in your function
Seems like you are not connected to a database.
Have you done R::setup() before R::find()?
RedBeanPHP raises this error if it can't find the R::$redbean instance, the facade static functions just route calls to the $redbean object (to hide all object oriented fuzzyness for people who dont like that sort of thing).
However you need to bootstrap the facade using R::setup(). Normally you can start using RB with just two lines:
require('rb.php'); //cant make this any simpler :(
R::setup(); //this could be done in rb.php but people would not like that ;)
//and then go...
R::find( ... );
I recommend to check whether the $redbean object is available or whether for some reason the code flow has skipped the R::setup() boostrap method.
Edited to account for your updated question:
According to the error message, the error is happening inside the function find() in rb.php on line 2433. I'm guessing that rb.php is the RedBean package.
Make sure you've included rb.php in your script and set up your database, according to the instructions in the RedBean Manual.
As a starting point, look at what it's trying to do on line 2433 in rb.php. It appears to be calling a method on an invalid object. Figure out where that object is being created and why it's invalid. Maybe the find function was supplied with bad parameters.
Feel free to update your question by pasting the entirety of the find() function in rb.php and please indicate which line is 2433. If the function is too lengthy, you can paste it on a site like pastebin.com and link to it from here.
Your error sounds like you haven't done R::setup() yet.
My approach to performing the check you want would be something like this:
$count = count(R::find('users', 'email LIKE :email', array(':email' => $email)));
if($count === 0)
{
$user = R::dispense('users');
$user->name = $name;
$user->email = $email;
$user->dob = $dob;
R::store($user);
}
I don't know if it is this basic or not, but with SQL (using PHP for variables), a query could look like
$lookup = 'customerID';
$result = mysql_fetch_array(mysql_query("SELECT columnName IN tableName WHERE id='".$lookup."' LIMIT 1"));
$exists = is_null($result['columnName'])?false:true;
If you're just trying to find a single value in a database, you should always limit your result to 1, that way, if it is found in the first record, your query will stop.
Hope this helps