Skip to content

Instantly share code, notes, and snippets.

View jonathascosta's full-sized avatar

Jonathas Costa jonathascosta

  • Porto, Portugal
View GitHub Profile
if (entity.GetType() != typeof(LogAuditoriaEntity) && (entity is AuditableEntity))
{
try
{
var logAuditoria = new LogAuditoriaEntity
{
NomeTabela = ObterNomeTabela(persister),
TipoOperacao = operacao,
TxtComando = ObterComandoSql(session),
ForeignId = id.ToString()
@jonathascosta
jonathascosta / SimNaoType.cs
Created December 7, 2012 06:57
Tipo de suporte a colunas S/N no Oracle
using System;
using System.Data;
using NHibernate;
using NHibernate.SqlTypes;
using NHibernate.UserTypes;
namespace Framework.DataAccess.NHibernate.UserTypes
{
[Serializable]
public class SimNaoType : IUserType
@jonathascosta
jonathascosta / gist:4528916
Created January 14, 2013 09:38
Copy properties from an object to another object
public void CopyProperties(object from, object to)
{
foreach (var p in ((object)from).GetType().GetProperties())
{
var toProperty = to.GetType().GetProperty(p.Name);
var fromValue = p.GetValue(from, null);
if (toProperty.PropertyType.IsValueType)
{
var convertedValue = Convert.ChangeType(fromValue, toProperty.PropertyType);
toProperty.SetValue(to, convertedValue, null);
@jonathascosta
jonathascosta / stopwatch.snippet
Last active December 11, 2015 03:48
Stopwatch snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Stopwatch</Title>
<Author>Jonathas Piazzarollo Costa</Author>
<Shortcut>stopwatch</Shortcut>
<Description>Surrounds code with Stopwatch.</Description>
<SnippetTypes>
<SnippetType>SurroundsWith</SnippetType>
</SnippetTypes>
@jonathascosta
jonathascosta / rulesproperty.snippet
Last active December 11, 2015 03:48
Rules property snippet
<?xml version="1.0" encoding="utf-8"?>
<CodeSnippet Format="1.0.0" xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<Header>
<Title>Rules Property</Title>
<Author>Jonathas Piazzarollo Costa</Author>
<Shortcut>rulesproperty</Shortcut>
<Description>Creates a Rules property.</Description>
<SnippetTypes>
<SnippetType>Expansion</SnippetType>
</SnippetTypes>
@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>
@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 / 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;
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;
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;