Skip to content

Instantly share code, notes, and snippets.

@jammycakes
jammycakes / deps.js
Created February 28, 2012 00:59
Node.js script to install dependencies using npm
var child_process = require('child_process');
function install(modules, callback) {
if (modules.length == 0) {
if (callback) callback(null);
return;
}
var module = modules.shift();
child_process.exec(
'npm install ' + module,
@jammycakes
jammycakes / gitpredict.py
Created May 27, 2012 21:35
A script to attempt to predict how Git's popularity will increase over the next few years.
import math
import scipy.optimize
'''
This script attempts to predict how Git's popularity will increase
over the next few years by extrapolating the results of the annual
Eclipse Community Survey.
The forecast assumes that Git adoption is following an S-curve
(http://en.wikipedia.org/wiki/Sigmoid_function) up to an asymptotic
@jammycakes
jammycakes / LazyDisposable.cs
Last active December 26, 2022 22:31
A subclass of System.Lazy<T> that implements IDisposable and forwards calls to the Dispose method on to the lazily created instance if it exists.
/// <summary>
/// A <see cref="Lazy"/> object that implements <see cref="IDisposable"/>.
/// </summary>
/// <typeparam name="T">
/// The object being lazily created.
/// </typeparam>
public class LazyDisposable<T> : Lazy<T>, IDisposable where T: IDisposable
{
/// <summary>
@jammycakes
jammycakes / namespace.js
Last active December 19, 2015 14:39
Provides the ability to define namespaces in JavaScript.
/* ====== namespace.js ====== */
// Provides the ability to define namespaces in JavaScript.
/**
* Declares a namespace in JavaScript.
*
* This function can be called in one of two ways:
*
* namespace(ns, obj)
@jammycakes
jammycakes / dropall.sql
Created March 26, 2014 15:27
A script to drop all objects from a SQL Server database
declare @name varchar(100)
declare @table varchar(100)
-- Drop all foreign key constraints: this goes through alter table
declare c cursor for
select a.name as [constraint], b.name as [table] from dbo.sysobjects a
inner join dbo.sysobjects b on a.parent_obj = b.id
where a.xtype='F' and b.xtype='U'
open c
@jammycakes
jammycakes / gist:f7138a3ae6b916dfbfed
Last active June 29, 2019 14:18
Find the MSBuild executable in a PowerShell script and run a build script in the same directory
$msbuild = (Get-ItemProperty hklm:\software\Microsoft\MSBuild\ToolsVersions\4.0).MSBuildToolsPath
$MyDir = [System.IO.Path]::GetDirectoryName($myInvocation.MyCommand.Definition)
. "$msbuild\msbuild.exe" "$MyDir\build.proj"
@jammycakes
jammycakes / .bashrc
Created September 15, 2016 13:14
Bash command to open a program in a new window, detached from the console. Run dos <your command>
#! /bin/bash
function run_disowned() {
"$@" & disown
}
function dos() {
run_disowned "$@" 1>/dev/null 2>/dev/null
}

Keybase proof

I hereby claim:

  • I am jammycakes on github.
  • I am jammycakes (https://keybase.io/jammycakes) on keybase.
  • I have a public key whose fingerprint is 6C63 B606 EAF0 B758 4630 DE32 9177 2E70 1B9D C839

To claim this, I am signing this object:

@jammycakes
jammycakes / README.md
Last active February 22, 2017 03:17
A snippet of code to detect the path to the current script. Works in bash and zsh.

This snippet detects various information about the shell script in which it is being executed. Copy and paste it into the top of your script.

Variables set are as follows:

  • $__SHELL: bash or zsh
  • $__SOURCED: true if the file was invoked using source filename or . filename, otherwise it will be blank.
  • $__SCRIPT_PATH: the full absolute path to the script.
  • $__SCRIPT_DIR: the full absolute path to the script's directory.
@jammycakes
jammycakes / snapshots.py
Created November 3, 2017 10:25 — forked from Eyjafjallajokull/README.md
AWS EBS - Find unused snapshots - this script generates csv raport about snapshot usage
import re
import boto3
import csv
from botocore.exceptions import ClientError
ec2 = boto3.client('ec2')
def get_snapshots():
return ec2.describe_snapshots(OwnerIds=['self'])['Snapshots']