Skip to content

Instantly share code, notes, and snippets.

Marius Schulz mariusschulz

Block or report user

Report or block mariusschulz

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@mariusschulz
mariusschulz / deserialization.js
Last active Apr 19, 2018
Automatic JSON date deserialization
View deserialization.js
const DATE_PATTERN = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d+$/;
function deserializeProperty(key, value) {
return typeof value === "string" && DATE_PATTERN.test(value)
? new Date(value)
: value;
}
const obj = JSON.parse('{ "date": "2016-04-26T18:09:16.61" }', deserializeProperty);
console.log(typeof obj.date);
@mariusschulz
mariusschulz / trimStart.js
Created Oct 11, 2014
A JavaScript trimStart function
View trimStart.js
function trimStart(character, string) {
var startIndex = 0;
while (string[startIndex] === character) {
startIndex++;
}
return string.substr(startIndex);
}
@mariusschulz
mariusschulz / HtmlHelperExtensions.cs
Last active Mar 13, 2018
Two C# extension methods for inlining script and style bundles into the HTML response using ASP.NET MVC and the System.Web.Optimization framework.
View HtmlHelperExtensions.cs
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;
public static class HtmlHelperExtensions
{
public static IHtmlString InlineScripts(this HtmlHelper htmlHelper, string bundleVirtualPath)
{
return htmlHelper.InlineBundle(bundleVirtualPath, htmlTagName: "script");
View main.bundle.js
/******/ (function(modules) { // webpackBootstrap
/******/ // The module cache
/******/ var installedModules = {};
/******/
/******/ // The require function
/******/ function __webpack_require__(moduleId) {
/******/
/******/ // Check if module is in cache
/******/ if(installedModules[moduleId]) {
/******/ return installedModules[moduleId].exports;
@mariusschulz
mariusschulz / ExternalJavaScriptFileAttribute.cs
Last active Dec 28, 2017
Here's the ExternalJavaScriptFileAttribute that I showed in my blog post "Generating External JavaScript Files Using Partial Razor Views" (see http://blog.mariusschulz.com/generating-external-javascript-files-using-partial-razor-views).
View ExternalJavaScriptFileAttribute.cs
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;
namespace DemoApp
{
public class ExternalJavaScriptFileAttribute : ActionFilterAttribute
{
@mariusschulz
mariusschulz / lesson-1-global-context.js
Last active Nov 29, 2017
Code for my egghead.io course "Understand JavaScript's this Keyword in Depth"
View lesson-1-global-context.js
// "use strict";
console.log(this === window);
View arrow-functions.js
const square = function(x) {
return x * x;
};
const cube = (x) => {
return x * x * x;
};
const numbers = [11, 20, 33, 40, 55];
@mariusschulz
mariusschulz / list.md
Last active Jun 25, 2016
ECMAScript 2015 Resources
View gist:6594870
public string DecryptQueryString(string inputText, string key, string salt)
{
byte[] encryptedData = Convert.FromBase64String(inputText);
var secretKey = new PasswordDeriveBytes(Encoding.ASCII.GetBytes(key), Encoding.ASCII.GetBytes(salt));
using (var rijndaelCipher = new RijndaelManaged())
using (var decryptor = rijndaelCipher.CreateDecryptor(secretKey.GetBytes(32), secretKey.GetBytes(16)))
using (var memoryStream = new MemoryStream(encryptedData))
using (var cryptoStream = new CryptoStream(memoryStream, decryptor, CryptoStreamMode.Read))
{
@mariusschulz
mariusschulz / .eslintrc
Created Nov 7, 2015
My ESLint configuration
View .eslintrc
{
"env": {
"es6": true,
"browser": true,
"node": true
},
"ecmaFeatures": {
"modules": true
},
"rules": {
You can’t perform that action at this time.