Skip to content

Instantly share code, notes, and snippets.

View peted70's full-sized avatar
™️

Pete D peted70

™️
View GitHub Profile
using System;
namespace MSHealthBot
{
public class Sleep
{
public Sleepactivity[] sleepActivities { get; set; }
public int itemCount { get; set; }
}
@peted70
peted70 / convert-audio.cs
Created February 17, 2018 10:57
Convert floating point audio data in the range -1.0 to 1.0 to signed 16-bit audio data and populate the provided stream
/// <summary>
/// Convert floating point audio data in the range -1.0 to 1.0 to signed 16-bit audio data
/// and populate the provided stream
/// </summary>
/// <param name="audioData"></param>
/// <param name="stream"></param>
/// <returns></returns>
int BufferConvertedData(float[] audioData, Stream stream)
{
// Can't just do a block copy here as we need to convert from float[-1.0f, 1.0f] to 16bit PCM
@peted70
peted70 / translator-api-auth.cs
Created February 17, 2018 13:01
auth with the Azure translator api
private async Task<string> GetTokenAsync()
{
string key = "--- YOUR API KEY HERE ---";// Environment.GetEnvironmentVariable("SKYPE_KEY");
if (string.IsNullOrEmpty(key))
{
Debug.Log("Please set an environment variable named 'SKYPE_KEY' to your Skype api key");
return string.Empty;
}
// First retrieve a time-restricted key to use to access the API (will need to write code
using (var httpClient = new HttpClient())
{
var response = await httpClient.GetAsync("https://dev.microsofttranslator.com/languages?api-version=1.0&scope=text,tts,speech");
response.EnsureSuccessStatusCode();
var jsonString = await response.Content.ReadAsStringAsync();
dynamic obj = JsonConvert.DeserializeObject(jsonString);
// Do some stuff with obj...
}
future<shared_ptr<GraphNode>> RootPageViewModel::LoadFileAsync()
{
auto fop = ref new FileOpenPicker();
fop->FileTypeFilter->Append(".glb");
fop->FileTypeFilter->Append(".gltf");
auto file = co_await fop->PickSingleFileAsync();
if (file == nullptr)
co_return nullptr;
#include <map>
#include <functional>
#include "sub_token.h"
using namespace std::placeholders;
using namespace std;
template <typename... Args>
class subject
{
// I can declare a variable like this
subject<SceneManager const&> SceneChanged;
// subscribe for changes using an arbitrary function signature
sub_token RegisterForUpdates(function<void(SceneManager const&)> slot)
{
return SceneChanged.subscribe(slot);
}
// Then when changes happen, notify observers like this..
#ifdef HAS_METALROUGHNESSMAP
// Roughness is stored in the 'g' channel, metallic is stored in the 'b' channel.
// This layout intentionally reserves the 'r' channel for (optional) occlusion map data
float4 mrSample = metallicRoughnessTexture.Sample(metallicRoughnessSampler, input.texcoord);
perceptualRoughness = mrSample.g * perceptualRoughness;
metallic = mrSample.b * metallic;
#endif
void MeshNode::CompileAndLoadPixelShader()
{
// Create a shader descriptor which we can use to either find the shader in the
// shader cache or create and add it.
// The hash used for lookup is generated from the shader name and defines passed
// when it is compiled
ShaderDescriptor descriptor("pbrpixel.hlsl", DevResources());
auto textures = _material->Textures();
// Allocate the defines map...
void GLTF_Parser::ParseFile(StorageFile^ storageFile)
{
// try to get an IStorageItemHandleAccess interface from the StorageFile
ComPtr<IUnknown> unknown(reinterpret_cast<IUnknown*>(storageFile));
ComPtr<IStorageItemHandleAccess> fileAccessor;
ThrowIfFailed(unknown.As(&fileAccessor));
// Use the IStorageItemHandleAccess::Create method to retrieve an OS HANDLE
shared_ptr<void> fileHandle;
HANDLE file = nullptr;