Skip to content

Instantly share code, notes, and snippets.

View iAnatoly's full-sized avatar

Anatoly Ivanov iAnatoly

View GitHub Profile
@iAnatoly
iAnatoly / Permutations in natural order
Last active August 29, 2015 14:22
Permutations in natural vs. lexigraphical order
def permutations(array):
if len(array) < 2:
yield array
else:
for shorter_permutation in permutations(array[1:]):
for i in range(len(array)):
yield shorter_permutation[:i] + array[0:1] + shorter_permutation[i:]
@iAnatoly
iAnatoly / gist:883826b79d18ab13e72a
Created June 11, 2015 22:54
Generating permutations in C#
public static IEnumerable<IEnumerable<T>> GeneratePermutations<T>(IEnumerable<T> source)
{
var c = source.Count();
if (c == 1)
yield return source;
else
for (int i = 0; i < c; i++)
foreach (var shorter_permuttaion in GeneratePermutations<T>(source.Take(i).Concat(source.Skip(i + 1))))
yield return source.Skip(i).Take(1).Concat(shorter_permuttaion);
}
@iAnatoly
iAnatoly / .NETway
Last active May 2, 2016 20:53
3.5 ways to display IIS App pool identities (usernames and passwords)
[System.Reflection.Assembly]::LoadFrom( “C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll” )
$mgr = New-Object Microsoft.Web.Administration.ServerManager
$mgr.ApplicationPools | % { $pm = $_.ChildElements[“processModel”]; Write-Host $_.Name $pm.Attributes[“userName”].Value$pm.Attributes[“password”].Value }
# Or, if you do not appreciate the brevity:
[System.Reflection.Assembly]::LoadFrom( “C:\windows\system32\inetsrv\Microsoft.Web.Administration.dll” )
$mgr = New-Object Microsoft.Web.Administration.ServerManager
$pools = $mgr.ApplicationPools
foreach ($pool in $pools)
@iAnatoly
iAnatoly / gist:a9a8c7fc30c5b5b075aa67d0122c2280
Created August 4, 2016 17:33
One-liner to generate password in PowerShell
[reflection.assembly]::LoadWithPartialName("System.Web")
[System.Web.Security.Membership]::GeneratePassword(32,4)
@iAnatoly
iAnatoly / reclaimWindows10.ps1
Created January 7, 2017 19:54 — forked from alirobe/reclaimWindows10.ps1
"Reclaim Windows 10" turns off a bunch of unnecessary Windows 10 telemetery, removes bloatware, and privacy invasions. Review and tweak before running. Scripts for reversing are included and commented. Fork via https://github.com/Disassembler0 (different defaults)
##########
# Win10 Initial Setup Script
# Author: Disassembler <disassembler@dasm.cz>
# Version: 1.7, 2016-08-15
# dasm's script: https://github.com/Disassembler0/Win10-Initial-Setup-Script/
# THIS IS A PERSONALIZED VERSION
# This script leaves more MS defaults on, including MS security features.
# Tweaked based on personal preferences for @alirobe 2016-11-16 - v1.7.1
@iAnatoly
iAnatoly / generate.sh
Created June 15, 2017 12:50
Interruptible script generating pre-defined number of random files
#!/bin/bash
TARGET_FILE_NUM=10000
CURRENT_FILE_NUM=`ls -l | wc -l`
FILES_TO_GENERATE=$((TARGET_FILE_NUM - CURRENT_FILE_NUM))
MAX_FILE_SIZE=8192
FILE_NAME_PREFIX="test_"
if [[ $FILES_TO_GENERATE -lt 0 ]]; then
echo "We already have $CURRENT_FILE_NUM files, no need to generate more"
@iAnatoly
iAnatoly / tweak.sh
Created June 15, 2017 12:58
MacOS tweaks
# override DHCP hostname assignment
sudo scutil --set HostName myhostname.domain.local
# tweak network
cat >> /etc/sysctl.conf <<EOF
# OSX default of 3 is not big enough
net.inet.tcp.win_scale_factor=8
# increase OSX TCP autotuning maximums
net.inet.tcp.autorcvbufmax=33554432
net.inet.tcp.autosndbufmax=33554432
@iAnatoly
iAnatoly / import-hashes.ps1
Last active June 19, 2018 20:43
How to upload 501M SHA1 hashes into a SQL database
# How to upload 501M SHA1 hashes into a SQL database
#
# Based on:
# https://blog.netnerds.net/2015/01/powershell-high-performance-techniques-for-importing-csv-to-sql-server/
# https://gallery.technet.microsoft.com/scriptcenter/Import-Large-CSVs-into-SQL-216223d9
#
# Database variables
$sqlserver = "YOUR_SERVER"
$database = "YOUR_DATABASE"
$table = "YOUR_TABLE"
# coding=UTF-8
from __future__ import division
import re
# This is a naive text summarization algorithm
# Created by Shlomi Babluki
# April, 2013
class SummaryTool(object):
#!/bin/bash
#
# based off https://developer.atlassian.com/blog/2016/02/best-way-to-store-dotfiles-git-bare-repo/
#
git clone --bare git@github.com:iAnatoly/homedot.git $HOME/.cfg
function config {
/usr/bin/git --git-dir=$HOME/.cfg/ --work-tree=$HOME $@
}
config checkout