Skip to content

Instantly share code, notes, and snippets.

View bcnzer's full-sized avatar

Ben Chartrand bcnzer

View GitHub Profile
@bcnzer
bcnzer / run.csx
Created May 1, 2017 07:49
Sample Azure Function calling the Redis cache we configured
using System.Net;
using StackExchange.Redis;
public static async Task<HttpResponseMessage> Run(HttpRequestMessage req, TraceWriter log)
{
log.Info("C# HTTP trigger function processed a request.");
// **** REDIS CODE STARTS HERE
var connString = System.Configuration.ConfigurationManager.ConnectionStrings["mycats"].ConnectionString;
var redis = ConnectionMultiplexer.Connect(connString);
@bcnzer
bcnzer / getDownloadURL-example.js
Created February 9, 2020 09:41
Example of using the getDownloadURL method to check for a file's existance
// Using promise
const listRef = storage
.ref('screenshots/abc123.png')
.getDownloadURL()
.then((response) => {
// Found it. Do whatever
})
.catch((err) => {
// Didn't exist... or some other error
})
@bcnzer
bcnzer / mockwolfimages.json
Created December 17, 2017 19:00
The mock wolf image JSON
{
"wolves": [
{ "images": [
"https://wolftracker9eee.blob.core.windows.net/wolfpictures-mock/big-wolf1.png",
"https://wolftracker9eee.blob.core.windows.net/wolfpictures-mock/wolf1.png"
]},
{ "images": [
"https://wolftracker9eee.blob.core.windows.net/wolfpictures-mock/big-wolf2.png",
"https://wolftracker9eee.blob.core.windows.net/wolfpictures-mock/wolf2.png"
]},
@bcnzer
bcnzer / quiz.html
Created May 26, 2020 10:07
Simple HTML and JS quiz
<html>
<body>
<div class="question">
Q1: What is fun?
</div>
<div>
<input type="radio" id="a0" name="question0">
<label for="a0">Going for a walk</label>
</div>
<div>
@bcnzer
bcnzer / downloadpython.sh
Last active April 20, 2020 06:45
Download python
cd /usr/src
wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tgz
sudo tar xzf Python-3.6.0.tgz
@bcnzer
bcnzer / index.js
Created December 27, 2019 21:35
Google Cloud Function for sending an email via SendGrid, triggered by a document being added to Firestore
const functions = require('firebase-functions')
const admin = require('firebase-admin')
admin.initializeApp(functions.config().firebase)
const SENDGRID_API_KEY = functions.config().sendgrid.key
const sendGridEmail = require('@sendgrid/mail')
sendGridEmail.setApiKey(SENDGRID_API_KEY)
@bcnzer
bcnzer / launch.json
Created December 25, 2019 09:03
VS Code debug config in which we are attaching to the Chrome instance. Note that you must launch Chrome with the remote debugging port i.e. chrome.exe --remove-debugging-port=9222
{
"version": "0.2.0",
"configurations": [
{
"type": "chrome",
"request": "attach",
"name": "attach to Chrome",
"port": 9222,
"webRoot": "${workspaceFolder}",
"sourceMapPathOverrides": {
@bcnzer
bcnzer / nuxt.config.js
Created December 25, 2019 00:47
Partial nuxt.config.js file showing the extend method you need to add
/*
** Build configuration
*/
build: {
/*
** You can extend webpack config here
*/
extend(config, ctx) {
if (ctx.isDev) {
config.devtool = ctx.isClient ? 'source-map' : 'inline-source-map'
@bcnzer
bcnzer / workerOptions.js
Last active December 12, 2019 09:19
Cloudflare Worker example of how you can handle the OPTIONS verb and set some CORS details in the response header
addEventListener('fetch', event => {
event.respondWith(handleRequest(event))
})
/**
* Entry point of the worker
*/
async function handleRequest(event) {
// Generate the CORS headers I'll have to return with requests
const corsHeaders = setCorsHeaders(new Headers())
@bcnzer
bcnzer / RegisterViewModel.cs
Last active November 25, 2019 06:04
Registration view model with a complex password requirement
public class RegisterViewModel
{
[Required]
[Display(Name = "First Name")]
[StringLength(100, ErrorMessage = "{0} must be at least {2} characters long.", MinimumLength = 2)]
public string FirstName { get; set; }
[Required]
[Display(Name = "Last Name")]
[StringLength(100, ErrorMessage = "{0} must be at least {2} characters long.", MinimumLength = 2)]