Skip to content

Instantly share code, notes, and snippets.

View Thorium's full-sized avatar

Tuomas Hietanen Thorium

View GitHub Profile
@Thorium
Thorium / gulpfile.js
Last active August 29, 2015 14:11
JavaScript minifier for FunScript
// Put this file to your FunScript output folder.
var gulp = require('gulp'),
concat = require('gulp-concat'),
uglify = require('gulp-uglify'),
sourcemaps = require('gulp-sourcemaps');
var jsfile = {
targetPath: '',
//This is your FunScript-generated .js-file:
sources: ['generated.js']
@Thorium
Thorium / ParallelReduce.fs
Last active August 29, 2015 14:13
Idea from Guy L. Steele - Organizing Functional Code for Parallel Execution; or, foldl and foldr Considered Slightly Harmful - https://vimeo.com/6624203
// Reduce / Aggregate / Fold
// Usual way makes deep recursion and trusts tail-opt:
// (a,b,c,d,e,f,g,h) => (((((((a + b) + c) + d) + e) + f) + g) + h)
// This more is quicksort-style parallel:
// (a,b,c,d,e,f,g,h) => (((a + b) + (c + d)) + ((e + f) + (g + h)))
// No Haskell Kinds support for F# so List and Array are easiest to make as separate methods.
open System.Threading.Tasks
module List =
let reduceParallel<'a> f (ie :'a list) =
@Thorium
Thorium / findrefs.fsx
Last active August 29, 2015 14:13
Fetching dll-infos and their references from a source directory.
open System
open System.IO
open System.Net
open System.Reflection
let ``not in gac`` (filename:string) =
try
Assembly.Load filename |> ignore
false
with | :? IOException -> true
@Thorium
Thorium / gist:c64b8c5bd105f4f53d1e
Last active August 29, 2015 14:15
Getting started with Akka.NET
// Create Console-application, then NuGet: Install-Package Akka
module AkkaConsoleApplication
open Akka
open Akka.Actor
type Greet(who) =
member x.Who = who
type GreetingActor() as g =
inherit ReceiveActor()
@Thorium
Thorium / gist:c155e8404dedc7b5610b
Last active August 29, 2015 14:18
Create NuGet packages.config files for csproj-files.
// This program will create packages.config files for each .csproj.
// It will enumerate your projects dll references to know the corresponding NuGet packages.
// packages.config files are used by Paket when converting from NuGet.
#if INTERACTIVE
#r "System.Xml.dll" //for scripts or interactive
#r "System.Xml.Linq.dll" //add reference if using F# as library
#else
module GeneratePaketConfigs
#endif
@Thorium
Thorium / myfile.fsx
Last active August 29, 2015 14:23
One script to create MS-SQL-database and host OWIN Web-server with SignalR-clients
#if INTERACTIVE
open System
open System.IO
Console.WriteLine "Downloading components, etc. Will take a while."
// Run as admin, developer command prompt or F# Interactive. e.g. "fsi myfile.fsx"
[<Literal>]
let connectionString = "Data Source=localhost; Initial Catalog=myDatabase; Integrated Security=True;"
let serverDir = __SOURCE_DIRECTORY__ + @"/frontend"
@Thorium
Thorium / InstallBowerAndGulpMac.sh
Last active December 24, 2016 12:48
Installation script: Bower and Gulp for JavaScript development
#!/bin/bash
# Mac version
# Install Homebrew package manager:
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew update
# Install Node.js and npm
brew install node
npm install -g npm
@Thorium
Thorium / .gitignore
Last active August 29, 2015 14:24
How to use Paket also in JavaScript references: How to get Bower-components without npm and Node.js
lib/
paket-files/
[Pp]ackages/
@Thorium
Thorium / Dockerfile
Last active August 29, 2015 14:24 — forked from junosuarez/Dockerfile
Dockerfile to start F# Owin project
FROM ubuntu:14.04
RUN apt-get -y update
# Install Mono (and fsharp)
RUN apt-get -y install mono-devel autoconf pkg-config make git libtool
RUN git clone https://github.com/fsharp/fsharp
RUN cd fsharp && ./autogen.sh --prefix /usr && make && make install
# Add some files
@Thorium
Thorium / Program.fs
Created July 16, 2015 13:29
Simple CRUD -application. What you will need: 1) a Mac, Windows or Linux computer with FSharp (F#) installed. 2) MariaDB or MySQL installed. 3) Paket package manager. Run "paket.exe install" or "mono paket.exe install". 4) If on Mono, you have to add Program.fs to a project to compile it (or SignalR won't work).
// In MONO, won't work in interactive, you need to make a project and compile a dll.
#if INTERACTIVE
#r @"./packages/FSharp.Data/lib/net40/FSharp.Data.dll"
#r @"./packages/SQLProvider/lib/net40/FSharp.Data.SqlProvider.dll"
// OWIN and SignalR-packages:
#I @"./packages/Microsoft.AspNet.SignalR.Core/lib/net45"
#r @"./packages/Microsoft.AspNet.SignalR.Core/lib/net45/Microsoft.AspNet.SignalR.Core.dll"
#I @"./packages/Microsoft.Owin/lib/net45"