Thursday, 3 October 2013

Performing a union in LINQ

Performing a union in LINQ

I'm trying to get the union of these two queries but keep getting the
following error:
'System.Linq.IQueryable<AnonymousType#1>' does not contain a definition
for 'Union' and the best extension method overload
'System.Linq.ParallelEnumerable.Union<TSource>(System.Linq.ParallelQuery<TSource>,
System.Collections.Generic.IEnumerable<TSource>)' has some invalid
arguments
The linq queries look like this:
var g = from p in context.APP_PROD_COMP_tbl
where p.FAM_MFG == fam_mfg
group p by new
{
a_B_G = p.B_G,
a_MFG = p.MFG,
a_PRODUCT_FAM = p.PRODUCT_FAM,
};
var q = from p in context.APP_COMP_tbl
where p.FAM_MFG == fam_mfg
group p by new
{
a_B_G = p.a_B_G,
a_MFG = p.a_MFG,
a_PRODUCT_FAM = p.a_PRODUCT_FAM,
};
var data = q.Union(g);
I've tried using IEnumerable around the queries, but it still didn't work.
Not really sure where I'm going wrong at this point, although admittedly
LINQ isn't something I've had a ton of exposure to.

Wednesday, 2 October 2013

div show / hide horizontal

div show / hide horizontal

i used below source code for show / hide div, how to move horizontal.
demo link: http://papermashup.com/demos/jquery-show-hide-plugin/
(function ($) { $.fn.showHide = function (options) {
//default vars for the plugin
var defaults = {
speed: 1000,
easing: '',
changeText: 0,
showText: 'Show',
hideText: 'Hide'
};
var options = $.extend(defaults, options);
$(this).click(function () {
$('.toggleDiv').slideUp(options.speed, options.easing);
// this var stores which button you've clicked
var toggleClick = $(this);
// this reads the rel attribute of the button to determine which
div id to toggle
var toggleDiv = $(this).attr('rel');
// here we toggle show/hide the correct div at the right speed
and using which easing effect
$(toggleDiv).slideToggle(options.speed, options.easing, function() {
// this only fires once the animation is completed
if(options.changeText==1){
$(toggleDiv).is(":visible") ? toggleClick.text(options.hideText)
: toggleClick.text(options.showText);
}
});
return false;
});
};
})(jQuery);

TaglibSharp doesn't do anything

TaglibSharp doesn't do anything

I have a method to replace something in name of the music's artist id3
tag. I'm using taglibSharp and this is my code:
public static void TagArtistRename(this FileInfo file, string from, string
to, bool UseRegex = true)
{
TagLib.File f = TagLib.File.Create(file.FullName);
for (int i = 0; i < f.Tag.Performers.Count(); i++)
{
if (UseRegex)
{
f.Tag.Performers[i] = Regex.Replace(f.Tag.Performers[i], from,
to);
}
else
{
f.Tag.Performers[i] = f.Tag.Performers[i].Replace(from, to);
}
}
f.Save();
}
and here I call my code:
static void Main(string[] args)
{
string file = Console.ReadLine();
file = file.Replace("\"", "");
new FileInfo(file).TagArtistRename(" (www.Downloadha.com)", "", false);
TagLib.File f = TagLib.File.Create(file);
foreach (var item in f.Tag.Performers)
{
Console.WriteLine(item);
}
Console.ReadLine();
}
the code runs without any exceptions but in console, it'll write the old
artists names and also the file's metadata doesn't change.

Open a new browser for a copied spreadsheet

Open a new browser for a copied spreadsheet

I need to open a new browser after I copied my original spreadsheet, and
add the copied spreadsheet to the new browser, so user can edit the copied
spreadsheet and download or email their edits. I'm able to do the copy
part but not the new browser part
Thanks

Why does new Date() and Date.parse treat ISO-8601 strings different?

Why does new Date() and Date.parse treat ISO-8601 strings different?

I have this test date 2013-09-15T11:09:00 Depending on if I use Date.parse
and new Date the outcome will be different, but the UTC is same
Date.parse("2013-09-15T11:09:00")
Sun Sep 15 2013 11:09:00 GMT+0200 (W. Europe Daylight Time)
new Date("2013-09-15T11:09:00");
Sun Sep 15 2013 13:09:00 GMT+0200 (W. Europe Daylight Time)
If i add UTC both output same time and same UTC, a bug in Emacs standard? :D
new Date("2013-09-15T11:09:00+02:00");
Sun Sep 15 2013 11:09:00 GMT+0200 (W. Europe Daylight Time)
Date.parse("2013-09-15T11:09:00+02:00");
Sun Sep 15 2013 11:09:00 GMT+0200 (W. Europe Daylight Time)

Tuesday, 1 October 2013

Prepared statement security while fetching

Prepared statement security while fetching

I just don't get it. How is a prepared statement more safe than a
non-prepared statement for fetching data. I am not talking about writing
to the database, only fetching data. I cant see how userFname and
userLname is any more safe than userEmail and userPassword. Thanks in
advance.
$stmt = $mysqli->stmt_init();
if ($stmt->prepare("SELECT userFname, userLname FROM users WHERE
userEmail = ? and userPassword = ?")) {
$stmt->bind_param("ss", $userEmail, $userPassword);
$stmt->execute();
$stmt->bind_result($userFname, $userLname);
while ($stmt->fetch()) {
//Remember first name, last name, and email
$_SESSION['Email']=$userEmail;
$_SESSION['Fname']=$userFname;
$_SESSION['Lname']=$userLname;
$stmt->close();
//go to dashboard page
header ("location: dashboard.php");
}
$error2="Email and Password do not match, please try again.";
}

Algorithm for decision tree in continuous time

Algorithm for decision tree in continuous time

I'm attempting to build a fairly simple AI that has an input of 3 discreet
variables and is trying to predict a discreet output. This seems fairly
simple using an entropy calculation if you have a complete data set to
analyze beforehand. However, the program I am writing will be presented
one piece of data at a time and will have to learn to play a game as the
data is presented (eg. Playing a poker game or Rock Paper Scissors). How
would I be able to construct a tree on the fly as the data is received one
row at a time?
Thank you