How to print user input in malbolge? - malbolge

Finally, after some months of research I accept user input, but now I'm trying to print it in the screen.
Is that possible using Malbolge?

It is easy like this:
(=BA#9"=<;:3y7x54-21q/p-,+*)"!h%B0/.~P<<:(8&66#"!~}|{zyxwvugJ%
(Malbolge cat program, public domain)

Related

How to save variable after closing mIRC?

I'm new to do this language and i'm trying to code my own bot. I alredy got the basics and manage to use variables and aliases, however i was looking forward to do a mini-game in my chat in which you could have your own pet, name it and level it up.
I could do all this, however my problem resides in that at the end of the day, i would close the program and all the pets would go away, and that kind of destroys the purpose of it.
I was wondering if there was any way in i could save these variables and reload them each time i open the program, maybe save them on a .txt?
Any suggestion are greatly appreciated.
I agree with one of the comments that it's best to go with .ini files for this problem.
An example of the syntax, taken from the url linked above:
writeini reminder.ini birthday jenna 2/28/1983
writeini reminder.ini birthday Mike 10/10/1990
This produces the following file:
[birthday]
jenna = 2/28/1983
Mike = 10/10/1990
And is to be read like this:
echo -a Mike: $readini(reminder.ini, n, birthday, mike)
echo -a Jenna: $readini(reminder.ini, n, birthday, jenna)
If you want more flexibility to define your own data format, you can also revert to plain text files. The basic /write and $read functions have some pretty neat functionality: see the docs
Something like this should work for writing:
; search if the pet is already saved
$read(pets.txt,ns,%petname)
if ($readn == 0) {
; append to end of file
write pets.txt %petname %age %mood
}
else {
; replace line
write -l $readn pets.txt %petname %age %mood
}
To retrieve specific pets:
var %pet_info = $read(pets.txt, ns, %petname)
; Split the found line on space (ASCII-code 32)
tokenize 32 %pet_info
var %age = $2
var %mood = $3
This returns the line that starts with the petname you're looking for.

Problems check username input against flat file for user creation

I am working on a user login and am having trouble with the user creation part. My problem is that I am trying to check the input username against a text file to see if that username already exists. I can't seem to get it to compare the input username to the array that I have brought in. I have tried two different ways of accomplishing this. One using an array and another using something I read online that I don't quite understand. Any help or explanation would be greatly appreciated.
Here is my attempt using an array to compare off of
http://codepad.org/G7xmsf3z
Here is my second attempt
http://codepad.org/SbeqmdbG
In your first attempt, try to put the if inside of the loop:
foreach my $pair(#incomingarray) {
(my $name,my $value) = split (/:/, $pair);
if ($name eq $username) {
print p("Username is already taken, try again");
close(YYY);
print end_html();
}
else {
open(YYY, ">>password.txt");
print YYY $username.":".$hashpass."\n";
print p("Your account has been created sucessfully");
close(YYY);
print end_html();
}
}
In you second attempt, I think you should try and change the line:
if (%users eq $username) {
with this one:
if (defined $users{$username}) {
As has been stated above regarding locking the flatfile from other processes there is the issue with scaling too. the more users you have the slower the lookup will be.
I started years ago with a flat file, believing I would never scale enough to require a real database and didn't want to learn how to use mySQL for example. Eventually after flatfile corruptions and long lookup times I had no choice but to move to a database.
Later you will find yourself wanting to store user preferences and such, it's easy to add a new field to a database. Flatfile will end up having the overhead of splitting each line into separate fields.
I'd suggest you do it properly with a database.
As in my comment, you should not be using a flatfile to hold your user info. You should use a proper database that will handle concurrent access for you rather than having to understand and code up how to deal with all of that yourself!
If you insist on using an array, you can search it with grep() if it is not "too large":
if (grep /^$username:/, #incomingarray) {
print "user name '$username' is already registered, try again\n";
}
else {
print "user name '$username' is not already registered\n";
}
I see some other problems in your code as well.
You should always prefer lexical (my) variables over package (our) variables.
Why do you think (erroneously) that $name and $username cannot be lexical variables?
You should always use the 3-arg form of open() and check its return value like in your 2nd code example. Your open() in the 1st code example is how it was done many many years ago.

Translation rule

I like to create a translation rule to a VoIP system to obtain the following result:
If someone dials the 4545 the system must convert this to 1234545, I managed to do this with the following rule: s/^4545/1234545/
My problem now is if someone dials 454567 my rule will convert this to 123454567 and I want to get 1234545
thx
Not clear on why should 454567 become 1234545? Should a string with a run of 4545 anywhere in it be come 1234545?
If you just want to change the exact string 4545 to 1234545 then you can use s/^4545$/1234545/.
If you want a string with a run of 4545 anywhere in it to become 1234545 then you can use s/.*4545.*/1234545.
$number='1234545' if ($number eq '4545'); #eq because phone number can contain non-digits.
If you want to convert any number that starts with '4545', use this code:
s/^4545.*/1234545/

How to deal with nameless forms on websites?

I would like to write a script that lets me use this website
http://proteinmodel.org/AS2TS/LGA/lga.html
(I need to use it a few hundred times, and I don't feel like doing that manually)
I have searched the internet for ways how this could be done using Perl, and I came across WWW::Mechanize, which seemed to be just what I was looking for. But now I have discovered that the form on that website which I want to use has no name - its declaration line simply reads
<FORM METHOD="POST" ACTION="./lga-form.cgi" ENCTYPE=multipart/form-data>
At first I tried simply not setting my WWW::Mechanize object's form_name property, which gave me this error message when I provided a value for the form's email address field:
Argument "my_email#address.com" isn't numeric in numeric gt (>) at /usr/share/perl5/WWW/Mechanize.pm line 1618.
I then tried setting form_name to '' and later ' ', but it was to no avail, I simply got this message:
There is no form named " " at ./automate_LGA.pl line 40
What way is there to deal with forms that have no names? It would be most helpful if someone on here could answer this question - even if the answer points away from using WWW::Mechanize, as I just want to get the job done, (more or less) no matter how.
Thanks a lot in advance!
An easy and more robust way is to use the $mech->form_with_fields() method from WWW::Mechanize to select the form you want based on the fields it contains.
Easier still, use the submit_form method with the with_fields option.
For instance, to locate a form which has fields named 'username' and 'password', complete them and submit the form, it's as easy as:
$mech->submit_form(
with_fields => { username => $username, password => $password }
);
Doing it this way has the advantage that if they shuffle their HTML around, changing the order of the forms in the HTML, or adding a new form before the one you're interested in, your code will continue to work.
I don't know about WWW::Mechanize, but its Python equivalent, mechanize, gives you an array of forms that you can iterate even if you don't know their names.
Example (taken from its homepage):
import mechanize
br = mechanize.Browser()
br.open("http://www.example.com/")
for form in br.forms():
print form
EDIT: searching in the docs of WWW::Mechanize I found the $mech->forms() method, that could be what you need. But since I don't know perl or WWW::Mechanize, I'll leave there my python answer.
Okay, I have found the answer. I can address the nameless form by its number (there's just one form on the webpage, so I guessed it would be number 1, and it worked). Here's part of my code:
my $lga = WWW::Mechanize->new();
my $address = 'my_email#address.com';
my $options = '-3 -o0 -d:4.0';
my $pdb_2 = "${pdb_id}_1 ${pdb_id}_2";
$lga->get('http://proteinmodel.org/AS2TS/LGA/lga.html');
$lga->success or die "LGA GET fail\n";
$lga->form_number(1);
$lga->field('Address', $address);
$lga->field('Options', $options);
$lga->field('PDB_2', $pdb_2);
$lga->submit();
$lga->success or die "LGA POST fail\n";

How can I get the extension entered by user in a Perl AGI script?

I'm new to Asterisk AGI programming. Im trying to create a simple IVR, using asterisk-perl, where a user can enter any extension from 1 to 4. Here is my code so far:
use Asterisk::AGI;
$AGI = new Asterisk::AGI;
for($i = 0 ; $i < 2 ; $i++)
{
$AGI->exec('Playback','welcome');
$AGI->exec('WaitExten','5|m');
}
Now, I want to know the extension the user entered and take some action accordingly. How to get the extension entered by the user?
Thank You.
I believe you want to use get_data, allowing you to play a file and then wait a given time for a given number of digits e.g.:
$AGI->get_data('demo-welcome', 15000, 5);
See here
Well since the WaitExten command changes the user to a new extension, I suppose you can read the special variable ${EXTEN} after calling WaitExten. I'm not familiar with Asterisk::Perl though, I've only used FastAGI from Java, so I don't know the exact command, but there must be some command to read a variable's value.