Skip to content

Instantly share code, notes, and snippets.

Avatar
🚲
Tant que je respire, j’attaque

Nic Doye nicdoye

🚲
Tant que je respire, j’attaque
View GitHub Profile
@nicdoye
nicdoye / my_date.sh
Created Jul 31, 2017
macOS ISO8601 dates
View my_date.sh
my_date () {
local date_cmd
local date
# Check if GNU date installed as gdate
: type gdate 2> /dev/null
[ $? == 0 ] && date_cmd=gdate || date_cmd=date
# Attempt GNU date - date will be unset if this fails
date=$(${date_cmd} --iso-8601=second 2> /dev/null)
@nicdoye
nicdoye / get-ip.pl
Created Jul 27, 2017
Finding your IP in Perl
View get-ip.pl
#!/usr/bin/env perl
use strict;
use warnings;
use feature qw/say/;
use WebService::IFConfig::Client;
my $client = WebService::IFConfig::Client->new();
say $client->get_ip;'
@nicdoye
nicdoye / IntegerDivision.pm
Last active Jul 2, 2017
Perl Integer Division Module
View IntegerDivision.pm
package Math::IntegerDivision;
use Carp;
use Moose;
has 'numerator' => (
is => 'rw',
isa => 'Int'
);
@nicdoye
nicdoye / tunnel.sh
Created Jun 15, 2017
SSH tunnel to Windows server in AWS VPC
View tunnel.sh
#!/bin/bash
# SECURITY WARNING: the password will be visible in the process list on your local machine.
# Note: you need PuTTY's plink to get this to work, even on macOS
# macOS: `brew install putty`
# Windows: `choco install putty`
# Arguments:
# vpc_ip = Private IP Address of the Windows box. e.g. 172.16.1.1
@nicdoye
nicdoye / inode-remover.sh
Created Jun 15, 2017
Incredibly dangerous script to remove open inodes of deleted files
View inode-remover.sh
#!/bin/bash
while [[ $(lsof -nP +L1 | wc -l) > 1 ]]
do
pair=$(lsof -nP +L1 | tail -n 1 | awk '{print $2" " $4}')
pid=$(echo $pair | awk '{print $1}')
fd=$(echo $pair | awk '{print $2}' | sed -e 's_[a-z]__g')
file=$(mktemp)
# Race condition check on first line of lsof output
@nicdoye
nicdoye / mount-cleaner.sh
Created Apr 18, 2017
Unmounting installation disks on macOS
View mount-cleaner.sh
#!/bin/bash
# IMPORTANT ASSUMPTION:
# YOU DO NOT HAVE ANY OTHER DISKS MOUNTED WITH AN `s1` PARTITION!
# A better way would be to use `diskutil list --plist` and parse the
# plist using ruby/python/javascript/your-language-of-choice
for disk in $(mount | egrep 'disk.+s1' | awk '{print $1}' | sed -e 's_^/dev/__' -e 's_s1$__')
do
diskutil eject ${disk}
@nicdoye
nicdoye / config
Created Mar 4, 2017
A sample ssh config for bastions/gateways
View config
# Your bastion host
Host bastion bastion.example.com
IdentityFile ~/.ssh/bastion-example-com.pem
Port 12345
User bastion-user
# Inside the VPC
Host host0.internal host1.internal
View keybase.md

Keybase proof

I hereby claim:

  • I am nicdoye on github.
  • I am nicdoye (https://keybase.io/nicdoye) on keybase.
  • I have a public key ASB0JEma1L_Ga1DDnc5C5PjOQeUqdd-te4Byt53qpDDzFAo

To claim this, I am signing this object:

@nicdoye
nicdoye / shrink-png.sh
Created Feb 14, 2017
Shrink a PNG file so you can make a custom emoji in Slack, using NetPBM
View shrink-png.sh
pngtopam -alphapam < filename.png | pamscale -xyfit 128 128 | pamtopng > filename-shrunk.png
View gotcha.sh
# This is what you'd expect - prints 1
declare var
var=$(false)
echo $?
# This does not do what you'd expect - prints 0
declare var2=$(false)
echo $?
You can’t perform that action at this time.