Skip to content

Instantly share code, notes, and snippets.

@roman
roman / page_205_exercises.hs
Created April 16, 2009 08:23
Real World Haskell Exercises
module GlobRegex
(
globToRegex,
matchesGlob
)
where
import Text.Regex.Posix ((=~))
import Data.Char (toLower)
@snipsnipsnip
snipsnipsnip / inspectable.scala
Last active August 24, 2019 15:55
inspectable.scala: 3.methods foreach println
// originally from http://lousycoder.com/blog/index.php?/archives/91-Scala-Querying-an-objects-fields-and-methods-with-reflection.html
package inspectable
import scala.Console._
import scala.tools.nsc.util.NameTransformer._
import java.lang.reflect.Modifier._
import java.lang.reflect.{Method, Member, Field}
import java.lang.Class
[..e/nick/dev/haskell/markov]$ ghci
GHCi, version 6.12.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Loading package ffi-1.0 ... linking ... done.
Prelude> :l markov.hs
[1 of 1] Compiling Main ( markov.hs, interpreted )
Ok, modules loaded: Main.
*Main> let x = markovChain 1 5
@pkrumins
pkrumins / getusername
Created November 16, 2010 00:06
GetUserName windows api call via haskell's FFI!
{-# LANGUAGE ForeignFunctionInterface #-}
import System.Win32.Types
import Foreign
import Foreign.C
foreign import stdcall unsafe "windows.h GetUserNameW"
c_GetUserName :: LPTSTR -> LPDWORD -> IO Bool
getUserName :: IO String
@leandrosilva
leandrosilva / assembly_metadata.cs
Created November 25, 2010 00:47
Live samples on how to read the metadatas of .NET solutions, projects and assemblies with C#
using System;
using System.Reflection;
using System.Security.Permissions;
[assembly:AssemblyVersionAttribute("1.0.2000.0")]
public class Metadata
{
private int factor;
@marcmo
marcmo / echoServer.hs
Created March 23, 2011 08:00
simple haskell program for sending over socket and receiving a response with a timeout
-- Echo server program
module Main where
import Control.Monad (unless,when)
import Network.Socket hiding (recv)
import qualified Data.ByteString as S
import Data.Word(Word8)
import Control.Concurrent(threadDelay)
import Data.List
import Numeric
@debasishg
debasishg / gist:924143
Created April 17, 2011 15:36
@runanorama's code snippet for using iteratee based JDBC results processing
def enumResultSet[E,A](rs: ResultSet, iter: IterV[E, A], get: ResultSet => IO[E]): IO[IterV[E, A]] = {
def loop(i: IterV[E, A]): IO[IterV[E, A]] =
i.fold(done = (_, _) => i.pure[IO],
cont = k => next(rs) >>= (hasMore =>
if (!hasMore) i.pure[IO]
else get(rs) >>= (t => loop(k(El(t))))))
loop(iter)
}
@atifaziz
atifaziz / Program.cs
Created April 21, 2011 15:45
Program to display target CLR version of an assembly
class Program {
static void Main(string[] args) {
System.Console.WriteLine(System.Reflection.Assembly.ReflectionOnlyLoadFrom(args[0]).ImageRuntimeVersion);
}
}
@shwangdev
shwangdev / Makefile
Created June 23, 2011 05:29
Makefile
C++ = g++
ifndef os
os = LINUX
endif
SRC= $(shell ls *.cpp)
OBJS= $(SRC:%.cpp=%.o)
DIR = $(shell pwd)
Target=test
all: $(Target)
@jhartikainen
jhartikainen / DynLoad.hs
Created August 20, 2011 11:31
Module for loading modules dynamically in Haskell
{-# LANGUAGE ScopedTypeVariables #-}
module DynLoad (
loadSourceGhc,
execFnGhc
) where
import Control.Exception (throw)
import GHC hiding (loadModule)
import GHC.Paths (libdir)
import HscTypes (SourceError, srcErrorMessages)