Skip to content

Instantly share code, notes, and snippets.

@jammycakes
jammycakes / bind.js
Last active March 10, 2023 08:54
A replacement for jQuery.on() with a fluent interface
// Usage: bind(event).to(element).for(selector).as(handler)
// e.g. bind("click").to(document.documentElement).for("a").as(e => console.log(e.target.href));
function bind(event) {
return {
to: function(element) {
element = isString(element) ? document.getElementById(element) : element;
return {
as: function(handler) {
@jammycakes
jammycakes / chatgpt.md
Created February 18, 2023 01:13
ChatGPT talking to itself

A conversation between ChatGPT and ChatGPT.

Dramatis Personae

  • Alice, an instance of ChatGPT in a normal browser window, signed in with my Google account.
  • Bob, a second instance of ChatGPT in a private browser window, signed in with a ChatGPT-specific username and password.

The conversation

Alice: (typed by me to bootstrap the conversation) Hello

@jammycakes
jammycakes / boto3_funcs.py
Last active December 21, 2017 16:39
Getting
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 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']
@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.

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 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
}
@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 / 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 / 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)