Beginner programmer having problems with first program assignment

I have made a few adjustments, I still can not seem to find the problem. any help would be appreciated.

          1 ##         2 # This program computes the price of an order            from           3 # the total price and the number of the books            that          4 # were ordered from the bookstore.         5 # Constant tax rate of 7.5% on the total price            of          6 # each book.         7         8 TAX_RATE = 0.075         9         10 # Obtain number of books and book price from            order.         11 userInput = input(Number of Books purchased            ?")         12 numBooks = float(userInput)         13         14 userInput = input("Total Book Costs ?")         15 bookPrice = float(userInput)         16         17 # Calculate total for books.         18 totalForBooks = numBooks * bookPrice         19         20 totalTax = numBooks * TAX_RATE         21         22 shippingCostPerBook = 2         23 totalShippingCost = shippingCostPerBook *            numBooks         24         25 # Calculate the total of their order            including price         26 # of book(s), tax, and shipping costs.         27         28 totalOfOrder = totalForBooks + totalTax +            totalShippingCost         29 print("tax : %2f" % totalTax)         30 print("Total Shipping :" % totalShippingCost)           x 31 print("Total Order : %.2f % totalOfOrder)  

I have tried to add parenthesis, (str). I continue to get an X error in line 31. again, help would be appreciated.

I am beginner in Laravel, I am stuck into this error from the last two days. How will I solve this error. and where I will find the Grant_type code

{ “error”: “unsupported_grant_type”, “error_description”: “The authorization grant type is not supported by the authorization server.”, “hint”: “Check that all required parameters have been provided”, “message”: “The authorization grant type is not supported by the authorization server.” }

Simple .NET encryption for a beginner who wants to secure information at rest in app.config and in memory

I’m a reasonably competent developer who is happy to admit I’m a complete beginner when it comes to encryption (specifically .NET / C#). I have an application which holds some AWS credentials (access and secret key in an application configuration file (app.config). I have to do this as the machine the app runs on is not a VM, it’s a physical machine outside AWS, so it must have an IAM user with an access and secret key in order to authenticate. Initially I had just stored the credentials in the app.config file and used SecureString to encrypt at rest. The problem is, in order to use the credentials I must decrypt them in memory to a normal string. Even though I’m a complete dummy when it comes to hacking/encryption I believe this is an issue because as soon as the secure string is turned into a string, it’s in plain text in memory which means an attacker could somehow peek at the data and get the credentials.

So I want a better method to protect the credentials both at rest, and possibly while being used in memory. The AWS credentials object will only take plain strings as the access and secret key, so I guess at some point I have to decrypt them, but is there any better way / method to protect these values at rest and/or in memory?

I know there are a wealth of encryption libraries, but they are very imposing for a beginner who isn’t super familiar with salts/hashes and all that. Does anyone know of a good step by step easy to understand tutorial and/or library/plug in I can use to offer better protection? It’s hard to assess one library or technique versus any other when you don’t know the jargon. All I know is that AES-256 is probably the right ‘level’ of protection needed.

I have found lots of libraries and tutorials, but many of them assume a certain level of knowledge around encryption. I’m happy to learn, but I need some pointers and tips on how to get started, or a library that might abstract some of the heavy lifting. I dont’ want to roll my own thing here, I want to use something established. But my limited understanding means I can’t get my head around how secure using encryption of any kind would be, as I guess I’d have to – at some point – store some kind of key somewhere in the file system that could be found and used to decrypt the data.

Assistance appreciated, and please be gentle – as I said I’m a beginner here, and am happy to admit my ignorance in the hopes that people can suggest helpful solutions 🙂

ActiveDirectory and DNS Practice Setup for Beginner

Not sure if this is the correct site in the network for this question, but here goes!

I have a very strong software background (root cause analysis, troubleshooting, deployment and config).

I’ve recently taken a job where Active Directory and Networking is very much needed.

I was wondering if it is possible to create a 2 VMs on something like DigitalOcean and spin up Windows Server and create my own DomainController and DNS server to practice and to join my home PC to that domain.

I have a registered domain name already on GoDaddy: www.keplerio.com

Should I name my AD domain something like keplerio-ad.com? Or domain.keplerio.com?

Also, would joining my home PC to this theoretical domain controller take away my ability to sign in with the local user created by using my Microsoft account on Windows 10?

Any info that could fill in the gaps for me or give me a meaningful learning path is appreciated! I’m looking into a cert path that will benefit me in the most meaningful ways but am foggy on where I should start with those. All of my experience is from my last 3 jobs!

Beginner c# snake game

I just started using c# and I made this snake game in a console application . It is a bit jittery when i run it in visual studio. How could I improve it to be cleaner and less jittery.

using System; using System.Collections.Generic; using System.Linq; using System.Threading;  namespace _2017project1 {     class Program     {         const int SCREEN_MULT = 5;         public const int SCREEN_W = 12 * SCREEN_MULT;         public const int SCREEN_H = 5 * SCREEN_MULT;          static void Main(string[] args)         {             var s = new Snake();             var f = new Fruit();             bool escape = false;              InitGame(s, f);             escape = Welcome(escape);              while (!escape)             {                 ResetGame(s, f);                 escape = PlayGame(s, f, escape);                 if (!escape)                 {                     escape = DoGameOver(s, escape);                 }             }         }          static bool Welcome(bool escape)         {             ConsoleKeyInfo keyInfo;              string[] Instructions = { "Welcome to the snake game", "Your goal is to collect the red fruit", "Use the arrow keys to move around", "Press esc to exit", "Press any key to begin" };              for (int i = 0; i < Instructions.Count(); i++)             {                 Console.SetCursorPosition((SCREEN_W / 2) - ((Instructions[i].Length / 2)), (SCREEN_H / 2) + i - (Instructions.Count() / 2));                 Console.WriteLine(Instructions[i]);             }              if ((keyInfo = Console.ReadKey(true)).Key == ConsoleKey.Escape)             {                 return true;             }              return false;         }          static void InitGame(Snake s, Fruit f)         {             Console.CursorVisible = false;             Console.ForegroundColor = ConsoleColor.Green;             Console.WindowHeight = SCREEN_H;             Console.WindowWidth = SCREEN_W;         }          static bool PlayGame(Snake s, Fruit f, bool escape)         {             ConsoleKeyInfo keyInfo;             Snake.ShowScore(s);              while (true)             {                 s.doGrow = false;                  Thread.Sleep(Convert.ToInt16(100 / s.speed));                 Console.Clear();                 if (Console.KeyAvailable == true)                 {                     keyInfo = Console.ReadKey(true);                     switch (keyInfo.Key)                     {                         case ConsoleKey.UpArrow:                             Snake.SetDir(0, -1, s);                             break;                         case ConsoleKey.DownArrow:                             Snake.SetDir(0, 1, s);                             break;                         case ConsoleKey.RightArrow:                             Snake.SetDir(1, 0, s);                             break;                         case ConsoleKey.LeftArrow:                             Snake.SetDir(-1, 0, s);                             break;                         case ConsoleKey.Escape:                             escape = true;                             return escape;                     }                 }                 Snake.Eat(s, f);                 Snake.Update(s);                 if (s.dead)                 {                     break;                 }                 Snake.ShowScore(s);                 Fruit.Show(f);                 Snake.Show(s);             }             return false;         }          static bool DoGameOver(Snake s, bool escape)         {             string[] Instructions = { "Game  Over", "Score: " + s.score };             ConsoleKeyInfo keyInfo;              for (int i = 0; i < Instructions.Count(); i++)             {                 Console.SetCursorPosition((SCREEN_W / 2) - ((Instructions[i].Length / 2)), (SCREEN_H / 2) + i - (Instructions.Count() / 2));                 Console.WriteLine(Instructions[i]);             }              if (s.score > s.highScore)             {                 s.highScore = s.score;                 Console.SetCursorPosition((SCREEN_W / 2) - 7, (SCREEN_H / 2) + 2);                 Console.WriteLine("NEW HIGH SCORE!!!");             }              Console.SetCursorPosition((SCREEN_W / 2) - 6, (SCREEN_H / 2) + 3);             Console.WriteLine("Highscore: " + s.highScore);             Thread.Sleep(3000);             if (!escape)             {                 Console.Clear();                 Console.SetCursorPosition((SCREEN_W / 2) - 8, (SCREEN_H / 2) - 1);                 Console.WriteLine("Press esc to exit");                 Console.SetCursorPosition((SCREEN_W / 2) - 12, (SCREEN_H / 2) + 1);                 Console.WriteLine("Or press any key play again");                 if ((keyInfo = Console.ReadKey(true)).Key == ConsoleKey.Escape)                 {                     return true;                 }                 else                 {                     return false;                 }             }             return true;         }          static void ResetGame(Snake s, Fruit f)         {             Fruit.NewPosition(f, s);             Snake.InitSnake(s);         }     }             class Snake     {         const double SPEED_INCREMENT = 0.3;         const int START_LENGTH = 10;         const char SNAKE_CHAR = '@';         const ConsoleColor SNAKE_COLOUR = ConsoleColor.Green;          public int x;         public int y;         public int xDir;         public int yDir;         public int score;         public int highScore = 0;         public double speed;         public bool doGrow;         public bool dead;         public List<int> xPositions = new List<int>();         public List<int> yPositions = new List<int>();          public static void InitSnake(Snake s)         {             s.x = 9;             s.y = 3;             s.xDir = 1;             s.yDir = 0;             s.score = 0;             s.speed = 1.2;             s.doGrow = false;             s.dead = false;             s.xPositions.Clear();             s.yPositions.Clear();              for (int i = START_LENGTH - 1; i >= 0; i--)             {                 s.xPositions.Add(s.x - i);                 s.yPositions.Add(s.y);             }         }          public static void SetDir(int x, int y, Snake s)         {             if (s.xDir != -x && s.yDir != -y)             {                 s.xDir = x;                 s.yDir = y;             }         }          public static void Update(Snake s)         {             s.x = s.x + s.xDir;             s.y = s.y + s.yDir;              if (IsGameOver(s))             {                 s.dead = true;             }              s.xPositions.Add(s.x);             s.yPositions.Add(s.y);             if (!s.doGrow)             {                 s.xPositions.RemoveAt(0);                 s.yPositions.RemoveAt(0);             }         }          public static void Eat(Snake s, Fruit f)         {             if (s.x == f.x && s.y == f.y)             {                 s.speed = s.speed + SPEED_INCREMENT;                 s.score++;                 Fruit.NewPosition(f, s);                 s.doGrow = true;             }         }          public static void Show(Snake s)         {             Console.ForegroundColor = ConsoleColor.Green;             for (int i = 0; i < s.xPositions.Count(); i++)             {                 Console.SetCursorPosition(s.xPositions[i], s.yPositions[i]);                 Console.Write(SNAKE_CHAR);             }         }          public static void ShowScore(Snake s)         {             Console.ForegroundColor = SNAKE_COLOUR;             Console.SetCursorPosition(0, 0);             Console.WriteLine("Score: " + s.score);         }          static bool IsGameOver(Snake s)         {             if (s.x < 0 || s.x > Program.SCREEN_W - 1 || s.y < 0 || s.y > Program.SCREEN_H - 1)             {                 return true;             }             for (int i = 0; i < s.xPositions.Count(); i++)             {                 if (s.xPositions[i] == s.x && s.yPositions[i] == s.y)                 {                     return true;                 }             }             return false;         }     }      class Fruit     {         const ConsoleColor FRUIT_COLOUR = ConsoleColor.Red;         const ConsoleColor BACK_COLOUR = ConsoleColor.Black;         const int fruitPosBuffer = 2;          public int x = 10;         public int y = 10;          public static void Show(Fruit f)         {             Console.SetCursorPosition(f.x, f.y);             Console.BackgroundColor = FRUIT_COLOUR;             Console.WriteLine(" ");             Console.BackgroundColor = BACK_COLOUR;         }          public static void NewPosition(Fruit f, Snake s)         {             int newX;             int newY;             Random pos = new Random();              do             {                 newX = pos.Next(fruitPosBuffer, Program.SCREEN_W - fruitPosBuffer);                 newY = pos.Next(fruitPosBuffer, Program.SCREEN_H - fruitPosBuffer);             } while (ValidPos(f, s, newX, newY) == false);              f.x = newX;             f.y = newY;         }          static bool ValidPos(Fruit f, Snake s, int newX, int newY)         {             if (newX == f.x || newY == f.y)             {                 return false;             }             if (s.xPositions.Contains(newX) || s.yPositions.Contains(newY))             {                 return false;             }             else             {                 return true;             }         }      } } 

Beginner: Is my .htaccess file ok?

I have absolutely no idea about all this. Does this look good, and at least like it will do my site no harm?

I'm frustrated, because I don't even know if my ISP has contradictory settings that might be keeping me from getting business, and they appear to have no interested in helping me.

View attachment 241955 View attachment 241956

Android – how much Firebase should beginner android programmers use

So i just discovered that Firebase has some insane options. I’m working on some basic apps that require stuff like Basic user management, authentication, caching, storing stuff in both a remote database and in SQLite, and similar stuff. I’ve spent time learning how to implement stuff like this manually. I made some basic authentication on my back-end, i set up a pretty good database, used livedata, and stuff like that. Basically my questions are:

  • Should i continue doing stuff like this manually till i learn this stuff properly, or should i start learning firebase, since it seems like you need to spend some time on tutorials concerning firebase as well?

  • What do most experienced android programmers do these days? Do they all use firebase? Do they only use firebase for some common stuff like messaging and authentication? Do people find that the price you pay for firebase is worth it ?

Which websites should i use to start learning the basics of AI and machine language in python? Java beginner here

i am a student that has only picked up the basics of java and object oriented programming. My school is attending a workshop on machine learning and AI based in python. I would like to know where and which websites should i start off with to get a better idea of the topics before the workshop.

There are many sites that cover AI but they do not seem to be that easy to understand due to the top down approach.

i am currently using this site https://machinelearningmastery.com/machine-learning-in-python-step-by-step/ to start with ML. Any recommendations that might be useful for beginners to start?

SQL beginner trying to calculate total time in minutes; need help with WHERE syntax error

I’m trying to calculate the total minutes employees were on a system. The data, stored as ‘Action’ looks something like below. Note that employees log on and off multiple times a day.

|---------------------|------------------|------------------------| |         empid       |      action      |         log_date       |  |---------------------|------------------|------------------------| |          a1         |         ON       |2019-01-01T07:00:00.000Z| |---------------------|------------------|------------------------| |          a1         |         OFF      |2019-01-01T07:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         ON       |2019-01-01T08:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         OFF      |2019-01-01T11:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         ON       |2019-01-01T12:30:00.000Z| |---------------------|------------------|------------------------| |          a1         |         OFF      |2019-01-01T12:45:00.000Z| |---------------------|------------------|------------------------| |          a2         |         ON       |2019-01-01T08:45:00.000Z| |---------------------|------------------|------------------------| |          a2         |         OFF      |2019-01-01T09:15:00.000Z| |---------------------|------------------|------------------------| |          a2         |         ON       |2019-01-01T10:00:00.000Z| |---------------------|------------------|------------------------| |          a2         |         OFF      |2019-01-01T11:45:00.000Z| |---------------------|------------------|------------------------| 

Below is the SQL query code that I have been working on so far, but it’s returning ‘Query Error: error: syntax error at or near “WHERE”‘.

SELECT e.empid, CAST(e.log_date AS DATE) AS date, SUM(DATEPART(MINUTE, CAST(e.log_date - s.log_date AS TIME))) AS work_minutes FROM (SELECT empid, log_date       FROM Activity       WHERE action = 'ON') AS s JOIN (SELECT empid       FROM Activity       WHERE action = 'OFF') AS e ON e.empid = s.empid WHERE e.log_date = (SELECT log_date                     FROM Activity                     LIMIT 1                     WHERE empid = e.empid                     AND log_date > s.log_date) GROUP BY e.empid, CAST(e.log_date AS DATE); 

What seems to be the problem? I want the query result to look something like this:

|---------------------|------------------|------------------------| |         empid       |        date      |      work_minutes      |  |---------------------|------------------|------------------------| |          a1         |    2019-01-01    |        100 minutes     | |---------------------|------------------|------------------------| |          b2         |    2019-01-01    |        150 minutes     | |---------------------|------------------|------------------------| 

(work_minutes values above are random)

Any help will be greatly appreciated. Thank you!

Beginner Console Conway’s Game of Life in C

For an Information System Security course I’ll be taking later this year, I need to learn C and decided to start learning it yesterday.

Conway’s Game of Life has historically been a good project to start with, so I picked it. Here’s a GIF of the end result (sorry about the wobble; it’s just simple console printing so the result isn’t perfect. I might try using Curses next):

Conway's GoL Sample

I’d like comments on anything. I’ve never worked this low down before, so I’m likely doing some things incorrectly. I have a few main concerns though:

  • Am I allocating and handling memory correctly? Do I have any undefined behavior?

  • Is there a better way of writing formatWorld? In Clojure, that would be like 5 lines. It ended up getting a little messy on me here though. String operations seem incredibly difficult to pull off.

  • Is my use of size_t appropriate here? It seems to be the type to use when dealing with data that shouldn’t be allowed to be negative, but as soon as I started looking for places to use it, I realized that it seems it should be used everywhere.

  • Am I using headers properly? It seems like I should declare functions in the header that I expect the end user to use, and don’t declare internal “private” functions.

  • Any stylistic/convention concerns.


world.h

#pragma once #include <stdbool.h> #include <stdlib.h>  typedef struct {     bool* readCells;     bool* writeCells;      size_t width;     size_t height;  } World;  // All write operations are done to writeArray, and all read operations are read from //  read array.  // Returns a pointer to a newly allocated World with the given dimensions World* newWorld(size_t width, size_t height);  // Gets/Sets the Cell at the given position void setCell(World* world, size_t x, size_t y, bool isAlive); bool getCell(World*, size_t x, size_t y);  // Returns a char array representing the World  char* formatWorld(World*); // Helper that prints the array returned from the function void printWorld(World*);  // Advances the world by one "tick" void advanceWorld(World*); 

world.c

#include <stdio.h> #include <stdbool.h> #include <stdlib.h> #include <string.h> #include <time.h>  #include <windows.h> // For sleep  #include "world.h"   #define MOORE_SEARCH_DEPTH 1  #define WORLD_WIDTH 50 #define WORLD_HEIGHT 50  #define LOOP_ADVANCE_DELAY 100  // Returns a representation of a non-ragged 2D array with the given dimensions //  where all the cells are dead bool* newDeadCells(size_t width, size_t height) {     bool* cells = malloc(sizeof(bool) * width * height);      for (size_t i = 0; i < (width * height); i++) {         cells[i] = false;     }      return cells; }  World* newWorld(size_t width, size_t height) {     World* w = malloc(sizeof(World));      w->width = width;     w->height = height;      w->readCells = newDeadCells(width, height);     w->writeCells = newDeadCells(width, height);      return w; }  // Randomizes the cells so that each cell has an aliveChance chance of being alive void randomizeCells(World* world, float aliveChance) {     size_t width = world->width;     size_t height = world->height;      for (size_t i = 0; i < (width * height); i++) {         world->readCells[i] = (rand() % 100) < aliveChance * 100;     } }  // Overwrites the readable cells with the writable cells void copyWritableToReadable(World* world) {     memcpy(world->readCells, world->writeCells,         sizeof(bool) * world->width * world->height); }  // Frees the given World and any memory associated with it void freeWorld(World* world) {     free(world->readCells);     free(world->writeCells);     free(world); }  size_t indexOf(size_t width, size_t x, size_t y) {     return width * y + x; }  void setCell(World* world, size_t x, size_t y, bool isAlive) {     size_t index = indexOf(world->width, x, y);      world->writeCells[index] = isAlive; }  bool getCell(World* world, size_t x, size_t y) {     int index = indexOf(world->width, x, y);      return world->readCells[index]; }  // Returns the number of live neighbors surrounding the given position. // depth returns how many squares to look in each direction. 1 = Standard Moore Neighborhood. size_t nAliveNeighborsSurrounding(World* world, size_t x, size_t y, size_t depth) {     size_t xBound = min(x + depth + 1, world->width);     size_t yBound = min(y + depth + 1, world->height);      size_t aliveCount = 0;     for (size_t ny = max(0, y - depth); ny < yBound; ny++) {         for (size_t nx = max(0, x - depth); nx < xBound; nx++) {              if (getCell(world, nx, ny) && !(nx == x && ny == y)) {                 aliveCount++;             }         }     }      return aliveCount; }  bool cellShouldLive(bool isAlive, size_t nNeighbors) {     return (isAlive && nNeighbors >= 2 && nNeighbors <= 3)         || (!isAlive && nNeighbors == 3); }  // Decides if a cell should live or die, and sets it accordingly void advanceCellAt(World* world, size_t x, size_t y) {     size_t nNeighbors = nAliveNeighborsSurrounding(world, x, y, MOORE_SEARCH_DEPTH);     bool isAlive = getCell(world, x, y);      setCell(world, x, y, cellShouldLive(isAlive, nNeighbors)); }  void advanceWorld(World* world) {     size_t width = world->width;     size_t height = world->height;      for (size_t y = 0; y < height; y++) {         for (size_t x = 0; x < width; x++) {             advanceCellAt(world, x, y);         }     }      copyWritableToReadable(world); }  char* formatWorld(World* world) {     size_t width = world->width;     size_t height = world->height;      size_t nCells = width * height;      // total cells needed + extra for newlines + NL term     size_t buffSize = sizeof(char) * nCells + height + 1;     char* buffer = malloc(buffSize);     buffer[buffSize - 1] = '';      size_t i = 0;     for (size_t y = 0; y < height; y++) {         for (size_t x = 0; x < width; x++) {             bool isAlive = getCell(world, x, y);             char rep = isAlive ? '#' : ' ';             buffer[i] = rep;              i++;         }          buffer[i] = '\n';          i++;     }      return buffer; }  void printWorld(World* world) {     char* formatted = formatWorld(world);     printf("%s", formatted);     free(formatted); }  void simpleConsoleRoutine() {     srand(NULL);      World* world = newWorld(WORLD_WIDTH, WORLD_HEIGHT);     randomizeCells(world, 0.3);      // Leaving it with a counter so I can limit it easily later     for (size_t i = 0; ; i++) {         printWorld(world);         printf("----------\n");          advanceWorld(world);          Sleep(LOOP_ADVANCE_DELAY);     }      // No need to free world? }  int main() {     simpleConsoleRoutine(); }