Skip to content

Instantly share code, notes, and snippets.

@MartinBodocky
MartinBodocky / gist:7d366c7d3834bdd0e396
Created September 29, 2014 13:14
Play with async calls
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
namespace AsyncTest
{
@MartinBodocky
MartinBodocky / bn.fs
Created July 22, 2014 15:57
Binomial Distribution
(* http://www.fssnip.net/nu *)
(* Factorial function *)
let rec (!!) x =
if x = 1 || x = 0 then 1
else x * !! (x-1)
(* Choose function *)
let (+?) (n:int) (x:int) =
!!n / (!!x * !!(n - x))
@MartinBodocky
MartinBodocky / RProviderPlay.fs
Last active August 29, 2015 14:03
RProvider with Fslab nuget package!
(*
BEFORE you start to play you need to add
Fslab to your project by nuget package manager
*)
#nowarn "211" // Ignore warning that a search path does not exist on #I
#I "../packages/FSharp.Data.2.0.9/lib/net40/"
#r "FSharp.Data.dll"
#I "../../bin/"
@MartinBodocky
MartinBodocky / pandas.py
Last active August 29, 2015 14:00
Learning about Python library Pandas
__author__ = 'martinbodocky'
from pandas import Series, DataFrame
import pandas as pd
import numpy as np
obj = Series([4, -7, 5, 3])
obj.values
obj.index
@MartinBodocky
MartinBodocky / LinearRegression.py
Created April 25, 2014 00:53
First linear regression in Python
__author__ = 'martinbodocky'
from numpy import *
import matplotlib.pyplot as plt
import csv
def loadDataSet(filename):
"""Load CSV comma formatted file without header,
which contains features values and target value in last column
@MartinBodocky
MartinBodocky / gist:11124032
Created April 20, 2014 20:12
Doing Data Science Chap2 Exercise
#doing data science chapter 2
setwd("~/GitHub/doing_data_science/dds_datasets")
#read dataset to memory
data <- read.csv("dds_ch2_nyt/nyt1.csv")
#categorize
head(data)
dim(data)
data$agecat <- cut(data$Age, c(-Inf,0,18,24,34,44,54,64,Inf))
@MartinBodocky
MartinBodocky / simpleKNN
Created April 14, 2014 23:49
Simple KNN
let distance v1 v2 =
Array.zip v1 v2
|> Array.fold (fun sum e -> sum + pown (fst e - snd e) 2) 0.0
|> sqrt
let classify subject dataSet labels k =
dataSet
|> Array.map (fun row -> distance row subject)
|> Array.zip labels
|> Array.sortBy snd
@MartinBodocky
MartinBodocky / asyncParallel
Last active August 29, 2015 13:58
Asynchronous and Parallel Programming in F#
// Creating new threads
open System
open System.Threading
//What will execute on each thread
let threadBody() =
for i in 1..5 do
//Wait 1/10 of a second
Thread.Sleep(100)
printfn "[Thread %d] %d ..."
//Mutable record types
open System
type MutableCar =
{
Make : string
Model : string
mutable Miles : int
}
let driveForAReason (car : MutableCar) : unit =
let snacks = ("Soda", "Cookies", "Candy")
let x, y, z = snacks
let tens = [0 .. 10 ..50]
let countDown = [5L .. -1L .. -5L]
let x2 =
[ let negate x = -x
for i in 1 .. 10 do
if i % 2 = 0 then