Need help with my risk game program – i need to insert 2 players, throw x number of dices, order them and confront the results of the 2 players

using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; using System.Text;

namespace ConsoleApp8 { class Program { static List names; static List dices; // [2, 3] static List player1Dices = new List(); static List player2Dices = new List();

    static List<string> PromptNames()     {         Console.Write("Nome del primo giocatore: ");         string player1 = Console.ReadLine();         Console.Write("Nome del secondo giocatore: ");         string player2 = Console.ReadLine();          List<string> names = new List<string>();          names.Add(player1);         names.Add(player2);         return names;     }      static int GetDieValue(string x, string msg)     {         Console.Write("{0}, {1} ", x, msg);         string rawDie = Console.ReadLine();         int parsedDie;         // qui devi usare do, while perché non sai a priori quante volte un giocatore potrebbe inserire un valore sbagliato         if (!Int32.TryParse(rawDie, out parsedDie))         {             Console.WriteLine("Meti un numero");             return GetDieValue(x, msg);         }         return parsedDie;     }      static List<int> PromptDices()     {         int p1Dices = GetDieValue(names[0], "con quanti dadi vuoi attaccare?");         int p2Dices = GetDieValue(names[1], "con quanti dadi ti vuoi difendere?");          return new List<int>() { p1Dices, p2Dices };     }     static void Play()     {         Console.WriteLine("{0} attacca con {1} dadi", names[0], dices[0]);         Console.WriteLine("{0} difende con {1} dadi", names[1], dices[1]);         CalculateResult();      }     static void CalculateResult()     {         System.Random random = new System.Random();         for (int i = 0; i <= dices.Count; i++)         {             player1Dices.Add(random.Next(1, 7));         }         Console.WriteLine("Prima: {0}{1}{2}", player1Dices[0], player1Dices[1], player1Dices[2]);         player1Dices = player1Dices.OrderByDescending(x => x).ToList();         Console.WriteLine("Dopo: {0}{1}{2}", player1Dices[0], player1Dices[1], player1Dices[2]);           for (int i = 0; i <= dices.Count; i++)         {             player2Dices.Add(random.Next(1, 7));         }         Console.WriteLine("Prima: {0}{1}{2}", player2Dices[0], player2Dices[1], player2Dices[2]);         player2Dices = player2Dices.OrderByDescending(x => x).ToList();         Console.WriteLine("Dopo: {0}{1}{2}", player2Dices[0], player2Dices[1], player2Dices[2]);      }         private static void PlayAgain(string x)     {         Console.WriteLine("Se vuoi finire il gioco scrivi Exit");         string Exit = x;         do         {             RunGame();             player1Dices.Clear();             player2Dices.Clear();         }         while (x != Console.ReadLine());                }      static void RunGame()     {         names = PromptNames();         dices = PromptDices();         CalculateResult();         Play();         PlayAgain();                          // generate random numbers - and sort them         // display results - compare dices         // repeat or quit?     }      private static void PlayAgain()     {         throw new NotImplementedException();     }      static void Main(string[] args)     {         RunGame();         Console.WriteLine("Thanks for playing");         Console.ReadKey();     } } 

}

php mysql create an entry into a field. (INSERT INTO) WHILE logged in currentuser/session

I did the php registration system and it works https://www.tutorialrepublic.com/php-tutorial/php-mysql-login-system.php

but i created extra fields in the DB so the user can add some data to the database.

All search results are only to add to database from scratch, not from CURRENT SESSION USER. or they are just how to make php user reg systems but no further PHP CURRENT SESSION user interaction with DB

DB structure is just like on that site, i posted above, but created a URL field so a user can save their favorite URL. DB = **users > username > URL ** once i get that working im going to figure out how a user can append to the field and keep adding URLs

i came up with this.. .

if (isset($  _SESSION['loggedin']) && $  _SESSION['loggedin'] == true) { echo "<a href="file.php?save=yes>Add to Favorites</a>";}   if(isset($  _GET['save'])){          echo "got a save";      userID = $  _SESSION["username"];      echo $  userID; //it does give the current username, meaning im logged in , session-start is on the header .        $  URL = $  _GET['URLforbookmark'];      $  sql = "INSERT INTO users (URL, UserID)      VALUES ('$  URL', '$  UserID')";            if (mysqli_query($  sql)) {         echo "New record created successfully !";      } else {         echo "Error: " . $  sql . " " . mysqli_error($  sql);      }      mysqli_close($  sql); } 

Feedback Error reads: Error: INSERT INTO users (test, UserID) VALUES (‘theusersfavorurl’, ”)

thank you !

How to mark nodes and insert weights in an adjacency graph?

I have a graph with 12 nodes. The x and y coordinates are give as

xcord={154.780094065851,    302.747331652902,   348.235746943268,   959.228504576796,   1021.26721027296,   1114.13365936238,   358.208241883160,   181.741156296042,   838.759299985938,   906.502702816486,   662.579285251179,   536.372745335719};  ycord={347.543166449207,    461.536311618993,   261.753095520236,   431.778284592051,   250.920713280060,   432.113192132818,   1044.66583584371,   1044.70069210915,   1135.19457237168,   984.121301679063,   792.153882418914,   708.946190878097}; 

Also, these are the edges connecting the nodes.

Edges={{1,2},{1,3},{1,8},{1,11},{1,12},{2,3},{2,4},{2,7},{2,8},{2,11},{2,12},{3,4},{3,5},{3,11},{3,12},{4,5},{4,6},{4,10},{4,11},{4,12},{5,6},{5,11},{5,12},{6,10},{6,11},{6,12},{7,8},{7,9},{7,10},{7,11},{7,12},{8,9},{8,11},{8,12},{9,10},{9,11},{9,12},{10,11},{10,12},{11,12}}; 

Let’s say, The weight of the edges are randomly generated.

I want to plot the graph. The nodes should be depicted as circles with the index within it. I also want to place the weight over the edges.

How can I do it?

How to insert ads after an “h2, p, h3, etc…” tag

This code below is well known on the internet, I tried several times to change it and make it not only count the

tag as a paragraph, but the , , etc. tags. Does anyone have an idea how to do this?

Insert ad after second paragraph of single post content.

function prefix_insert_after_paragraph2( $ ads, $ content ) { if ( ! is_array( $ ads ) ) { return $ content; } $ closing_p = ‘

‘; $ paragraphs = explode( $ closing_p, $ content );

foreach ($  paragraphs as $  index => $  paragraph) {     if ( trim( $  paragraph ) ) {         $  paragraphs[$  index] .= $  closing_p;     }      $  n = $  index + 1;      if ( isset( $  ads[ $  n ] ) ) {         $  paragraphs[$  index] .= $  ads[ $  n ];     } }  return implode( '', $  paragraphs ); 

}

add_filter( ‘the_content’, ‘prefix_insert_post_ads’ );

function prefix_insert_post_ads( $ content ) { if ( is_single() && ! is_admin() ) { $ content = prefix_insert_after_paragraph2( array( // The format is: ‘{PARAGRAPH_NUMBER}’ => ‘AD_CODE’, ‘1’ => ‘ ad code 1 goes here ‘, ‘6’ => ‘ ad code 2 goes here’, ), $ content ); }

return $  content; 

}

Is Postgres insert performance the same in the replica

We’ve got a Postgres database with a table that takes heavy select, update and inserts that needs some tuning (it has too many indexes).

We have a read replica, and I’m wondering if moving all of our SELECT queries over to the replica will be a quick win while we sort out the indexes performance. (Our application can be switched over to a replica fairly easily while sorting the indexes is going to take longer).

My understanding is that pointing read operations at the replica probably won’t improve performance in this case, but wanted to check my understanding.

My understanding is that:

  1. INSERT and UPDATE operations will return once they’re committed to memory (which is then written to the WAL asynchronously), so they’ll be not much faster.
  2. The replica will stream the WAL and will have to update it’s own copy of the tables and indexes. So SELECT operations on the replica will have to contend with the same IO and CPU demands that those updates impose on the primary, so will gain no performance.

If our app were simply streaming inserts, then I could see a performance improvement for the inserts, but in practice since the clients are performing SELECT/INSERT together, I can’t see a real performance gain here in this use case?

Is this correct, or have I missed something?

NDSolve How do I insert another boundry condition

So I’m new to programming and I am trying to solve a very simple differential equation (i can do this by hand but the thing is i can’t program it), the equation is a'[t] == - 0.0118, with the boundary conditions a[0]==3 and I want to know a[180]=?, how do I insert this (a[180]=?) into the code, this is my short code.

Sol = NDSolve[{a'[t] == -0.0118 , a[0] == 3 }, a, {t, 0, 180}] Plot[Sol, {t, 0, 180}]  

It doesn’t show anything in the plot

Thanks a lot, any type of help will be appreciated

Insert custom data to custom table on wordpress database

i need some help here

i wanna create some form for user to subscribe our article and store the data to database. i have tried to search it on google, but nothing worked when i tried that. i know that some plugin can do that but i dont know how to create the validation when user already subscribed and the form never show again.

how do i do to insert the data to my database? hope you guys understand what the problem and any help will appreciate

thank you

here is my code

the form

                    <form action="<?php echo site_url() . '/insert-data.php'; ?>" method="POST" name="form-subscribe">                         <div class="row">                             <div class="col-12 col-lg-12 col-md-12">                                 <p>Name*</p>                                 <input type="text" name="subs_name" placeholder="Full Name*" required="">                                                            </div>                         </div>                         <div class="row mt-3">                             <div class="col-12 col-lg-12 col-md-12">                                 <p>Email*</p>                                 <input type="text" name="subs_email" placeholder="Email Address*" required="">                                                           </div>                         </div>                         <div class="row mt-3">                             <div class="col-12 col-lg-12 col-md-12">                                 <p><button type="submit" class="btn btn-primary" name="submitForm">Submit</button></p>                             </div>                         </div>                     </form> 

the action file aka insert-data.php

<?php      //setting up the form     function insertuser() {        $  name   = $  _POST['subs_name'];       $  email  = $  _POST['subs_email'];          global $  wpdb;        $  table_name = $  wpdb->prefix . "subscriber";       $  wpdb->insert($  table_name, array('subs_name' => $  name, 'subs_email' => $  email) );       }  if( isset($  _POST['submitForm']) ) insertuser();  ?> 

Here is the table of wp_subscriber enter image description here

insert an HTML element if there is a submenu only

I am trying to insert an HTML element "an arrow or a checkbox" to make use of the "checkbox technique" so I can use it to expand the submenu "only if submenu is there" when checked. my question is: how to insert this HTML element if there is a "sub-menu" class only or only when the list < li> has a class "menu-item-has-children" then insert this HTML element.

I have tried to hook on 2 filters: nav_menu_css_class and wp_nav_menu_items but didn’t succeed.

I have also tried to add this element when calling the menu:

wp_nav_menu(array(  'theme_location' => 'main-menu',  'depth'          => 0,  'menu_class'     => 'topNav-List',  'menu_id'        => 'topNL',  'after'          => ' <label for="dropDown" class="btn-dropdown"></label>                        <input class="dropdown-open" type="checkbox" id="dropDown"/>                        <label for="dropDown" class="dropdown-overlay"></label>' )); 

but it will add this checkbox to all list items, which I don’t want at all.

Ajax contact form widget plugin data not insert in database

I have been working at this for weeks without success. I’ve figured out problem after problem with the code, but none of the corrections seem to fix my core problem. The form doesn’t insert anything into the database and I don’t know why. all my data’s passed in the ajax call but it doesn’t insert in the data in the database.

I’m new to ajax and to WordPress plugins so I might be missing something obvious. Please help me know where I am going wrong. Thanks in advance.

My widget form plugin code

public function widget( $  args, $  instance ) {       if ( ! isset( $  args['widget_id'] ) ) {          $  args['widget_id'] = $  this->id;                  }          $  title = ( ! empty( $  instance['title'] ) ) ? $  instance['title'] : __( 'Contact' );          $  title = apply_filters( 'widget_title', $  title, $  instance, $  this->id_base );                            ?>     <?php         if ( $  title ) {            echo '<h2 class="widget-title">'.$  args['before_title'] . $  title . $  args['after_title'].'</h2>';                    }        ?>      <form  class="form-group" method="POST" id="form" action="">         <label>Name</label><br>         <input class="form-control" type="text" id="name" name="name" ><br>         <label>Mobile</label><br>         <input type="text" class="form-control" id="mobileno" name="mobileno" required><br>         <label>Email</label><br>         <input class="form-control"  type="email" id="email" name="email" ><br>         <label>Message</label><br>         <textarea class="form-control" id="message" name="message"  maxlength="10" onKeyPress="lengthcheck()"></textarea><br><br>         <button  class="btn btn-warning" type="submit" id="submit">Send Message</button>     </form> <?php }    

This is my enqueue methods:

add_action( 'wp_enqueue_scripts', 'vs_con_enqueue_scripts' );  function vs_con_enqueue_scripts(){  wp_register_script(     'ajaxHandle',     plugins_url('valid.js', __FILE__),     array('jquery'),     false,     true   );  wp_enqueue_script( 'ajaxHandle');  wp_localize_script(     'ajaxHandle',     'ajax_object',     array( 'ajaxurl' => admin_url( 'admin-ajax.php' ) )   );  wp_enqueue_style( 'bootstrap-style','https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css' );  }   add_action( "wp_ajax_contact", "vs_contact_form" ); add_action( "wp_ajax_nopriv_contact", "vs_contact_form" );   function vs_contact_form(){     global $  wpdb;         $  name = $  _POST["name"];        $  email = $  _POST["email"];        $  mobileno = $  _POST["mobileno"];        $  messsage = $  _POST["messsage"];                $  tablename = $  wpdb->prefix.'contactdetails';        $  insert_row = $  wpdb->insert(           $  tablename,             array(                 'name' => $  name,                 'email' => $  email,                 'mobileno' => $  mobileno,                'messsage' => $  messsage             )          );            // if row inserted in table         if($  insert_row){            echo json_encode(array('res'=>true, 'message'=>__('Message Sent Successfully')));        }else{           echo json_encode(array('res'=>false, 'message'=>__('Something went wrong. Please try again later.')));        }        wp_die(); }  

Here this is my form submit jquery ajax call function

valid.js

jQuery(document).ready(function($  ){     $  ('form#form').on('submit', function(e){        e.preventDefault();        var name =jQuery('#name').val();        var email = jQuery('#email').val();        var mobileno = jQuery('#mobileno').val();        var message = jQuery('#message').val();        debugger;        var text;        if(name.length < 5){          text = "Please Enter valid Name";         alert(text);          return false;        }        if(isNaN(mobileno) || mobileno.length != 10){          text = "Please Enter valid mobileno Number";          alert(text);          return false;        }        if(email.indexOf("@") == -1 || email.length < 6){          text = "Please Enter valid Email";          alert(text);          return false;        }                $  .ajax({           url: ajax_object.ajaxurl,           type:"POST",           dataType:'json',           data: {              action:'contact',              name: name,              email: email,              mobileno: mobileno,              message: message         },   success: function(data){             if (data.res == true){                 alert(data.message);    // success message             }          }, error: function(data){             if (data.res == false){                 alert(data.message);    // success message             }            }        });     $  ('#form')[0].reset();       });     });  

please help me to find out where I am wrong?

Disk space efficient foreign key index for insert intensive scientific database?

I’m working tuning a scientific database whose associated simulation is very insert intensive (i.e., run for a long time inserting data, execute summary query at the end). One of the tables is starting to cause some problems since the table size is 235 GB with index sizes of 261 GB, and the server only has 800 GB so we would like to free up a bit of space.

Currently there is one foreign key reference (integer data) that is stored as a clustered b-true. This has been good for the summary queries, but likely isn’t helping the disk space issues.

Is there a more disk efficient way of storing this foreign key index? Would it make sense to switch over to a hash index instead of the b-tree index?