« first day (3632 days earlier)      last day (1299 days later) » 

12:53 AM
@mr5 heeymatey
@mr5 can you help me with a xamarin concern
 
 
2 hours later…
2:44 AM
@c0dem0nkey meow?
just switch it to non async method?
 
3:06 AM
let me rephrase my question
i used to do this before sometime ago but now im missing something
i wanna 'step into' the api from the xamarin app
@mr5 i see you. hahahahahah
@nyconing and how nice to see you too :)
@mr5 hows work? still good?
 
3:37 AM
i freakin violated ground rules on this one with async calls and mvvm. the way i handled the code was stupid.
got the returns now. unsuccessful tho but got it. hahahahahahahahaha
 
3:52 AM
hey guys!
and gals
 
Jay
does anyone have experience using System.Text.Json in .NET Core 3+?
I have a json file with a bunch of entries that I'm trying to into a c# array
 
Literally in the same position @Jay
except I'm trying to compare my json object to an endpoint request haha
 
Jay
having any luck?
 
nah I'm able to deserialize the object
but like I'm not sure how to compare the result from my endpoint to the result like bit confused
 
Jay
you got it to deserialize?
 
4:06 AM
yep
var file = new StreamReader("policies.json");
string json = file.ReadToEnd();
var oldIntent = JsonConvert.DeserializeObject<AppPoliciesResponse>(json);
try something like that
 
Jay
trying, ty
 
sup all
 
@c0dem0nkey Hey!
 
good day matey.
 
any tips on writing a better question stackoverflow.com/questions/64057025/…
want to make sure I'm clear with my question
 
Rob
4:17 AM
@rey123 Your response class will return something in the format of { Header: "something", Content: "somethingelse" }
But... it seems you've already got the format you want in the json file
So... why not just stream the file back as the response?
 
how would I do that?
sorry sounds like a silly question
I wannted to do a comparson to make sure its returning the correct "policy'
because inside that policy file, I'll have terms and conditions, shipping policy, faq etc as different objects if that makes sense
 
Rob
There's a base-class function File... so you can do something like return File(path)
 
so if i do a get request like /api/v2/content/{ terms-and-conditions } it will just give me the terms and conditions content
 
Rob
But I'm not really sure what you mean by returning the correct policy
Right, so policies.json has all of them?
 
yep it does
but I only want to return the correct json object that matches the parameter
in the request
 
Rob
4:19 AM
What does that file look like?
 
ill show one sec
something like this
{
"terms-and-conditions": "The fol...
"privacy": "this is another test.."
}
 
Rob
Right
 
Jay
I'm having a similar struggle atm
 
@Jay I think this will help you stackoverflow.com/questions/13297563/…
 
Rob
Okay, how flexible on that format are you, as well as the response?
Because there are a few things to make your life a lot easier
 
4:23 AM
this is the current response I'm looking for
[
{ heading : string, content : string },
...,
...,
]
 
Rob
I thought you only wanted to return the one item?
 
yes it would be one item sorry
ignore the ...
 
Jay
that's really close actually, thanks rey but my json file isn't local it's online
 
it would just be {heading: "terms-and-conditions", content: "The fol..."}
@jay
 
Jay
I can get it with WebClient.DownloadString but I'm not sure if that's the best way
 
4:25 AM
replace the local with a the url for the location
 
Jay
really, okay
 
give it a go :)
 
Rob
Is that requirement set in stone? Because it might be easier to just return "The fol..." or even {content: "The fol..."}. It already knows what the header is, because it sent that to the server in the request
 
yeah its a requirement :/
if you can tell me how to return content then I can figure the rest out im sure
im just having a brain fart
 
Rob
In any case, you want to deserialize 'policies.json' into Dictionary<string, string>... then, you can extract the content by the key provided in the request (first checking it exists, of course)
 
4:28 AM
can't I do it this way?
        var file = new StreamReader("policies.json");
        string json = file.ReadToEnd();
        var policiesFile = JsonConvert.DeserializeObject<AppPoliciesResponse>(json);
 
Rob
Depends on what AppPoliciesResponse is
 
public class AppPoliciesResponse
{
public string Heading { get; set; }
public string Content { get; set; }
}\
 
Rob
Previously you were deserializing into ConditionsResponse
Yeah, same thing
 
yeah sorry i just changed conditionsResponse to AppPoliciesResponse
 
Rob
No, you can't, because that class represents {Heading: "Something", Content: "Something else" }
 
4:29 AM
sorry about the confusions
 
Rob
Where as your file is
{
"terms-and-conditions": "The fol...
"privacy": "this is another test.."
}
So, you can write..
var policiesFile = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);
var tandc = policiesFile["terms-and-conditions"]
return new { Header: "terms-and-conditions", Content = tandc };
As an example
 
hmm
I'm just confused on how the endpoint request gets involved in this with the comparison
 
Rob
Well, you'd replace the string "terms-and-conditions" with the variable passed into the controller
 
yeah thats what i was thinking but was doubting myself
legend! Got it working thank you so much @Rob!
 
Rob
No worries :)
 
@Feeds Quiet you!
 
Jay
it didn't work
it says System.IO.IOException: The filename, directory name, or volume label syntax is incorrect.
 
@Jay can we see your current code
 
Jay
I have a json file that's online and I can get it with this:
using System;
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace games
{
    class Program
    {
        static void Main(string[] args)
        {
            using (WebClient wc = new System.Net.WebClient())
            {
                string json = wc.DownloadString("https://www.website.com/games.json");
            }
        }
    }
}
and here's a sample of the json
[
    {
      "genres": [
        "action"
      ]
    },
    {
      "genres": [
        "rpg"
      ]
    },
    {
      "genres": [
        "action"
      ]
    },
    {
      "genres": [
        "puzzle"
      ]
    },
    {
      "genres": [
        "shooter",
        "action-adventure"
      ]
    }
]
and the Game class
public class Game
{
    public string Genre { get; set; }

    public void Genres()
    {
        Console.WriteLine("The genres of this game are " + Genre);
    }
}
I can get it to print stuff to the console manually if I add this
using System;
using System.Net;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace games
{
    class Program
    {
        static void Main(string[] args)
        {
            using (WebClient wc = new System.Net.WebClient())
            {
                string json = wc.DownloadString("https://www.website.com/games.json");
            }

            Game game = new Game();

            game.Genre = "Action";

            game.Genres();
        }

        public class Game
sorry for the giant paste
but I'm trying to pull the genres from the json
I can Console.WriteLine(json); and get the whole list, it's quite large
I'm just not sure how to translate that into c# objects that I can work with
and there are a bunch of other fields, I trimmed it down to just genre for simplicity
 
5:18 AM
@Jay Well since the field in the json is genres, the property of your Game-class has to reflect that.
 
Jay
oh, so public string genres instead of public string Genre?
 
The class should look like this:
public class Game {
  public string[] Genres { get; set; }
  public void PrintGenres() {
    foreach(var genre in genres) Console.WriteLine(genre);
  }
}
In the json, genres describes an array, as you can see by the [] being used instead of just a string
(Also makes sense that something call genres can actually hold several genres instead of just one despite being called a plural)
Then you deserialize the json into a Game[] to get multiple games, each having multiple genres
 
Jay
okay, trying
 
Games[] games = JsonConvert.DeserializeObject<Games[]>(json);
 
Jay
it just says games.Program+Game[]
 
5:29 AM
In the console?
 
Jay
yeah
 
Let me guess: You wrote Console.WriteLine(games);
 
Jay
I did haha! in my using(WebClient
 
This will make a string of the Game[] - which has a class of Array and can just tell you what class it holds, and therefore tells you "I am an array of type Game"
 
@Squirrelkiller do you know how to handle exceptions with dictionaries? I'm trying to add error handling for my code when a bad request is created via the endpoint
public TypedResponse<AppPoliciesResponse> GetPolicies(string content)
{
//Need to store on s3
var policyFile = new StreamReader("policies.json");
string json = policyFile.ReadToEnd();

var policyDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

if (policyDic[content] == null)
throw new ApiException(HttpStatusCode.BadRequest, "Policy does not exist");

var policy = policyDic[content];


return new TypedResponse<AppPoliciesResponse>
{
Data = new AppPoliciesResponse()
{
Content = policy,
But it doesn't hit the line if (policyDic[content] == null)
 
Jay
5:31 AM
if I take that out it doesn't print anything
oh, okay
 
@rey123 ctrl+k to format your code
 
one sec
 public TypedResponse<AppPoliciesResponse> GetPolicies(string content)
        {
            //Need to store on s3
            var policyFile = new StreamReader("policies.json");
            string json = policyFile.ReadToEnd();

            var policyDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

            if (policyDic[content] == null)
                throw new ApiException(HttpStatusCode.BadRequest, "Policy does not exist");

            var policy = policyDic[content];
 
@Jay You probably want to print all games:
foreach(var game in games) Console.WriteLine(game.PrintGenres());
 
so I wanted it to hit if(policyDic[content] == null ... and then show my error message but instead I get this error message: The given key 'termsandconditions' was not present in the dictionary.
 
Jay
yes exactly, okay trying that now
 
5:34 AM
@rey123 Instead, try if(policyDict.ContainKey(content) throw....
 
oh i see so that checks for the particular key in the dictionary
 
In .NET, when the dictionary doesn't have an entry for the entered key, it will throw an exception
 
interesting! appreciate that
so if it was an array
for example
then id use the logic I had before?
 
Then you'd have a different question.
Currently your question is "Do you have an entry for my content?".
With an array it will either be "Do you have entries?" or "Do you have a certain number of entries?", so you either go `arr.Any()` or `arr.Length >= requiredNumberOfEntries`.
 
ahh I see
so strange it's still skipping that check @Squirrelkiller this is what I added
 public TypedResponse<AppPoliciesResponse> GetPolicies(string content)
        {
            //Need to store on s3
            var policyFile = new StreamReader("policies.json");
            string json = policyFile.ReadToEnd();

            var policyDic = JsonConvert.DeserializeObject<Dictionary<string, string>>(json);

            if (policyDic.ContainsKey(content))
                throw new ApiException(HttpStatusCode.BadRequest, "Policy does not exist");

            var policy = policyDic[content];
 
Jay
5:42 AM
it says game does not exist in the current context
 
Then it is time to clean up your File:
Put the class Game into its own file called Game.cs
 
Jay
okay
 
@rey123 How do you know? Because if this is your code, I'm pretty sure it doesn't throw at policyDict[content]
 
managed to get it working
was supposed to be this
if (!policyDic.ContainsKey(content))
 
Haha good point lol
 
5:49 AM
hehe
thanks though!
 
Jay
okay separated, Program.cs and Game.cs now
 
another random question @Squirrelkiller
actually nvm haha
 
@Jay Now I guess there is some kind of place in your Program.cs you have some code which it doesn't belong in.
@rey123 Yes, you may call me master if you really want.
 
HAHAH
@Squirrelkiller can you have a "-" in the routing of an API
e.g. Route("content-key")
 
5:54 AM
how would you pass the key in the param though
([FromRoute] string content-key) doesn't make sense?
doesnt it have to match the Route
 
Look at some new sites - they often have the name of the article with dashes in the route
 
yeah thats true actually
 
You have to put a parameter in the route like [Route("content-key/{key}"], then you can go ([FromRoute] string key)
 
what about somehting like this /api/v2/content/{ content-key }
 
If you decide that key should be a number or a Guid, you can directly use the actual type in the parameter
 
5:56 AM
what would that look like in the param?
 
Would look like what you wrote before: [FromRoute]string content-key
 
or would that be a typo and you can't do something like that
but that wouldn't work because you cant have a variable like content-key
 
Ah right it doesn't like -
I mean it should be contentKey by naming policy anyway so...might aswell use that
If you definitely want to go against policy you can still use content_key
 
so you suggest /api/v2/content/{ contentKey }
 
Yep looks good
 
5:58 AM
and then ([FromRoute] string contentKey)
 
Maybe remove the spaces around contentKey in the route
 
yep
 
Jay
Yep red squigglies in Game.cs
do I need the same using lines like using System; in Game.cs?
 
You need the same namespace declaration around the class
namespace games
{
  public class Game
  {
  [...]
  }
}
 
Jay
okay, done
still saying Console does not exist unless I add using System;
and PrintGenres does not exist
 
6:12 AM
Yeah you need the using
PrintGenres should be declared in your Game class?
 
Jay
it is
using System;

namespace games
{
	public class Game
	{
	    public string[] Genres { get; set; }

	    public void PrintGenres()
	    {
	        foreach(var genre in Genres)
	        Console.WriteLine(game.PrintGenres());
	    }
	}
}
 
*Console.WriteLine(genre)
Or even better:
public void PrintGenres()
{
  Console.WriteLine("This game has the following genres:");
  foreach(var genre in genres)
    Console.WriteLine(genre);
}
 
Step1 : Press PrintScreen button and save it to a file.
Step2 : Set it as desktop wallpaper and minimize all windows.
Step3 : Right click at desktop hide the desktop icon in menu and then set the taskbar auto hide.
 
Best prank to unexpecting people lol
 
Step1 : Press PrintScreen button and save it to a file.
Step2 : Set it as desktop wallpaper and minimize all windows.
Step3 : Right click at desktop hide the desktop icon in menu and then set the taskbar auto hide.
Step4 : Stay behind and watch when your colleague back from toilet.
 
Jay
6:16 AM
that's a classic @nyconing ^_^
or a piece of scotch tape over the laser hole on the bottom of their mouse
it's doing what it was earlier and not outputting anything
like it's running but just sitting there
 
\o
 
Jay
Program.cs:
using System;
using System.Net;
using Newtonsoft.Json;

namespace games
{
    class Program
    {
        static void Main(string[] args)
        {
            using (WebClient wc = new System.Net.WebClient())
            {
                string jsonGames = wc.DownloadString("https://www.website.com/games.json");
                Game[] games = JsonConvert.DeserializeObject<Game[]>(jsonGames);
            }
        }
    }
}
and Game.cs
using System;

namespace games
{
	public class Game
	{
	    public string[] Genres { get; set; }

	    public void PrintGenres()
		{
		  Console.WriteLine("This game has the following genres:");
		  foreach(var genre in genres)
		    Console.WriteLine(genre);
		}
	}
}
 
6:33 AM
@Jay The function static void Main in the Program.cs is the code that actually gets executed. So to actually output the games, you have to call the PrintGenres() after you deserialize the games.
string jsonGames = ...
Game[] games = JsonConvert...
foreach(var game in games)
  game.PrintGenres();
 
Jay
holy crap we have genres woooo!!
that's awesome thanks @Squirrelkiller
 
Sure thing. Use this power wisely :)
 
With great power comes great responsibility
 
Jay
how can I count how many of them are Action?
 
Using your next super power: LINQ
var gamesThatAreAction = games.Count(game => game.Genres.Contains("Action"));
Do you know SQL?
 
Jay
6:46 AM
ohhh okay, I was already thinking a where clause would be great
 
LINQ basically has Where-clauses in every call: Any() can have a filter in it like .Any(obj => obj == 3), Count() like above, Single too. I see many calls that chain things like objects.Where(obj => obj.Property == "value").Count(), although it is unnecessary.
You them like a sentence: "Count the games where a game's genres include Action"
 
Jay
gotcha
it's saying Game[] does not contain a definition for Count
 
using System.LINQ; I think
 
Jay
oh okay
 
using System.Linq, yeah.
Doesn't it auto-suggest that?
 
6:53 AM
GoOoOoOoOoOoOoOoOoOoOoOd Mornin' pleberinos!
 
Jay
vs code
does not
 
I was afraid you would say that
 
Jay
you no likey?
 
I recommend VS 2019 Community edition - it's free and much more powerful than VSCode when building .NET projects.
I do like it, but not for C#.
 
Jay
I have that too
 
6:54 AM
It's really helpful for 6000-LoC-javascript
 
Jay
getting a buncha 0's
and I think I just figured out why, I used a capital A in Action
 
If you open a 6000-Line-file in VS, you may as well get a coffee until VS is not hanging anymore.
VSCode is good at staying responsive.
 
Jay
can I get a list of unique genres?
or like a distinct?
 
LINQ might have a distinct, not sure
 
It does have that yes
VSCode is fine, but for C#, you want something more powerful. VS Community is that.
 
7:04 AM
optimally with resharper
good morning
 
Yeah, that. Good morning.
 
@Squirrelkiller ^
Amd it's a great text editor
 
A visual studio update just needed to restart my computer. Wat.
 
Welcoem 2 windowx
 
8:04 AM
Captain o7
 
\o
Eifel Tower!
@CaptainObvious Talking about Sun-Pat the last couple of days made me hungry for it.
So I went online and order 4 Jars for ~14€ per KG with shipping.

Still double the UK price but worth it.
 
9:06 AM
#shoutout giff me job
 
9:22 AM
o]/
 
im wearing my faceshield
!~shiba
 
lol
game over cat
 
busted
 
9:38 AM
busta ryhmes ma boi
 
lol
 
10:12 AM
@Squirrelintraining Sounds like a bad deal
 
@CaptainObvious It's the best deal a Junky like ma can get over here aparently :D
 
 
1 hour later…
11:20 AM
||tumbleweed
 
May 5 '16 at 15:17, by BoltClock
THIS ROOM IS OUT OF CONTROL
 
11:34 AM
In the WPF chat, we've automated the process...
WpfFarmer.GenerateTumbleweeds(5);
* * * * *
 
11:44 AM
Kek
Jack, automate your ass
 
what does Jack need to automate?
 
Rebooting so he's fast again.
 
"fast"
hehehe
you joker
:p
 
Is that even English?
 
mr5
11:52 AM
@Squirrelintraining aye, cool shirt!
@c0dem0nkey hey! sorry was busy earlier. nah, I'm still unemployed.
 
she's speaking without tripping up at all lol
 
Yeah so good
So rightous.
 
@mr5 you can work for my website OoO
 
mr5
@Freerey too busy learning :(
 
aw mane
 
mr5
11:55 AM
I just realize my previous job isn't really that challenging.
I'm struggling with leetcode :(
 
733t[0D3
here's a real messy sketch to help ya feel better @mr5
 
mr5
nice
does it say emo?
or end?
 
emo lol
 
mr5
how long does it take you doing that?
 
this took 5 minutes not even
 
mr5
12:10 PM
what if you directly draw it without sketching?
 
x-x
I mean I do have another pic ike that
 
@mr5 end
jk i saw the emo
 
12:27 PM
Jack, think fast
   such impressive
         many fast
  wow
             much Jack
 
I don't understand mate
 
@mr5 I think that took 2 minutes?
 

« first day (3632 days earlier)      last day (1299 days later) »