Skip to content

Instantly share code, notes, and snippets.

@0liver
0liver / safeLocalStorage.js
Last active July 19, 2021 22:22
A safe localStorage access wrapper
(function(n) {
function t(n) {
function i() {
try {
var t = "__some_random_key_we_are_not_going_to_use__";
return n().setItem(t, t),
n().removeItem(t),
!0
} catch (i) {
return false;
@0liver
0liver / ConcurrentListAddTest.cs
Created November 21, 2017 12:50
Test code to show non-thread-safety of List<>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using NUnit.Framework;
namespace Tests {
[TestFixture]
public class ConcurrentListAddTest {
[Test]
@0liver
0liver / Get non-matchin elements.js
Last active August 29, 2015 14:19
Getting to grips with lodash
var missingCpsInside = _.filter(result.campsiteInside, function(cp) {
// using the `_.matchesProperty` callback shorthand
return !_.any(currentHitMarkers, 'id', cp.id);
});
@0liver
0liver / Themes\TheAdmin\Views\Menu.cshtml
Last active August 29, 2015 14:16
Orchard Admin Menu
@using Orchard.Utility.Extensions;
@{
Script.Require("jQuery");
Script.Include("admin.js");
IEnumerable<dynamic> firstLevelMenuItems = Model;
if (Model.ImageSets != null) {
foreach (var imageSet in Model.ImageSets) {
RegisterImageSet("menu." + imageSet, Model.MenuName /* style */, 16 /* bounding box */);
}
@0liver
0liver / ContentHelpers.cs
Created December 6, 2014 11:06
ContentHelpers for Unit Testing in Orchard CMS
using Orchard.ContentManagement;
using Orchard.ContentManagement.FieldStorage.InfosetStorage;
using Orchard.ContentManagement.Records;
namespace Nwazet.Commerce.Tests.Helpers {
public class ContentHelpers {
public static ContentItem PreparePart<TPart, TRecord>(TPart part, string contentType, int id = -1)
where TPart : ContentPart<TRecord>
where TRecord : ContentPartRecord, new() {
/* see https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide */
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Text;
using System.Web;
@0liver
0liver / GoogleAnalyticsApi.cs
Last active March 24, 2023 09:34
C# wrapper around the Google Analytics Measurement Protocol API
/* based on the docs at: https://developers.google.com/analytics/devguides/collection/protocol/v1/devguide */
/*
* LICENSE: MIT
* AUTOHR: oliver@teamaton.com
*/
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
public class LanguageSpecificFileRule : RegExRewriteRule
{
private string _defaultLanguageIso2;
public override void Initialize(UrlRewritingNet.Configuration.RewriteSettings rewriteSettings)
{
base.Initialize(rewriteSettings);
_defaultLanguageIso2 = rewriteSettings.GetAttribute("defaultLanguage", "de").ToLowerInvariant();