Instantly share code, notes, and snippets.

David Starr dstarr

View GitHub Profile
View Cosmos_4_ModifyDocs.cs
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);
View Program3.cs
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);
}
View Cosmos_2.cs
private async Task AddSensorData()
{
SensorTickerFactory sensorTickerFactory = new SensorTickerFactory();
for (int i = 0; i < 10; i++)
{
var tick = sensorTickerFactory.GetSensorTick();
await AddSensorTickIfNotExists(tick);
}
}
View Program.cs
private async Task ProvisionDbIfNeeded()
{
await client.CreateDatabaseIfNotExistsAsync(new Database { Id = dbName });
await client.CreateDocumentCollectionIfNotExistsAsync(
UriFactory.CreateDatabaseUri(dbName),
new DocumentCollection { Id = collectionName }
);
}
View SensorTick.cs
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; }
View ColorSwatchClass.js
import React from 'react';
import PropTypes from 'prop-types';
class ColorSwatchClass extends React.Component {
constructor(props) {
super(props);
}
View ColorSwatch.js
import React from 'react';
import PropTypes from 'prop-types';
const ColorSwatch = (props) => {
let style = {
backgroundColor: props.color,
};
return (
View gulpfile.js
const gulp = require('gulp');
const nodemon = require('gulp-nodemon');
gulp.task('default', launchServer);
function launchServer() {
var restart_called = false;
var nm = nodemon({