Skip to content

Instantly share code, notes, and snippets.

@h09shais
h09shais / ExcelPackageExtension.cs
Created January 11, 2023 13:05
EPPlus ExcelPackage to Html table
public static class ExcelPackageExtension
{
internal static byte[] HtmlBytes(this ExcelPackage package)
{
string html = string.Empty;
string headerHtml = string.Empty;
string footerHtml = string.Empty;
string theadHtml = string.Empty;
const string header = "{{header}}";
@h09shais
h09shais / Download.cs
Created February 23, 2021 17:27
HttpResponseMessage download file and zip
private static HttpResponseMessage HttpReport(byte[] bytes, string fileName)
{
HttpResponseMessage httpResponseMessage;
using (var stream = new MemoryStream(bytes))
{
httpResponseMessage = new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ByteArrayContent(stream.ToArray())
};
@h09shais
h09shais / CorsHandler.cs
Created November 6, 2020 10:33 — forked from Kashkovsky/CorsHandler.cs
CORS delegating handler for Web API
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
//Add to Global.asax -- GlobalConfiguration.Configuration.MessageHandlers.Add(new CorsHandler());
namespace Common.Helpers
{
public class CorsHandler : DelegatingHandler
@h09shais
h09shais / proxy.ashx
Created November 4, 2020 12:12 — forked from kai5263499/proxy.ashx
A simple proxy in C# which persists the entire request to the target
<%@ WebHandler Language="C#" CodeBehind="proxy.ashx.cs" Class="PIPE.Host.proxy" %>
@h09shais
h09shais / JS-LINQ.js
Created June 16, 2020 12:03 — forked from DanDiplo/JS-LINQ.js
JavaScript equivalents of some common C# LINQ methods. To help me remember!
// JS array equivalents to C# LINQ methods - by Dan B.
// Here's a simple array of "person" objects
var people = [
{ name: "John", age: 20 },
{ name: "Mary", age: 35 },
{ name: "Arthur", age: 78 },
{ name: "Mike", age: 27 },
{ name: "Judy", age: 42 },
{ name: "Tim", age: 8 }
@h09shais
h09shais / FileSystemCache.cs
Created February 26, 2020 08:44 — forked from kocubinski/FileSystemCache.cs
A simple write-invalidated cache for JSON on the file system.
public interface ICache<out T>
{
T Get(string key);
}
public class CacheObject<T>
{
public T Value { get; set; }
public DateTime CachedDate { get; set; }
@h09shais
h09shais / Note.md
Created October 8, 2019 12:01
Tip to avoid dirty commits

Tip to avoid "dirty commits" When you create a new branch, instead of doing

git checkout develop
git checkout -b [branch-name]

do

git checkout -b [branch-name] origin/develop
@h09shais
h09shais / Extract-TarGz.ps1
Last active September 16, 2019 11:47 — forked from jermdavis/Extract-TarGz.ps1
A PowerShell script that can extract .tar.gz files on Windows - with minimal dependencies to make it easy to use on servers.
[cmdletbinding(SupportsShouldProcess=$True)]
param(
# What .tar.gz file should be extracted? Must exist.
[Parameter(Mandatory=$True)]
[string]$FileToExtract,
# What folder should the files be extracted into? Does not need to exist
[Parameter(Mandatory=$True)]
[string]$TargetFolder,
@h09shais
h09shais / map.js
Created June 21, 2019 13:44
JavaScript map fun
[1, 2, 3].map(x => x + 1)
> (3) [2, 3, 4]
const add = (x) => x + 1;
const substract = (x) => x - 1;
function mapArray(values, func) { return values.map(func); }
mapArray([1, 2, 3], add)
> (3) [2, 3, 4]
@h09shais
h09shais / function.js
Created June 19, 2019 15:34
Higher order function
const add = (x, y) => x + y
add(1,3)
const createAdder = (a) => (b) => add(a, b) // Higher order function
const add2 = createAdder(3)
add2(1)