Skip to content

Instantly share code, notes, and snippets.

View metablaster's full-sized avatar
😎
Chilling out

metablaster

😎
Chilling out
  • European Union
View GitHub Profile
@nicktoumpelis
nicktoumpelis / repo-rinse.sh
Created April 23, 2014 13:00
Cleans and resets a git repo and its submodules
git clean -xfd
git submodule foreach --recursive git clean -xfd
git reset --hard
git submodule foreach --recursive git reset --hard
git submodule update --init --recursive
@dhh1128
dhh1128 / variadic_macro_1
Created November 21, 2014 20:38
simple variadic macro
#define eprintf(fmt, ...) \
fprintf(stderr, fmt, __VA_ARGS__)
@dhh1128
dhh1128 / paired_sliding_arg_list_macro_trick_1
Last active October 5, 2019 11:46
the "paired, sliding arg list" macro trick
// Accept any number of args >= N, but expand to just the Nth one. In this case,
// we have settled on 5 as N. We could pick a different number by adjusting
// the count of throwaway args before N. Note that this macro is preceded by
// an underscore--it's an implementation detail, not something we expect people
// to call directly.
#define _GET_NTH_ARG(_1, _2, _3, _4, N, ...) N
// Count how many args are in a variadic macro. Only works for up to N-1 args.
#define COUNT_VARARGS(...) _GET_NTH_ARG(__VA_ARGS__, 4, 3, 2, 1)
@dhh1128
dhh1128 / paired_sliding_arg_list_macro_trick_2
Last active October 5, 2019 11:45
"paired, sliding arg list" that handles zero args
// Accept any number of args >= N, but expand to just the Nth one. The macro
// that calls us still only supports 4 args, but the set of values we might
// need to return is 1 larger, so we increase N to 6.
#define _GET_NTH_ARG(_1, _2, _3, _4, _5, N, ...) N
// Count how many args are in a variadic macro. We now use GCC/Clang's extension to
// handle the case where ... expands to nothing. We must add a placeholder arg before
// ##__VA_ARGS__ (its value is totally irrelevant, but it's necessary to preserve
// the shifting offset we want). In addition, we must add 0 as a valid value to be in
// the N position.
@dhh1128
dhh1128 / macros_overridden_by_arg_count
Last active October 5, 2019 11:45
macros overridden by arg count
// Define two overrides that can be used by the expansion of
// our main macro.
#define _MY_CONCAT3(a, b, c) a b c
#define _MY_CONCAT2(a, b) a b
// Define a macro that uses the "paired, sliding arg list"
// technique to select the appropriate override. You should
// recognize this as similar to the GET_NTH_ARG() macro in
// previous examples.
#define _GET_OVERRIDE(_1, _2, _3, NAME, ...) NAME
@dhh1128
dhh1128 / for_each_macro
Last active October 5, 2019 11:41
"for each"-style macro
// Accept any number of args >= N, but expand to just the Nth one.
// Here, N == 6.
#define _GET_NTH_ARG(_1, _2, _3, _4, _5, N, ...) N
// Define some macros to help us create overrides based on the
// arity of a for-each-style macro.
#define _fe_0(_call, ...)
#define _fe_1(_call, x) _call(x)
#define _fe_2(_call, x, ...) _call(x) _fe_1(_call, __VA_ARGS__)
#define _fe_3(_call, x, ...) _call(x) _fe_2(_call, __VA_ARGS__)
@jeffpatton1971
jeffpatton1971 / New-HelpFile.ps1
Last active September 3, 2020 15:36
This script will build output to the screen a properly formatted XML help file. I based this on one of the installed helpfiles in System32.
<#
.SYNOPSIS
This script will generate a proper XML helpfile
.DESCRIPTION
This script will build output to the screen a properly formatted
XML help file. I based this on one of the installed helpfiles
in System32.
.PARAMETER Commands
You can pass in the output from Get-Command cmdletname or you
can pass in Get-Command -Module moduleName

Contributing

When contributing to this repository, please first discuss the change you wish to make via issue, email, or any other method with the owners of this repository before making a change.

Please note we have a code of conduct, please follow it in all your interactions with the project.

Pull Request Process

  1. Ensure any install or build dependencies are removed before the end of the layer when doing a
$array = 'item01', 'item02', 'item03', 'item04'
$count = 0
$start = Get-Date
[nullable[double]]$secondsRemaining = $null
foreach ($item in $array) {
$count++
# calculate percent complete
$percentComplete = ($count / $array.Count) * 100
@lukas-h
lukas-h / license-badges.md
Last active April 28, 2025 11:10
Markdown License Badges for your Project

Markdown License badges

Collection of License badges for your Project's README file.
This list includes the most common open source and open data licenses.
Easily copy and paste the code under the badges into your Markdown files.

Notes

  • The badges do not fully replace the license informations for your projects, they are only emblems for the README, that the user can see the License at first glance.

Translations: (No guarantee that the translations are up-to-date)