Skip to content

Instantly share code, notes, and snippets.

View chinhvo's full-sized avatar

Chinh Vo Wili chinhvo

View GitHub Profile
@chinhvo
chinhvo / IEnumerableExtension.cs
Created June 15, 2020 11:16 — forked from icedog48/IEnumerableExtension.cs
C# - How to flatten tree via LINQ ?
///http://stackoverflow.com/questions/11830174/how-to-flatten-tree-via-linq
public static IEnumerable<T> Flatten<T>(
this IEnumerable<T> e,
Func<T,IEnumerable<T>> f)
{
return e.SelectMany(c => f(c).Flatten(f)).Concat(e);
}
@chinhvo
chinhvo / index.js
Created June 12, 2020 02:41 — forked from stephanbogner/index.js
Create tree structure from paths array
var paths = [
["Account"],
["Account", "Payment Methods"],
["Account", "Payment Methods", "Credit Card"],
["Account", "Payment Methods", "Paypal"],
["Account", "Emails"],
["Account", "Emails", "Main Email"],
["Account", "Emails", "Backup Email"],
["Account", "Devices"],
["Account", "Devices", "Google Pixel"],
@chinhvo
chinhvo / gist:6a30ffd55a3136d8274f2b99047f4bfc
Created May 30, 2020 12:16 — forked from afreeland/gist:6730973
C#: Create an Expression to use with LINQ
public ActionResult Grid(string FirstName, string LastName)
{
GridHelper.Filters filter = new GridHelper.Filters("FirstName", "LastName");
var _page =(!String.IsNullOrEmpty(HttpContext.Request.QueryString["page"])) ? Convert.ToInt32(HttpContext.Request.QueryString["page"]) : 1;
var _contacts = from c in testDB.Contacts
join ac in testDB.Account_Contact on c.ID equals ac.ContactID
where ac.AccountID == 725
select c;
@chinhvo
chinhvo / number-pad-zero.js
Created May 27, 2020 12:04 — forked from endel/number-pad-zero.js
Simplest way for leading zero padding in JavaScript
Number.prototype.pad = function(size) {
var s = String(this);
while (s.length < (size || 2)) {s = "0" + s;}
return s;
}
(1).pad(3) // => "001"
(10).pad(3) // => "010"
(100).pad(3) // => "100"
@chinhvo
chinhvo / readme.md
Created May 5, 2020 05:01 — forked from JaimeStill/readme.md
FormData Uploads in ASP.NET Core and Angular

Walkthrough Uploading FormData with Angular

For an example application that integrates this process, see my FullstackOverview repo on GitHub. The code in this example is taken directly from this app.

upload-demo

File Upload Component

This component allows you have a custom styled file upload element.

@chinhvo
chinhvo / gist:15515404fc7f253dd0bc54fa88361ae6
Created April 17, 2020 15:37 — forked from robban/gist:328191
Easily add a google map location picker to your form
<!--
Use this snippet to add a google map location chooser to your form
Step 1: Get a google map api key and insert it in the first javascript tag
Step 2: In your html form, create two hidden elements, one for latitude, and one for longitude. Give the elements ids and set the LATITUDE_ELEMENT_ID and LONGITUDE_ELEMENT_ID to the appropriate variables
Done!
-->
@chinhvo
chinhvo / generate_dto.sql
Created April 16, 2020 06:50 — forked from gemyago/generate_dto.sql
TSQL script to generate POCO/DTO from database table
DECLARE @tableName NVARCHAR(MAX), @schemaName NVARCHAR(MAX), @className NVARCHAR(MAX)
--------------- Input arguments ---------------
SET @tableName = 'Incidents'
SET @schemaName = 'dbo'
SET @className = 'IncidentDto'
--------------- Input arguments end -----------
DECLARE tableColumns CURSOR LOCAL FOR
SELECT cols.name, cols.system_type_id, cols.is_nullable FROM sys.columns cols
/*
*ngFor="let c of oneDimArray | sortBy:'asc'"
*ngFor="let c of arrayOfObjects | sortBy:'asc':'propertyName'"
*/
import { Pipe, PipeTransform } from '@angular/core';
import { orderBy } from 'lodash';
@Pipe({ name: 'sortBy' })
export class SortByPipe implements PipeTransform {
@chinhvo
chinhvo / AppendImageExtension.cs
Created April 11, 2020 04:14 — forked from ChuckSavage/AppendImageExtension.cs
C# Is file an image and get its type
// Includes a mini-program for checking and fixing files that have no extension
// Only checks for the most common types
// If you create a better version, please upload it here.
using System;
using System.Collections.Generic;
using System.IO;
namespace AppendJPG
{
@chinhvo
chinhvo / XframeOptionsAttribute.cs
Created February 25, 2020 11:39 — forked from richardszalay/XframeOptionsAttribute.cs
ASP.NET MVC action filter for specifying an X-FRAME-OPTIONS header
/*
Copyright (C) 2013 Richard Szalay
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation
files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy,
modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
Software is furnished to do so.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR