Skip to content

Instantly share code, notes, and snippets.

@losvedir
losvedir / ecr_cleanup.md
Last active May 25, 2022 19:15
Clean up old ECR images

Cleaning up old ECR images

A process to delete old ECR images using the aws CLI tool and jq.

The general idea is to use aws ecr describe-images to enumerate the images, and aws ecr batch-delete-image to delete them. The latter command can take a --cli-input-json argument specifying a JSON file which lists the images to delete. jq is used to filter describe-images to only the old ones, and munge it into the format that batch-delete-image expects. Unfortunately, batch-delete-image supports a maximum of 100 images at a time, so the process may need to be repeated several times.

Limitations:

  • I can't find a way to do this as a neat command line pipeline. --cli-input-json seems to require that the input comes from a file, rather than STDIN. (AWS CLI tracking issue: aws/aws-cli#3209)
  • Since batch-delete-image can only handle 100 images at a time, the jq command slices to [0:100] after filtering to just the old images. This means the process may have to be re
@losvedir
losvedir / rspec_magic.rb
Last active December 25, 2015 22:39
Exploration into how Rspec could provide some of its nice syntactical features
require 'ostruct'
class Object
def expect(value)
@expector = Expector.new(value)
end
def eq(val)
[:==, val]
end
class CreateOrganizations < ActiveRecord::Migration
def change
create_table :organizations do |t|
t.string :name
t.boolean :has_octocats
t.timestamps
end
end
end
@losvedir
losvedir / Rails SQL stuff
Created December 3, 2012 20:29
Rails 3 ActiveRelation counting, grouping, sorting, and limiting
Model.joins(:relation)
.merge(Relation.scope)
.count(group: 'column or postgres function',
order: 'count_all DESC',
limit: 10
)
# Note: the count_all is the 'AS' variable ActiveRelation makes for you.
@losvedir
losvedir / take_that
Created August 22, 2012 21:36
For Stripe CTF
haha
@losvedir
losvedir / rspec-syntax-cheat-sheet.rb
Created May 11, 2012 15:45 — forked from dnagir/rspec-syntax-cheat-sheet.rb
RSpec 2 syntax cheat sheet by example
# RSpec 2.0 syntax Cheet Sheet by http://ApproachE.com
# defining spec within a module will automatically pick Player::MovieList as a 'subject' (see below)
module Player
describe MovieList, "with optional description" do
it "is pending example, so that you can write ones quickly"
it "is already working example that we want to suspend from failing temporarily" do
pending("working on another feature that temporarily breaks this one")
@losvedir
losvedir / 1 - NEW _delivery.html.erb
Created March 22, 2012 22:16
Convert delivery methods from radio buttons to select options
<%= form.select :shipping_method, shipping_methods_for_select(@order) %>
@losvedir
losvedir / 1 - NEW _delivery.html.erb
Created March 22, 2012 22:13
Convert delivery methods from radio buttons to select options
<%= form.select :shipping_method, shipping_methods_for_select(@order) %>
@losvedir
losvedir / Vinegar.txt
Created February 15, 2011 23:18
Breaking Wilhelm von Hackensplat's Vinegar cipher
From HN thread here: http://news.ycombinator.com/item?id=2222228
Challenge posed here: http://blog.hackensplat.com/2011/02/vinegar.html
It seems the cipher is an application of viginere four times. So, if the original
17 character key is x1 x2 y1 y2 y3 z1 z2 z3 z4 z5 t1 t2 t3 t4 t5 t6 t7, and the
original text is C1 C2 C3 C4, then the ciphertext we're given of IWY SEIX....
can be thought of as follows:
I = (C1+x1+y1+z1+t1)
W = (C2+x2+y2+z2+t2)
@losvedir
losvedir / gist:661564
Created November 3, 2010 19:33
Cracker Barrel Triangle Peg Jumping Game Solver
/* Solves one of those triangle shaped peg jumping puzzles.
You begin with a board composed of n rows, where the i-th
row contains i columns. e.g.:
X
X X
X X X
The board begins with pegs in all holes but one. A peg can
jump over another peg if it can land in a hole on the other
side. The jumped peg is removed. The goal is to finish with
a single peg remaining.