Skip to content

Instantly share code, notes, and snippets.

View martijn's full-sized avatar

Martijn Storck martijn

View GitHub Profile
@martijn
martijn / JsonApi.cs
Last active December 22, 2022 21:35
Expose a JSON dataset as an HTTP API with minimal C# code
using System.Text.Json;
var jsonDocument = JsonSerializer.Deserialize<JsonElement>("""
{
"Germany": { "Population": 83783942, "Language": "German" },
"France": { "Population": 65273511, "Language": "French" },
"the Netherlands": { "Population": 17134872, "Language": "Dutch" }
}
""");
/* eslint-disable @typescript-eslint/no-empty-function */
import { Context, Form, HttpRequest, Logger } from "@azure/functions";
export const buildContext = (): Context => ({
bindingData: undefined,
bindingDefinitions: [],
bindings: { },
executionContext: undefined,
invocationId: "",
log: createLogger(),
require "compress/zip"
abstract class SaxParser
ATTR_REGEX = /([[:alnum:]]+)\=\"(.*?)\"/m
def initialize(xml : IO)
@xml = xml
end
def parse!
@martijn
martijn / Dockerfile
Created January 26, 2021 12:09
Ruby on Rails deployment Dockerfile
# This multi-stage Dockerfile will use the full ruby image during build phase
# after this it wil build the deployment image based on the slim ruby container,
# copying over all artifacts from the build phase.
#
# The deployer image will not include a Javascript runtime and will come in at
# under 200MB for an average Rails application.
ARG BUILDER_FROM_IMAGE=ruby:3.0
ARG DEPLOY_FROM_IMAGE=ruby:3.0-slim
ARG NODE_VERSION 14.15.4
@martijn
martijn / iteration_1.ex
Last active March 6, 2017 19:59
An example of writing proper Elixir code instead of Ruby code in Elixir
# Iteration 1: This is basically writing Ruby in Elixir
params = %{"name" => "Foobar", "time" => %{"hour" => "8", "minute" => "30"}}
defmodule Example do
def cast_times_to_minutes(params, fields) do
Enum.map(params, fn({key, value}) ->
if Enum.member?(fields, key) && is_map(value) do
{key, time_to_minutes(value)}
else