Skip to content

Instantly share code, notes, and snippets.

View Tritlo's full-sized avatar

Matthías Páll Gissurarson Tritlo

View GitHub Profile
@Tritlo
Tritlo / McCabeCounter.py
Last active December 14, 2015 15:28
A program that calculates the (McCabe complexity)[https://en.wikipedia.org/wiki/McCabe_complexity] of python programs in a directory and subdirectories. Usage: python McCabeCounter.py directory
#!/usr/bin/python
#encoding utf-8
import sys, os
from itertools import takewhile
def getFuncs(filename, funcDef = "def "):
lines = open(filename,'r').readlines()
funcDefIn = lambda line: True if line.strip().startswith(funcDef) else False
funcs = map(lambda i: [lines[i]] + list(takewhile(lambda x: not funcDefIn(x),lines[i+1:])),filter(lambda i: funcDefIn(lines[i]),range(len(lines))))
# grabs lines until start of next func/end of file lines where functions start
@Tritlo
Tritlo / Heroku.hs
Created November 12, 2013 22:50
Heroku helper for haskell
module Helpers.Heroku (herokuConf) where
import Prelude
import Data.ByteString (ByteString)
import Data.Text (Text)
import Data.Text.Encoding (encodeUtf8)
import Database.Persist.Postgresql (PostgresConf(..))
import Web.Heroku (dbConnParams)
import qualified Data.Text as T
@Tritlo
Tritlo / packages.el
Last active June 8, 2016 18:24 — forked from cstrahan/packages.el
Private spacemacs layer to try out Chris Done's Intero mode for haskell
;; 1. place this in ~/.emacs.d/private/intero/packages.el
;; 2. add intero, syntax-checking and auto-completion to your
;; ~/.spacemacs layer configuration & remove the haskell layer
;; if you were using that before
;; 3. make sure you have stack installed http://haskellstack.org
;; 4. fire up emacs & open up a stack project's source files
@Tritlo
Tritlo / LightCrumb.js
Last active February 7, 2017 11:19 — forked from plexsoup/LightCrumb.js
LightCrumb - based on "Mark" by the Aaron. For lighting your trail on maps with dynamic lighting.
// Gist: https://gist.github.com/plexsoup/64852540504101b520b25f7c3fa84e5f
// By: Plexsoup - copied from Mark by The Aaron. With help from Scott C, Stephen L and Tritlo
// Thanks: Testers and Feedback: al e., DM Robzer, Vince, Pat S, Gold, Anthony, Kryx, Sudain
// Contact: https://app.roll20.net/users/258125/plexsoup
// Roll20 API Script to leave a breadcrumb trail of torches. Based on "Mark" from The Aaron //
/*
#!/usr/bin/env python3
import uuid
import datetime
import time
# Configuration
bucket = 'REDACTED' #Make sure you have permissions to Put, Delete and Get.
path = "nullid/picam-" #The prefix of the pictures.
@Tritlo
Tritlo / APDoTest.hs
Created November 9, 2017 16:40
An example of how ApplicativeDo can be inefficient with uniform costs.
{-# LANGUAGE ApplicativeDo #-}
module Main where
import Control.Concurrent
import Control.Concurrent.MVar
import Data.Time.Clock
-- We create a wrapper around IO for this example
newtype PIO a = PIO { runPIO :: IO a }
@Tritlo
Tritlo / Main.hs
Last active January 23, 2018 13:48
Using typed holes to lookup functions with types with non-functional properties.
{-# LANGUAGE TypeInType, TypeOperators #-}
module Main where
import Sorting
import ONotation
-- Here we say that sorted can use at most complexity N^2 and at most memory N^1
-- and that the sort has to be stable.
mySort :: Sorted (O(N ^. 2)) (O(N)) True Integer
@Tritlo
Tritlo / OverloadedDo.hs
Last active February 13, 2018 19:06
OverloadedDo exploration
{-# LANGUAGE RebindableSyntax #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeInType #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE PartialTypeSignatures #-}
{-# LANGUAGE DeriveDataTypeable #-}
@Tritlo
Tritlo / DependentTypingExample.hs
Last active March 26, 2018 18:29
Dependent typing in Haskell (example)
-- This is a simple example showing the use of dependent typing in haskell, in a
-- vein similar to http://www.idris-lang.org/example/
{-# LANGUAGE TypeFamilies, GADTs, TypeOperators, DataKinds, KindSignatures #-}
-- We can also just add TypeInType, and skip DataKinds and KindSignatures,
-- since TypeInType enables both of those, PolyKinds (and more!)
module Main where
import Data.Kind (Type)
-- Define a Type for the natural numbers, Zero and a successor
{-# LANGUAGE GADTs #-}
import Data.List
import Data.Monoid
import Data.Typeable
import Data.Dynamic
import GHC.Err
import GHC.Prim