Skip to content

Instantly share code, notes, and snippets.

@vors
vors / PowerShellScriptInjectionTests.cs
Last active August 29, 2015 14:04
This is a demo of unsecure and secure usage of PowerShell.AddScript()
namespace testSandbox
{
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Management.Automation;
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
public class LsHelper
@vors
vors / vktracks.js
Last active August 29, 2015 14:06 — forked from aslushnikov/download.sh
Scrap mp3 urls from vk.com music pages
var trackElements = document.querySelectorAll(".audio");
console.log("Loaded " + trackElements.length + " track");
var tracks = [];
for (var i = 0; i < trackElements.length; ++i) {
var trackElement = trackElements[i];
var input = trackElement.querySelector("input");
var title = trackElement.querySelector(".title_wrap");
if (!input || !title) {
@vors
vors / DelegatesGenerator.ps1
Created December 1, 2014 23:58
Generate signatures for C# delegates
function Get-Action([int]$i)
{
'public delegate void Action<' + [string]::Join(", ", (1..$i | %{"in T$_"})) + '>(' + [string]::Join(", ", (1..$i | %{"T$_ arg$_"})) + ');'
}
function Get-Func([int]$i)
{
'public delegate TResult Func<' + [string]::Join(", ", (1..$i | %{"in T$_"})) + ', out TResult>(' + [string]::Join(", ", (1..$i | %{"T$_ arg$_"})) + ');'
}
@vors
vors / stripdown.rb
Last active August 29, 2015 14:10
Converts markdown to plain text with https://github.com/vmg/redcarpet
#!/usr/bin/env ruby
require 'redcarpet'
require 'redcarpet/render_strip'
# require 'redcarpet/render_man.rb'
# Get stdin as a string
input = STDIN.readlines.join("\n")
# Initializes a Markdown parser
markdown = Redcarpet::Markdown.new(Redcarpet::Render::ManPage)
@vors
vors / profile.ps1
Created December 16, 2014 03:12
Sample of $profile.CurrentUserAllHosts file that can be used to load profile only when session is interactive
# This is $profile.CurrentUserAllHosts file
function Get-IsSessionIntaractive() {
$parentProcess = Get-Process -id (Get-WmiObject Win32_Process -Filter "ProcessId = '$pid'").ParentProcessId
$parentProcess.Name -eq "explorer"
}
# put your profile in this file and access it with $psrc instead of $profile
$psrc = 'C:\Users\sevoroby\Documents\WindowsPowerShell\psrc.ps1'
if (Get-IsSessionIntaractive)
@vors
vors / revert.js
Created January 19, 2015 20:32
Revert colors for open and closed issues in github
// past this line to dev tools console
a = $(".closed.octicon"); for (var i = 0; i < a.length; i++) { a[i].style.color = 'green'}; a = $(".open.octicon"); for (var i = 0; i < a.length; i++) { a[i].style.color = 'red'}
@vors
vors / ScriptAnalyzer.ps1
Created February 25, 2015 00:02
Script Analyzer sample 1
<#
.SYNOPSIS
You should never use Write-Host to create any script output whatsoever.
.DESCRIPTION
It is generally accepted that you should never use Write-Host to create any script output whatsoever, unless your script (or function, or whatever) uses the Show verb (as in, Show-Performance).
That verb explicitly means “show on the screen, with no other possibilities.” Like Show-Command.
To fix a violation of this rule, please replace Write-Host with Write-Output in most scenarios.
.EXAMPLE
Test-WriteHost -CommandAst $CommandAst
.INPUTS
@vors
vors / PS-blog-post-formatting.html
Created February 28, 2015 01:18
Formatting that can be used to style blog post about PowerShell
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<!-- Replace this gist by your own blog gist -->
<script src="https://gist.github.com/vors/4bf101a457e6816f3c0f.js"></script>
<script type="text/javascript">
$( document ).ready(function() {
$('.markdown-body > p > code')
.css("white-space","nowrap");
@vors
vors / hacky_const.ps1
Created March 11, 2015 16:40
Workaround that can be used in WMF 5 February Preview to emulate const.
# don't use it, it's a workaround
class ClassWithConst
{
[ValidateSet(100)]
static [int] $CONST_FOO = 100
}
[ClassWithConst]::CONST_FOO
[ClassWithConst]::CONST_FOO = 10
@vors
vors / azure-dsc-extension-schema.json
Created April 10, 2015 18:49
Experimental json schema of DSC azure extension
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "http://schema.management.azure.com/schemas/2014-04-01/Microsoft.Powershell.DSC.json",
"title": "Microsoft.Powershell.DSC",
"description": "Microsoft.Powershell.DSC Extension for Azure VMs",
"definitions": {
"DscConfigurationArguments": {
"oneOf": [
{
"type": "array",