Skip to content

Instantly share code, notes, and snippets.

View boto3_funcs.py
import boto3
def get_paginated_results(func, key, **kwargs):
"""
Many boto3 methods return only a limited number of results at once,
with pagination information. This function handles the pagination to
retrieve the entire result set.
@param func
The function to call to get the data.
@jammycakes
jammycakes / snapshots.py
Created Nov 3, 2017 — forked from Eyjafjallajokull/README.md
AWS EBS - Find unused snapshots - this script generates csv raport about snapshot usage
View snapshots.py
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']
@jammycakes
jammycakes / README.md
Last active Feb 22, 2017
A snippet of code to detect the path to the current script. Works in bash and zsh.
View README.md

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.
View keybase.md

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 / .bashrc
Created Sep 15, 2016
Bash command to open a program in a new window, detached from the console. Run dos <your command>
View .bashrc
#! /bin/bash
function run_disowned() {
"$@" & disown
}
function dos() {
run_disowned "$@" 1>/dev/null 2>/dev/null
}
@jammycakes
jammycakes / gist:f7138a3ae6b916dfbfed
Last active Jun 29, 2019
Find the MSBuild executable in a PowerShell script and run a build script in the same directory
View gist:f7138a3ae6b916dfbfed
$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 / dropall.sql
Created Mar 26, 2014
A script to drop all objects from a SQL Server database
View dropall.sql
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 / namespace.js
Last active Dec 19, 2015
Provides the ability to define namespaces in JavaScript.
View namespace.js
/* ====== 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 / LazyDisposable.cs
Last active Oct 9, 2021
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.
View LazyDisposable.cs
/// <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 / gitpredict.py
Created May 27, 2012
A script to attempt to predict how Git's popularity will increase over the next few years.
View gitpredict.py
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