Skip to content

Instantly share code, notes, and snippets.

View cguldogan's full-sized avatar
💭
😼 This is the way

Can GULDOGAN cguldogan

💭
😼 This is the way
View GitHub Profile
@cguldogan
cguldogan / angularget.html
Created February 28, 2016 00:17
Angular Get
<!doctype html>
<html ng-app='myApp'>
<head>
<title>Simple Angular.Js Get Sample Snippet</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0-beta.1/angular.min.js"></script>
<script>
angular.module('myApp', []).controller('myCtrl', function ($scope, $http) {
$scope.hello = {};
$scope.newName = "";
@cguldogan
cguldogan / PreFlightHandler.cs
Created March 9, 2016 09:49
PreFlightHandler for Asp.net Web Api
public class PreFlightHandler : DelegatingHandler
{
protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
if (request.Headers.Contains("Origin"))
{
var origin = request.Headers.GetValues("Origin").ToList()[0];
if (request.Method.Method.Equals("OPTIONS"))
{
@cguldogan
cguldogan / base.cs
Created March 20, 2016 19:02
a generic repository for net entity framework 6 with async operations
using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Linq.Expressions;
using System.Threading.Tasks;
namespace BUSINESS
{
//http://www.itworld.com/article/2700950/development/a-generic-repository-for--net-entity-framework-6-with-async-operations.html
@cguldogan
cguldogan / ExcelOperations.cs
Last active March 29, 2016 13:06
Read Excel in C#
public class ExcelOperations
{
public List<List<string>> Read(string filePath)
{
OleDbConnection conn = new OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0; Data Source = " + filePath + "; Extended Properties = 'Excel 8.0; HDR=NO'");
OleDbCommand cmd = new OleDbCommand("select * from [Sheet1$]", conn);
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
@cguldogan
cguldogan / PrintAllProperties
Created June 7, 2016 06:06
C# Class which returns the properties of an object
public static class PrintAllProperties
{
public static string PropertyList(this object obj)
{
var props = obj.GetType().GetProperties();
var sb = new System.Text.StringBuilder();
foreach (var p in props)
{
sb.AppendLine(p.Name + ": " + p.GetValue(obj, null));
}
@cguldogan
cguldogan / gist:b0f515a9440b52baf1f4d500658ba33d
Created August 16, 2017 15:42
ASP.NET WEB API Camel Case Json Formatter Setting
var jsonFormatter = config.Formatters.OfType<JsonMediaTypeFormatter>().First();
jsonFormatter.SerializerSettings.ContractResolver = new CamelCasePropertyNamesContractResolver();
@cguldogan
cguldogan / AuthorizeIPAddressAttribute.cs
Last active November 7, 2017 17:24
ASP.NET Web API IP ACCESS FILTER
using System;
using System.Configuration;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http.Controllers;
using ActionFilterAttribute = System.Web.Http.Filters.ActionFilterAttribute;
namespace Api.Filters
@cguldogan
cguldogan / SwaggerConfig.cs
Created November 7, 2017 17:29
Hide Swagger in production etc.
public class SwaggerConfig
{
public static void Register()
{
if (System.Configuration.ConfigurationManager.AppSettings["DisableSwagger"].Equals("True"))
{
return;
}
......
@cguldogan
cguldogan / tablepaging
Created November 8, 2017 17:58
Angularjs Table Paging
//Use : http://angular-ui.github.io/bootstrap/
HTML PART
---
....
</table>
<pagination
ng-click="ctrl.showPageUkOnly()"
ng-model="ctrl.currentPageUkOnly"
total-items="ctrl.ukOnlyResults.length"
max-size="ctrl.maxSize"
@cguldogan
cguldogan / b64toBlob.js
Created November 24, 2017 10:28
c# base64 to js Blob convertion
function b64toBlob(b64Data, contentType, sliceSize) {
contentType = contentType || '';
sliceSize = sliceSize || 512;
var byteCharacters = atob(b64Data);
var byteArrays = [];
for (var offset = 0; offset < byteCharacters.length; offset += sliceSize) {
var slice = byteCharacters.slice(offset, offset + sliceSize);