ivaylokenov

Life Represented as Code

Sep 21st, 2019
1,630
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.23 KB | None | 0 0
  1. /// Code by Ivaylo Kenov from My Tested ASP.NET
  2. ///
  3. /// Follow me on GitHub and take a look at my projects
  4. /// https://github.com/ivaylokenov
  5. ///
  6. /// Subscribe to my YouTube channel, if you want to learn advanced C# techniques
  7. /// https://www.youtube.com/channel/UCP5Ons7fK3yKhX6lhc9XcfQ
  8.  
  9. namespace KeepPushing
  10. {
  11.     using System;
  12.     using System.Collections.Generic;
  13.     using System.Text;
  14.     using System.Threading;
  15.  
  16.     public class LimitPusher
  17.     {
  18.         private const int Sec2Milsec = 1000;
  19.  
  20.         private static readonly Random Random = new Random();
  21.         private static readonly IList<string> StartUps = new List<string>();
  22.  
  23.         private bool isAlive;
  24.         private long ageInSeconds;
  25.  
  26.         public LimitPusher()
  27.         {
  28.             this.ageInSeconds = 0;
  29.             this.isAlive = true;
  30.         }
  31.  
  32.         internal static Random RandomInstance { get { return Random; } }
  33.  
  34.         internal static IList<string> AllStartUps { get { return StartUps; } }
  35.  
  36.         public static void Main()
  37.         {
  38.             new LimitPusher().Start();
  39.         }
  40.  
  41.         public void Start()
  42.         {
  43.             while (isAlive)
  44.             {
  45.                 Eat();
  46.                 Work<Company>();
  47.                 Work<Outsourcing>();
  48.                 Work<StartUp>();
  49.                 Train();
  50.                 Eat();
  51.                 Learn();
  52.                 GoOutside();
  53.                 F_ck();
  54.                 Sleep();
  55.             }
  56.  
  57.             this.Resurrect();
  58.         }
  59.  
  60.         private void Eat()
  61.         {
  62.             var secondsForEating = 60 * 60;
  63.             this.UpdateAge(secondsForEating);
  64.             Console.WriteLine("Converts pizza and coffee to code...");
  65.         }
  66.  
  67.         private void Work<TEmployer>()
  68.             where TEmployer : IEmployer, new()
  69.         {
  70.             // because reflection is cool, that's why! (MAGIC! DO NOT TOUCH!)
  71.             var secondsFromWork = (int)typeof(TEmployer).GetMethod("DoTheJob").Invoke(new TEmployer(), null);
  72.             this.UpdateAge(secondsFromWork);
  73.         }
  74.  
  75.         private void Train()
  76.         {
  77.             var secondsForTraining = 30 * 60; // fast trainings, no time for more, just keep the belly to the minimum
  78.             this.UpdateAge(secondsForTraining);
  79.             Console.WriteLine("Removes pizza leftovers from organism...");
  80.         }
  81.  
  82.         private void GoOutside()
  83.         {
  84.             Console.WriteLine("Tries to go outside but there are too many interesting things in the code...");
  85.  
  86.             // will go outside after the sun dies out, too bright!
  87.             return;
  88.         }
  89.  
  90.         private void Learn()
  91.         {
  92.             var secondsForLearning = 60 * 60;
  93.             this.UpdateAge(secondsForLearning);
  94.             Console.WriteLine("Reads about EcmaScript 2015, ASP.NET 5, etc.");
  95.         }
  96.  
  97.         private void F_ck()
  98.         {
  99.             if (Random.Next(0, int.MaxValue) == 69) // chances of getting laid with so much sh*t to do
  100.             {
  101.                 var secondsNeeded = 5 * 60; // no time for more, the code awaits
  102.                 this.UpdateAge(secondsNeeded);
  103.                 Console.WriteLine("Le sexy time...");
  104.             }
  105.  
  106.             return;
  107.         }
  108.  
  109.         private void Sleep()
  110.         {
  111.             var secondsToSleep = 5 * 60 * 60; // because 5 hours are enough... I guess...
  112.             this.UpdateAge(secondsToSleep);
  113.         }
  114.  
  115.         private void UpdateAge(int seconds)
  116.         {
  117.             this.ageInSeconds += seconds;
  118.             Thread.Sleep(seconds * Sec2Milsec);
  119.  
  120.             if (this.ageInSeconds > (52 * 365 * 24 * 60 * 60 + (52 / 4) * 24 * 60 * 60)) // leap years calculated
  121.             {
  122.                 // oh, no, I am dead
  123.                 this.isAlive = false;
  124.             }
  125.         }
  126.  
  127.         private void Resurrect()
  128.         {
  129.             // oh, no, I am alive
  130.             this.isAlive = true;
  131.             this.ageInSeconds = 0;
  132.             this.Start(); // trolololo
  133.         }
  134.  
  135.         private interface IEmployer
  136.         {
  137.             int DoTheJob();
  138.         }
  139.  
  140.         /// <summary>
  141.         /// Represents regular 9-6 job.
  142.         /// </summary>
  143.         public class Company : IEmployer
  144.         {
  145.             public int DoTheJob()
  146.             {
  147.                 var secondsToWork = 10 * 60 * 60; // counting one hour overtime on average per day
  148.                 Console.OutputEncoding = Encoding.UTF8;
  149.                 Console.WriteLine("Ворк, ворк, ворк...");
  150.                 return secondsToWork;
  151.             }
  152.         }
  153.  
  154.         /// <summary>
  155.         /// Represents various projects from various friends.
  156.         /// </summary>
  157.         public class Outsourcing : IEmployer
  158.         {
  159.             public int DoTheJob()
  160.             {
  161.                 var secondsToWork = RandomInstance.Next(0, 10) * 60 * 60; // sometimes there are projects, sometimes there are not
  162.                 Console.WriteLine("Working here, working there...");
  163.                 return secondsToWork;
  164.             }
  165.         }
  166.  
  167.         /// <summary>
  168.         /// Represents start-up ideas and working on them.
  169.         /// </summary>
  170.         public class StartUp : IEmployer
  171.         {
  172.             public int DoTheJob()
  173.             {
  174.                 if (RandomInstance.Next(1, 100) == 42) // chance to get new idea
  175.                 {
  176.                     var startUpName = Guid.NewGuid().ToString(); // code name "Riba Mech"
  177.                     AllStartUps.Add(startUpName);
  178.                     Console.WriteLine("New start-up idea generated: {0}", startUpName);
  179.                 }
  180.  
  181.                 var totalSeconds = 0;
  182.                 foreach (var startUp in AllStartUps)
  183.                 {
  184.                     // make a deal with the devil
  185.                     if (RandomInstance.Next(1, 10000) == 666) // chance for start-up to be successful
  186.                     {
  187.                         Console.WriteLine("Start-up successful: {0}", startUp);
  188.                     }
  189.  
  190.                     var workingForStartUpSeconds = RandomInstance.Next(1, 5) * 60 * 60; // working between 1 and 5 hours a day
  191.                     totalSeconds += workingForStartUpSeconds;
  192.                 }
  193.  
  194.                 return totalSeconds;
  195.             }
  196.         }
  197.     }
  198. }
Advertisement
Add Comment
Please, Sign In to add comment