Skip to content

Instantly share code, notes, and snippets.

//==========================================
// Hypothetical fully self-contained getting-started example for Suave Web Server scripting
//
// This script fetches the Paket.exe component which is referenced later in the script.
// Initially the #r "paket.exe" reference is shown as unresolved. Once it has been
// downloaded by the user (by executing the first part of the script) the reference
// shows as resolved and can be used.
//------------------------------------------
@Larry57
Larry57 / AssemblyResolver.cs
Created January 21, 2015 15:45
Hook an AppDomain to a generic assembly resolver that accepts to several folders
using System.IO;
using System.Linq;
using System.Reflection;
namespace System
{
public static class AssemblyResolver
{
internal static void Hook(params string[] folders)
{
#I @"..\packages\"
#r @"FSharp.Data\lib\net40\FSharp.Data.dll"
#load @"FSPlot\FsPlotBootstrap.fsx"
#r @"Deedle\lib\net40\Deedle.dll"
do fsi.AddPrinter(fun (printer:Deedle.Internal.IFsiFormattable) -> "\n" + (printer.Format()))
open Deedle
open FSharp.Data
open System
type Twitter = CsvProvider< @"C:\Users\Isaac\Downloads\fsharp_2013-2014.csv">
@Jim-Holmstroem
Jim-Holmstroem / functional_gtk.py
Created December 29, 2014 13:47
Fixes parts of gtk's Jurassic imperative programming style
from functools import partial
from collections import Iterable
def component(Component):
"""
{
label = gtk.Label('label')
label.set_size_request(640, 480)
label.set_justify(gtk.JUSTIFY_FILL)
} =>
@apruden
apruden / gist:c7655738acb244e1a3d3
Created December 11, 2014 02:52
Monad Transformers
case class Reader[C, A](g: C => A) {
def apply(c: C) = g(c)
def map[B](f: A => B): Reader[C, B] =
(c:C) => f(g(c))
def flatMap[B](f: A => Reader[C, B]): Reader[C, B] =
(c:C) => f(g(c))(c)
}
object Reader {
implicit def Reader[A,B](f: A => B): Reader[A,B] = Reader(f)
@DuoSRX
DuoSRX / Main.hs
Created December 7, 2014 06:07
simplistic haskell web server
{-# LANGUAGE ScopedTypeVariables #-}
module Main where
import Network (listenOn, withSocketsDo, accept, PortID(..), Socket)
import Control.Concurrent (forkIO)
import Control.Exception (handle, IOException)
import Control.Monad (liftM)
import System.IO (hSetBuffering, hPutStr, hClose, hGetContents, BufferMode(..), Handle, readFile)
import Debug.Trace
#r @"packages\Streams.0.2.5\lib\Streams.Core.dll"
open System
open System.IO
open System.Collections.Generic
open Nessos.Streams
// make Visual Studio use the script directory
Directory.SetCurrentDirectory(__SOURCE_DIRECTORY__)
(defun a-function (option callback)
"Open the message with key."
(interactive)
(let* ((buffer (get-buffer-create "aprocessbuffer"))
(command (a-build-autocomple-command option))
(proc (start-process "aproccess" buffer "ls" "-l" )))
(set-process-sentinel proc (lambda (process signal)
(cond
((equal signal "finished\n")
(let ((output (with-current-buffer (process-buffer process)
@MarcoSero
MarcoSero / contacts.hs
Created November 2, 2014 11:21
Simple JSON-backed address book in Haskell
{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}
import Data.Aeson ((.:), (.:?), decode, encode, FromJSON(..), ToJSON(..), Value(..))
import Data.Aeson.Encode.Pretty
import qualified Data.ByteString.Lazy as BS (readFile, writeFile)
import Control.Applicative ((<$>), (<*>))
import Control.Monad.IO.Class
import Control.Monad
@sergey-tihon
sergey-tihon / gist:ceaf835ef2df2d9bcf8f
Created October 21, 2014 20:28
NuGet download stats
#I @"packages\Nuget.Core.2.8.3\lib\net40-Client"
#r "NuGet.Core.dll"
#r "System.Xml.Linq.dll"
let repository =
NuGet.PackageRepositoryFactory.Default.CreateRepository
"https://nuget.org/api/v2"
type NuGetStat =
{ Id: string; DownloadCount:int}