Skip to content

Instantly share code, notes, and snippets.

View epost's full-sized avatar

Erik Post epost

View GitHub Profile
@epost
epost / add.hs
Created July 7, 2012 16:46
Mischa's adder
import Data.Digits
carry r i x y | i == 0 = 0
| x + y + carry r (i-1) x y <= r-1 = 0
| True = 1
-- currently works iff x and y have same # of digits, due to zip3
add x y =
sum [ (x_i + y_i + carry r i x y)*r^i | (x_i, y_i, i) <- (zip3 xs ys [0..])]
@epost
epost / IESupport.scala
Created August 13, 2012 15:42
Liftweb body tag in conditional comments
object IESupport {
/**
* Lift strips out HTML comments, including IE conditional comments, so this is a workaround. We can't seem to do this
* for the 'html' tag though, due to restrictions in he HTML5 parser that Lift uses.
*/
def bodyTag(bodyContent: NodeSeq): NodeSeq = {
val bodyTagOpen = Unparsed("""
<!--[if lt IE 7]> <body class="home ie6 ie-lt-7 ie-lt-8 ie-lt-9"> <![endif]-->
<!--[if IE 7]> <body class="home ie7 ie-lt-8 ie-lt-9"> <![endif]-->
@epost
epost / liftAjaxIncludes.html
Created August 13, 2012 16:20
Liftweb AJAX includes
<html>
<head>
<script type="text/javascript" src="/ajax_request/liftAjax.js"></script>
</head>
<body>
<!-- ... -->
<script type="text/javascript">
// <![CDATA[
@epost
epost / conditionalComments.html
Created August 13, 2012 16:36
Conditional comments around the body tag
<html>
<!--[if lt IE 7]> <body class="home ie6 ie-lt-7 ie-lt-8 ie-lt-9"> <![endif]-->
<!--[if IE 7]> <body class="home ie7 ie-lt-8 ie-lt-9"> <![endif]-->
<!--[if IE 8]> <body class="home ie8 ie-lt-9"> <![endif]-->
<!--[if IE 9]> <body class="home ie9"> <![endif]-->
<!--[if gt IE 9]><!--> <body class="home"> <!--<![endif]-->
</html>
@epost
epost / gitweb_show_readme_markdown.pl
Created October 5, 2012 19:18
Show README.md as part of a project summary in Gitweb
# Convert README.md (Markdown file) to HTML and include in output #using external Markdown
if (!$prevent_xss) {
$file_name = "README.md";
my $proj_head_hash = git_get_head_hash($project);
my $readme_blob_hash = git_get_hash_by_path($proj_head_hash, "README.md", "blob");
if ($readme_blob_hash) { # if README.md exists
print "<div class=\"header\">readme</div>\n";
print "<div class=\"readme page_body\">"; # TODO find/create a better CSS class than page_body
@epost
epost / gist:7787727
Created December 4, 2013 13:53
A little working example of Haskell's 'comprehensive comprehensions' as supported by the TransformListComp extension.
{-# LANGUAGE TransformListComp #-}
-- There are three new keywords: group, by, and using.
-- The functions sortWith and groupWith are not keywords; they are ordinary functions that are exported by GHC.Exts.)
import GHC.Exts (sortWith, groupWith)
--import Data.List (sort)
-- actual syntax: http://www.haskell.org/ghc/docs/latest/html/users_guide/syntax-extns.html#generalised-list-comprehensions
--
module Main where
import Prelude
import Control.Monad.Eff
import Data.Array
main =
let test1 = concat [1, 2, 3] [4, 5, 6]
x = 3
in do
@epost
epost / gist:ac561174021c6be5d88f
Last active August 29, 2015 14:01
Getting started with PureScript template projects
# install some tools we'll need
npm install -g grunt grunt-init bower
# install a PureScript project template for use with grunt-init
mkdir ~/.grunt-init
git clone https://github.com/purescript-contrib/grunt-init-purescript.git ~/.grunt-init/purescript
# create a PureScript project from the template and fetch its dependencies
mkdir /path/to/your_ps_project
cd /path/to/your_ps_project
@epost
epost / shell-command-on-save.el
Last active August 29, 2015 14:02
run shell command on saving PureScript file
(defun do-something ()
(interactive) ; not sure if necessary
(shell-command "ls")
)
(defun my-purescript-mode-hook ()
(message "in purescript-mode-hook...")
(add-hook 'write-contents-hooks 'do-something nil t)
)
@epost
epost / Build.scala
Last active August 29, 2015 14:02
Example SBT web project for Vlad
import sbt._
import sbt.Keys._
import com.earldouglas.xsbtwebplugin.WebPlugin
import com.earldouglas.xsbtwebplugin.PluginKeys._
import Tests._
/*
// don't monitor dirs when using JRebel
scanDirectories := Nil