Skip to content

Instantly share code, notes, and snippets.

View rnagasam's full-sized avatar

Ramana Nagasamudram rnagasam

  • Stevens Institute of Technology
  • Hoboken, NJ
View GitHub Profile
@rnagasam
rnagasam / i3.config
Created June 18, 2018 16:46
current i3 config
# This file has been auto-generated by i3-config-wizard(1).
# It will not be overwritten, so edit it as you like.
#
# Should you change your keyboard layout some time, delete
# this file and re-run i3-config-wizard(1).
#
# i3 config file (v4)
#
# Please see http://i3wm.org/docs/userguide.html for a complete reference!
@rnagasam
rnagasam / forbidden.py
Created June 16, 2018 02:46
Forbidden Fruit is one crafty library
from forbiddenfruit import curse, reverse
# add method to int type
def words_of_wisdom(self):
return self * "blah "
curse(int, "words_of_wisdom", words_of_wisdom)
# add classmethod
def hello(self):
@rnagasam
rnagasam / dynamic_add.py
Created June 16, 2018 02:32
Dynamically add methods to classes
from types import MethodType
class MyObj(object):
def __init__(self, val):
self.val = val
def new_method(self, value):
return self.val + value
obj = MyObj(3)
@rnagasam
rnagasam / infix.py
Created June 16, 2018 02:24
Infix functions in Python
from functools import partial
class Infix(object):
def __init__(self, func):
self.func = func
def __or__(self, other):
return self.func(other)
def __ror__(self, other):
return Infix(partial(self.func, other))
def __call__(self, v1, v2):
@rnagasam
rnagasam / 20exercises.hs
Last active June 14, 2018 20:14
Solutions to Tony Morris's Haskell Exercises
{-# LANGUAGE InstanceSigs #-}
-- http://blog.tmorris.net/posts/20-intermediate-haskell-exercises/
-- Functor
class Fluffy f where
furry :: (a -> b) -> f a -> f b
instance Fluffy [] where
furry :: (a -> b) -> [a] -> [b]
alias ghci-core="ghci -ddump-simpl -dsuppress-idinfo \
-dsuppress-coercions -dsuppress-type-applications \
-dsuppress-uniques -dsuppress-module-prefixes"
@rnagasam
rnagasam / ghci.conf
Created June 13, 2018 03:43
GHCi configuration
:set prompt "\ESC[1;34m%s\n\ESC[0;34mλ: \ESC[m"
:def hoogle \s -> return $ ":!hoogle --count=15 \"" ++ s ++ "\""
:def doc \s -> return $ ":!haskell-docs " ++ s
:set -XOverloadedStrings
:set -XFlexibleContexts
@rnagasam
rnagasam / vamosMatroid.hs
Created June 13, 2018 03:40
svg-builder example2
{-# LANGUAGE OverloadedStrings #-}
-- Translated from https://upload.wikimedia.org/wikipedia/commons/b/b7/Vamos_matroid.svg
-- For an absolutely amazing collection of Mathematical illustrations take a
-- look at https://commons.wikimedia.org/wiki/User:David_Eppstein/Gallery
import Graphics.Svg
svg :: Element -> Element
svg content =
@rnagasam
rnagasam / svg1.hs
Created June 13, 2018 03:40
svg-builder example
{-# LANGUAGE OverloadedStrings #-}
import Graphics.Svg
svg :: Element -> Element
svg content = doctype
<> with (svg11_ content) [Version_ <<- "1.1", Width_ <<- "300", Height_ <<- "200"]
contents :: Element
contents =
@rnagasam
rnagasam / RoseTree.hs
Created June 11, 2018 19:59
Multiway Trees
{-# LANGUAGE InstanceSigs #-}
-- Rose Trees
data Tree a =
a :> [Tree a]
deriving (Eq, Show)
singleton :: a -> Tree a
singleton = (:> [])