Skip to content

Instantly share code, notes, and snippets.

module Foo
( module Control.Applicative
, g
) where
import Control.Applicative
g :: Int
g = 1
@bergmark
bergmark / A.hs
Last active December 22, 2015 22:19
failing persistent migration
{-# LANGUAGE EmptyDataDecls, FlexibleContexts, GADTs, OverloadedStrings, QuasiQuotes, TemplateHaskell, TypeFamilies #-}
module A where
import Database.Persist.TH
share [mkPersist sqlSettings, mkMigrate "migrateAll"] [persistLowerCase|
A
|]
@bergmark
bergmark / maybe-remove-newlines
Created August 16, 2013 19:02
If there are two linebreaks at the end of a file, keep them, if there's only one it is kept as is to not add extra changes to commits.
(defun delete-trailing-whitespace-and-extra-nl ()
(interactive)
(let ((two? (ends-with-two-linebreaks?)))
(progn
(delete-trailing-whitespace)
(if (and two? (string-match "silk" (buffer-file-name)))
(save-excursion
(let ((undo-list (undo-copy-list buffer-undo-list)))
(progn
(buffer-disable-undo)
<!-- page structure showing the title (line 7) and subtitle (line 8) -->
<article>
<section class="body">
<div class="layout meta"> <!-- left column -->
<div class="block header text" data-component-uri="http://silkapp.com/component/block/text">
<h1>Title</h1>
<p>Subtitle</p>
</div>
</div>
# create new page (or adjust existing page) called 'test'
$ curl https://api.silkapp.com/v1.4.0/site/uri/yoursite.silkapp.com/page/test
-d '<article>...</article>'
-b 'silk_sid=...'
-X PUT
-H 'Content-Type: application/xml'
;; Enable editable dired mode.
(add-hook 'dired-mode-hook
(lambda ()
(define-key dired-mode-map
"r" 'wdired-change-to-wdired-mode)
(setq truncate-lines t)))
;; Enable a in dired mode to view a file w/o creating a new buffer.
(put 'dired-find-alternate-file 'disabled nil)
Haskell:
data Select = FirstAlternative String String
| SecondAlternative Select Select
| ThirdAlternative Select
printSelect :: Select -> IO ()
printSelect (FirstAlternative str1 str2) =
putStr("FirstAlternative(" ++ str1 ++ ", " ++ str2 ++ ")")
printSelect (SecondAlternative sel1 sel2) = do
Prelude Text.Regex.Posix> "bar" =~ "(foo|bar)" :: Bool
<interactive>:1:7:
No instances for (RegexMaker Regex CompOption ExecOption [Char],
RegexContext Regex [Char] Bool)
arising from a use of `=~'
Possible fix:
add instance declarations for
(RegexMaker Regex CompOption ExecOption [Char],
RegexContext Regex [Char] Bool)
@bergmark
bergmark / gist:1625460
Created January 17, 2012 07:34
fallout hack solver
#!/usr/bin/env ruby
pairs = []
while !(print '> ') && (s = gets.strip) != ''
word,num = /^(\S+)\s*(\d+)?$/.match(s)[1..2]
if num
pairs << [word,num.to_i]
else
print(pairs.map { |p_word,p_num|
p_num == word.chars.zip(p_word.chars).inject(0) { |s,(a,b)| s + (a == b ? 1 : 0) }
}.all? ? "match\n" : "no match\n")
cpanm (App::cpanminus) 1.4008 on perl 5.010001 built for x86_64-linux-gnu-thread-multi
Work directory is /home/adam/.cpanm/work/1314969734.22227
You have make /usr/bin/make
You have LWP 5.836
You have /bin/tar: tar (GNU tar) 1.23
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.