Skip to content

Instantly share code, notes, and snippets.

View jessicamilene's full-sized avatar
👀

Jéssica Machado jessicamilene

👀
View GitHub Profile
@jessicamilene
jessicamilene / add-project-to-git.md
Last active November 15, 2021 14:42
Adding an existing project to GitHub (command line)

Git

How to add your local code to a git repository?

  1. Create a repository on GitHub and save the HTTPS for later
  2. Open a command line on the root folder of your project
  3. Init a local repository git init
  4. Stage all the files git add .
  5. Commit git commit -m "First commit"
  6. Associate the Gii repository git remote add origin [YOUR_REPO_URL]

C#

Callback using an interface

Some times we want to do something when a specific event occurs, for that we can use a callback as I will show next. For me this implementation was realy important to solve a problem, I had a Library so the code will be closed (can't be changed), but I wanted to provide a way to allow extra operations when some event occurs, that was the solution that I had found.

Lets imagine that the next code from SmartHouse.cs and ISmartHouseOperations.cs is closed.

SmartHouse.cs

@jessicamilene
jessicamilene / AsyncCallOnConstructor.md
Last active January 23, 2024 10:15
C# - Call an async method on the constructor

C#

Call an async method on the contructor and wait for it's execution

Task.Run(() => this.FunctionAsync()).Wait();
@jessicamilene
jessicamilene / ParallelAsync.md
Last active January 8, 2020 14:22
[C#] Parallel asynchronous execution example

Parallel asynchronous execution - C# Example

Synchronous

Below we have a synchronous example when each worker counts to 10.

private static List<string> workers = new List<string>(){"A","B","C"};

static void Main(string[] args)
{
 CallWorkers();
@jessicamilene
jessicamilene / AsyncMethods.md
Last active November 10, 2021 14:46
[C#] Asynchcronous methods execution examples

Asynchronous Methods - C# Examples

Below we have a synchronous method that counts to 5.

static void Main(string[] args)
{
  Console.WriteLine("START");
  Count();
  Console.WriteLine("END");
  Console.ReadKey();