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 / objectToJson.cs
Created February 27, 2018 14:49
Object To JSON C#
var myObjectAsJsonStringInCSharp = Newtonsoft.Json.JsonConvert.SerializeObject(myObj);
@cguldogan
cguldogan / downloadBase64BlobFile.js
Created November 24, 2017 10:31
Download base 64 to blob file
function downloadBase64BlobFile(response) {
var blob = b64toBlob(response.data, 'application/vnd.ms-excel');
if (blob != null && navigator.msSaveBlob) {
return navigator.msSaveBlob(blob, response.fileName);
}
var a = $('<a style=\'display: none;\'/>');
var url = window.URL.createObjectURL(new Blob([blob], {
type: 'application/vnd.ms-excel',
@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);
@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 / 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 / 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 / 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 / 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 / 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();