Skip to content

Instantly share code, notes, and snippets.

View Krzysztof-Cieslak's full-sized avatar
#BlackLivesMatter

Krzysztof Cieślak Krzysztof-Cieslak

#BlackLivesMatter
View GitHub Profile
@Krzysztof-Cieslak
Krzysztof-Cieslak / Find_languages.graphql
Created January 22, 2021 11:01
GraphQL query to find number of "active" repositories in programming language. Can be run on https://docs.github.com/en/graphql/overview/explorer
{
search(query: "language:F# stars:>10 pushed:>=2020-01-01", type: REPOSITORY, first: 100) {
repositoryCount
edges {
node {
... on Repository {
nameWithOwner
stargazers {
totalCount
}
@Krzysztof-Cieslak
Krzysztof-Cieslak / dsl.fsx
Created November 19, 2019 15:36
Using F# 4.7 implicit yield feature to implement DSL in F#
//Builder represeting only one entity in DSL
type Child1State = {SomeState : string}
type Child1Builder () =
[<CustomOperation("set_state")>]
member __.SetState (st, x) = {st with SomeState = x}
@Krzysztof-Cieslak
Krzysztof-Cieslak / Index.js
Created January 11, 2019 21:58
PureScript + Functions
var main = require("../output/Main/index.js");
module.exports = async function (context, req) {
context.log('JavaScript HTTP trigger function processed a request.');
context.log(main);
let resp = main.answer(999);
context.res = {
// status: 200, /* Defaults to 200 */
body: "Answer is " + resp
};
@Krzysztof-Cieslak
Krzysztof-Cieslak / Main.purs
Created January 11, 2019 21:55
PureScript + Functions
module Main where
import Prelude
import Data.List (range, filter, List)
import Data.Foldable (sum)
ns :: Int -> List Int
ns max = range 0 999
@Krzysztof-Cieslak
Krzysztof-Cieslak / Sample.fs
Created September 14, 2018 19:54
Sample usage of analyzer
// Learn more about F# at http://fsharp.org
open System
let x = None
[<EntryPoint>]
let main argv =
x.Value
printfn "Hello World from F#!"
@Krzysztof-Cieslak
Krzysztof-Cieslak / paket.dependencies
Created September 14, 2018 19:49
Sample paket.dependencies for Analyzers
// [ Analyzers Group ]
group Analyzers
source https://api.nuget.org/v3/index.json
nuget FSharp.Analyzers.Sample 1.0.1
@Krzysztof-Cieslak
Krzysztof-Cieslak / analyzer.fs
Created September 14, 2018 19:29
Option Analyzer
[<Analyzer>]
let optionValueAnalyzer : Analyzer =
fun ctx ->
let state = ResizeArray<range>()
let handler (range: range) (m: FSharpMemberOrFunctionOrValue) =
let name = String.Join(".", m.DeclaringEntity.Value.FullName, m.DisplayName)
if name = "Microsoft.FSharp.Core.FSharpOption`1.Value" then
state.Add range
ctx.TypedTree.Declarations |> List.iter (visitDeclaration handler)
state
@Krzysztof-Cieslak
Krzysztof-Cieslak / gist:34c2a43c52119fde8d55315c7831244d
Created September 14, 2018 19:23
Run function for any member call
let rec visitExpr memberCallHandler (e:FSharpExpr) =
match e with
| BasicPatterns.AddressOf(lvalueExpr) ->
visitExpr memberCallHandler lvalueExpr
| BasicPatterns.AddressSet(lvalueExpr, rvalueExpr) ->
visitExpr memberCallHandler lvalueExpr; visitExpr memberCallHandler rvalueExpr
| BasicPatterns.Application(funcExpr, typeArgs, argExprs) ->
visitExpr memberCallHandler funcExpr; visitExprs memberCallHandler argExprs
| BasicPatterns.Call(objExprOpt, memberOrFunc, typeArgs1, typeArgs2, argExprs) ->
memberCallHandler e.Range memberOrFunc
@Krzysztof-Cieslak
Krzysztof-Cieslak / UserView.fs
Created August 3, 2018 22:30
Gists for "Using OAuth with Saturn" blog posts
module UserViews
open Giraffe.GiraffeViewEngine
module AdminPage =
let view = [
h1 [] [rawText "I'm admin"]
]
let layout = App.layout view
@Krzysztof-Cieslak
Krzysztof-Cieslak / Router.fs
Last active August 3, 2018 22:21
Gists for "Using OAuth with Saturn" blog posts
module Router
open Saturn
open Giraffe.Core
open Giraffe.ResponseWriters
open Users
let browser = pipeline {
plug acceptHtml