Skip to content

Instantly share code, notes, and snippets.

View jonathascosta's full-sized avatar

Jonathas Costa jonathascosta

  • Porto, Portugal
View GitHub Profile
@jonathascosta
jonathascosta / sc2-timer.ps1
Created January 7, 2021 19:07
Starcraft 2 basic timer for zergs
Add-Type -AssemblyName System.Speech
$cycle = 1
$speak = New-Object System.Speech.Synthesis.SpeechSynthesizer
while (1)
{
if ($cycle % 24 -eq 0)
{
[console]::beep(4800, 4800);
@jonathascosta
jonathascosta / IAuthorizationRule.cs
Last active July 16, 2020 07:16
Checks when is the resource owner or someone with admin role
public interface IAuthorizationRule : IFilterMetadata
{
Task<bool> HasAccess(ActionExecutingContext context);
}
@jonathascosta
jonathascosta / create-dotnet-solution.sh
Created March 10, 2020 22:59
Bash script to create a default solution for .net projects
#!/bin/bash
mkdir $1
cd $1
dotnet new sln
dotnet new classlib -n "$1.Infrastructure.CrossCutting" -f netstandard2.1
dotnet sln add -s "04.Infrastructure" "$1.Infrastructure.CrossCutting"
dotnet new classlib -n "$1.Domain" -f netstandard2.1
dotnet sln add -s "03.Domain" "$1.Domain"
using Microsoft.CodeAnalysis.CSharp;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis;
namespace UnitTestGenerator
@jonathascosta
jonathascosta / DateExtensions.js
Created September 5, 2016 20:26 — forked from anonymous/DateExtensions.js
Date Extensions for Javascript
Date.prototype.clone = function () {
return new Date(this.valueOf());
}
Date.prototype.addDays = function (days) {
var d = this.clone();
d.setDate(d.getDate() + days);
return d;
}
extern int BarCount = 100;
extern int MagicNumber = 123456789;
extern double InitialVolume = 0.01;
extern int SlipPage = 3;
extern int MaxOrders = 40;
extern double MinimumDistanceForNewOrder = 70;
extern bool AutoConfig = false;
double lowest, highest;
double buyVolume, sellVolume;
extern int MonthsToLimitZone = 8;
extern double volume = 0.01;
extern double spaceBetweenOrders = 0.001;
extern int MagicNumber = 1234567890;
extern double profitInCurrency = 0.01;
extern double stopLossOrderLimit = 5.0;
double lowestDay, highestDay;
double beginOfSellZone, endOfSellZone;
double beginOfBuyZone, endOfBuyZone;
@jonathascosta
jonathascosta / LinqExtensions.cs
Created February 20, 2014 17:52
Transforms a flat list into a hierarchic collection
public static class LinqExtensions
{
public static IEnumerable<T> AsHierarchy<T>(this IEnumerable<T> collection,
Func<T, T> parentSelector, Expression<Func<T, IEnumerable<T>>> childrenSelector, T root = default(T))
{
var items = collection.Where(x => parentSelector(x).Equals(root)).Safe();
foreach (var item in items)
{
var childrenProperty = (childrenSelector.Body as MemberExpression).Member as PropertyInfo;
@jonathascosta
jonathascosta / ScriptEngineTest.cs
Created January 30, 2013 08:35
Testing Roslyn's ScriptEngine
var engine = new ScriptEngine();
new[] {
"System",
"System.Core"
}.ToList().ForEach(assembly => engine.AddReference(assembly));
new[] {
"System",
"System.Linq"
@jonathascosta
jonathascosta / unittest.snippet
Created January 15, 2013 18:08
Unit test snippet
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSnippet Format="1.0.0">
<Header>
<Title>Test case</Title>
<Shortcut>testcase</Shortcut>
<Description>Test case method</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>