Skip to content

Instantly share code, notes, and snippets.

View markembling's full-sized avatar

Mark Embling markembling

View GitHub Profile
@markembling
markembling / hosts.ps1
Created August 24, 2009 13:38
Powershell script for adding/removing/viewing entries to the hosts file.
#
# Powershell script for adding/removing/showing entries to the hosts file.
#
# Known limitations:
# - does not handle entries with comments afterwards ("<ip> <host> # comment")
#
$file = "C:\Windows\System32\drivers\etc\hosts"
function add-host([string]$filename, [string]$ip, [string]$hostname) {
@markembling
markembling / gitutils.ps1
Last active March 29, 2023 01:47
Powershell functions for git information
# Git functions for PowerShell
# Copyright 2009-2019 Mark Embling (http://www.markembling.info/)
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
@markembling
markembling / profile.ps1
Created September 4, 2009 12:27
My preferred prompt for Powershell - includes git info.
# My preferred prompt for Powershell.
# Displays git branch and stats when inside a git repository.
# See http://gist.github.com/180853 for gitutils.ps1.
. (Resolve-Path ~/Documents/WindowsPowershell/gitutils.ps1)
function prompt {
$path = ""
$pathbits = ([string]$pwd).split("\", [System.StringSplitOptions]::RemoveEmptyEntries)
if($pathbits.length -eq 1) {
@markembling
markembling / .bash_profile
Created September 6, 2009 15:03
My preferred prompt for Bash (inc. Git info)
# Function for determining current git branch (if any)
# Gracefully fails if not in a git repo and returns nothing.
__gitBranch() {
ref=$(git symbolic-ref HEAD 2> /dev/null) || return
echo ${ref#refs/heads/}
}
# Retrieves status information for git and places into predefined variables.
__gitStatus() {
# Initialise git status variables
# SSH Agent Functions
# Mark Embling (http://www.markembling.info/)
#
# How to use:
# - Place this file into %USERPROFILE%\Documents\WindowsPowershell (or location of choice)
# - Import into your profile.ps1:
# e.g. ". (Resolve-Path ~/Documents/WindowsPowershell/ssh-agent-utils.ps1)" [without quotes]
# - Enjoy
#
# Note: ensure you have ssh and ssh-agent available on your path, from Git's Unix tools or Cygwin.
@markembling
markembling / gist:207757
Created October 11, 2009 17:10
Symlink your Powershell profile to a folder within your dropbox
mklink /D ".\WindowsPowershell" ".\My Dropbox\PowershellProfile"
// Gets all items more expensive than £5.
var q = mongoContext.Query<Item>()
.Where(x => x.Price)
.IsGreaterThan(5);
// Gets all Smiths in the given cities.
var q2 = mongoContext.Query<Customer>()
.Where(x => x.Name).IsEqualTo("Smith")
.Where(x => x.City).IsIn("Bournemouth","Farnborough","London");
@markembling
markembling / MongoUtils.ps1
Created April 9, 2010 18:02
Utility functions for MongoDB
# Start the MongoDB server running (foreground)
function Start-MongoD {
$dropBox = (Resolve-Path '~\Documents\My Dropbox').Path
$mongoConfig = "$dropBox\Software\MongoDB\mongo.conf"
$mongoData = "$dropBox\Software\MongoDB\data\"
& $dropBox\Software\MongoDB\bin\mongod.exe --config "'$mongoConfig'" --dbpath "'$mongoData'"
}
# Start the MongoDB client app
@markembling
markembling / .gitignore
Created November 8, 2010 11:00
.gitignore file for .NET projects
[Bb]in
[Oo]bj
*.suo
TestResult.xml
*.sln.cache
*.[Rr]e[Ss]harper.user
_ReSharper*
*.csproj.user
@markembling
markembling / gist:769462
Created January 7, 2011 13:43
Dynamically create and submit a form.
// This would (does) work in proper browsers.
jQuery(createElement('form'))
.attr({'method':'post','action':/*some url*/})
.submit();
// IE needs it to be attached to the document somewhere first before submission will work. :(
var f = jQuery(createElement('form'))
.attr({'method':'post','action':/*some url*/});
jQuery('body').append(f);
f.submit();