Roel van Lisdonk on May 26th, 2015

 

If you want to use the font awesome icons directly in your HTML, you can use the font awesome cheatsheet:

http://fortawesome.github.io/Font-Awesome/cheatsheet/

Roel van Lisdonk on May 22nd, 2015

This post describes in 3 examples, how you can create a triangle with pure CSS and HTML.

 

clip_image001[4]

 

HTML
<br />
Example 1
<br />
<br />
<div class="example1"></div>

<br />
Example 2
<br />
<br />
<div class="example2"></div>

<br />
Example 3
<br />
<br />
<div class="example3"></div>

CSS
.example1 {
    height: 40px;
    width: 40px;
    border-left: 10px solid blue;
    border-right: 10px solid blue;
    border-bottom: 10px solid #000000;
    border-top: 10px solid #000000;
}

.example2 {
    height: 20px;
    width: 20px;
    border-left: 10px solid blue;
    border-right: 10px solid blue;
    border-bottom: 10px solid #000000;
    border-top: 10px solid #000000;
}

.example3 {
    width: 0;
    height: 0;
    border-left: 5px solid transparent;
    border-right: 5px solid transparent;
    border-bottom: 5px solid #2f2f2f;
}

Tags: ,

Roel van Lisdonk on May 20th, 2015

If you are running an IIS server and you want to capture HTTP traffic send from remote clients, you can add a custom rule in Fiddler.

 

Before you create the custom rule make sure port 8888 is open in de Windows firewall.

Just add an new inbound firewall rule:

 

Open Windows Firewall:

image

 

Click on “Advanced settings”:

image

 

Click on “Inbound Rules” > “New Rule…”:

image

 

Assume your computer has an ip4 address:

 

image

 

Click on “Port”:

 

image

 

Enter “8888” in the “Specific local ports” textbox:

 

image

image

 

image

 

Enter “Port 8888” in the “Name” textbox and click Finish:

image

 

 

Now we are ready to add a custom rule to Fiddler:

image

 

Assuming the ip4 address of the IIS machine = “10.2.200.20” and de site you want to debug run in IIS under port 80, then:

 

In the “OnBeforeRequest” function add:

if (oSession.host.toLowerCase() == "10.2.200.20:8888") oSession.host = "10.2.200.20:80";

 

image

 

Restart fiddler and when you access the website from an other machine by using the 10.2.200.20:8888 address, fiddler should capture the traffic and pass is to the website running on port 80.

Tags:

 

Note

When you want to run / edit / debug PowerShell scripts inside Visual Studio 2013 / 2015 you will have to install the “PowerShell Tools for Visual Studio” Visual Studio extension found at: https://visualstudiogallery.msdn.microsoft.com/c9eb3ba8-0c59-4944-9a62-6eee37294597

 

I wanted to run and debug a PowerShell script inside Visual Studio 2013 / 2015, on a machine that only had SQL Server 2014 installed as database server. This threw an exception: The term ‘Invoke-Sqlcmd’ is not recognized as the name of a cmdlet http://blog.sqlauthority.com/2014/11/23/sql-server-fix-the-term-invoke-sqlcmd-is-not-recognized-as-the-name-of-a-cmdlet/

 

Turns out you have to update the PowerShell “PSModulePath”, so it can find the PowerShell modules containing the SQL Server 2014 cmdlets.

 

Temp fix:

http://stackoverflow.com/questions/29562742/invoke-sqlcmd-failing-after-automated-sql-install-with-powershell

Existing Powershell session isn’t aware about Sql’s modules that were just installed. Take a look at environment variable $env:PSModulePath. Compare new shell’s variable to existing and you should see a missing path like …\Microsoft SQL Server\110\Tools\PowerShell\Modules\.
For a work-around, modify the path to include module dir. Like so,

$env:PSModulePath += ";C:\Program Files (x86)\Microsoft SQL Server\120\Tools\PowerShell\Modules"

 

If you want to persist this extra “Module load path”, you have to change the registry:

http://tomtalks.uk/2013/06/powershell-add-a-persistent-module-path-to-envpsmodulepath/

 

image

 

Now I can run and debug the following PowerShell script inside Visual Studio 2013 / 2015:

# This sccript requires the system to allow running powershell scripts, when not allowed the following code can be used to allow running powershell scripts.
# Set-ExecutionPolicy RemoteSigned

# The following import statement enables the SQL Server PowerShell cmdlets, like "Invoke-Sqlcmd".
Import-Module SqlPs

$serverInstance = "(localdb)\v11.0"
$database = "App"


function ExecuteSqlFile {
    [string]$file = $args[0]
    Invoke-Sqlcmd -ServerInstance $serverInstance -Database $database -InputFile $file
}

ExecuteSqlFile('C:\Temp\test.sql')

Tags: , ,

 

# Add table names to the "$tables" array in the order they should be created.
$tables = @(
    "dbo.Person",
    "dbo.Settings",
    "dbo.SmsStatus",
    "dbo.Sms"
)

# Create a table if it does not exist.
# It expects the "create scripts" to be located in a subfolder "Tables".
function CreateTable
{
    [string]$table = $args[0]
    [string]$file = "{0}\Tables\{1}.sql" -f $PSScriptRoot, $table
    Echo("create table {0}" -f $table) 
    Invoke-Sqlcmd -ServerInstance "(localdb)\v11.0" -Database "MyDatabase" -InputFile $file
}

# Drop a table if it exists.
function DropTable
{
    [string]$table = $args[0]
    [string]$query = "if object_id('{0}') is not null begin drop table {0} end" -f $table
    Echo("drop table {0}" -f $table) 
    Invoke-Sqlcmd -ServerInstance "(localdb)\v11.0" -Database "MyDatabase" -Query $query
}

function DropTables
{
    $reverseTable = $tables.Clone()
    [array]::Reverse($reverseTable)
    foreach ($table in $reverseTable) {
       DropTable $table
    }    
}

function CreateTables {
    foreach ($table in $tables) {
       CreateTable $table
    }
}

DropTables
CreateTables

Will drop all tables in $tables if they exist and then will create all tables in $tables if they do not exist.

Tags:

If you want to format a string when echoing to the screen, use parentheses.

Echo("This is {0} " -f "a test.")

 

Will output:

This is a test.

 

Note

http://stackoverflow.com/questions/17623644/what-is-the-difference-between-echo-and-write-host-in-powershell

echo is an alias for Write-Output, which writes to the Success output stream. This allows output to be processed through pipelines or redirected into files. Write-Host writes directly to the console, so the output can’t be redirected/processed any further.

Tags:

 

If you want to add a “named” default and a “named” unique constraint to one column, when creating a table with T-SQL, you can use the “inline syntax”:

 

Here we create a table with a column “Code”, that has a “named” default and a “named” unique constraint:

if object_id('dbo.Product') is null
begin
    create table dbo.Product
    (
        Id int identity(1,1) not null constraint PK_dbo_Product_Id primary key,
        Code uniqueidentifier not null constraint UQ_dbo_Product_Code unique(Code)
                                       constraint DF_dbo_Product_Code default newid()
    )
end
go

Tags:

Roel van Lisdonk on April 29th, 2015

I had some input type=”text” html elements inside a kendo sortable. These textboxes couldn’t get focus, I was unable to type in the textbox, due to the fact it was inside a “draggable” element.

(first I thought it was the css property “user-select”, but that was not the case).

 

The fix is documented on the kendo api site:

http://docs.telerik.com/kendo-ui/web/sortable/overview#sortable-widget-with-focus-able-input-elements

 

image

Tags: ,

Roel van Lisdonk on April 10th, 2015

I used the following code to send a free SMS from C#, by using the messagebird REST service.

 

using System;
using System.Net.Http;
using System.Net.Http.Headers;
using System.Threading.Tasks;

namespace DocumentenService.Client
{
public class Program
{
public static void Main(string[] args)
{
    SendSms().Wait();

    // Wait for the user to close this application.
    Console.WriteLine("Press enter to close this application.");
    string result = Console.ReadLine();
}

/// <summary>
/// Send a sms
/// </summary>
/// <returns></returns>
public static async Task SendSms()
{
    using (var client = new HttpClient())
    {
        client.BaseAddress = new Uri("https://rest.messagebird.com/");
        client.DefaultRequestHeaders.Accept.Clear();
        client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
        client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("AccessKey", "live_...");
        var message = new SmsMessage
        {
            body = "SMS send from C#, greetings Roel.",
            originator = 31611111111, // Sender
            recipients = new long[] { 31622222222 } // Receivers
        };

        HttpResponseMessage response = await client.PostAsJsonAsync("messages", message);
        if (response.IsSuccessStatusCode)
        {
            Console.WriteLine("succes!");
        }
    }
}
}

public class SmsMessage
{
/// <summary>
/// Example: This is a test message.
/// </summary>
public string body { get; set; }
/// <summary>
/// Example: 31611111111
/// </summary>
public long originator { get; set; }
/// <summary>
/// Example: new long[] { 31622222222 } 
/// </summary>
public long[] recipients { get; set; }
}
}

Tags:

The following link exactly describes, how I create my Angular v1.3 directives:

http://kwilson.me.uk/blog/writing-cleaner-angularjs-with-typescript-and-controlleras/

Tags: ,