Skip to content

Instantly share code, notes, and snippets.

Avatar

Isak Sky isaksky

View GitHub Profile
@isaksky
isaksky / re-frame-helper.cljs
Created Jan 9, 2018
reframe - Request Effect
View re-frame-helper.cljs
(def req-counter (atom 0))
;; Not battle tested - adapted from an existing codebase
(rf/reg-fx
:request-giving-id
(fn [[request-id {:keys [on-complete resp-body-formatter request-args]
:or {on-complete identity
resp-body-formatter identity}
:as args}]]
@isaksky
isaksky / sq.ps1
Created May 5, 2017
Powershell Query SQL
View sq.ps1
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
@isaksky
isaksky / gist:ceceeb64a5d7cf666c4a18991403f97a
Last active Apr 19, 2017
Things I'd like to see in a .NET (F#) web framework
View gist:ceceeb64a5d7cf666c4a18991403f97a

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 / reframe-helper.cljs
Last active Sep 15, 2020
Register delayed subscription
View reframe-helper.cljs
(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:
View Html.fs
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 / Working-with-SQL-syntax-trees-in-F.md
Last active Dec 14, 2019
Working with SQL syntax trees in F#
View Working-with-SQL-syntax-trees-in-F.md

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 / TransactSqlWrapping.fs
Last active Oct 29, 2016
F# Generated wrapper for Microsoft.SqlServer.TransactSql
View TransactSqlWrapping.fs
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 / Program.fs
Created Aug 23, 2016
Benchmark various ways to read N rows async
View Program.fs
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 / Program.fs
Created Aug 12, 2016
Json type generator
View Program.fs
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 / stack_pls.ex
Created Jul 11, 2016
iex - Missing stacktrace
View stack_pls.ex
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