Skip to content

Instantly share code, notes, and snippets.

@sudipto80
sudipto80 / CreateModelFromCSV.cs
Created Jan 25, 2020
Code to create ModelInput from CSV
View CreateModelFromCSV.cs
void Main()
{
string csvFile = @"C:\MLDOTNET\iris.csv";
var columns = File.ReadLines(csvFile)
.Take(1)
.First()
.Split(new char[] { ',' });
var firstLine = File.ReadLines(csvFile)
.Skip(1)
.Take(1)
@sudipto80
sudipto80 / avoidBoxing.linq
Created Jun 20, 2016
Finding Boxing calls using Roslyn
View avoidBoxing.linq
//Avoid Boxing
var code = @"public void fun(){int x = 32;
object o = x;}";
var tree = CSharpSyntaxTree.ParseText(code);
//x - Int
@sudipto80
sudipto80 / sentiment.fs
Created Jan 22, 2016
Sentiment Analysis
View sentiment.fs
open System.Text.RegularExpressions
type SentiWordNetEntry = {POS:string; ID:string; PositiveScore:string; NegativeScore:string; Words:string}
let sentiWordList = System.IO.File.ReadAllLines(@"SentiWordNet_3.0.0_20130122.txt")
|> Array.filter (fun line -> not (line.StartsWith("#")))
|> Array.map (fun line -> line.Split '\t')
|> Array.map (fun lineTokens -> {POS = lineTokens.[0];
ID = lineTokens.[1];
PositiveScore = lineTokens.[2].Trim();
View ifExpr.kt
package hello
fun main() {
var x = 11
var y = if (x > 10) { println("Hey!"); ":Kotlin"} else
{
println("NO!")
"OUCH!"
}
println(y)
View intersectMany.kt
package hello
fun main() {
var xs = listOf(listOf(1,2,3),
listOf(1,5,6,2),
listOf(7,8,2,11,1))
var result = xs[0]
for(i in 1 .. xs.size - 1)
{
result = result.intersect(xs[i]).toList()
View CollaborativeFiltering.fs
// Learn more about F# at http://fsharp.org
// See the 'F# Tutorial' project for more help.
//Comprehensive coverage of Collaborative Filtering Techniques
//http://www.hindawi.com/journals/aai/2009/421425/
module confusion =
let TP (matches : int [] []) =
matches |> Array.mapi( fun i j -> matches.[i].[i]) |> Array.sum
View Cartesian.cs
void Main()
{
Cartesian<string>(new List<List<string>>()
{
new List<string>() { "A", "B" },
new List<string>() { "C", "D", "E" }
}).Dump();
}
public static List<List<T>> Cartesian<T>(List<List<T>> sets)
View Calculating average rainfall
let rainfall = [[1.17;0.78];[1.24;3.22];[1.277;1.4]]
let months = [|"January";"February"|]
let rainfalStats = [ 0 .. months.Length - 1]
|> List.map
(
fun index ->
(
months.[index],
rainfall |> List.map (fun row -> List.nth row index)
View UniquePrefix.cs
string[] words = new string[]
{"zebra","beard","duck","zest", "ducklin", "bearcat","dumb","beautiful","zebracrossing"};
//{ "zebra", "dog", "duck", "zimbawae", "zest","god","dove", "dig","got","dumb"};
Array.Sort(words);
Func<string, string, int> DiffersAt = (a, b) =>
{
int m = a.Length;
int n = b.Length;
@sudipto80
sudipto80 / LongestSeq.cs
Created Jun 25, 2016
Longest Continuous Sequence
View LongestSeq.cs
string[] words = new string[]
{"zebra","beard","duck","zest", "ducklin", "bearcat","dumb","beautiful","zebracrossing"};
//{ "zebra", "dog", "duck", "zimbawae", "zest","god","dove", "dig","got","dumb"};
Array.Sort(words);
Func<string, string, int> DiffersAt = (a, b) =>
{
int m = a.Length;
int n = b.Length;