Skip to content

Instantly share code, notes, and snippets.

@arkein
arkein / test-numbers.ps1
Created April 4, 2019 13:27
PowerShell Continue Gotcha
function Test-Number([int]$In) {
if ($In -eq 3) {
continue
} else {
return (($In % 2) -eq 0)
}
}
foreach ($test in @(1,2,3,4,5)) {
Write-Host "checking $test"
@arkein
arkein / codeGenFromXsd.cs
Last active January 11, 2019 08:46
Draft code generator from XSD in runtime
void Main()
{
XmlSchemaSet schemaSet = new XmlSchemaSet();
schemaSet.Add("http://rookie.ru/schema", "D:\\test.xsd");
schemaset.Compile();//throws
var schemas = new XmlSchemas();
foreach (XmlSchema schema in schemaSet.Schemas())
{
@arkein
arkein / scanDotNetAssembly.ps1
Last active February 9, 2018 12:35
Output a list of .NET assemblies with System.Diagnostics.DebuggableAttribute flags
foreach ( $file in gci -Path .\ -Filter "*.dll" -Recurse) {
$assembly = [System.Reflection.Assembly]::LoadFrom($file.FullName)
$attributes = $assembly.GetCustomAttributes([System.Diagnostics.DebuggableAttribute], $false);
if ($attributes.Length -gt 0) {
[System.Diagnostics.DebuggableAttribute]$debuggable = $attributes[0];
if ($debuggable -ne $null -and $debuggable.DebuggingFlags.HasFlag([System.Diagnostics.DebuggableAttribute+DebuggingModes]::Default)) {
$file.FullName
$debuggable.DebuggingFlags
}
}
@arkein
arkein / scanFiles.ps1
Created February 8, 2018 23:30
powrshell script to scan through files and find lines that match to one regex but don't match to another regex, e.g. Release|AnyCPU = Debug|AnyCPU
$debugRegex = 'Debug'
$releaseRegex = 'Release'
$path = 'g:\Projects\'
$f = "*.*proj"
foreach ( $file in gci -Path $path -Filter $f -Recurse) {
$file.FullName
foreach($line in [System.IO.File]::ReadLines($file.FullName) | Where-Object {$_ -match $debugRegex})
{
if( $line -match $releaseRegex) {
@arkein
arkein / pool.go
Created September 10, 2014 07:28
Pool with one shared resource, more like a handle
package main
import (
"fmt"
"runtime"
"sync"
"time"
)
type Pool interface {
@arkein
arkein / singleton.go
Created July 12, 2013 08:07
Beautiful way to create a singleton in Go
package singleton
var Instance *_Singleton
type _Singleton struct {
SharedResource int
}
func _Load() {
Instance = &_Singleton{SharedResource: 1}