Skip to content

Instantly share code, notes, and snippets.

Daniel Córdoba Cárdenas DaniCCardenas

View GitHub Profile
View CreateCosmosDbAndCollection.ps1
#Source: https://stackoverflow.com/questions/52722373/create-database-and-collection-on-cosmos-db-sql-api-inside-azuredevopps-vsts
param($endpoint, $masterKey, $databaseName, $collectionName, $collectionRUs, $partitionKey)
Add-Type -AssemblyName System.Web
Add-Type -TypeDefinition @"
public enum CosmosResourceType
{
Database,
Collection
}
View SecurityProtocol.cs
System.Net.ServicePointManager.SecurityProtocol =
SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 |
SecurityProtocolType.Tls12;
@DaniCCardenas
DaniCCardenas / ProgramAsync.cs
Created Nov 6, 2018
Console app with async
View ProgramAsync.cs
using System.Threading.Tasks;
namespace ConsoleAsyncDemo
{
static class Program
{
static void Main(string[] args)
{
Main().Wait();
}
View BulkUploadToSql.cs
public class BulkUploadToSql<T>
{
public IList<T> InternalStore { get; set; }
public string TableName { get; set; }
public int CommitBatchSize { get; set; } = 1000;
public SqlConnection Connection { get; set; }
public async Task Commit()
{
if (InternalStore.Count > 0)
View CreateTableFromEntity.cs
public static string GetCreateTableQuery<T>(IEnumerable<T> list, string tableName)
{
Type type = typeof(T);
var properties = type.GetProperties();
var query = new StringBuilder();
query.Append($"CREATE TABLE {tableName} (");
foreach (PropertyInfo info in properties)
{
View EjemploRandom3.cs
static void EjemploRandom3()
{
for (int i = 0; i <= 10; i++)
{
var guid = Guid.NewGuid();
var justNumbers = new String(guid.ToString().Where(Char.IsDigit).ToArray());
var seed = int.Parse(justNumbers.Substring(0, 4));
var random = new Random(seed);
var value = random.Next(0, 5);
View EjemploRandom2.cs
static void EjemploConTickCount()
{
var seed = Environment.TickCount;
var random = new Random(seed);
for (int i = 0; i <= 10; i++)
{
var value = random.Next(0, 5);
Console.WriteLine($"Iteración {i} - semilla {seed} - valor {value}");
}
View EjemploRandom1.cs
static void EjemploRandom1()
{
for (int i = 0; i <= 10; i++)
{
var seed = Environment.TickCount;
var random = new Random(seed);
var value = random.Next(0, 5);
Console.WriteLine($"Iteración {i} - semilla {seed} - valor {value}");
}
View AzureTableStorage.cs
public class AzureTableStorage<T> where T : TableEntity, IAzureStorageTable, new()
{
CloudStorageAccount storageAccount = CloudStorageAccount.Parse(
CloudConfigurationManager.GetSetting("StorageConnectionString"));
CloudTableClient tableClient;
CloudTable table;
public AzureTableStorage(string tableName)
{
You can’t perform that action at this time.