Skip to content

Instantly share code, notes, and snippets.

@pxotox
Last active April 2, 2019 10:34
Show Gist options
  • Select an option

  • Save pxotox/1962af2db2edea73f70106bc40267b48 to your computer and use it in GitHub Desktop.

Select an option

Save pxotox/1962af2db2edea73f70106bc40267b48 to your computer and use it in GitHub Desktop.

Revisions

  1. pxotox revised this gist Apr 2, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion component.html
    Original file line number Diff line number Diff line change
    @@ -22,7 +22,7 @@
    </header>

    <div>
    <img src="https://resizing.flixster.com/aPS8LGbr1cFMrBiJ3gGDEz_QFSw=/fit-in/200x296.2962962962963/v1.bTsxMjcwMDQ5MztqOzE3OTY2OzEyMDA7MTY4ODsyNTAw">
    <img src="https://resizing.flixster.com/Xjz2VShAGgZ6Z5AaSxUcgw4MRNo=/fit-in/200x296.2962962962963/v1.bTsxMjcwMDQ5MztqOzE4MDU2OzEyMDA7MTY4ODsyNTAw">
    <a href="https://www.rottentomatoes.com/m/avengers_infinity_war" target="_blank">
    Check review
    </a>
  2. pxotox revised this gist Mar 25, 2019. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions date-format.html
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,7 @@
    <body>
    <script>
    // This will create elements for testing every second
    // Don't change this code if possible
    (() => {
    let elementsCount = 100
    for (i = 0; i < elementsCount; i++) {
  3. pxotox revised this gist Feb 7, 2019. No changes.
  4. pxotox created this gist Feb 7, 2019.
    42 changes: 42 additions & 0 deletions README.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,42 @@
    # Technical challenge

    Here is the description of what you'll need to implement and answer on this technical challenge.

    # Challenges

    You'll answer the 4 following challenges.

    ## 1. Cache function
    Implement a function (it may be on the same module - `SimpleJsonRequest.cs`) to cache requests preventing unecessary calls. You may use [this Redis module](https://stackexchange.github.io/StackExchange.Redis/) as a cache service.

    **Note**: You can use any .NET version

    ## 2. Date formatting
    Implement a JavaScript code (on the same file - `date-format.html`) that replaces the date value of all elements (that have `js-date-format` class) with the value of the time passed from now (`new Date()`). Use the following format:
    * 1 second ago OR X seconds ago
    * 1 minute ago OR X minutes ago
    * 1 hour ago OR X hours ago
    * Date in ISO format (original format)

    Example:

    ![Working example](https://i.ibb.co/LnQF3yx/example.gif)

    **Note**: You should use ecmascript 6 features but may not use any framework or add any dependency.

    ## 3. Apply style
    Implement the CSS code to make the component on `component.html` look like the desired mockup below.

    Mockup:

    ![Desired mockup](https://i.ibb.co/Brh3jXQ/mockup.png)

    **Note #1**: You should use new CSS features and add classes as you need, but try not to change the HTML structure.

    **Note #2**: We recommend you try using [BEM](http://getbem.com/introduction/).

    ## 4. Question

    Send us your answer for the following question:

    > What are the main HTTP verbs used in REST applications and what are they meant for?
    69 changes: 69 additions & 0 deletions SimpleJsonRequest.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,69 @@
    using System.IO;
    using System.Net;
    using System.Text;
    using System.Threading.Tasks;
    using System.Collections.Generic;
    using Newtonsoft.Json;

    namespace Challenge
    {
    class SimpleJsonRequest
    {
    public static async Task<string> GetAsync(string url)
    {
    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;

    using(HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
    using(Stream stream = response.GetResponseStream())
    using(StreamReader reader = new StreamReader(stream))
    {
    return await reader.ReadToEndAsync();
    }
    }

    public static async Task<string> PostAsync(string url, Dictionary<string, string> data)
    {
    return await RequestAsync("POST", url, data);
    }

    public static async Task<string> PutAsync(string url, Dictionary<string, string> data)
    {
    return await RequestAsync("PUT", url, data);
    }

    public static async Task<string> PatchAsync(string url, Dictionary<string, string> data)
    {
    return await RequestAsync("PATCH", url, data);
    }

    public static async Task<string> DeleteAsync(string url, Dictionary<string, string> data)
    {
    return await RequestAsync("DELETE", url, data);
    }

    private static async Task<string> RequestAsync(string method, string url, Dictionary<string, string> data)
    {
    string dataString = JsonConvert.SerializeObject(data);
    byte[] dataBytes = Encoding.UTF8.GetBytes(dataString);

    HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
    request.AutomaticDecompression = DecompressionMethods.GZip | DecompressionMethods.Deflate;
    request.ContentLength = dataBytes.Length;
    request.ContentType = "application/json";
    request.Method = method;

    using(Stream requestBody = request.GetRequestStream())
    {
    await requestBody.WriteAsync(dataBytes, 0, dataBytes.Length);
    }

    using(HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync())
    using(Stream stream = response.GetResponseStream())
    using(StreamReader reader = new StreamReader(stream))
    {
    return await reader.ReadToEndAsync();
    }
    }
    }
    }
    38 changes: 38 additions & 0 deletions component.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,38 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>CrossKnowledge - Code challenge</title>
    <link href="https://fonts.googleapis.com/css?family=Roboto:300,400,500" rel="stylesheet">
    </head>
    <body>
    <article>
    <header>
    <div>
    <div>
    Avengers: Infinity War
    </div>
    <div>
    156 minutes
    </div>
    </div>
    <div>
    85% <img src="https://www.rottentomatoes.com/assets/pizza-pie/images/icons/global/cf-lg.3c29eff04f2.png" alt="">
    </div>
    </header>

    <div>
    <img src="https://resizing.flixster.com/aPS8LGbr1cFMrBiJ3gGDEz_QFSw=/fit-in/200x296.2962962962963/v1.bTsxMjcwMDQ5MztqOzE3OTY2OzEyMDA7MTY4ODsyNTAw">
    <a href="https://www.rottentomatoes.com/m/avengers_infinity_war" target="_blank">
    Check review
    </a>
    </div>

    <footer>
    <p>
    An unprecedented cinematic journey ten years in the making and spanning the entire Marvel Cinematic Universe, Marvel Studios' "Avengers: Infinity War" brings to the screen the ultimate, deadliest showdown of all time. The Avengers and their Super Hero allies must be willing to sacrifice all in an attempt to defeat the powerful Thanos before his blitz of devastation and ruin puts an end to the universe.
    </p>
    </footer>
    </article>
    </body>
    </html>
    23 changes: 23 additions & 0 deletions date-format.html
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,23 @@
    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8">
    <title>CrossKnowledge - Code challenge</title>
    </head>
    <body>
    <script>
    // This will create elements for testing every second
    (() => {
    let elementsCount = 100
    for (i = 0; i < elementsCount; i++) {
    setTimeout(() => {
    let el = document.createElement("div")
    el.className = 'js-date-format'
    el.innerHTML = (new Date()).toISOString()
    document.body.appendChild(el)
    }, i * 1000)
    }
    })();
    </script>
    </body>
    </html>