Welcome, Guest
You have to register before you can post on our site.

Username
  

Password
  





Search Forums

(Advanced Search)

Forum Statistics
» Members: 20,946
» Latest member: blackopsdlc
» Forum threads: 21,976
» Forum posts: 22,943

Full Statistics

Online Users
There are currently 1446 online users.
» 0 Member(s) | 1440 Guest(s)
Applebot, Baidu, Bing, DuckDuckGo, Facebook, Google

Latest Threads
BO6 & Warzone devs promis...
Forum: PC Discussion
Last Post: xSicKxBot

» Replies: 0
» Views: 0
I Thought Block Blast Was...
Forum: Lounge
Last Post: starfishmil

» Replies: 0
» Views: 2
[Steam Release] Good Comp...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 9
[DevBlog MS] Performance ...
Forum: C#, Visual Basic, & .Net Frameworks
Last Post: xSicKxBot

» Replies: 0
» Views: 16
[WoW Retail News] Over 20...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 13
[WoW Retail News] Mythic ...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 19
[Steam Release] Raft, 15%...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 16
Marvel Rivals Ace icon ex...
Forum: PC Discussion
Last Post: xSicKxBot

» Replies: 0
» Views: 19
[WoW Retail News] Undocum...
Forum: World of Warcraft
Last Post: xSicKxBot

» Replies: 0
» Views: 20
[Steam Release] Factory T...
Forum: New Game Releases
Last Post: xSicKxBot

» Replies: 0
» Views: 25

 
  PC - Patch Quest
Posted by: xSicKxBot - 03-09-2023, 02:27 AM - Forum: New Game Releases - No Replies

Patch Quest



The ONLY Roguelike-Metroidvania fusion where you can mount and ride EVERY monster in the game! Get ready to Leap, Glide, Tunnel, Bite, Slither, Websling and Explode your way through a shuffling patchwork maze. Survival depends on bending the forces of nature to your own ends! Supports 2P Local coop.

Publisher: Lychee Game Labs

Release Date: Mar 02, 2023




https://www.metacritic.com/game/pc/patch-quest

Print this item

  [Tut] My Journey to Help Build a P2P Social Network – Database Code Structure
Posted by: xSicKxBot - 03-08-2023, 08:45 AM - Forum: Python - No Replies

My Journey to Help Build a P2P Social Network – Database Code Structure

5/5 – (1 vote)

Welcome to part 3 of this series, and thank you for sticking around!

I’ve come to realize this might become a rather long series. The main reason for that is that it documents two things. This is the birth of an application and my personal journey in developing that application. I know parts 1 and 2 have been very wordy. This will change now. I promise that you will see a lot of code in this episode :-).

Database Code


So after that slight philosophical tidbit, it is time to dive into the actual database code. As I mentioned in the previous article, I chose to use Deta Space as the database provider. There are two reasons for this. The first is the ease of use and the second are its similarities to my favorite NoSQL database MongoDB.

? Recommended: Please check my article on creating a shopping list in Streamlit on how to set it up. It takes only a few minutes.

For reference, the server directory with all the code to get the FastAPI server working looks as follows:

server
├── db.py
├── main.py
├── models.py
├── requirements.txt
├── .env

All the database code will live in the db.py file. For the Pydantic models, I’ll use models.py.

Database Functions


The database functions are roughly divided into three parts.

  • We first need functionality for everything related to users.
  • Next, we need to code that handles everything related to adding and managing friends.
  • The third part applies to all the code for managing thoughts. Thoughts are Peerbrain’s equal of messages/tweets.

The file will also contain some helper functions to aid with managing the public keys of users. I’ll go into a lot more detail on this in the article about encryption.

To set up our db.py file we first need to import everything needed. As before, I’ll show the entire list and then explain what everything does once we write code that uses it.

"""This file will contain all the database logic for our server module. It will leverage the Deta Base NoSQL database api.""" from datetime import datetime
import math
from typing import Union
import os
import logging
from pprint import pprint #pylint: disable=unused-import
from uuid import uuid4
from deta import Deta
from dotenv import load_dotenv
from passlib.context import CryptContext

The #pylint comment you can see above is used to make sure pylint skips this import. I use pprint for displaying dictionaries in a readable way when testing. As I don’t use it anywhere in the actual code, pylint would start to fuss otherwise.

? Tip: For those interested, pylint is a great tool to check your code for consistency, errors and, code style. It is static, so it can’t detect errors occurring at runtime. I like it even so?.

After having imported everything, I first initialize the database. The load_dotenv() below, first will load all my environment variables from the .env file.

load_dotenv() #---DB INIT---#
DETA_KEY = os.getenv("DETA_KEY")
deta = Deta(DETA_KEY)
#---#
USERS = deta.Base("users")
THOUGHTS = deta.Base("thoughts")
KEYS = deta.Base("keys_db")

Once the variables are accessible, I can use the Deta API key to initialize Deta. Creating Bases in Deta is as easy as defining them with deta.Base. I can now call the variable names to perform CRUD operations when needed.

Generate Password Hash


The next part is very important. It will generate our password hash so the password is never readable. Even if someone has control of the database itself, they will not be able to use it. Cryptcontext itself is part of the passlib library. This library can hash passwords in multiple ways.?.

#---PW ENCRYPT INIT---#
pwd_context = CryptContext(schemes =["bcrypt"], deprecated="auto")
#---#
def gen_pw_hash(pw:str)->str: """Function that will use the CryptContext module to generate and return a hashed version of our password""" return pwd_context.hash(pw)

User Functions


The first function of the user functions is the easiest. It uses Deta’s fetch method to retrieve all objects from a certain Base, deta.users, in our case.

#---USER FUNCTIONS---#
def get_users() -> dict: """Function to return all users from our database""" try: return {user["username"]: user for user in USERS.fetch().items} except Exception as e: # Log the error or handle it appropriately print(f"Error fetching users: {e}") return {}

The fact that the function returns the found users as a dictionary makes them easy to use with FastAPI. As we contact a database in this function and all the others in this block, a tryexcept block is necessary.

The next two functions are doing the same thing but with different parameters. They accept either a username or an email.

I am aware that these two could be combined into a single function with an if-statement. I still do prefer the two separate functions, as I find them easier to use. Another argument I will make is also that the email search function is primarily an end user function. I plan to use searching by username in the background as a helper function for other functionality.

def get_user_by_username(username:str)->Union[dict, None]: """Function that returns a User object if it is in the database. If not it returns a JSON object with the message no user exists for that username""" try: if (USERS.fetch({"username" : username}).items) == []: return {"Username" : "No user with username found"} else: return USERS.fetch({"username" : username}).items[0] except Exception as error_message: logging.exception(error_message) return None def get_user_by_email(email:str)->Union[dict, None]: """Function that returns a User object if it is in the database. If not it returns a JSON object with the message no user exists for that email address""" try: if (USERS.fetch({"email" : email}).items) == []: return {"Email" : "No user with email found"} else: return USERS.fetch({"email" : email}).items[0] except Exception as error_message: logging.exception(error_message) return None

The functions above both take a parameter that they use to filter the fetch request to the Deta Base users.

If that filtering results in an empty list a proper message is returned. If the returned list is not empty, we use the .items method on the fetch object and return the first item of that list. In both cases, this will be the user object that contains the query string (email or username).

The entire sequence is run inside a try-except block as we are trying to contact a database.

Reset User Password


When working with user creation and databases, a function to reset a user’s password is required. The next function will take care of that.

def change_password(username, pw_to_hash): """Function that takes a username and a password in plaintext. It will then hash that password> After that it creates a dictionary and tries to match the username to users in the database. If successful it overwrites the previous password hash. If not it returns a JSON message stating no user could be found for the username provided.""" hashed_pw = gen_pw_hash(pw_to_hash) update= {"hashed_pw": hashed_pw } try: user = get_user_by_username(username) user_key = user["key"] if not username in get_users(): return {"Username" : "Not Found"} else: return USERS.update(update, user_key), f"User {username} password changed!" except Exception as error_message: logging.exception(error_message) return None 

This function will take a username and a new password. It will first hash that password and then create a dictionary. Updates to a Deta Base are always performed by calling the update method with a dictionary. As in the previous functions, we always check if the username in question exists before calling the update. Also, don’t forget the try-except block!

Create User


The last function is our most important one :-). You can’t perform any operations on user objects if you have no way to create them! Take a look below to check out how we’ll handle that.

def create_user(username:str, email:str, pw_to_hash:str)->None: """Function to create a new user. It takes three strings and inputs these into the new_user dictionary. The function then attempts to put this dictionary in the database""" new_user = {"username" : username, "key" : str(uuid4()), "hashed_pw" : gen_pw_hash(pw_to_hash), "email" : email, "friends" : [], "disabled" : False} try: return USERS.put(new_user) except Exception as error_message: logging.exception(error_message) return None

The user creation function will take a username, email, and password for now. It will probably become more complex in the future, but it serves our purposes for now. Like the Deta update method, creating a new item in the database requires a dictionary. Some of the necessary attributes for the dictionary are generated inside the function.

The key needs to be unique, so we use Python’s uuid4 module. The friend’s attribute will contain the usernames of other users but starts as an empty list. The disabled attribute, finally, is set to false.

After finishing the initialization, creating the object is a matter of calling the Deta put method. I hear some of you thinking that we don’t do any checks if the username or email already exists in the database. You are right, but I will perform these checks on the endpoint receiving the post request for user creation.

Some Coding Thoughts and Learnings


GitHub ? Join the open-source PeerBrain development community!

One thing that never ceases to amaze me is the amount of documentation I like to add. I do this first in the form of docstrings as it helps me keep track of what function does what. I find it boring most of the time, but in the end, it helps a lot!

The other part of documenting that I like is type hints. I admit they sometimes confuse me still, but I can see the merit they have when an application keeps growing.

We will handle the rest of the database function in the next article. See you there!

Participate in Building the Decentralized Social Brain Network ?


As before, I state that I am completely self-taught. This means I’ll make mistakes. If you spot them, please post them on Discord so I can remedy them ?.

As always, feel free to ask me questions or pass suggestions! And check out the GitHub repository for participation!

? GitHub: https://github.com/shandralor/PeerBrain



https://www.sickgaming.net/blog/2023/03/...structure/

Print this item

  [Tut] Convert PHP JSON to CSV
Posted by: xSicKxBot - 03-08-2023, 08:45 AM - Forum: PHP Development - No Replies

Convert PHP JSON to CSV

by Vincy. Last modified on March 7th, 2023.

This tutorial gives examples for converting a PHP JSON variable content into a CSV file.

This quick example achieves it in a few steps. It uses the PHP fputcsv() method to prepare the CSV output.

  1. It reads the input JSON and decodes it into an array.
  2. Iterate the JSON array to read the line of the record.
  3. Apply PHP fputcsv() to write the array keys in the header, followed by array values.

Quick example


<?php function convertJsonToCSV($jsonFile, $csvFile)
{ if (($json = file_get_contents($jsonFile)) == false) { die('Unable to read JSON file.'); } $jsonString = json_decode($json, true); $fp = fopen($csvFile, 'w'); fputcsv($fp, array_keys($jsonString[0])); for ($i = 0; $i < count($jsonString); $i ++) { fputcsv($fp, array_values($jsonString[$i])); } fclose($fp); return;
}
$jsonFile = 'animals.json';
$csvFile = 'animals.csv'; convertJsonToCSV($jsonFile, $csvFile);
echo 'JSON to CSV converted. <a href="' . $csvFile . '" target="_blank">Download CSV file</a>';

The input JSON file is in the local drive and specified to a PHP variable $jsonFile.

This example creates a custom function convertJsonToCSV(). It requires the input JSON and the target CSV file names.

It converts the input JSON object to a PHP array. Then, it iterates the PHP array to read the row.

This function uses the PHP fputcsv() function to write each row into the target CSV file.

Output:

The above program will return the following CSV content in a file. In a previous tutorial, we have seen how to export to a CSV file using the PHP fputcsv() function.

Id,Name,Type,Role
1,Lion,Wild,"Lazy Boss"
2,Tiger,Wild,CEO
3,Jaguar,Wild,Developer

Note: The input JSON must be a one-dimensional associative array to get a better output.

php json to csv

JSON string to CSV in PHP


This example has a different approach to dealing with PHP JSON to CSV conversion.

It uses a JSON string as its input instead of reading a file. The JSON string input is initiated in a PHP variable and passed to the convertJSONtoCSV() function.

It reads the JSON string and converts it into a JSON array to prepare CSV. The linked article has an example of reading CSV using PHP.

Then, it iterates the JSON array and applies PHP fputcsv() to write the CSV row.

It reads the array_keys to supply the CSV header. And this will be executed only for the first time. It writes the column names as the first row of the output CSV.

json-string-to-csv.php

<?php
function convertJsonToCSV($jsonString, $csvFile)
{ $jsonArray = json_decode($jsonString, true); $fp = fopen($csvFile, 'w'); $header = false; foreach ($jsonArray as $line) { if (empty($header)) { $header = array_keys($line); fputcsv($fp, $header); $header = array_flip($header); } fputcsv($fp, array_merge($header, $line)); } fclose($fp); return;
}
$jsonString = '[ { "Id": "1", "Name": "Lion", "Type": "Wild", "Role": "Lazy Boss" }, { "Id": "2", "Name": "Tiger", "Type": "Wild", "Role": "CEO" }, { "Id": "3", "Name": "Jaguar", "Type": "Wild", "Role": "Developer" }
]';
$csvFile = 'animals.csv'; convertJsonToCSV($jsonString, $csvFile);
echo 'JSON to CSV converted. <a href="' . $csvFile . '" target="_blank">Download CSV file</a>';

Upload CSV file to convert into JSON in PHP


This example is to perform the JSON to CSV with a file upload option.

This code will be helpful if you want to convert the uploaded JSON file into a CSV.

It shows an HTML form with a file input field. This field will accept only ‘.json’ files. The restriction is managed with the HTML ‘accept’ attribute. It can also be validated with a server-side file validation script in PHP.

The $_FILES[‘csv-file’][‘tmp_name’] contains the posted CSV file content. The JSON to CSV conversion script uses the uploaded file content.

Then, it parses the JSON and converts it into CSV. Once converted, the link will be shown to the browser to download the file.

upload-json-to-convert-to-csv.php

<?php
if (! empty($_FILES["csv-file"]["tmp_name"])) { $csvFile = 'animal.csv'; if (($json = file_get_contents($_FILES["csv-file"]["tmp_name"])) == false) { die('Unable to read JSON file.'); } $jsonString = json_decode($json, true); $fp = fopen($csvFile, 'w'); fputcsv($fp, array_keys($jsonString[0])); for ($i = 0; $i < count($jsonString); $i ++) { fputcsv($fp, array_values($jsonString[$i])); } fclose($fp); echo 'JSON to CSV converted. <a href="' . $csvFile . '" target="_blank">Download CSV file</a>';
}
?>
<HTML>
<head>
<title>Convert JSON to CSV</title>
<style>
body { font-family: arial;
} input[type="file"] { padding: 5px 10px; margin: 30px 0px; border: #666 1px solid; border-radius: 3px;
}
input[type="submit"] { padding: 8px 20px; border: #232323 1px solid; border-radius: 3px; background: #232323; color: #FFF;
}
</style>
</head> <body> <form method="post" enctype="multipart/form-data"> <input type="file" name="csv-file" accept=".json" /> <input type="submit" name="upload" value="Upload"> </form>
</body>
</HTML>

Download

↑ Back to Top



https://www.sickgaming.net/blog/2023/03/...on-to-csv/

Print this item

  (Indie Deal) Blockstorm is now FREE on Steam
Posted by: xSicKxBot - 03-08-2023, 08:44 AM - Forum: Deals or Specials - No Replies

Blockstorm is now FREE on Steam

We are excited to announce that Blockstorm, the voxel first-person shooter game, our first passion project (but not our last), is now free to play on Steam, forever and for everyone!
https://store.steampowered.com/app/263060/Blockstorm/

What's Blockstorm again?
For the newcomers, Blockstorm is a fast-paced game that combines the classic elements of first-person shooters with the endless creativity of sandbox games. With an extensive collection of customizable weapons, maps, and game modes, Blockstorm offers endless hours of fun and excitement for both you and your friends.

From today onwards, players can download and play Blockstorm for free on Steam. This means that everyone can now experience the adrenaline rush of shooting and building their way through the game's dynamic levels without having to pay a penny.

Why go free to play?
We want to thank our dedicated community of players for their support and feedback over the years. We hope that going free-to-play, our gift to all of our loyal fans and involved community, will encourage even more players to join the Blockstorm community and enjoy the game.

So, what are you waiting for? Download Blockstorm for free on Steam today and start building, fighting, and creating your own adventure. We can't wait to see you on the battlefield!
https://store.steampowered.com/app/1874190/Vorax/
And since we are on the topic of passion projects, our latest one is called Vorax. It’s an Open World Survival Horror game. Feel free to check it out, try it and even maybe wishlist it to stay updated on its release.

We look forward to seeing you in the game!

Best regards,
The IndieGala Team[www.indiegala.com]



https://steamcommunity.com/groups/indieg...1902445555

Print this item

  PC - Grim Guardians: Demon Purge
Posted by: xSicKxBot - 03-08-2023, 08:44 AM - Forum: New Game Releases - No Replies

Grim Guardians: Demon Purge



Grim Guardians: Demon Purge centers around two demon hunters who return to their school after a mission only to find a demonic castle where it once stood.

Players control both of the demon hunting sisters in this 2D side-scrolling action game. Players must master each of the sisters' unique abilities and attributes to overcome the challenging stages with bosses awaiting their arrival. They'll also be able to find new routes through each stage using the two characters' abilities, keeping play throughs fresh.

Other features include two-player co-op with special actions, extensive difficulty options with the "Style System," unique changes on repeat plays, and most importantly the quality and challenge players have come to expect from Inti Creates titles, this time with a new gothic horror aesthetic.

Publisher: Inti Creates

Release Date: Feb 23, 2023




https://www.metacritic.com/game/pc/grim-...emon-purge

Print this item

  (Indie Deal) FREE Through the Mirror, THQ Adventures, Mystery & Horror Sale
Posted by: xSicKxBot - 03-07-2023, 01:35 PM - Forum: Deals or Specials - No Replies

FREE Through the Mirror, THQ Adventures, Mystery & Horror Sale

[freebies.indiegala.com]
[freebies.indiegala.com]

THQ Nordic Adventures, Mystery & Horror Sale, up to 80% OFF
[www.indiegala.com]
[www.indiegala.com]

Ex Natura: Nature Corrupted
[www.indiegala.com]
https://www.youtube.com/watch?v=FbUTME6DBm0&embeds_euri=https%3A%2F%2Fwww.indiegala.com%2F&feature=emb_imp_woyt&ab_channel=BlackburneGames

Medibang Adult Sale, up to 60% OFF
[www.indiegala.com]
[www.indiegala.com]

Patch Quest
[www.indiegala.com]
https://www.youtube.com/watch?v=cj409KY5qHE&embeds_euri=https%3A%2F%2Fwww.indiegala.com%2F&feature=emb_imp_woyt&ab_channel=PatchQuest


https://steamcommunity.com/groups/indieg...1920654318

Print this item

  (Indie Deal) Star Wars Giveaways, Wo Long is out, 2K & Racing Deals
Posted by: xSicKxBot - 03-06-2023, 09:12 PM - Forum: Deals or Specials - No Replies

Star Wars Giveaways, Wo Long is out, 2K & Racing Deals

Vorax Pre-Purchase
[vorax.indiegala.com]
Pre-orders are now open for Vorax! This is your chance to grab the game at a much lower cost! For more info, please visit our faq section.[vorax.indiegala.com]

Giveaways
[www.indiegala.com]
Wo Long: Fallen Dynasty
[www.indiegala.com]
https://www.youtube.com/watch?v=_O1DrfIxY1I&embeds_euri=https%3A%2F%2Fwww.indiegala.com%2F&feature=emb_imp_woyt&ab_channel=KOEITECMOEUROPELTD.
2K Sale, up to 92% OFF
[www.indiegala.com]

Voltaire: The Vegan Vampire
[www.indiegala.com]
https://www.youtube.com/watch?v=b0bge-DNVys&ab_channel=FreedomGames
505 Racing Sale, up to 84% OFF
[www.indiegala.com]



https://steamcommunity.com/groups/indieg...1913137903

Print this item

  (Free Game Key) Figment - Free GOG Game
Posted by: xSicKxBot - 03-06-2023, 09:12 PM - Forum: Deals or Specials - No Replies

Figment - Free GOG Game

Figment - Free GOG Game
This giveaway is on gog.com gog is a platform for games that is dedicated to drm-free games (those are games that do not require login or registration to play the game)

How to grab Figment
- Go to the home page of https://www.gog.com/#giveaway

?GrabFreeGames.com ?Twitter ?Steam Curator ?Facebook[fb.me]?Discord[discord.gg]
❤️Support us: HumbleBundle Partner[www.humblebundle.com] Fanatical Affiliate[www.fanatical.com]


https://steamcommunity.com/groups/GrabFr...2476462869

Print this item

  PC - Destiny 2: Lightfall
Posted by: xSicKxBot - 03-06-2023, 09:12 PM - Forum: New Game Releases - No Replies

Destiny 2: Lightfall



The last stand against Calus--who became the latest disciple of The Witness at the end of Season of the Haunted--and a "pivotal" moment for the Destiny franchise as it heads to the end of the Light and Darkness saga. Lightfall takes place in a new city on Neptune, Neomuna, which has a pristine and retro-futuristic design. As for the fifth subclass that was briefly seen, this new Darkness power is called Strand and allows for new traversal methods in Neomuna. The city is inhabited by a new race known as Cloudstriders, who managed to escape The Collapse of the solar system and remain hidden from the Darkness. With The Witness having discovered the city, it has come under siege from Calus, the Shadow Legion, and gigantic Pyramid Demons that can use a scythe to attack from a distance and drain your life-force.

Publisher: Bungie

Release Date: Feb 28, 2023




https://www.metacritic.com/game/pc/destiny-2-lightfall

Print this item

  [Oracle Blog] Announcing Java Card 3.2 Release
Posted by: xSicKxBot - 03-06-2023, 04:42 AM - Forum: Java Language, JVM, and the JRE - No Replies

Announcing Java Card 3.2 Release

With the whole Java Card team, I am delighted to announce the new Java Card 3.2 release. It is now live and available on the portal of Oracle.


https://blogs.oracle.com/java/post/annou...32-release

Print this item