Skip to content

Instantly share code, notes, and snippets.

View kkoziarski's full-sized avatar

Krzysztof Koziarski kkoziarski

View GitHub Profile
@kkoziarski
kkoziarski / replace-yt-http-2-http.js
Created February 9, 2015 15:07
Replace IFrame http://youtube with https://www.youtube IFrame HTTP -> HTTPS bookmarklet.
//#JS #bookmarkelt
(function($) {
$('iframe[src^="http://youtube"],iframe[src^="http://www.youtube"]').each(function(){
var attr = $(this).attr("src");
attr = attr.replace('http', 'https');
$(this).attr("src", attr);
//var a = document.createElement("a");
//a.href = attr;
//a.innerHTML = attr;
//$(this).parent().get(0).appendChild(a);
//Eager loading. When the entity is read, related data is retrieved along with it.
//This typically results in a single join query that retrieves all of the data that's needed.
//You specify eager loading by using the Include method.
//Query: All department rows and all related rows in one query
var departments = db.Departments.Include(d => d.Courses);
foreach (var department in departments)
{
foreach (var course in department.Courses)
private static List<T> ConvertEnumerableToListSafe<T>(IEnumerable<T> enumerable)
{
if (enumerable == null)
{
return Enumerable.Empty<T>().ToList();
}
List<T> resultList = enumerable.ToList();
////if (resultList.Any() == false)
////{
@kkoziarski
kkoziarski / OperationAsync.cs
Created December 4, 2015 07:30
OperationAsync helper method
public async Task<TResult> OperationAsync<TResult>(Func<TResult> operation)
{
return await Task.Run(operation).ConfigureAwait(false);
}
public async Task<object> UsageExample()
{
return await this.OperationAsync(() => new object());
}
@kkoziarski
kkoziarski / bootstrap.ext.less
Last active February 8, 2016 16:14
Generate boostrap grid columns
@import "../Scripts/lib/bootstrap/less/mixins/grid-framework.less";
/*col-sm-w-* is for setting with only without other properties. It uses bootstrap internal mixin*/
.loop-grid-columns(@grid-columns, xs-w, width);
@media (min-width: @screen-sm-min) {
.loop-grid-columns(@grid-columns, sm-w, width);
}
@media (min-width: @screen-md-min) {
<Themes>
<Theme Name="SonOfObsidian R#(krho)" GUID="{31615139-e60b-4d1d-ab8b-1ae07148d94a}">
<Category Name="Autos" GUID="{a7ee6bee-d0aa-4b2f-ad9d-748276a725f6}">
<Color Name="ChangedText">
<Background Type="CT_INVALID" Source="00000000" />
<Foreground Type="CT_RAW" Source="FFF7A1A1" />
</Color>
<Color Name="Plain Text">
<Background Type="CT_INVALID" Source="00000000" />
<Foreground Type="CT_INVALID" Source="00000000" />
git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
@kkoziarski
kkoziarski / CustomValidationBehavior.cs
Last active April 5, 2016 06:33
WCF Behavior Extension - validation on methods invoking
namespace WCFBehaviorExtension
{
using System;
using System.Collections.ObjectModel;
using System.Diagnostics;
using System.ServiceModel;
using System.ServiceModel.Channels;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
@kkoziarski
kkoziarski / CustomValidationBehavior.Implementation.cs
Last active April 5, 2016 06:33
WCF Behavior Extension - validation on methods invoking. Generic (base-implementation) version
namespace WCFBehaviorExtension
{
using System.ServiceModel;
using System.ServiceModel.Description;
using System.ServiceModel.Dispatcher;
using BBR.WebService.Shared.Infrastructure.BehaviorExtensions.Validation;
public sealed class CustomValidationOperationInvoker : CustomValidationOperationInvokerBase
{
@kkoziarski
kkoziarski / post_data.sql
Last active June 18, 2016 13:33
Script.PostDeployment.sql update or insert (MERGE)
MERGE INTO [TABLE_NAME]
USING (VALUES
(1, 'some text', 'some value'),
(2, 'some text', 'some value')
)
AS Source ([ID], [Text], [Value])
ON [TABLE].[ID] = Source.[ID]
-- update matched rows
WHEN MATCHED THEN