Skip to content

Instantly share code, notes, and snippets.

View owickstrom's full-sized avatar

Oskar Wickström owickstrom

View GitHub Profile
(ns scratch.core
(:require [clojure.core.typed :as t]))
(t/defalias DropboxEntry
(t/Rec [x]
(t/U '{:type (Value :file)
:path String
:mime-type String}
'{:type (Value :directory)
:path String
{
"graph": {
"label": "Some Title",
"metadata": {
"id": "uc1"
},
"nodes": [
{
"id": "user",
"label": "User",
@owickstrom
owickstrom / InstanceEffTrouble.purs
Last active August 29, 2015 14:21
Instance Effects Trouble
module Test.Spec where
import Debug.Trace
import Control.Monad
import Control.Monad.Error.Class
import Control.Monad.Trans
import Control.Monad.Eff
import Control.Monad.Eff.Exception
import Control.Monad.Eff.Class
import Control.Monad.Aff
@owickstrom
owickstrom / Rackla.hs
Created May 12, 2015 11:09
Rackla Types (in my mind, at least)
module Main where
import Control.Applicative
-- value with type a is only for demo purposes, it would be supplied
-- asyncronously in Rackla (or with messages, I don't know how it works
-- exactly).
data PID a = PID a deriving (Show)
instance Functor PID where
@owickstrom
owickstrom / Eq.purs
Last active August 29, 2015 14:19
Purescript Eq instance
module Main where
import Debug.Trace
data T = A | B Number
instance eqT :: Eq T where
A == A = true
(B v1) == (B v2) = v1 == v2
_ == _ = false
@owickstrom
owickstrom / typed_pmap.clj
Created December 11, 2014 05:01
core.typed pmap error
(require '[clojure.core.typed :as t])
; This seem to work nicely
(t/cf (identity 1)) ;=> [(t/Val 123) {:then tt, :else ff}]
; And this
(t/cf pmap) ;=> (All [c a b ...] (t/IFn [[a b ... b -> c] (t/NonEmptySeqable a) (t/NonEmptySeqable b) ... b -> (t/NonEmptyASeq c)] [[a b ... b -> c] (t/U nil (Seqable a)) (t/U nil (Seqable b)) ... b -> (t/ASeq c)]))
; But when I combine the two...
(t/cf (pmap identity [1 2 3]) ;=> Type Error (/tmp/form-init5174330476817989076.clj:1:7) Polymorphic function pmap could not be applied to arguments:
@owickstrom
owickstrom / test.ex
Created November 18, 2014 05:39
Missing binary concatenation operator in Elixir gives no warning
defmodule BinaryConcat do
def run do
data =
<<65, 32, 119, 97>> <>
<<114, 110, 105, 110>> # <- binary concatenation operator missing here
<<103, 32, 112, 101>> <>
<<114, 104, 97, 112, 115, 63>>
IO.puts <<data :: binary>>
end
@owickstrom
owickstrom / state.ex
Last active July 28, 2020 20:52
Exposing a synchronous API in Elixir. Inspired by http://elixir-lang.org/getting_started/mix_otp/3.html.
defmodule State.Counter do
use GenServer
def start_link(opts \\ []) do
GenServer.start_link(__MODULE__, :ok, opts)
end
## Client API
@doc "Gets the counter's current value."
@owickstrom
owickstrom / defer.go
Last active December 23, 2015 07:09
Going Async in Go
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
syslog, err := os.Open("/var/log/system.log")
@owickstrom
owickstrom / create_user.rake
Last active December 18, 2015 09:58
This is an update of https://gist.github.com/svanzoest/4028058 for Gitlab 5.2.0.
# gitlab 5.2.0 create user
# rake create_user["john@doe.com","johndoe","John Doe"] RAILS_ENV=production
desc "Create new user"
task :create_user, [:email, :username, :name] => :environment do |t, args|
puts "creating user '" + args.username + "' ('" + args.name + "') with email '" + args.email + "'"
@user = User.new({ email: args.email, name: args.name, username: args.username, force_random_password: true, projects_limit: 10 }, as: :admin)
if @user.save
puts "success"
else