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/checkout@v2.2.0
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 / OptionsExtensions.cs
Last active January 12, 2023 15:22
Helper methods for reading values from options types at runtime
using System;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
namespace Microsoft.Extensions.Options;
public static class OptionsExtensions
{