Skip to content

Instantly share code, notes, and snippets.

View tugberkugurlu's full-sized avatar
:shipit:
💥 shakalaka

Tugberk Ugurlu tugberkugurlu

:shipit:
💥 shakalaka
View GitHub Profile
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
namespace ConsoleApplication1 {
# to install a package right from GitHub
# this will install the package under the {current_path}/node_modules/{package_name}/
npm install https://github.com/windowsazure/azure-sdk-tools-xplat/tarball/dev
# if you wanna install a global package, use the -g switch
# This will put the package under %appdata%\npm\ and it'll also put
# directly invokable cmd and sh (I assue it is sh file. It has no extension) files.
# For example, for azure, it'll create the azure and azure.cmd files under %appdata%\npm\.
# As the %appdata%\npm\ is under my path, we can just do: azure.
# However, this only happens for azure AFA I can see. this may be enabled by a "after install"
public class UserHostAddressSetterHandler : DelegatingHandler {
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) {
request.Properties[ApiCommonRequestKeys.UserHostAddressKey] = request.GetUserHostAddress();
return base.SendAsync(request, cancellationToken);
}
}
internal static class HttpRequestMessageExtensions {
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
<packageSources>
<add key="LocalRepositoryName" value="c:\dev\nuget" />
</packageSources>
</configuration>
public virtual async Task DeleteAsync(Guid id) {
var obj = await _service.GetByIdAsync(id);
if (!_authorization.IsCurrentUserAllowedToDelete(obj)) {
throw new UnauthorizedAccessException(Exceptions.IdentityNotMapped);
}
await _service.DeleteAsync(id);
}
<appSettings>
<add key="aspnet:UseHostHeaderForRequestUrl" value="true"/>
</appSettings>
@tugberkugurlu
tugberkugurlu / define3rdPartyModules.js
Last active December 11, 2015 04:59
define3rdPartyModules requirejs
(function () {
var root = this;
define3rdPartyModules();
function define3rdPartyModules() {
// These are already loaded via bundles.
// We define them and put them in the root object.
define('jquery', [], function () { return root.jQuery; });
@tugberkugurlu
tugberkugurlu / HttpApiLogRecords_queries.sql
Last active December 11, 2015 01:08
Select the first and last log records for a request (Group by CorrelationId)
-- http://stackoverflow.com/questions/3800551/sql-select-first-row-in-each-group-by-group
-- http://dbaspot.com/sqlserver-programming/363437-union-two-ctes-together.html
-- http://stackoverflow.com/questions/354224/combining-union-all-and-order-by-in-firebird
WITH FirstLogs AS (
SELECT
l.[CorrelationId],
l.[Timestamp],
ROW_NUMBER() OVER(PARTITION BY l.[CorrelationId] ORDER BY l.[Timestamp] ASC) AS rk
FROM [DependencyScopeTracingDisposeBug.Models.Entities.WebApiTracerContext].[dbo].[HttpApiLogRecords] l
),
[EditorBrowsable(EditorBrowsableState.Never)]
internal static class HttpResponseMessageExtensions {
internal static async Task<HttpApiResponseMessage<TEntity>> GetHttpApiResponseAsync<TEntity>(this Task<HttpResponseMessage> responseTask) {
HttpResponseMessage response = await responseTask.ConfigureAwait(false);
HttpApiResponseMessage<TEntity> apiResponse = await response.GetHttpApiResponseAsync<TEntity>().ConfigureAwait(false);
return apiResponse;
}
using Newtonsoft.Json;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Linq;
using System.Linq.Expressions;
using System.Net;