array(2) { ["meta"]=> array(6) { ["name"]=> string(10) "openaq-api" ["license"]=> string(0) "" ["website"]=> string(1) "/" ["page"]=> int(1) ["limit"]=> int(100) ["found"]=> int(0) } ["results"]=> array(0) { } } object(stdClass)#2 (13) { ["coord"]=> object(stdClass)#1 (2) { ["lon"]=> float(125.6081) ["lat"]=> float(9.0125) } ["weather"]=> array(1) { [0]=> object(stdClass)#3 (4) { ["id"]=> int(804) ["main"]=> string(6) "Clouds" ["description"]=> string(15) "overcast clouds" ["icon"]=> string(3) "04d" } } ["base"]=> string(8) "stations" ["main"]=> object(stdClass)#4 (8) { ["temp"]=> float(84.94) ["feels_like"]=> float(97.54) ["temp_min"]=> float(84.94) ["temp_max"]=> float(84.94) ["pressure"]=> int(1010) ["humidity"]=> int(84) ["sea_level"]=> int(1010) ["grnd_level"]=> int(1009) } ["visibility"]=> int(10000) ["wind"]=> object(stdClass)#5 (3) { ["speed"]=> float(2.35) ["deg"]=> int(98) ["gust"]=> float(7.9) } ["clouds"]=> object(stdClass)#6 (1) { ["all"]=> int(100) } ["dt"]=> int(1711616537) ["sys"]=> object(stdClass)#7 (5) { ["type"]=> int(2) ["id"]=> int(2093017) ["country"]=> string(2) "PH" ["sunrise"]=> int(1711575434) ["sunset"]=> int(1711619268) } ["timezone"]=> int(28800) ["id"]=> int(1705545) ["name"]=> string(11) "Los Angeles" ["cod"]=> int(200) } DrPunchman

Code Bites C#

Learning C#

Learning C#

I've always wanted to learn to program in the "C" family. C# is very close to JavaScript, and no longer does one have to lift the hefty Visual Studio pricetag to lean it. When you add in my years of JavaScript and Flash, this should be ...fun?


There is nothing I love more than a good Multidimensional Array. So it is one of the first things I wanted to figure out.


multiarr.cs


// set the var

public string[][] pass = new string[2][];

// add values
pass[0] = new string[] { "book", "librarian", "quiet","read" };
pass[1] = new string[] { "dog","cop","cuffs","coffee","doughnut","butts" };

// grab a random value
passUse = pass[level - 1][Random.Range(0, pass[level - 1].Length)];
Debug.LogWarning("Shhhh, the password is: " + passUse);

String Abuse

Useful little class (not mine) for creating anagrams. I like the way it's structured, and again--check out how it loops through the array.


anagram.cs


public static class StringExtension

{
    // shuffle the selected string
    public static string Anagram(this string str) 
    {
        string attempt = Shuffle(str);
        // keep doing this till it is all mixed up
        while (attempt == str)
        {
            attempt = Shuffle(str);
        }
        return attempt;
    }

    // rearrange characters in a string
    private static string Shuffle(string str)
    {
        char[] characters = str.ToCharArray();
        System.Random randomRange = new System.Random();
        int numberOfCharacters = characters.Length;
        while (numberOfCharacters > 1)
        {
            numberOfCharacters--;
            int index = randomRange.Next(numberOfCharacters + 1);
            var value = characters[index];
            characters[index] = characters[numberOfCharacters];
            characters[numberOfCharacters] = value;
        }
        return new string(characters);
    }
}