C# Linq Grouping and Distinct

var px = parents.SelectMany(p => p.Childs.Select(c => new {
                        number = c.Number,
                        parent = p
                 })).GroupBy(g => g.number).Distinct().Select(s => s.First())
                .GroupBy(g => g.parent)
                .Select(s => s.First());
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Linq Sample to Join 3 Collections / Tables

void Main()
{
    var members = Members();
    var locations = Locations();
    var planets = Planets();
    var l = members
                .Join(locations,
                      mem => mem.mId,
                      loc => loc.mId,                      
                      (mem, loc) => new { loc, mem })
                 .Join(planets,
                       lm => lm.loc.mId,
                       pla => pla.mId,
                       (lm,pl) => new { pl.Name, lm.loc, lm.mem })   
                  .Select(s => new {
                     s.mem.FullName,
                     s.Name,
                     s.loc.Address                   
                  })
                  .ToList();                   
     l.Dump();
}

public List<Planet> Planets(){
  var x = new List<Planet>(){
     new Planet(){ mId = 1, Name = "Mercury" },
     new Planet(){ mId = 2, Name = "Venus" },
     new Planet(){ mId = 3, Name = "Earth" },
     new Planet(){ mId = 4, Name = "Mars" }
  };
  return x;
}

public List<Location> Locations(){
   var x = new List<Location>(){
      new Location(){ mId = 1, Address = "Busugon" },
      new Location(){ mId = 2, Address = "Tacup" },
      new Location(){ mId = 3, Address = "Kinawahan" },
      new Location(){ mId = 4, Address = "Victoria" },
   };
   return x;
}

public List<Member> Members(){
    var x = new List<Member>(){
       new Member(){ mId = 1, FullName = "Julius", Number = 1 },
       new Member(){ mId = 2, FullName = "Elvira", Number = 2 },
       new Member(){ mId = 3, FullName = "Roberto",  Number = 3 }      
    };
    return x;
}

public class Member {
    public int mId { get; set; }
    public string FullName { get; set; }
    public int Number { get; set; }
}

public class Location {
   public int mId { get; set; }
   public string Address { get;set; }
}

public class Planet {
   public int mId { get; set; }
   public string Name { get; set; }
}
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Ethereum and Blockchain Programming with Solidity

Got a nice read of Ethereum and Blockchain today. Downloaded the Ethereum Wallet and Mist.
Still got a lot of things to read before I can start building applications for this Decentralized Application concept. Got a new Hobby now with blockchain and cryptocurrency. whewww!

Cheers to New Wave and Synthpop!

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

File Upload Get MIME Type using JavaScript

<html>
<body>

    <input type="file" id="upload-files" multiple>
    <script>
    var control = document.getElementById("upload-files");
    control.addEventListener("change", function(event) {      
        var files = control.files;
        for (var i = 0; i < files.length; i++) {
            console.log("Filename: " + files[i].name);
            console.log("Type: " + files[i].type);
            console.log("Size: " + files[i].size + " bytes");
        }
    }, false);
    </script>

</body>
</html>
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Printing Directly from Asp.Net MVC Controller Action to Printer in the Network

public async Task<ActionResult> Generate(string id)
{
     PrintDocument pd = new PrintDocument();
     pd.DefaultPageSettings.Margins.Left = 30;
     pd.DefaultPageSettings.Margins.Top = 10;
     pd.DefaultPageSettings.Margins.Right = 10;
     pd.DefaultPageSettings.Margins.Bottom = 10;
     pd.OriginAtMargins = true;
     pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
     // Set the printer name.
     //pd.PrinterSettings.PrinterName = "\\NS5\hpoffice
     //pd.PrinterSettings.PrinterName = "HP LaserJet 200 color M251 PCL6 Class Driver";
     pd.PrinterSettings.PrinterName = "EPSON LX-310";
     pd.Print();

     return RedirectToAction("Index", "Payslip", new { area = "Accounting", id = "", code = 801 });
}

void pd_PrintPage(object sender, PrintPageEventArgs ev)
{
     Font printFont = new Font("3 of 9 Barcode", 18);
     Font printFont1 = new Font("Times New Roman", 11, FontStyle.Bold);
     SolidBrush br = new SolidBrush(Color.Black);
     ev.Graphics.DrawString("hello", printFont, br, 10, 65);
     ev.Graphics.DrawString("world", printFont1, br, 10, 85);
}
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

LAMP DB Backup from Command Line Tips

  mysqldump --databases database_one database_two > two_databases.sql
 
  scp your_username@remotehost.edu:foobar.txt /local/dir
  scp -i key_file.pem your_username@remotehost.edu:/remote/dir/foobar.txt /local/dir

  some git tips
  git push https://[username]@github.com/repo.git origin [branchhere]
  git clone -b [branchhere] --single-branch https://github.com/repo.git
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

Adding Custom Hook on Contact Form 7

How to add Custom Hook on Contact Form 7

/*
    Prevent the email sending step for specific form
*/

add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");  
function wpcf7_do_something_else($cf7) {
    // get the contact form object
    $wpcf = WPCF7_ContactForm::get_current();

    // if you wanna check the ID of the Form $wpcf->id  
    $submission = WPCF7_Submission::get_instance();

    $yourname   = $submission->get_posted_data('your-name');    
    $youremail  = $submission->get_posted_data('your-email');


    return $wpcf;
}
It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn

General Steps on setting up SSL in your Website

1. Buy SSL
2. Generate CSR
3. Copy Generated CSR to SSL location setup
4. download crt from ssl location
5. update install crt to hosting server
6. Install SSL

Once SSL in installed. Force make a 301 redirection to all links via .htaccess

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRUle ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

It's only fair to share...Share on FacebookShare on Google+Tweet about this on TwitterShare on LinkedIn