Skip to content

Instantly share code, notes, and snippets.

View sudipto80's full-sized avatar
🎯
Focusing

SUDIPTA MUKHERJEE sudipto80

🎯
Focusing
View GitHub Profile
@sudipto80
sudipto80 / gist:f307ed836b57d9bdce3e
Created October 28, 2014 02:36
Squirrel Example : Iris dataset Aggregation
Table iris = DataAcquisition.LoadCSV(@"iris.csv");
StringBuilder builder = new StringBuilder();
builder.AppendLine("<html>");
builder.AppendLine("<h2>Range</h2>");
builder.AppendLine(iris.Aggregate("Name", AggregationMethod.Range).ToHTMLTable());
builder.AppendLine("<h2>Average</h2>");
builder.AppendLine(iris.Aggregate("Name", AggregationMethod.Average).ToHTMLTable());
@sudipto80
sudipto80 / gist:98f6d3add50e9cfd3900
Created October 28, 2014 02:39
Squirrel Example : Finding Gender Ration in North America
Table births = DataAcquisition.LoadCSV(@"..\..\births.csv");
var splits = births.SplitOn("sex");
var boys = splits["boy"].Aggregate("state").Drop("year");
var girls = splits["girl"].Aggregate("state").Drop("year");
Table combined = new Table();
combined.AddColumn("State", boys["state"]);
combined.AddColumn("Boys", boys["births"]);
@sudipto80
sudipto80 / gist:5c53f9d53c5372cdb4c8
Created October 28, 2014 02:42
Squirrel Example : Live Stock Analytics
//Stock symbols of companies for which you want to run this
string[] symbols = { "AAPL", "GOOG", "MSFT" };
Dictionary<string, Table> stocks = new Dictionary<string, Table>();
string template = @"http://real-chart.finance.yahoo.com/table.csv?s=[Symbol]&d=8&e=4&f=2014&g=d&a=0&b=2&c=1962&ignore=.csv";
foreach (var symb in symbols)
{
WebClient wc = new WebClient();
wc.DownloadFile(template.Replace("[Symbol]", symb), "temp" + symb + ".csv");
stocks.Add(symb, DataAcquisition.LoadCSV("temp" + symb + ".csv").Top(30));
}
#r @"C:\Users\mukhsudi\Documents\GitHub\SquirrelLatest\ConsoleApplication2\bin\Debug\TableAPI.dll"
//type NameAndSex = {Name : string ; Sex : string}
type SurvivalStat = {PClass : string; Died : float; Survived :float}
let titanic = Squirrel.DataAcquisition.LoadCSV(@"C:\titanic.csv")
let classes = titanic.SplitOn("Pclass")
let result = new Squirrel.Table()
let pClasses = [|"1";"2";"3"|]
let persons = pClasses |> Array.map ( fun pClass ->
{
@sudipto80
sudipto80 / gist:84e5280c4eb1bda427b4
Last active September 15, 2015 19:29
Arranging books in your bookshelves
Table books = DataAcquisition.LoadCSV(@"C:\personal\books.csv");
//genre,author,height-genre*author
books.AddColumn("GenreAsNum", books.ValuesOf("Genre"));
books.Transform("GenreAsNum", x => x == "fiction" ? "1" : x == "nonfiction" ?
"2" : x == "philosophy" ?
"3" : x == "science" ?
"4" : x == "tech" ?
"5" :
"-1");
books = books.Transform("Author", x =>
@sudipto80
sudipto80 / gist:5924e76c6570d2d7547c
Created September 15, 2015 19:33
Books per bookshelf
Moon is Down, The Steinbeck fiction 196
Winter of Our Discontent, The Steinbeck fiction 196
Grapes of Wrath, The Steinbeck fiction 196
Great Indian Novel, The Tharoor fiction 198
20000 Leagues Under the Sea Verne fiction 190
Slaughterhouse Five Vonnegut fiction 198
----------
Title Author Genre Height
Final Crisis fiction 257
Crisis on Infinite Earths fiction 258
@sudipto80
sudipto80 / bookOrg.cs
Created September 15, 2015 19:44
Squirrel to organize books
Table books = DataAcquisition.LoadCSV(@"C:\personal\books.csv");
//genre,author,height-genre*author
books.AddColumn("GenreAsNum", books.ValuesOf("Genre"));
books.Transform("GenreAsNum", x => x == "fiction" ? "1" : x == "nonfiction" ?
"2" : x == "philosophy" ?
"3" : x == "science" ?
"4" : x == "tech" ?
"5" :
"-1");
books = books.Transform("Author", x =>
@sudipto80
sudipto80 / lettercombo.cs
Created September 18, 2015 02:52
Generate all case for all letters in a word using LINQ
void Main()
{
string word = "abcd";
List<List<string>> letters = new List<List<string>>();
letters = word.ToCharArray().Select(w => new List<string>(){w.ToString().ToLower(),w.ToString().ToUpper()} ).ToList();
CartesianProduct(letters)
.Select (x => x.Aggregate ((a,b) => a + b))
@sudipto80
sudipto80 / ExtendedEventBeautifier.cs
Last active November 27, 2015 09:17
Making Extended Events Creation SQL Beautiful
void Main()
{
string tsql = @"CREATE EVENT SESSION [CheckMyQuery] ON SERVER
ADD EVENT sqlserver.lock_acquired(SET collect_database_name=(1),collect_resource_description=(1)
ACTION(package0.collect_cpu_cycle_time,sqlos.task_time,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_id,sqlserver.database_name,sqlserver.nt_username,sqlserver.plan_handle,sqlserver.query_hash,sqlserver.server_instance_name,sqlserver.session_id,sqlserver.session_nt_username,sqlserver.sql_text,sqlserver.username)
WHERE ([sqlserver].[equal_i_sql_unicode_string]([database_name],N'MyDB'))),
ADD EVENT sqlserver.lock_released(
ACTION(sqlos.task_time,sqlserver.client_app_name,sqlserver.client_hostname,sqlserver.database_name,sqlserver.nt_username,sqlserver.query_hash,sqlserver.server_instance_name,sqlserver.session_nt_username,sqlserver.sql_text,sqlserver.username)
WHERE ([sqlserver].[database_name]='MyDB')),
ADD EVENT sqlserver.lock_timeout(
@sudipto80
sudipto80 / FizzBuzzBySetTheory.cs
Created December 14, 2015 03:51
FizzBuzz using Set Theory
var range = Enumerable.Range(1,40);
var mod3 = range.Where(e => e % 3 == 0);
var mod5 = range.Where(e => e % 5 == 0);
var mod15 = mod3.Intersect(mod5);
//Find numbers that are divisible by 3 but not by 5 or 15
mod3 = mod3.Except(mod15);
//Find numbers that are divisible by 5 but not by 3 or 15
mod5 = mod5.Except(mod15);
//Find integers that are not divisible by either 3 or 5