Skip to content

Instantly share code, notes, and snippets.

@cajones
cajones / jsonx-amd.js
Created January 23, 2012 15:00
Possible module boilerplate for AMD, CommonJS and namespace methods
var library =
function(container) {
var stringify = function(obj, rootName) {
/* implementation goes here */
};
container.stringify = stringify;
return container;
}; // define the library in a function, injecting external dependencies if needed
@cajones
cajones / Edit-UsingSublimeText2.ps1
Created January 27, 2012 16:04
function to open one or more files in a text editor (SublimeText2 in this case)
function Execute-Each($list) {
$list |% { & $exe $_ }
}
function Edit-UsingSublimeText2($path) {
$exe = "C:\Program Files\Sublime Text 2\sublime_text.exe"
$files = @()
$files += $path
$files += $input
(Execute-Each $files)
}
@cajones
cajones / Git-Init.ps1
Created February 3, 2012 10:07
GitHub: Init local repo
function Git-Init($project, $username = 'your-username-here') {
md $project
cd $project
git init
ni -t f readme.md
git add .
git commit -m "first commit"
git remote add origin git@github.com:$username/$project.git
git push -u origin master
Write-Host "$project has been created and pushed to github."
var SharepointSearchForm = (function () {
var uniqueArray = function (arr) {
var uniqueValues = [];
$.each(arr, function (index, item) {
if ($.inArray(item, uniqueValues) === -1) {
uniqueValues.push(item);
}
@cajones
cajones / flatten.ps1
Created March 23, 2012 10:38
Powershell script to flatten a folder structure from Adobe Captivate
param($directoryToFlatten = '.', $scormSubDir = 'SCORM_support')
$supportDir = "$directoryToFlatten\$scormSubDir"
if((Test-Path $supportDir)) {
mi "$supportDir\*.*" $directoryToFlatten
ri $supportDir
Write-Host 'Support files moved...'
}
@cajones
cajones / CamlQueryBuilder.js
Created March 23, 2012 12:14
Caml Query Builder
var CamlQueryBuilder = function() {
};
CamlQueryBuilder.prototype.withExactValues = function(fieldValues) {
this.exactFieldValues = fieldValues;
this.doExactQuery = true;
};
CamlQueryBuilder.prototype.thatContains = function(fields, values) {
@cajones
cajones / find.ps1
Created April 4, 2012 10:08
Find shell scripts
function Find-File([string[]]$patterns, [string]$extension, [string] $joinPattern = "[\w|/|\\]*") {
$regex = $patterns -join $joinPattern
ls -r -i "*.$extension" | where { $_.Fullname -match $regex } |% { $_.Fullname }
}
Set-Alias -Name ff -Value Find-File
function Find-Solution([string[]]$patterns){
Find-File -e sln $patterns
}
@cajones
cajones / head-tail.ps1
Created April 27, 2012 10:10
String manipulation
function Select-Head ([string]$text, [int]$index, [string]$pattern) {
$input += $text
return $input | where { $_ -is [string] } |% {
if($pattern) {
$index = $_.IndexOf($pattern)
}
if($index -ge $_.length) {return $_}
return $_.Substring(0, $index)
}
}
@cajones
cajones / AsyncSpecification.cs
Created July 19, 2012 13:38
Async Specification
using System;
using System.Threading;
namespace Testing
{
public class AsyncSpecification
{
private static readonly AutoResetEvent signal = new AutoResetEvent(false);
protected static void Wait(TimeSpan timeout)
@cajones
cajones / find-hiddendrives.ps1
Created July 20, 2012 08:51
Find hidden network drives on a remote server
function Find-HiddenDrive($server) {
$alpha = [char[]]"cdefghijklmnopqrstuvwxyz"
return $alpha | ? { test-path \\$server\$_`$ }
}