Skip to content

Instantly share code, notes, and snippets.

View dstarr's full-sized avatar
💭
Learning starts here

David Starr dstarr

💭
Learning starts here
View GitHub Profile
@dstarr
dstarr / ActionMethod.cs
Created November 25, 2022 20:02
IServiceProvider Constructor injection
public ActionResult Index(string[] array)
{
int[] result = [0];
using (var scope = _serviceProvider.CreateScope())
{
var service = scope.GetService<IArrayReversalService>();
result = await service.Reverse(array);
}
@dstarr
dstarr / provision.sh
Created June 18, 2019 19:43
Provisions an app gateway and a scale set
#!/bin/bash -e
set -e
location="westus2"
resource_group="dms-dev-10-rg"
ag_be_gw="dms-ag-backend-gw"
ag_be_pool="dms-ag-backend-pool"
ag_public_ip="dms-ag-public-ip"
ag_subnet="dms-app-gw-subnet"
private async Task AddSensorData()
{
SensorTickerFactory sensorTickerFactory = new SensorTickerFactory();
for (int i = 0; i < 10; i++)
{
var tick = sensorTickerFactory.GetSensorTick();
await AddSensorTickIfNotExists(tick);
}
}
@dstarr
dstarr / Program3.cs
Last active March 7, 2018 19:06
Updating the docs my adding 100 degrees to the temperature.
private void DeleteAllDocs()
{
List<SensorTick> ticks = _client.CreateDocumentQuery<SensorTick>(_dbcUri).ToList();
foreach (var tick in ticks)
{
Uri docUri = UriFactory.CreateDocumentUri(DbName, CollectionName, tick.Id);
_client.DeleteDocumentAsync(docUri);
Console.WriteLine(@"Deleted: {0}", tick.Id);
}
@dstarr
dstarr / Cosmos_4_ModifyDocs.cs
Last active March 7, 2018 19:02
Deleting all the files in the Azure Cosmos DB,
private async Task ModifyAllDocs()
{
List<SensorTick> docs = _client.CreateDocumentQuery<SensorTick>(_dbcUri).ToList();
foreach (var doc in docs)
{
doc.Temperature += 100;
Uri docUri = UriFactory.CreateDocumentUri(DbName, CollectionName, doc.Id);
await _client.ReplaceDocumentAsync(docUri.ToString(), doc);
Console.WriteLine(@"Updated: {0}", doc.Id);
@dstarr
dstarr / Program.cs
Created March 6, 2018 23:26
Provision Azure Cosmos DB if needed
private async Task ProvisionDbIfNeeded()
{
await client.CreateDatabaseIfNotExistsAsync(new Database { Id = dbName });
await client.CreateDocumentCollectionIfNotExistsAsync(
UriFactory.CreateDatabaseUri(dbName),
new DocumentCollection { Id = collectionName }
);
}
@dstarr
dstarr / SensorTick.cs
Created March 6, 2018 23:16
Simple Entity for Sensor Data
public class SensorTick
{
[JsonProperty(PropertyName = "id")]
public string Id { get; set; }
[JsonProperty(PropertyName = "temperature")]
public int Temperature { get; set; }
[JsonProperty(PropertyName = "humidity")]
public int Humidity { get; set; }
import React from 'react';
import PropTypes from 'prop-types';
const ColorSwatch = (props) => {
let style = {
backgroundColor: props.color,
};
return (
const hello = () => { return <h1>Hello</h1> }
import React from 'react';
import PropTypes from 'prop-types';
class ColorSwatchClass extends React.Component {
constructor(props) {
super(props);
}