Skip to content

Instantly share code, notes, and snippets.

@joastbg
joastbg / gist:3945574
Created October 24, 2012 11:32
Recursive bisection solver
// Recursive bisection solver
// n: start iteration (0)
// N: max iterations
// f: function to solve (find root)
// a: lower range bound
// b: upper range bound
// t: tolerance
let rec bisect n N (f:float -> float) (a:float) (b:float) (t:float) : float =
if n >= N then -1.0
else
@joastbg
joastbg / gist:3946351
Created October 24, 2012 14:23
Data grid in F#
// The form
let form = new Form(Visible = true, Text = "Data grid #1",
TopMost = true, Size = Drawing.Size(600,600))
// The grid
let data = new DataGridView(Dock = DockStyle.Fill, Text = "Data grid",
Font = new Drawing.Font("Lucida Console", 10.0f),
ForeColor = Drawing.Color.DarkBlue)
form.Controls.Add(data)
@joastbg
joastbg / gist:6280065
Created August 20, 2013 11:01
F# project file (fsproj)
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">x86</Platform>
<ProductVersion>8.0.30703</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{a9120397-fd09-4e7f-9384-c7fd8976acc5}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>ApplicativeFParsec</RootNamespace>
@joastbg
joastbg / bochsrc
Created September 25, 2013 19:41
Config file for Bochs to boot from a floppy drive (probably a virtual one)
romimage: file=BIOS-bochs-latest, address=0xfffe0000
vgaromimage: file=VGABIOS-lgpl-latest-debug
vga: extension=cirrus, update_freq=10
vga: extension=vbe
floppya: 1_44=a:, status=inserted
log: OSDEV.log
error: action=report
@joastbg
joastbg / cmd_args.hs
Last active December 26, 2015 21:09
Haskell - playing with command-line arguments using forM_ and mapM_
module Main where
import System.Environment
import Control.Monad
main :: IO ()
main = do
args <- getArgs
putStrLn ("Hello, " ++ args !! 0)
-- using for
@joastbg
joastbg / hdbc_mysql.hs
Last active December 26, 2015 21:09
Haskell - HDBC and MySQL
import Control.Monad
import System.IO
import Database.HDBC
import Database.HDBC.MySQL
import Data.Char
import qualified Data.Map as Map
main = do conn <- connectMySQL defaultMySQLConnectInfo {
mysqlUser = "testing",
mysqlPassword = "testing1234",
@joastbg
joastbg / json.hs
Created October 29, 2013 12:36
Haskell - Using Aeson for JSON (extended example from Aeson)
-- JSON in Haskell using Aeson
{-# LANGUAGE OverloadedStrings #-}
import Control.Applicative ((<$>), (<*>), empty)
import Data.Aeson
import qualified Data.ByteString.Lazy.Char8 as BL
data Coord = Coord {
x :: Double,
@joastbg
joastbg / happstack.hs
Created October 29, 2013 12:39
Haskell - Example using Happstack in Haskell
module Main where
import Control.Monad (msum)
import Data.Char (toLower)
import Happstack.Server (FromReqURI(..), dirs, dir, path, seeOther, nullConf, simpleHTTP, toResponse, ok)
--main :: IO ()
--main = simpleHTTP nullConf $ ok (toResponse "Hello, World!")
data Subject = World | Haskell
@joastbg
joastbg / redis.hs
Created November 11, 2013 12:07
Haskell - Simple example of how to use Redis, from the hedis documentation
{-# LANGUAGE OverloadedStrings #-}
import Database.Redis
import Control.Monad.Trans
main :: IO ()
main = do
conn <- connect defaultConnectInfo
runRedis conn $ do
set "foo" "123"
@joastbg
joastbg / zlib.hs
Created November 13, 2013 20:50
Haskell - Zlib example
import qualified Data.ByteString.Lazy as B
import qualified Codec.Compression.Zlib as Zlib
Zlib.decompress <$> Zlib.compress <$> B.readFile "sample.txt"