Skip to content

Instantly share code, notes, and snippets.

View owickstrom's full-sized avatar

Oskar Wickström owickstrom

View GitHub Profile
@owickstrom
owickstrom / GetFromTo.cs
Created December 30, 2012 14:27
Possible solution (not tested)
public virtual IEnumerable<Commit> GetFromTo(DateTime start, DateTime end)
{
this.ThrowWhenDisposed();
Logger.Debug(Resources.GettingAllCommitsFromToTime, start, end);
var selectedCommitIds = this.stamps.Where(x => x.Value >= start && x.Value < end).Select(x => x.Key);
var firstCommitId = selectedCommitIds.FirstOrDefault();
var lastCommitId = selectedCommitIds.LastOrDefault();
if (lastCommitId == Guid.Empty && lastCommitId == Guid.Empty)
@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
@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 / based-on-existing-syntax.lisp
Last active January 22, 2016 08:52
Alternate syntax
(pkg main)
(import fmt)
;; if expressions
(: fib (int -> int))
(def (fib n)
(if (== n 1)
0
(if (== n 2)
@owickstrom
owickstrom / protocols.go
Last active April 11, 2016 12:06
Protocols sketches for Oden
//----------//
// SEMIRING //
//----------//
// Types that support addition and multiplication.
protocol Semiring(a) {
add : a -> a -> a
zero : a
mul : a -> a -> a
one : a
@owickstrom
owickstrom / Name.idr
Created October 13, 2016 05:52
Idris String with validation?
-- A data type wrapping a non-empty string
data Name : Type where
MkName : (s : String) -> (not (s == "") = True) -> Name
-- Some function that expects a valid Name
test : Name -> String
test (MkName s _) = s
-- Usage of that function. Do I need Refl here? Any better way of doing this?
foo : String
@owickstrom
owickstrom / TypeSynonymsProblem.purs
Created October 29, 2016 12:26
PureScript type synonym problem with effect kind
module TypeSynonymsProblem where
import Prelude
import Control.Monad.Eff (Eff)
import Data.Either (Either)
import Data.Tuple (Tuple(Tuple))
type Foo e a a' b b' = Eff e (Tuple a b) -> Eff e (Tuple a' b')
type Bar e a a' b b' = Eff e (Either a b) -> Eff e (Either a' b')
@owickstrom
owickstrom / SafeWeb.purs
Last active November 13, 2016 14:46
Safe web routes in PureScript
module SafeWeb where
import Prelude
import Data.Array (filter)
import Data.Leibniz (type (~))
import Data.String (Pattern(Pattern), split, joinWith)
type Path = Array String
pathToHtml :: Path -> String
@owickstrom
owickstrom / composing-alt-functions.md
Last active November 28, 2016 17:16
Composing Alt Functions

What I want is to "compose" functions taking some argument and returning an Alt value, like a -> m b where Alt b. The resulting value should be a function from a -> m b. The implementation below does that, but I was wondering if there's a better way? I'm thinking that maybe I could create a newtype wrapper around these functions, and an Alt instance for that type, but I haven't gotten that to work, and I'm not sure it's a good approach.

@owickstrom
owickstrom / compile-error.txt
Created December 8, 2016 19:17
compile-error.txt
No type class instance was found for
Control.Monad.Monad m0
while checking that expression { path: [ "contact"
]
, GET: handler (\conn ->
...
)