Skip to content

Instantly share code, notes, and snippets.

@jehiah
jehiah / simple_args_parsing.sh
Created March 4, 2011 16:56
a simple way to parse shell script arguments
#!/bin/sh
#
# a simple way to parse shell script arguments
#
# please edit and use to your hearts content
#
ENVIRONMENT="dev"
@idavis
idavis / Use-Impersonation.ps1
Created March 5, 2011 18:52
Impersonate a user and execute a script block as that user
param( [ScriptBlock] $scriptBlock )
<#
.SYNOPSIS
Impersonates a user and executes a script block as that user. This is an interactive script
and a window will open in order to securely capture credentials.
.EXAMPLE
Use-Impersonation.ps1 {Get-ChildItem 'C:\' | Foreach { Write-Host $_.Name }}
This writes the contents of 'C:\' impersonating the user that is entered.
#>
@hekt
hekt / regex_css
Created August 14, 2011 16:59
RegEx for parsing CSS
(# comment )
(/\*(?:(?!\*/)[\s\S])*\*/)
(/\*(?:[^*]|\*[^/])*\*/)
(# @keyframes-rule )
(@(?:-webkit-|-moz-)?keyframes(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)+[a-zA-Z0-9_\-]+(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*{(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*(?:(?:from|to|[0-9]{1,3}%)(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*{(?:[^{}"']|/\*(?:(?!\*/)[\s\S])*\*/|'[^']*'|"[^"]*")*}(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*)+(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*})
(# ruleset )
((?:[^{}"']|'[^']*'|"[^"]*")+(?:[\s\n]|/\*(?:(?!\*/)[\s\S])*\*/)*{(?:[^{}"']|/\*(?:(?!\*/)[\s\S])*\*/|'[^']*'|"[^"]*")*})
@haf
haf / Colourized PowerShell
Created October 25, 2011 16:18
Colourized PowerShell ls command
#First in your powershell profile in
#C:\Users\<<username>>\Documents\WindowsPowerShell\Microsoft.PowerShell_profile.ps1
set-location D:\code
. "C:\Users\<<username>>\Documents\WindowsPowerShell\Get-ChildItemColor.ps1" # read the colourized ls
set-alias ls Get-ChildItemColor -force -option allscope
function Get-ChildItem-Force { ls -Force }
set-alias la Get-ChildItem-Force -option allscope
#Then in:
@pandeiro
pandeiro / 0main.md
Created January 2, 2012 22:49 — forked from SethRobertson/index.md
Git Best Practices

Git Best Practices

This is a fairly common question, and there isn't a One True Answer, but still, this represents a consensus from #git

Read about git

Knowing where to look is half the battle. I strongly urge everyone to read (and support) the Pro Git book. The other resources are highly

@TaoK
TaoK / Invoke-ElevatedCommand.ps1
Created January 9, 2012 09:33
Invoke-ElevatedCommand for Administrator-level commands in a common powershell pipeline
Function Invoke-ElevatedCommand {
<#
.DESCRIPTION
Invokes the provided script block in a new elevated (Administrator) powershell process,
while retaining access to the pipeline (pipe in and out). Please note, "Write-Host" output
will be LOST - only the object pipeline and errors are handled. In general, prefer
"Write-Output" over "Write-Host" unless UI output is the only possible use of the information.
Also see Community Extensions "Invoke-Elevated"/"su"
.EXAMPLE
@ScottPhillips
ScottPhillips / .htaccess
Created February 2, 2012 04:30
Common .htaccess Redirects
#301 Redirects for .htaccess
#Redirect a single page:
Redirect 301 /pagename.php http://www.domain.com/pagename.html
#Redirect an entire site:
Redirect 301 / http://www.domain.com/
#Redirect an entire site to a sub folder
Redirect 301 / http://www.domain.com/subfolder/
@tater9104
tater9104 / MassiveExtensions.cs
Last active January 16, 2023 00:55
A list of a few extension methods that I often use when working with massive.
public static class MassiveExtensions
{
// Extension method that coverts an concrete object to a dynamic object. When using massive, this is helpful
// to auto-convert concrete objects while skipping over key fields that would otherwise throw an
// error (such as ID's)
public static dynamic ToExpando(this object o, params string[] propertiesToIgnore)
{
var result = new ExpandoObject();
var d = result as IDictionary<string, object>; //work with the Expando as a Dictionary
if (o.GetType() == typeof(ExpandoObject)) return o; //shouldn't have to... but just in case
@jpoehls
jpoehls / encoding-helpers.ps1
Created April 17, 2012 14:54
Convert-FileEncoding and Get-FileEncoding
<#
.SYNOPSIS
Converts files to the given encoding.
Matches the include pattern recursively under the given path.
.EXAMPLE
Convert-FileEncoding -Include *.js -Path scripts -Encoding UTF8
#>
function Convert-FileEncoding([string]$Include, [string]$Path, [string]$Encoding='UTF8') {
$count = 0
@alimbada
alimbada / ReSharperMemberLayoutRules.xml
Created April 19, 2012 10:45
ReSharper custom type member layout rules for C#
<?xml version="1.0" encoding="utf-8" ?>
<!--
I. Overall
I.1 Each pattern can have <Match>....</Match> element. For the given type declaration, the pattern with the match, evaluated to 'true' with the largest weight, will be used
I.2 Each pattern consists of the sequence of <Entry>...</Entry> elements. Type member declarations are distributed between entries
I.3 If pattern has RemoveAllRegions="true" attribute, then all regions will be cleared prior to reordering. Otherwise, only auto-generated regions will be cleared
I.4 The contents of each entry is sorted by given keys (First key is primary, next key is secondary, etc). Then the declarations are grouped and en-regioned by given property