Skip to content

Instantly share code, notes, and snippets.

View mariusschulz's full-sized avatar
🤓

Marius Schulz mariusschulz

🤓
View GitHub Profile
const string placeholderPattern = @"
\[
\[
([^\]]+) # Description of whatever is in here
\]
\[
([^\]]+) # Description of whatever is in here
\]
\]";
isPrime = (n) ->
return true if n is 2 or n is 3
return false if n % 2 is 0
for i in [3..Math.sqrt n]
return false if n % i is 0
true
primesUnder100 = (n for n in [1..100] when isPrime n)
private static bool BinarySearch(int[] sortedHaystack, int needle)
{
int leftBoundary = 0;
int rightBoundary = sortedHaystack.Length - 1;
while (leftBoundary <= rightBoundary)
{
int pivotIndex = (int)(((long)leftBoundary + rightBoundary) / 2);
int pivotValue = sortedHaystack[pivotIndex];
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 / ExternalJavaScriptFileAttribute.cs
Last active April 16, 2020 15:24
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).
using System;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;
namespace DemoApp
{
public class ExternalJavaScriptFileAttribute : ActionFilterAttribute
{