Skip to content

Instantly share code, notes, and snippets.

@codepo8
codepo8 / localstorage.js
Created August 25, 2010 14:44
Store the state of a rendered form the easy way
<script>
// test for localStorage support
if(('localStorage' in window) && window['localStorage'] !== null){
var f = document.getElementById('mainform');
// test with PHP if the form was sent (the submit button has the name "sent")
<?php if(isset($_POST['sent']))){?>
// get the HTML of the form and cache it in the property "state"
localStorage.setItem('state',f.innerHTML);
@JoeSimmonds
JoeSimmonds / prompt.ps1
Created October 18, 2011 09:53
Powershell prompt script
function prompt {
write-host;
get-location | write-host;
if (isCurrentDirectoryGitRepository) {
$status = gitStatus
Write-Host('[') -nonewline -foregroundcolor Yellow
write-host $status["branch"] -nonewline -foregroundcolor Yellow;
if ($status["remote"] -ne ""){
if ($status["behind"] -ne 0){
@zommarin
zommarin / Get-FileEncoding.ps1
Created December 15, 2011 12:43
Get-FileEncoding
function Get-FileEncoding($Path) {
$bytes = [byte[]](Get-Content $Path -Encoding byte -ReadCount 4 -TotalCount 4)
if(!$bytes) { return 'utf8' }
switch -regex ('{0:x2}{1:x2}{2:x2}{3:x2}' -f $bytes[0],$bytes[1],$bytes[2],$bytes[3]) {
'^efbbbf' { return 'utf8' }
'^2b2f76' { return 'utf7' }
'^fffe' { return 'unicode' }
'^feff' { return 'bigendianunicode' }
@refractalize
refractalize / XmlKeyValues.cs
Created February 6, 2012 10:12
serializing key value pairs in a dictionary with System.Xml.Serialization.XmlSerializer
[TestFixture]
public class TrackXml {
[Test]
public void ShouldSerialiseKeyValuePairs() {
var xml = @"<track><title>Abracadabra</title><artist>Steve Miller Band</artist></track>";
var track = new Track();
track.Properties["title"] = "Abracadabra";
track.Properties["artist"] = "Steve Miller Band";
@jpoehls
jpoehls / output.txt
Created March 26, 2012 16:48
PowerShell benchmarking function. Or, the Windows equivalent of Unix's `time` command.
PS> time { ping -n 1 google.com } -Samples 10 -Silent
..........
Avg: 62.1674ms
Min: 56.9945ms
Max: 87.9602ms
PS> time { ping -n 1 google.com } -Samples 10 -Silent -Long
..........
Avg: 00:00:00.0612480
Min: 00:00:00.0572167
@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
@jamesmanning
jamesmanning / sp_generate_inserts2.sql
Created June 22, 2012 18:14
slightly better version of sp_generate_inserts
SET NOCOUNT ON
GO
PRINT 'Using Master database'
USE master
GO
PRINT 'Checking for the existence of this procedure'
IF (SELECT OBJECT_ID('sp_generate_inserts','P')) IS NOT NULL --means, the procedure already exists
BEGIN
@kitroed
kitroed / GenerateSqlScripts.ps1
Last active December 23, 2022 22:28
Generate a file-per-object representation of a given SQL Server database using PowerShell and SMO.
# Adapted from http://www.simple-talk.com/sql/database-administration/automated-script-generation-with-powershell-and-smo/
<#
.SYNOPSIS
Generate file-per-object scripts of specified server and database.
.DESCRIPTION
Generate file-per-object scripts of specified server and database to specified directory. Attempts to create specified directory if not found.
.PARAMETER ServerName
@yzorg
yzorg / IE 'Send to Chrome' bookmarklet
Last active December 11, 2015 03:08 — forked from anonymous/gist:4334192
'Send to Chrome' button in IE, adds chrome2:// protocol to Windows
// in desktop IE and metro IE - create a bookmark with the line below
javascript:document.location=("chrome2://"+document.location)
@kjeske
kjeske / ObjectExtensions.cs
Last active March 14, 2016 16:54
Safely get the property value from a source object. If the source object is null, then get the default value.
public static class ObjectExtensions
{
public static TReturn safe<T, TReturn>(this T testedObject, Func<T, TReturn> member, TReturn defaultValue = default(TReturn))
where T : class
{
return testedObject != null ? member(testedObject) : defaultValue;
}
}
// Usage example: