Skip to content

Instantly share code, notes, and snippets.

@nicokruger
nicokruger / git-foreach.sh
Created March 18, 2012 16:42
Execute a command for all commits in a git repository.
#!/bin/bash
if ! [ -d ".git" ]; then
echo "Script must be run from within a git repository"
exit 1
fi
if [ $# -ne 1 ]; then
echo "Please specify a script to execute for each commit"
echo "Script will recieve <repo_dir> <commit ref> as arguments"
@nicokruger
nicokruger / lambdapricing.js
Created April 27, 2020 10:08
Work out approximate cost per lambda across region over time period using Cloudwatch Log Insights
const aws = require('aws-sdk');
aws.config.region = 'eu-west-1';
const cloudwatchlogs = new aws.CloudWatchLogs();
const moment = require('moment');
const fs = require('fs');
const filename = `results-${new Date().getTime()}.csv`;
fs.appendFileSync(filename, ['logGroup','dollars','rcnt','numberdollars','total'].join(",") + "\n");
const endTime = moment().toDate().getTime();
@nicokruger
nicokruger / fix-slow-oh-my-zsh-big-git-repos.sh
Created October 6, 2020 10:36
Fix slow oh my zsh in large git repos
git config --add oh-my-zsh.hide-status 1
git config --add oh-my-zsh.hide-dirty 1
list databases: \l *;
non-binary way:
export PGPASSWORD=whatever
for F in $(cat dbs); do echo $F; psql -h dt-rds-test.coivvuccn9hs.eu-west-1.rds.amazonaws.com -v -U postgres -d ${F} < ${F}.sql ; done
binary way:
https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL.Procedural.Importing.html
# above way doesnt seem to work with roles etc.
umount /mnt/c; sudo mount -t drvfs C: /mnt/c -o metadata
@nicokruger
nicokruger / ports.ps1
Created July 19, 2020 12:22
Open WSL ports to windows host
$remoteport = bash.exe -c "ifconfig eth0 | grep 'inet '"
$found = $remoteport -match '\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}';
if( $found ){
$remoteport = $matches[0];
} else{
echo "The Script Exited, the ip address of WSL 2 cannot be found";
exit;
}
@nicokruger
nicokruger / getAllS3Objects.js
Created March 13, 2020 11:00
getAllS3Objects
async function getAllS3Objects(Params) {
let listing = true;
const objects = [];
while (listing) {
const data = await s3.listObjects(Params).promise();
if (!data.isTruncated) {
listing = false;
} else {
Params.Marker = data.NextMarker;
}
class Chezzers(sfn.IStepFunctionsTask):
def __init__(self, app, id, **kwargs):
super().__init__(app, **kwargs)
def bind(task):
print("called it!")
@nicokruger
nicokruger / rotn.js
Created July 5, 2012 06:43
Rot-n JS
var rot = function (n, l) { return l.slice(n).concat(l.slice(0,n)); };
@nicokruger
nicokruger / count-files.sh
Created March 18, 2012 21:02
count-files.sh
#!/bin/bash
echo $(find . -type f | grep -v .git | wc -l)