Skip to content

Instantly share code, notes, and snippets.

@gazlu
gazlu / AppendChar.cs
Created February 27, 2017 16:51
Append Char before string
string name = "420";
var prefix = "0";
prefix += new string('0', 10 - name.Length - 1);
Console.WriteLine(zeros+name);
Console.WriteLine((zeros+name).Length);
@gazlu
gazlu / ConfigurationTransformer.cs
Last active December 27, 2016 17:35
Configuration File transformer, easy to integrate config transformation with build systems
// You need to install 'Microsoft.Web.Xdt' from nuget ==> Install-Package Microsoft.Web.Xdt
using System;
using System.Reflection;
using Microsoft.Web.XmlTransform;
namespace ConfigTransformer
{
internal class Program
{
private enum ExitCode : int
@gazlu
gazlu / backup-localdb-database.bat
Created December 6, 2016 18:44
Backup SQL Server localdb database with sqlcmd
sqlcmd -E -S "(localdb)\v11.0" -q "BACKUP DATABASE <DBNAME> TO DISK='<DRIVE>:\<FOLDER_PATH>\<BACKUP_FILE_NAME>.bak'"
@gazlu
gazlu / view-large-nvarchar.sql
Created October 27, 2016 23:11
View large Nvarchar to debug in sql server
DECLARE BULKnvarchar nvarchar(max)
SELECT CAST('<data><![CDATA[' + @BULKnvarchar + ']]></data>' as xml)
-- use tools like 'http://coderstoolbox.net/string/#!encoding=xml&action=decode&charset=us_ascii' this
-- to decode the xml inside data element
@gazlu
gazlu / multi-insert-identity.sql
Created October 27, 2016 14:57
Insert multiple records and get the identity value
CREATE TABLE #A (ID int Identity(1,1), fn varchar(10))
DECLARE @output TABLE (id int)
Insert into #A (fn)
OUTPUT inserted.ID INTO @output
values ('1'), ('2'), ('3')
select * from @output
@gazlu
gazlu / extract-photos.bat
Created October 15, 2016 10:11
Extract photos from the Video with VLC
vlc "{video path from which you want to exctract photos}" --video-filter=scene --vout=dummy --start-time=1 --scene-ratio=15 --scene-prefix=VTS_01_4-img- --scene-path="{folder path where you want to exctract photos}" vlc://quit
@gazlu
gazlu / RestSharpImageDownload.cs
Created October 6, 2016 18:20
Download Image or file with RestSharp (Rest Sharp)
RestClient restClient = new RestClient(@"http://ia.media-imdb.com/images/M/MV5BMjM5OTQ1MTY5Nl5BMl5BanBnXkFtZTgwMjM3NzMxODE@._V1_SX300.jpg");
var fileBytes = restClient.DownloadData(new RestRequest("#", Method.GET));
File.WriteAllBytes(Path.Combine(directory, "poster-got.jpg"), fileBytes);
@gazlu
gazlu / XMLWrite.cs
Created September 21, 2016 09:18
Write XML in memory to XmlDocument
XmlWriterSettings setting = new XmlWriterSettings();
setting.ConformanceLevel = ConformanceLevel.Auto;
StringBuilder builder = new StringBuilder();
using (XmlWriter writer = XmlWriter.Create(builder, setting))
{
writer.WriteStartElement("Users");
foreach (var user in users)
{
writer.WriteStartElement("User");
@gazlu
gazlu / react.wrapper.js
Created September 18, 2016 17:17
A wrapper class to access ReactJS components in ES-5 easily, access Router, Route, Link, EventEmitter and Flux.Dispatcher in ES-5
//Include following js files
//"/scripts/react/react.js",
//"/scripts/react/react-dom.js",
//"/scripts/react/ReactRouter.js",
//"/scripts/Flux/Flux.js",
//"/scripts/EventEmitter/EventEmitter.js",
/// <reference path="scripts/react/react.js" />
/// <reference path="scripts/react/react-dom.js" />
/// <reference path="scripts/react/ReactRouter.js" />
@gazlu
gazlu / DynamicBundles.cs
Last active October 20, 2015 10:19
Create dynamic script and css bundles right from your views
//@Html.ScriptsBundle("~/bundles/ng-modules", "~/Scripts/vendor/ng/modules", true)
public static class DynamicBundles
{
public static IHtmlString StylesBundle(this HtmlHelper helper, string virtualPath, params string[] additionalPaths)
{
if (BundleTable.Bundles.GetBundleFor(virtualPath) == null)
{
BundleTable.Bundles.Add(new StyleBundle(virtualPath).Include(additionalPaths));
}
return MvcHtmlString.Create(@"<link href=""" + HttpUtility.HtmlAttributeEncode(BundleTable.Bundles.ResolveBundleUrl(virtualPath)) + @""" rel=""stylesheet""/>");