Skip to content

Instantly share code, notes, and snippets.

View isaksky's full-sized avatar

Isak Sky isaksky

View GitHub Profile
@isaksky
isaksky / gist:5906464
Created July 2, 2013 02:52
core.match example
(defn interactive-content?
"Check if an html element (in hiccup form) is interactive content. See http://www.w3.org/html/wg/drafts/html/master/dom.html#interactive-content-0"
[node]
(match node
[(:or :a :button :details :embed :iframe :keygen :label :select :textarea :video) & _] true
[(:or :audio :video) {:controls _} & _] true
[ (:or :img :object) {:usemap _} & _] true
[:input attrs & _ ] (not (= "hidden"(:type attrs)))
:else false))
@isaksky
isaksky / stack_pls.ex
Created July 11, 2016 00:53
iex - Missing stacktrace
defmodule StackPls do
@behaviour :gen_statem
def callback_mode(), do: :state_functions
def start_link(opts) do
:gen_statem.start_link(__MODULE__, opts, [])
end
# Mandatory callback functions
@isaksky
isaksky / Program.fs
Created August 12, 2016 05:17
Json type generator
open Newtonsoft.Json
open Newtonsoft.Json.Linq
open System.Collections.Generic
open System
open System.IO
open System.Text
type TypeNodeMut =
{ fieldname: string
children : Dictionary<string, TypeNodeMut>
@isaksky
isaksky / Program.fs
Created August 23, 2016 22:32
Benchmark various ways to read N rows async
open Hopac
open BenchmarkDotNet
open BenchmarkDotNet.Attributes
open BenchmarkDotNet.Running
open System
open System.Data
open System.Data.SqlClient
open System.Threading.Tasks
open BenchmarkDotNet.Configs
open BenchmarkDotNet.Diagnostics.Windows
@isaksky
isaksky / TransactSqlWrapping.fs
Last active July 24, 2021 14:07
F# Generated wrapper for Microsoft.SqlServer.TransactSql
module Foo
open System
open Microsoft.SqlServer.TransactSql
type [<RequireQualifiedAccess>] TSqlFragment =
| AdHocDataSource of InitString:StringLiteral option * ProviderName:StringLiteral option
| AddFileSpec of File:ScalarExpression option * FileName:Literal option
| AlterAvailabilityGroupAction of AlterAvailabilityGroupAction
| AlterAvailabilityGroupFailoverOption of OptionKind:ScriptDom.FailoverActionOptionKind * Value:Literal option
| AlterDatabaseTermination of ImmediateRollback:bool * NoWait:bool * RollbackAfter:Literal option
@isaksky
isaksky / Working-with-SQL-syntax-trees-in-F.md
Last active June 25, 2021 19:21
Working with SQL syntax trees in F#

Working with SQL syntax trees in F#

Update 12/15/2016 - Added Sql generation

Welcome to my blog post for #FsAdvent 2016.

If you're using a relational database, as your application grows in size, at some point you may find yourself looking for an SQL parser. This can give you lots of leverage, for example allowing you to:

  • Do permission checks on queries before executing them
  • Rewrite incorrect or inefficient queries
@isaksky
isaksky / Html.fs
Created January 18, 2017 20:41
Html Dsl
module Html =
type Tag(name:string) =
let mutable _safeContent = false
member val className = "" with get, set
member val content = "" with get, set
// For ease of use, support children in both list and resize array
member val childrenL : Tag list = [] with get, set
member val childrenR = ResizeArray<Tag>() with get, set
member this.name with get() = name
@isaksky
isaksky / reframe-helper.cljs
Last active September 15, 2020 14:56
Register delayed subscription
(ns foo
(:require [re-frame.core :as rf]
[re-frame.db]
[reagent.ratom :as ra :refer [reaction]])
(:import goog.async.Debouncer))
(defn reg-sub-delayed
"Similar to reg-sub, except the computation is debounced.
It can be called like this:
@isaksky
isaksky / gist:ceceeb64a5d7cf666c4a18991403f97a
Last active April 19, 2017 06:05
Things I'd like to see in a .NET (F#) web framework

Some things I'd like to see in a F# web framework, inspired from experience using Phoenix in Elixir.

  • Top knotch integrated i18n support, on par with gettext in Elixir.
    • Not sure if this is possible in F#, because of the lack of metaprogramming features. The Elixir solution is based on macros, so that one can extract .pot translation files at compile time.
  • Standard way to talk to databases suitable for most apps (Elixir example: Ecto)
  • Standard way to do database migrations suitable for most apps (Elixir example: Ecto)

This is more ecosystem related, but I'll include them anyway, because I think they are important to overall productivity:

  • Standardized, extensible project build/scripting tool already on my path. Examples:
@isaksky
isaksky / sq.ps1
Created May 5, 2017 02:00
Powershell Query SQL
function sq
{
param([string]$Query)
$SQLServer = "ISAK-NEW\SQLEXPRESS"
$SQLDBName = "AdventureWorks2014"
$SqlConnection = New-Object System.Data.SqlClient.SqlConnection
$SqlConnection.ConnectionString = "Server = $SQLServer; Database = $SQLDBName; Integrated Security = True;"
$SqlCmd = New-Object System.Data.SqlClient.SqlCommand
$SqlCmd.CommandText = $Query
$SqlCmd.Connection = $SqlConnection