Skip to content

Instantly share code, notes, and snippets.

View markusl's full-sized avatar

Markus Lindqvist markusl

  • Supercell
  • Finland
View GitHub Profile
@markusl
markusl / LongestCommonSubstring.fs
Created September 5, 2013 10:07
Longest common substring, in F#.
module LongestCommonSubstring
let get (strings:seq<string>) =
let first' = strings |> Seq.tryFind (fun _ -> true)
let isWhiteSpace = System.String.IsNullOrWhiteSpace
let mapper substringLength (first:string) currentStrings offset =
if substringLength + offset < first.Length then
let currentSubstring = first.Substring(offset, substringLength)
if not(isWhiteSpace(currentSubstring)) &&
@markusl
markusl / Boost Optional usage.cpp
Last active December 30, 2015 05:39
Purpose of this document is to define how boost::optional is used in unified way throughout the code.
/**
* RULES
* 1. Prefer using is_initialized() for checking the contents if the
* value is not assigned to a boost::optional right before
* 2. Prefer get() over 'operator ->', to make visible what's happening
* 3. Use get_value_or() if applicable, this makes the control flow less complex
* 4. Optionally prefix variable with 'opt' or postfix with 'Optional'
*
* DOCS http://www.boost.org/doc/libs/1_55_0/libs/optional/doc/html/index.html
*
struct handle_deleter_t
{
void operator()(HANDLE handle) {
if(handle != INVALID_HANDLE_VALUE)
CloseHandle(handle);
}
};
void foo()
{
#include <array>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <functional>
#include <cassert>
#include "memory_content.hpp"
// opcode | instruction | operands (mod 0) | operands (mod 1)
// -------+-------------+------------------+-----------------
@markusl
markusl / site.coffee
Last active August 29, 2015 14:13
Houm.io temperature collection with Enocean STM-330
Bacon = require('baconjs')
serialport = require("serialport")
sleep = require('sleep')
WebSocket = require('ws')
winston = require('winston')
Keen = require('keen.io')
Keen = Keen or
configure: (e) ->
@_cf = e
@markusl
markusl / yes.rs
Created June 14, 2017 10:05
'yes' implementation in Rust
use std::io::{stdout, Write};
// Compile: rustc -O -C lto yes.rs
// Use: ./yes | pv > /dev/null
// 97GiB 0:00:57 [3.72GiB/s] [ <=> ]
fn main() {
let buffer = "y\n".repeat(16384).into_bytes();
let stdout = stdout();
let mut stdout = stdout.lock();

Keybase proof

I hereby claim:

  • I am markusl on github.
  • I am markusl (https://keybase.io/markusl) on keybase.
  • I have a public key ASDgPVGd9rYgJsEPT_ztMJQY5qWIZLyqEp-UKkCqAWsQQgo

To claim this, I am signing this object:

@markusl
markusl / aws-cdk-s3-example.ts
Created August 7, 2019 10:17
AWS CDK S3 Example
#!/usr/bin/env node
import 'source-map-support/register';
import * as cdk from '@aws-cdk/core';
import * as s3 from '@aws-cdk/aws-s3';
/**
* npm run build
* cdk deploy --profile demo BucketStack
* change code
* cdk diff --profile demo BucketStack
#!/usr/bin/env node
import 'source-map-support/register';
import * as core from '@aws-cdk/core';
import * as ec2 from '@aws-cdk/aws-ec2';
import * as ecs from '@aws-cdk/aws-ecs';
import * as ecs_patterns from '@aws-cdk/aws-ecs-patterns';
// Example code from: https://docs.aws.amazon.com/cdk/latest/guide/home.html
export class MyEcsConstructStack extends core.Stack {
constructor(scope: core.App, id: string, props?: core.StackProps) {
@markusl
markusl / README.md
Last active April 14, 2025 17:03
AWS ALB Azure AD OIDC Provider

Example AWS CDK code for adding Azure AD OIDC provider in AWS ALB

AWS documentation https://docs.aws.amazon.com/elasticloadbalancing/latest/application/listener-authenticate-users.html

You can configure an Application Load Balancer to securely authenticate users as they access your applications. This enables you to offload the work of authenticating users to your load balancer so that your applications can focus on their business logic.

See also