Skip to content

Instantly share code, notes, and snippets.

View ThomasPe's full-sized avatar

Thomas Pentenrieder ThomasPe

View GitHub Profile
@ThomasPe
ThomasPe / RedStripeDealsCrawler.js
Created April 27, 2016 14:36
A simple Node.js script to crawl the Red Stripe Deals from the Windows Store and saving the app details into a JSON file.
var request = require('request');
var cheerio = require('cheerio');
var fs = require('fs');
var async = require('async');
var zlib = require('zlib');
var dealsUri = "https://www.microsoft.com/en-us/store/collections/redstripedeals/pc";
var baseUri = "http://microsoft.com";
var output = [];
var outputFilename = "redstripedeals.json";
@ThomasPe
ThomasPe / ScriptInvokeWebViewExtensions.cs
Last active November 11, 2017 13:12
This is an extension to the XAML WebView for invoking scripts from a ViewModel
public static class WebViewExtensions
{
/// <summary>
/// Using a DependencyProperty as the backing store for Content Uri.  This binding Content Uri.
/// </summary>
public static readonly DependencyProperty InvokeScriptProperty = DependencyProperty.RegisterAttached(
"InvokeScript",
typeof(string),
typeof(WebViewExtensions),
@ThomasPe
ThomasPe / GetAllIntent.json
Created November 14, 2017 08:02
This is a model for getting a complete sentence from Alexa Skills Service
{
"languageModel": {
"types": [
{
"name": "CatchAllSlotType",
"values": [
{
"id": null,
"name": {
"value": "test",
@ThomasPe
ThomasPe / WebhookTriggerFunction.csx
Created January 6, 2018 20:30
A C# Azure Function for calling webhooks with basic authentication
using System;
using System.Net;
[FunctionName("GetEnvironmentVariables")]
public static void Run(TimerInfo myTimer, TraceWriter log)
{
log.Info($"C# Timer trigger function executed at: {DateTime.Now}");
string username = GetEnvironmentVariable("Webhook_Username");
string password = GetEnvironmentVariable("Webhook_Password");
@ThomasPe
ThomasPe / index.mustache
Created July 30, 2018 11:19
Sample index.mustache
{{> header.mustache}}
<h1>WindowsArea.de News</h1>
<ul>
{{#news}}
<li><a href="{{link}}" target="_blank">{{title.rendered}}</a></li>
{{/news}}
</ul>
<h1>My Links</h1>
@ThomasPe
ThomasPe / getData.js
Created July 30, 2018 11:37
Get WordPress data from REST API
function getData(){
context.log('get data');
var options = {
url: 'https://windowsarea.de/wp-json/wp/v2/posts',
method: 'GET',
json: true
}
request(options, function (error, response, data) {
@ThomasPe
ThomasPe / prepareTemplates.js
Created July 30, 2018 11:47
Preparing mustache header & footer files
function prepareTemplates(){
context.log('prepare Templates');
mu.compileText('header.mustache', context.bindings.headerTemplate, function () {
mu.compileText('footer.mustache', context.bindings.footerTemplate, function () {
renderSite();
});
});
}
@ThomasPe
ThomasPe / renderSite.js
Created July 30, 2018 11:50
Render index.html from mustache templates & dynamic data
function renderSite(){
context.log("render site");
var pageFile = "";
mu.compileText('index.mustache', context.bindings.indexTemplate, function (err, parsed) {
var renderstream = mu.render(parsed, { news: mynews, links: mylinks });
renderstream.on('data', function (data) {
pageFile += data;
});
renderstream.on('end', function (data) {
context.log("done creating index.html");
@ThomasPe
ThomasPe / uploadSite.js
Created July 30, 2018 11:53
Upload html file to Azure Storage static web hosting
function uploadSite(page){
context.log("Upload site ");
var blobService = storage.createBlobService();
// create $web container
blobService.createContainerIfNotExists('$web', function(){
// upload index.html to $web container
const options = { contentSettings: { contentType: 'text/html' } }
blobService.createBlockBlobFromText("$web", "index.html", page, options, function (error) {
@ThomasPe
ThomasPe / index.js
Created October 2, 2018 11:39
Blank JavaScript Azure Function
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
context.res = {
status: 200,
body: "Result message"
};
};