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
@tugberkugurlu
tugberkugurlu / gist:6375703
Created August 29, 2013 08:47
Read a file from a FileStream and get the bytes. Pass the bytes to a new method and try to read it there with the right encoding.
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace StreamReadWrite
{
class Program
@tugberkugurlu
tugberkugurlu / gist:6362985
Created August 28, 2013 07:12
Boost your perf magically!!!!! (Disclaimer: NO, IT DOES NOT!!!!!!!!)
public class HomeController : Controller {
public async Task<ActionResult> Index() {
return await Task.FromResult<ActionResult>(View());
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
namespace CheckIfDebugOrRelease
{
class Program
{
@tugberkugurlu
tugberkugurlu / program.cs
Created July 3, 2013 10:57
Using SemaphoreSlim for async locking scenarios.
private static readonly SemaphoreSlim __questionCloseLock = new SemaphoreSlim(initialCount: 1);
public async Task<OperationResult<QuestionCloseRecord>> CloseQuestionAsync(int questionId, QuestionCloseType closeType)
{
try
{
await __questionCloseLock.WaitAsync().ConfigureAwait(false);
Question question = await GetQuestionAsync(questionId).ConfigureAwait(false);
if (question == null || question.CloseRecord != null)
@tugberkugurlu
tugberkugurlu / program.cs
Created July 3, 2013 09:50
This sample demonstrates the in-memory hosting of an ASP.NET Web API application.
using System;
using System.Net.Http;
using System.Threading.Tasks;
using System.Web.Http;
namespace WebApiInMemoryHost
{
class Program
{
static void Main(string[] args)
internal sealed class Configuration : DbMigrationsConfiguration<SpatialDemo.Models.SpatialDemoContext>
{
public Configuration()
{
AutomaticMigrationsEnabled = true;
}
protected override void Seed(SpatialDemo.Models.SpatialDemoContext context)
{
context.Locations.AddOrUpdate((x) => x.Name,
class Program
{
static void Main(string[] args)
{
Profile("i++", () =>
{
for (int i = 0; i < int.MaxValue; i++)
{
double foo = Math.Round(Math.Sqrt(3.4F) * 7823278.9F, 2);
}
Set-ExecutionPolicy RemoteSigned
$mongoDbPath = "C:\MongoDB"
$mongoDbConfigPath = "$mongoDbPath\mongod.cfg"
$url = "http://downloads.mongodb.org/win32/mongodb-win32-x86_64-2008plus-2.2.3.zip"
$zipFile = "$mongoDbPath\mongo.zip"
$unzippedFolderContent ="$mongoDbPath\mongodb-win32-x86_64-2008plus-2.2.3"
if ((Test-Path -path $mongoDbPath) -eq $True)
{
@tugberkugurlu
tugberkugurlu / foo.js
Created March 3, 2013 22:40
jQuery Validate for Ajax Requests
// These are jQuery fns.
(function ($) {
$.fn.removeMVCValidationSummary = function (settings) {
var form = $(this),
container = form.find("[data-valmsg-summary=true]"),
list = container.find("ul");
container.removeClass("validation-summary-errors").addClass("validation-summary-valid");
@tugberkugurlu
tugberkugurlu / program.cs
Created March 1, 2013 19:18
IsAssignableFrom
class Program {
static void Main(string[] args) {
var type = typeof(Foo);
var isIFoo = typeof(IFoo).IsAssignableFrom(type);
}
}
public interface IFoo {