Laravel update

At this point, I’ve written several applications in Laravel.  It is an amazing framework, and I like it better than symfony.  One drawback is that it makes cookie cutter data modeling deceptively easy.

 php artisan make:migration 

and

 php artisan make:model 

are powerful tools, but a default value on strings of varchar(255) could lead to poor performance, and you still have design an RDS if you want to scale.

Laravel in my opinion can do everything can do every SQL can, and sometimes, in a more sensible manner.  However, these out-of-the-box features must be used wisely, and are counter-productive in novice hands.

best solution on the net for phpMyAdmin/php7.2 conflict

My advice for using phpMyAdmin… don’t.   Use terminal.

But if you’re not a database fanatic and you need an easy answer, phpMyAdmin might help.  You may have encountered difficulties with php 7.2 conflicting with phpMyAdmin 4.6 on Ubuntu 18.04.  The pink screen of doom.

My recommendation is to manually upgrade.  Don’t waste your time picking through the source code and updating it.

This is the best tutorial I’ve found on the subject.  Great Website.  Great tutorial.  It saved me a ton of time.

https://devanswers.co/manually-upgrade-phpmyadmin/

scsvs: Simple CSVs.

I wrote a very basic script to export CSVs from AWS MySQL.  It’s not one of those rocket science applications that you’re going to tell your grandchildren about, but hopefully it will make life easier for anyone who uses AWS RDS of the MySQL flavor.

For some reason, AWS blocks users from exporting to CSV.  There are a lot of work arounds, but for PHP’rs, fputcsv is an easy go to.  My script basically just takes in database variables and spits out a CSV into the same folder on an apache2 server, using fputcsv.

You can find the source code here.  https://github.com/JustinLawrenceMS/scsvs.git

 

Using PHP to programmatically refresh javascript arrays with results from MySQL

This is not a working example. You will have to fix this to make it work. Also, this will not work for large data objects. However, this is really handy for updating a javascript array used by jQueryUI autocomplete, if you want to pull the results straight from MySQL but don’t need the lag that comes with a remote configuration.

A brief description, and then I’m going to cut to chase and give you some code.

Basically, autocomplete usually comes with some standard options.  You can draw from a Javascript array, or you can draw from a remote MySQL database, etc.  Sometimes, though, you get much better performance from a javascript array, even though it might have a couple thousand entries, making it easier to manipulate with MySQL.  Here’s what I did.

This is jQueryUI’s autocomplete source code:

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    var availableTags = [
      "ActionScript",
      "AppleScript",
      "Asp",
      "BASIC",
      "C",
      "C++",
      "Clojure",
      "COBOL",
      "ColdFusion",
      "Erlang",
      "Fortran",
      "Groovy",
      "Haskell",
      "Java",
      "JavaScript",
      "Lisp",
      "Perl",
      "PHP",
      "Python",
      "Ruby",
      "Scala",
      "Scheme"
    ];
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
  </script>
</head>
<body>
 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>
 
 
</body>
</html>

The computer languages in the middle are the javascript array that powers autocomplete. Imagine that there were 2000 of those. What a pain updating that would be! You could configure it as remote source, but this will slow down your autocomplete quite alot. This is what I did.

<!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Autocomplete - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
  <script>
  $( function() {
    var availableTags = <?php include '/path/to/file/autoCompArr.php' ?>
    $( "#tags" ).autocomplete({
      source: availableTags
    });
  } );
  </script>
</head>
<body>
 
<div class="ui-widget">
  <label for="tags">Tags: </label>
  <input id="tags">
</div>
 
 
</body>
</html>

Then, in autoCompArr.php, I created a PHP script that will pull the array from MySQL when the page loads. Here it is.

<?php

/* Store your database variables in a secure location and include them here 
*  For example
*  include '/path/to/file/databaseInfo.php'
*/

$connection = mysqli_connect(DBSERVER, DBUSER, DBPASS, DBNAME) or die("Can\'t connect to server. Please check credentials and try again");

$query =
"SELECT DISTINCT language
FROM csLanguages
group by language
order by language ASC"
;

$result = mysqli_query($connection, $query);

$data = array();

if(mysqli_num_rows($result) > 0)
{
 while($row = mysqli_fetch_assoc($result))
 {
  $data[] = $row['language'];
 }


 echo json_encode($data);

}
?>

Of course, you will have to tool the code to your needs. For example, changing the directories, adding database connect variables, etc. But this tactic will make changes from MySQL cascade to your Javascript array.

New project, nature conservancy Website

For the past few days, I have been diligently hacking away at a nature conservancy Website called https://locallywild.tk.  I know what it sounds like.  Most people hear that and think of Spring Break.  Basically what I am creating is a dictionary of wildlife that is iconic of the Lower Rio Grande Valley, or native to it and endangered.

The project appears to be going well thus far.  I used a Creative Commons HTML template from TEMPLATED.  The name of the template was INDUSTRIOUS, and infinite gratitude and thanks to its creators.  I used jQuery and jQueryUI for autocomplete, and I used MySQL to power the database.

I am drawing on my career as a librarian to put this together.  I have entered 36 species so far, and I plan to have at least 100 species by the end of the year.  I used Creative Commons for the photographs, and I used a variety of sources from the US Fish and Wildlife Service.  Let me tell you, it’s amazing what these folks have done (all of the above) and mil gracias.

I am really pleased with how the Website looks on an iPhone.  It still looks a little amateur on a Desktop or a Laptop, and I can’t quite put my finger on why.  I was however able to make the photos and even the tables responsive.

Well, it’s been good to finally have a hobby.  Unfortunately, both my job and my hobby is programming computers.

using PHP to change a variable name that is used several times in a folder on your Website.

Warning:  This can break your Website, and let me say, backing your Website up on gitHub is always a good idea, if you pay for a private repository.  Second, this only works for variable names that are very unique.  Changing names like “arr” or “var” are going to mutate commands and variables for which “arr” or “var” are a component.  For example, it could change array() to newNameay() and you would have to look through each php file to fix it, if you didn’t back up your Website first.

I used this to change a SQL table name that was getting out of hand.  In the beginning, I was a SQL noob and I didn’t think about putting metadata in a separate column or row.  So I put data about the most recent update in the table name.  (Terrible, I know).  It ended up looking something like:

dataSet_transactionInfo_2016_to_2018_1st_qtr

A SQL veteran could tell you right away that eventually, typing that is going to cause carpel tunnel.  So it was time to change it.  But on the company Website, I had entered it into dozens of pages, hundreds of times.  I needed a quick fix.

For that I have to thank Byron Whitlock at Stack Overflow for the inspiration.  You can find the post here:  https://stackoverflow.com/questions/3983090/find-and-replace-in-multiple-files

Based on that code, this is what I did to change that bulky, poorly named variable to “transactions”:

<?php

foreach (glob("/path/to/files/*.php") as $filename)
{
    $file = file_get_contents($filename);
    file_put_contents($filename, str_replace("dataset_transactionInfo_2016_to_2018_1st_qtr","transactions",$file));
}

?>

Of course the directory in the code will have to be adjusted for each unique scenario.  I put this code in the parent folder and saved it as ‘findAndReplace.php.  Then, from commandline, I ran:

php findAndReplace.php

I accomplished in seconds what would have taken me hours to accomplish inaccurately.  An added note, I had to run the code as written for each folder and subfolder I wanted it to run it in.  Maybe there is a shortcut.  I don’t know it.

Hello world!

I created this Website to share some of the things I’ve learned over the years in regards to Web development, database programming, and information science.  I’ve been working in this field formally since 2012.  I still find myself learning new things every day, and it is my hope that my readers will learn with me.