Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /// Code by Ivaylo Kenov from My Tested ASP.NET
- ///
- /// Follow me on GitHub and take a look at my projects
- /// https://github.com/ivaylokenov
- ///
- /// Subscribe to my YouTube channel, if you want to learn advanced C# techniques
- /// https://www.youtube.com/channel/UCP5Ons7fK3yKhX6lhc9XcfQ
- namespace KeepPushing
- {
- using System;
- using System.Collections.Generic;
- using System.Text;
- using System.Threading;
- public class LimitPusher
- {
- private const int Sec2Milsec = 1000;
- private static readonly Random Random = new Random();
- private static readonly IList<string> StartUps = new List<string>();
- private bool isAlive;
- private long ageInSeconds;
- public LimitPusher()
- {
- this.ageInSeconds = 0;
- this.isAlive = true;
- }
- internal static Random RandomInstance { get { return Random; } }
- internal static IList<string> AllStartUps { get { return StartUps; } }
- public static void Main()
- {
- new LimitPusher().Start();
- }
- public void Start()
- {
- while (isAlive)
- {
- Eat();
- Work<Company>();
- Work<Outsourcing>();
- Work<StartUp>();
- Train();
- Eat();
- Learn();
- GoOutside();
- F_ck();
- Sleep();
- }
- this.Resurrect();
- }
- private void Eat()
- {
- var secondsForEating = 60 * 60;
- this.UpdateAge(secondsForEating);
- Console.WriteLine("Converts pizza and coffee to code...");
- }
- private void Work<TEmployer>()
- where TEmployer : IEmployer, new()
- {
- // because reflection is cool, that's why! (MAGIC! DO NOT TOUCH!)
- var secondsFromWork = (int)typeof(TEmployer).GetMethod("DoTheJob").Invoke(new TEmployer(), null);
- this.UpdateAge(secondsFromWork);
- }
- private void Train()
- {
- var secondsForTraining = 30 * 60; // fast trainings, no time for more, just keep the belly to the minimum
- this.UpdateAge(secondsForTraining);
- Console.WriteLine("Removes pizza leftovers from organism...");
- }
- private void GoOutside()
- {
- Console.WriteLine("Tries to go outside but there are too many interesting things in the code...");
- // will go outside after the sun dies out, too bright!
- return;
- }
- private void Learn()
- {
- var secondsForLearning = 60 * 60;
- this.UpdateAge(secondsForLearning);
- Console.WriteLine("Reads about EcmaScript 2015, ASP.NET 5, etc.");
- }
- private void F_ck()
- {
- if (Random.Next(0, int.MaxValue) == 69) // chances of getting laid with so much sh*t to do
- {
- var secondsNeeded = 5 * 60; // no time for more, the code awaits
- this.UpdateAge(secondsNeeded);
- Console.WriteLine("Le sexy time...");
- }
- return;
- }
- private void Sleep()
- {
- var secondsToSleep = 5 * 60 * 60; // because 5 hours are enough... I guess...
- this.UpdateAge(secondsToSleep);
- }
- private void UpdateAge(int seconds)
- {
- this.ageInSeconds += seconds;
- Thread.Sleep(seconds * Sec2Milsec);
- if (this.ageInSeconds > (52 * 365 * 24 * 60 * 60 + (52 / 4) * 24 * 60 * 60)) // leap years calculated
- {
- // oh, no, I am dead
- this.isAlive = false;
- }
- }
- private void Resurrect()
- {
- // oh, no, I am alive
- this.isAlive = true;
- this.ageInSeconds = 0;
- this.Start(); // trolololo
- }
- private interface IEmployer
- {
- int DoTheJob();
- }
- /// <summary>
- /// Represents regular 9-6 job.
- /// </summary>
- public class Company : IEmployer
- {
- public int DoTheJob()
- {
- var secondsToWork = 10 * 60 * 60; // counting one hour overtime on average per day
- Console.OutputEncoding = Encoding.UTF8;
- Console.WriteLine("Ворк, ворк, ворк...");
- return secondsToWork;
- }
- }
- /// <summary>
- /// Represents various projects from various friends.
- /// </summary>
- public class Outsourcing : IEmployer
- {
- public int DoTheJob()
- {
- var secondsToWork = RandomInstance.Next(0, 10) * 60 * 60; // sometimes there are projects, sometimes there are not
- Console.WriteLine("Working here, working there...");
- return secondsToWork;
- }
- }
- /// <summary>
- /// Represents start-up ideas and working on them.
- /// </summary>
- public class StartUp : IEmployer
- {
- public int DoTheJob()
- {
- if (RandomInstance.Next(1, 100) == 42) // chance to get new idea
- {
- var startUpName = Guid.NewGuid().ToString(); // code name "Riba Mech"
- AllStartUps.Add(startUpName);
- Console.WriteLine("New start-up idea generated: {0}", startUpName);
- }
- var totalSeconds = 0;
- foreach (var startUp in AllStartUps)
- {
- // make a deal with the devil
- if (RandomInstance.Next(1, 10000) == 666) // chance for start-up to be successful
- {
- Console.WriteLine("Start-up successful: {0}", startUp);
- }
- var workingForStartUpSeconds = RandomInstance.Next(1, 5) * 60 * 60; // working between 1 and 5 hours a day
- totalSeconds += workingForStartUpSeconds;
- }
- return totalSeconds;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment