Skip to content

Instantly share code, notes, and snippets.

View Youenn-Bouglouan's full-sized avatar

Youenn Bouglouan Youenn-Bouglouan

View GitHub Profile
@Youenn-Bouglouan
Youenn-Bouglouan / .iex.exs
Last active September 26, 2023 19:59
Some useful Elixir iex console stuff
defmodule Utils do
def logw(content) do
write("iex_output.exs", content, [:write])
content
end
def loga(content) do
write("iex_output.exs", content, [:append], 1)
content
end
@Youenn-Bouglouan
Youenn-Bouglouan / hslToRgb.js
Created January 19, 2021 11:23
Convert HSL to RGB colors - helpers - javascript
const hueToRgb = (p, q, t) => {
let tlocal = t;
if (tlocal < 0) tlocal += 1;
if (tlocal > 1) tlocal -= 1;
if (tlocal < 1 / 6) return p + (q - p) * 6 * tlocal;
if (tlocal < 1 / 2) return q;
if (tlocal < 2 / 3) return p + (q - p) * (2 / 3 - tlocal) * 6;
return p;
};
@Youenn-Bouglouan
Youenn-Bouglouan / azure-service-bus-in-fsharp-with-fluent-api.fs
Last active April 17, 2020 11:44
Use the Azure Fluent .Net API in F# to create a service bus with a topic and a subscription
// Deploy service bus + topic & subscription using the Azure .NET Fluent API
// Some references in C# here:
// https://github.com/Azure-Samples/service-bus-dotnet-manage-publish-subscribe-with-advanced-features/blob/master/Program.cs
(*
Necessary references to be added to your fsproj
<ItemGroup>
<PackageReference Include="Microsoft.Azure.Management.Fluent" Version="1.33.0" />
<PackageReference Include="Microsoft.Azure.Management.ServiceBus.Fluent" Version="1.33.0" />
</ItemGroup>
@Youenn-Bouglouan
Youenn-Bouglouan / sample.fs
Created August 17, 2017 19:35
Akka.NET / Handling messages in F#
open System
open Akka.Actor
open Akka.FSharp
type ActorAMessages =
| MessageA1 of name: string
| MessageA2 of quantity: int
| MessageA3
type ActorBMessages =
@Youenn-Bouglouan
Youenn-Bouglouan / ShortCircuitingExceptionHandling.cs
Last active May 22, 2017 20:51
How to efficiently break your code by using exceptions? Example 2: short-circuiting exception handling
using System;
namespace FunWithExceptions
{
public class FolderCouldNotBeCreatedException : Exception
{
public FolderCouldNotBeCreatedException(string folderPath)
: base("Folder '" + folderPath + "' could not be created!")
{}
}
@Youenn-Bouglouan
Youenn-Bouglouan / PokemonExceptionCatching.cs
Last active May 22, 2017 19:52
How to efficiently break your code by using exceptions? Example 1: Pokemon exception catching
using System;
namespace FunWithExceptions
{
/*
* 'Vindigator' is an imaginary 3rd-party library that contains
* a lot of useful (if you're into the vindication business) APIs.
*/
public static class Vindigator
{
@Youenn-Bouglouan
Youenn-Bouglouan / Main.fs
Last active May 1, 2017 12:14
Websharper - issue with POST expecting a JSON body
// Issue decribed here: http://websharper.com/question/82758/post-endpoint-with-a-json-body-cannot-be-reached
namespace HelloWebSharper
open WebSharper.Html.Server
open WebSharper
open WebSharper.Sitelets
module Site =
@Youenn-Bouglouan
Youenn-Bouglouan / Pizzas.fs
Last active March 16, 2017 21:59
C# pizzas versus F# pizzas. Which ones are tastier?!
open System
type PizzaRecipe() = class end
type PizzaOrder() = class end
type ColdPizza() = class end
type HotPizza() = class end
type PizzaDelivery() = class end
let order (size:string) (recipe:PizzaRecipe) =
PizzaOrder()
@Youenn-Bouglouan
Youenn-Bouglouan / AreYouPolish.fsx
Last active March 12, 2017 23:10
Let's F# tell us if you're surname is Polish!
// Check out the associated blog post at:
// http://www.ybouglouan.pl/2017/03/are-you-polish-fharp-will-tell-us-probably/
open System
// -----------------------------------------------------------------------------------------------
/// Return the number of occurrences of a given char within a word (case-insensitive)
let countCharCI char word =
word