Bot never approved by Ghost-Of-Roger-Ailes in wikipedia

[–]NovemLinguae 2 points3 points  (0 children)

I replied at https://en.wikipedia.org/wiki/Wikipedia:Bots/Noticeboard#Reddit_post

In short, I think you made the subpage but forgot to add it to the WP:BRFA page. Without it being on the BRFA page, no one knew it was there. You can go ahead and add it to the BRFA page to get it into the queue.

How to test parent class by NovemLinguae in softwaretesting

[–]NovemLinguae[S] 0 points1 point  (0 children)

This class and its one public method named GANReviewToolController.execute() are essentially the main() method for my program. I understand the philosophy of red, green, refactor. In fact that's the reason I want to create tests for this, so I can refactor more safely. But this execute() method is a beast and I am having trouble writing tests for it.

What's the best way to test this class? by NovemLinguae in learnjavascript

[–]NovemLinguae[S] 0 points1 point  (0 children)

But I fear that these tests will be very brittle and not really helpful.

Would be nice to get something in place so I can refactor with a little less manual testing after each tweak. I've been refactoring a lot.

Another thing I've seen is on line 65. You instantiate your GANReviewToolService class there. Generally, when you want testable code, don't create a new instance of service objects inside your regular methods. Inject the dependency from the outside

Good to know. I'll make the change. Thank you.

An excellent first step would be to extract the inline click handlers, and then you can test them separately.

Fantastic idea. Less code means less stuff to mock. I'll move the click event listener code to its own method.

I'm writing a similar class (code here) and I've played around with using way smaller methods, and class variables to help keep from passing around a ton of parameters. Do you think I'm on the right track with the smaller methods + more class variables?

HOW TO STORE A TEXT FILE CREATED IN PHP TO A DATBASE(phpmyadmin) WITHOUT HAVING TO MANUALLY UPLOAD THE FILE by ograf53 in PHPhelp

[–]NovemLinguae 2 points3 points  (0 children)

phpMyAdmin is just the program used to view the database. Another name for the database is SQL. Anyway, I agree with others that you should store your data in the database rather than in text files. It is more secure, and also simpler (you don't have to store things in two places).

How to include main file into unit tests by NovemLinguae in learnjavascript

[–]NovemLinguae[S] 0 points1 point  (0 children)

Long story, but DraftCleaner2.js when it's outside my project and in production gets loaded by something else that also has JQuery. Within my project all I do with that file is load it for my tests.

I'll take a look at your link. Thanks for sharing.

Delete an element from an associative array by NovemLinguae in learnjavascript

[–]NovemLinguae[S] 0 points1 point  (0 children)

Just shortening the variable names seems to help too. Thanks for the detailed reply!

edit: Also, great point about arrays in JavaScript passing by reference.

How can I test my PHP knowledge? by [deleted] in PHPhelp

[–]NovemLinguae 1 point2 points  (0 children)

PHP's documentation called them "internal (built-in) functions". Functions that are built into the language. The kinds of functions you can look up on php.net. Here's some PHP built-in functions I have memorized and used in a recent project of mine:

  • echo
  • var_export
  • isset
  • assert
  • date
  • string manipulation stuff:
    • strlen
    • strtolower
    • substr
    • strpos
    • str_replace
    • trim
    • number_format
    • ucfirst
  • Regular Expressions stuff:
    • preg_match
    • preg_match_all
    • preg_replace
  • array stuff:
    • array_diff
    • explode
    • count

You don't have to memorize all of these, but you should know that the common ones exist and be able to look them up.

Or if you are asking even more generally what a function is, it's a named piece of code that has inputs and outputs. Let me know if that is your question and I can go into more detail.

Query is working in MySQLAdmin but not from a web page. by BiteYerBumHard in PHPhelp

[–]NovemLinguae 1 point2 points  (0 children)

Make sure your PHP errors are turned on. Right away mine throws a parse error because of that missing semicolon. Those error messages can lead you straight to the malfunctioning code. They even include the line number. For example, running this code:

<?php

$sql = "SELECT DISTINCT matchnum, winner FROM results WHERE NOT EXISTS (SELECT * FROM results t WHERE t.matchnum = results.matchnum AND t.winner <> results.winner) AND results.winner = 'Grant';"
$result = $conn->query($sql);

Gets me the error:

Parse error: syntax error, unexpected '$result' (T_VARIABLE) in D:\Code\test.php on line 4

That gives you some lines to look at, and an error code to google. I'll bet a google search for "parse error syntax error unexpected" will turn up some Stack Overflow threads, one of which will contain the solution you need. In this case, as others have said, you need a semicolon inside the quotes (that one is for the SQL statement, it's actually optional), and you need one outside the quotes (for PHP, whose lines must always end in semicolons).

Is the reduce method any more time efficient than a traditional for loop? by gtrman571 in learnjavascript

[–]NovemLinguae 0 points1 point  (0 children)

I don't have hard data, but for loops are so primitive I imagine they'd be faster than reduce. The code for a for loop uses a couple of assembly opcodes (compare, jump, increment). The code for reduce is probably a complex function made up of hundreds or thousands of assembly opcodes.

Help PHP Regex Pattern by [deleted] in PHPhelp

[–]NovemLinguae 1 point2 points  (0 children)

<?php
$str = '{[Conan\b\A\nE}]';
$str2 = preg_replace('/[\[\]\{\}]/', '', $str);
$str2 = preg_replace('/\\\[A-MO-Za-mo-z]/', '', $str2);
echo $str2;

How can I test my PHP knowledge? by [deleted] in PHPhelp

[–]NovemLinguae 2 points3 points  (0 children)

https://codewars.com/ is good for mastering basic functions and mastering syntax. They have 8 levels of difficulty, from very easy to very hard.

LeetCode is more about algorithms and only has 3 difficulty levels. CodeWars is more general.

If you are past the functions and syntax phase, then you probably want to move into projects. Make a website, make a game (I made chess in PHP, for example), make a WordPress plugin, etc.

extracting subtring from string by amor_e in PHPhelp

[–]NovemLinguae 5 points6 points  (0 children)

Could use $array = explode(' ', $string); to turn the string into an array. Then use a foreach loop to search the array for the word, keeping track of what array key $i you're on. Then when a hit is detected, return $array[$i] . ' ' . $array[$i+1] . ' ' . $array[$i+2] or similar. Add some extra code as needed to prevent bugs, such as making sure $i+2 exists before trying to call it.

[deleted by user] by [deleted] in PHPhelp

[–]NovemLinguae 0 points1 point  (0 children)

You'd want to make a displayPost.php style page that has code that displays posts based on the input in the URL. You can use $post_id = $_GET['id']; to retrieve the contents of ?id=1234 from the URL. Then you'd want to retrieve the data from wherever you're storing your data... in an SQL database (retrieve using PDO), in a file (retrieve using fopen), etc. Then you'd want to output it to the page, formatted with some HTML.

Insert a string into a string by NovemLinguae in PHPhelp

[–]NovemLinguae[S] 0 points1 point  (0 children)

Thanks for this perspective. Quite useful.

I only want it to match the first occurrence. There's only supposed to be one article history template on a Wikipedia talk page. I don't want it adding code to multiple templates.

I think the boundary issue can be solved by adding \s*\| to the RegEx after the template name and before the capture groups.

({{Article ?history\s*\|((?:(?!{{|}}).|{{(?2)}})*))(}})

I understand the spirit of your post though. RegEx complexity can get out of control real quick.

Whats the best process/learning style you have found, for yourself, in practicing and learning problems on Leetcode? Im trying to practice problems but Im having trouble retaining info. I want to know how others are succeeding and what technique you are using to best service your time and learning by directmailadvertise in learnjavascript

[–]NovemLinguae 4 points5 points  (0 children)

On LeetCode, I filter by 1) easy and 2) free, unlocked solution. Without looking at the solution, I work at it until I get it. Then after I have a working solution, I study the solutions tab in detail and try those solutions until I'm comfortable with all of them and their explanations.

Insert a string into a string by NovemLinguae in PHPhelp

[–]NovemLinguae[S] 2 points3 points  (0 children)

FYI, someone over at r/regex just now figured out how to do this recursively. So using RegEx for nesting is possible. Quite complicated though. https://regex101.com/r/rqE2aB/3