Skip to content

Instantly share code, notes, and snippets.

View thibautsacreste's full-sized avatar

Thibaut Sacreste thibautsacreste

View GitHub Profile
# Your init script
#
# Atom will evaluate this file each time a new window is opened. It is run
# after packages are loaded/activated and after the previous editor state
# has been restored.
#
# An example hack to log to the console when each text editor is saved.
#
# atom.workspace.observeTextEditors (editor) ->
# editor.onDidSave ->
@thibautsacreste
thibautsacreste / aws.sg.unused
Last active June 4, 2024 10:12
Bash: list unused AWS security groups
#!/usr/bin/env bash
# lists all unused AWS security groups.
# a group is considered unused if it's not attached to any network interface.
# requires aws-cli and jq.
# all groups
aws ec2 describe-security-groups \
| jq --raw-output '.SecurityGroups[] | [.GroupName, .GroupId] | @tsv' \
| sort > /tmp/sg.all
@thibautsacreste
thibautsacreste / aws.sg
Last active March 11, 2023 04:58
Bash: AWS security group uses
#!/usr/bin/env bash
# shows uses of an AWS security group:
# * lists all network interfaces it is attached to.
# * lists all other security groups referencing it in inbound rules.
# usage: aws.sg my-security-group-name
# requires aws-cli and jq.
group_name=$1
group_id=`aws ec2 describe-security-groups --filters "Name=group-name,Values=$group_name" | \
@thibautsacreste
thibautsacreste / rack_show_session.rb
Last active March 12, 2021 13:43
Ruby: decode rack session cookie
require 'base64'
require 'cgi'
def show_session(cookie)
Marshal.load(Base64.decode64(CGI.unescape(cookie.split("\n").join).split('--').first))
end
@thibautsacreste
thibautsacreste / uid.rb
Created June 7, 2012 13:25
Ruby: encoding/decoding uids generated by the ngx_http_userid_module
require 'base64'
// Decoding
cookie_value = 'CjpqE0+NhreIpEqgAyz3Ag=='
uid_hex_string = "uscc=" + Base64.decode64(cookie_value).unpack("VVVV").map{|x|x.to_s(16).rjust(8, '0')}.join.upcase
// Encoding with ruby > 1.9.2
uscc = "136A3A0AB7868D4FA04AA48802F72C03"
cookie_value = Base64.safe_encode64(uscc.scan(/.{8}/).map{|x| x.to_i(16)}.pack("VVVV"))