Skip to content

Instantly share code, notes, and snippets.

View a-bronx's full-sized avatar

Andrey Bronnikov a-bronx

  • HID Global
  • Fremont, CA
View GitHub Profile
//-------------------------------------------------------------------
// Provides a "finally" lambda block for C++.
// Example:
//
// void ReenterableFunction() {
// static bool isActive = true; // static reenterability flag
//
// if (isActive) return; // check the flag
// auto reset = finally([&]{ isActive = false; }); // we need to reset the flag on exit, even if there was an exception in the code below.
// isActive = true; // set the flag and proceed
static class EnumerableExtensions
{
/* Zips an arbitrary number of collections.
Parameters:
* sources: a collection of collections to zip.
* resultSelector: a function to process every 'slice' of the zipper and produce a result object.
* stopOnFirstSource: when 'true', the method will stop zipping when any of sources exhausted;
otherwize it will continue zipping until all sources are exhauste
<# Object initializer syntax ( $config = @{ … } ) produces a Hashtable.
Unlike this, the ConvertFrom-Json function returns PSCustomObject instead.
This may be inconvenient if you keep configuration both in JSON files and in PS1 files.
To keep uniformity, convert object to Hashtable using this function
#>
function ConvertTo-Hashtable {
param(
[Parameter(ValueFromPipeline=$true, ValueFromPipelineByPropertyName=$true)]
$InputObject
@a-bronx
a-bronx / angularjs_directive_attribute_explanation.md
Created April 28, 2019 02:29 — forked from CMCDragonkai/angularjs_directive_attribute_explanation.md
JS: AngularJS Directive Attribute Binding Explanation

AngularJS Directive Attribute Binding Explanation

When using directives, you often need to pass parameters to the directive. This can be done in several ways. The first 3 can be used whether scope is true or false. This is still a WIP, so validate for yourself.

  1. Raw Attribute Strings

    <div my-directive="some string" another-param="another string"></div>
@a-bronx
a-bronx / debounce.js
Created June 2, 2020 07:01 — forked from just-boris/debounce.js
small debounce implementation without lodash
export const DEBOUNCE_DEFAULT_DELAY = 200;
export default function debounce(func, delay = DEBOUNCE_DEFAULT_DELAY) {
let timeout;
return function(...args) {
if (timeout) {
clearTimeout(timeout);
}
timeout = setTimeout(() => {
@a-bronx
a-bronx / scooped.ps1
Last active November 18, 2023 10:01
A scoop of software
# Install scoop
Set-ExecutionPolicy RemoteSigned -scope CurrentUser
iwr -useb get.scoop.sh | iex
# Prepare scoop
scoop install aria2 # Multi-protocol download utility & accelerator
scoop install git # Version control system. Required for scoop.
# Add scoop buckets
class Schedule
{
// "Timetables" for different recurrence intervals.
private bool[] years;
private bool[] months;
private bool[] days;
private bool[] weekdays;
private bool[] hours;
private bool[] minutes;
private bool[] seconds;
@a-bronx
a-bronx / delete_git_submodule.md
Created November 16, 2022 20:47 — forked from myusuf3/delete_git_submodule.md
How effectively delete a git submodule.

To remove a submodule you need to:

  • Delete the relevant section from the .gitmodules file.
  • Stage the .gitmodules changes git add .gitmodules
  • Delete the relevant section from .git/config.
  • Run git rm --cached path_to_submodule (no trailing slash).
  • Run rm -rf .git/modules/path_to_submodule (no trailing slash).
  • Commit git commit -m "Removed submodule "
  • Delete the now untracked submodule files rm -rf path_to_submodule
@a-bronx
a-bronx / CMD-PS mapping.adoc
Last active January 1, 2025 01:04
PowerShell tricks

CMD vs PowerShell Analogs

Table 1. CMD special variables
CMD Variable PowerShell Analog Description

%0

$MyInvocation.MyCommand.Path

The full path to the script being executed.

%1, %2, …​

$args[0], $args[1], …​

Positional arguments passed to the script.

%*

$args

All arguments passed to the script as an array.

%~f1

$(Resolve-Path $args[0]).Path

Full path of the argument.