Skip to content

Instantly share code, notes, and snippets.

@blippy
blippy / sumvec.rs
Created November 12, 2015 19:47
Sum a vector using references
fn summit(vec:&Vec<i64>) -> i64
{
let mut sum = 0i64;
for x in vec { sum = sum + x };
return sum;
}
fn main()
{
@blippy
blippy / foo.uue
Last active November 15, 2015 21:52
Using C to print out an HDF5 file of float64's
begin 764 foo.h5
MB4A$1@T*&@H```````@(``0`$`````````````````#__________YX5````
M````__________\``````````&```````````0````````"(`````````*@"
M`````````0`!``$````8`````````!$`$```````B`````````"H`@``````
M`%12144```$`_____________________P``````````5A0````````(````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
M````````````````````````````````````````````````````````````
@blippy
blippy / OrdList.hs
Created November 16, 2015 20:13
A list that is automatically stored in order
module OrdList (empty, fromList, insert, toList, OrdList) where
import Data.List as L (span)
data OrdList a = OrdList [a] deriving (Show)
empty :: OrdList a
empty = OrdList []
insert :: (Ord a) => a -> OrdList a -> OrdList a
@blippy
blippy / preds.txt
Created November 18, 2015 18:44
Haskell idiom for predicate lifting
Suppose I want to use an argument twice, as for example in the expression:
(\x -> (pred1 x) and (pred2 x))
Is there a shorter way of doing this?
liftA2 (&&) pred1 pred2
You can be cute and use the applicative instance on functions:
(&&) <$> pred1 <*> pred2
@blippy
blippy / hdfy.m
Created November 18, 2015 18:56
HDF5 in Octave
#!/home/mcarter/.local/bin/octave-cli -qf -W
# -*- octave -*-
1;
h5name = "/home/mcarter/temp.h5"
printf("Hello world\n");
pkg load hdf5oct
data = h5read(h5name, "/D20151113/rs6mb");
@blippy
blippy / dillo.desktop
Created December 3, 2015 11:47
Example .desktop file
# Desktop entry for dillo.
# System wide install as /usr/share/applications, or /usr/local/share/applications
# Private install as $HOME/.local/share/applications
# See http://standards.freedesktop.org/desktop-entry-spec/desktop-entry-spec-1.0.html
# See http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
[Desktop Entry]
Version=3.0.5
Type=Application
Name=Dillo web browser
GenericName=Web Browser
@blippy
blippy / hint_return.hs
Created December 4, 2015 19:47
Haskell interpreter: using "return"
import Control.Monad
import Data.List
import Language.Haskell.Interpreter
main :: IO ()
main = do r <- runInterpreter testHint
case r of
Left err -> printInterpreterError err
Right () -> putStrLn "that's all folks"
@blippy
blippy / ExampleVersion.hs
Created December 6, 2015 11:17
Embed cabal package version in Haskell code
module ExampleVersion where
{-
links:
http://stackoverflow.com/questions/9857710/haskell-correct-practice-to-specify-%5Cversion-in-source
Be sure to put Paths_packagename in your Other-Modules section of the cabal file.
-}
import Paths_mypackage (version) -- replace 'mypackage' with you nnn.cabal 'name' tag
@blippy
blippy / loopCollect.hs
Created December 8, 2015 22:33
Looping and collecting using monads
loopCollect state0 xs func = fst $ runState (forM xs func) state0
-- result is ["hello", " ", "world"]
eg = loopCollect "hello world" [5, 1, 5]
(\i -> do
str <- get
let (h, t) = splitAt i str
put t
return h)
@blippy
blippy / meatlog.py
Created December 11, 2015 13:02
Using pyDatalog to perform a data join
from pyDatalog import pyDatalog as pdl
# set up some basic terms
pdl.create_terms('F,G,Q,what,eat')
# F G
+what('pork', 'meat')
+what('lamb', 'meat')
+what('peas', 'veg')
+what('beans', 'veg')