Skip to content

Instantly share code, notes, and snippets.

View shammelburg's full-sized avatar

Sander Hammelburg shammelburg

View GitHub Profile
@shammelburg
shammelburg / angular-url-rewrite.txt
Last active April 2, 2024 10:14
Angular URL Rewrite for web.config
<system.webServer>
<rewrite>
<rules>
<rule name="AngularJS Routes" stopProcessing="true">
<match url=".*" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
<add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
</conditions>
@shammelburg
shammelburg / encrypt-decrypt-web.config.txt
Last active November 26, 2015 16:02
Encrypt / Decrypt web.config
On the server locate folder
a. C:\Windows\Microsoft.NET\Framework64\v4.0.30319
b. Check "aspnet_regiis.exe" exists
Run cmd
a. cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319
To Encrypt:
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis –pef "connectionStrings" "path"
C:\Windows\Microsoft.NET\Framework64\v4.0.30319>aspnet_regiis –pef "appSettings" "path"
@shammelburg
shammelburg / convert-base64string-to-file
Created November 26, 2015 16:08
Convert Base64String to File
public void Convert(string Base64String)
{
string fileName = "test.jpg";
string rootpath = Server.MapPath(Path.Combine("~", "Image", fileName));
ConvertBase64ToFile.ConvertToFile(rootpath, Base64String.Split(',')[1]);
}
public class ConvertBase64ToFile
{
public static void ConvertToFile(string location, string file)
@shammelburg
shammelburg / angular-webapi-access.txt
Last active November 26, 2015 21:26
Angular Web API Access
// Add to Global.asax.cs
protected void Application_BeginRequest()
{
if (Request.Headers.AllKeys.Contains("Origin") && Request.HttpMethod == "OPTIONS")
{
Response.Flush();
}
}
@shammelburg
shammelburg / css-table-pivot.css
Last active November 26, 2015 21:22
CSS Table Pivot
/* Add data-title to the <td> element like this <td data-title="column header here"></td> */
media only screen and (max-width: 900px) {
/* Force table to not be like tables anymore */
#no-more-tables table,
#no-more-tables thead,
#no-more-tables tbody,
#no-more-tables th,
#no-more-tables td,
@shammelburg
shammelburg / server.js
Created November 26, 2015 21:20
Node.js Static Serve Connect
/*
npm install serve-static
npm install connect
http://localhost:5000/
*/
var connect = require("connect"), serveStatic = require("serve-static");
var server = connect();
server.use(serveStatic("."));
@shammelburg
shammelburg / get-file-cs.txt
Created November 26, 2015 21:34
Download File from Server using Web API and AngularJS
// This will download the file from the server
// Pass in the filepath of where file is stored and a new file name
private static void GetFileFromServer(string currentFilePath, string newFileName)
{
HttpResponse httpresponse = HttpContext.Current.Response;
httpresponse.Clear();
httpresponse.Charset = "utf-8";
httpresponse.ContentType = "application/pdf"; // mime type to suit file type
httpresponse.AddHeader("content-disposition", string.Format("attachment; filename={0}", newFileName));
httpresponse.BinaryWrite(File.ReadAllBytes(currentFilePath));
using Ionic.Zip;
[HttpPost]
public void ZipFiles(FormCollection collection)
{
using (ZipFile zip = new ZipFile())
{
zip.AlternateEncodingUsage = ZipOption.AsNecessary;
var file_collection = _repository.GetListOfFiles();
@shammelburg
shammelburg / comply.cs
Last active November 19, 2018 11:01
Creating CSV File C#
public string ComplyWithCSV(string sentense)
{
if(!string.IsNullOrEmpty(sentense))
{
var stripped = sentense.Replace("\"", "\"\""); // Replaces a " with ""
sentense = "\"" + stripped + "\""; // Add " to start and end to allow ,
}
return sentense;
}
@shammelburg
shammelburg / azure-sendgrid-smtp
Last active December 3, 2015 15:07
Azure SendGrid SMTP
<system.net>
<mailSettings>
<smtp deliveryMethod="Network">
<network host="smtp.sendgrid.net" port="587" defaultCredentials="false" userName="azure_{{guid}}@azure.com" password="*********" />
</smtp>
</mailSettings>
</system.net>