Skip to content

Instantly share code, notes, and snippets.

View egil's full-sized avatar

Egil Hansen egil

View GitHub Profile
@egil
egil / gist:1616481
Created January 15, 2012 17:14
Drupal: Removes all stylesheets except those added by the theme. Should be added to your template.php file. More info can be found here: http://api.drupal.org/api/drupal/modules--system--system.api.php/function/hook_css_alter/7
function THEME_css_alter(&$css) {
foreach ($css as $key => $value) {
if ($value['group'] != CSS_THEME) {
$exclude[$key] = FALSE;
}
}
$css = array_diff_key($css, $exclude);
}
@egil
egil / gist:1621550
Created January 16, 2012 16:07
Drupal: Get contextual links on nodes
// In template.php:
function THEME_menu_local_tasks($variables) {
// Add contextual links js and css library
drupal_add_library('contextual', 'contextual-links');
$output = '';
if (!empty($variables['primary'])) {
$variables['primary']['#prefix'] = '<div class="contextual-links-wrapper"><ul class="contextual-links">';
$variables['primary']['#suffix'] = '</ul></div>';
@egil
egil / drupal-webform-nationalities.txt
Created October 26, 2012 11:40
A list of nationalities formatted for use with Drupals Webform module
Afghan|Afghan
Albanian|Albanian
Algerian|Algerian
American|American
Andorran|Andorran
Angolan|Angolan
Antiguans|Antiguans
Argentinean|Argentinean
Armenian|Armenian
Australian|Australian
@egil
egil / AllCombinations.cs
Created October 7, 2019 21:55
A C# IList extension method that returns all combinations of the content of the list. See related question on StackOverflow: https://stackoverflow.com/questions/7802822/all-possible-combinations-of-a-list-of-values/40417765#40417765
using System;
using System.Collections.Generic;
public static class ListExtensions
{
public static IEnumerable<List<TInput>> AllCombinations<TInput>(this IList<TInput> list)
=> list.AllCombinations(() => new List<TInput>(), (list, item) => list.Add(item));
public static IEnumerable<TCombinationContainer> AllCombinations<TInput, TCombinationContainer>(
this IList<TInput> list,
@egil
egil / dotnet-format-action.yml
Created July 27, 2020 08:42 — forked from rickyah/dotnet-format-action.yml
Runs dotnet-format on every PR and create a commit that fixes the formatting if it doesn't comply with your code convention
name: Format check on pull request
on: pull_request
jobs:
dotnet-format:
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/[email protected]
with:
fetch-depth: 0
name: "Format code on PR"
on:
pull_request:
types:
- opened
- synchronize
- reopened
jobs:
@egil
egil / Entity.cs
Last active November 13, 2020 11:35
Draft for EntityCosmosJsonConverter that avoids poluting domain objects with Cosmos specific properties
using System;
public abstract class Entity
{
public Guid Id { get; set; }
}
@egil
egil / IdFactory.cs
Last active January 17, 2021 17:17
This can be used to hash key/value pairs, that should be used as a ID in e.g. a database like CosmosDB. This will produce the same length key, no matter how many key/value pairs are supplied.
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
public static class IdFactory
{
public static string CreateId(IEnumerable<(string key, string value)> kvps)
@egil
egil / StringAssertionExtensions.cs
Last active May 4, 2021 15:07
C# source code comparison / assertion helper (depends on the packages Microsoft.CodeAnalysis.CSharp and DiffPlex).
using System;
using System.Text;
using DiffPlex.DiffBuilder;
using DiffPlex.DiffBuilder.Model;
using FluentAssertions.Execution;
using FluentAssertions.Primitives;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CSharp;
namespace FluentAssertions
@egil
egil / MulticastAsyncEnumerable.cs
Last active October 10, 2024 20:00
A multi-cast IAsyncEnumerable<T>, where each reader/subscriber/iterator gets their own copy of the items passed to the enumerable, and can process them asynchronously at their own pace. Since it implements `IAsyncEnumerable<T>`, users can use all the LINQ style operators available in the System.Linq.Async package for easy filtering, projecting, …
/// <summary>
/// Represents a multi-cast <see cref="IAsyncEnumerable{T}"/> where
/// each reader can consume the <typeparamref name="T"/> items
/// at its own pace.
/// </summary>
/// <typeparam name="T">The item type produced by the enumerable.</typeparam>
public sealed class MulticastAsyncEnumerable<T> : IAsyncEnumerable<T>
{
private readonly UnboundedChannelOptions channelOptions;
private readonly object activeChannelsLock = new object();