Skip to content

Instantly share code, notes, and snippets.

View anapsix's full-sized avatar
😺

Anastas Dancha anapsix

😺
View GitHub Profile
@anapsix
anapsix / check_dns.sh
Created April 1, 2018 11:14
Watch for DNS changes and reload NGINX (or do something else)
#!/usr/bin/env bash
#
## example running it from cron
# MAILTO=""
# SHELL=/bin/bash
# VERBOSE=1
# CMD_ON_FAILURE='/etc/init.d/nginx reload'
# * * * * * root timeout -k 2 5 /tmp/check_dns.sh upstream.server.com 2>>/var/log/check_dns.log
# * * * * * root sleep 10 && sed -e :a -e '$q;N;501,$D;ba' -i /var/log/check_dns.log
#
@anapsix
anapsix / export_route53_zone.sh
Created March 5, 2018 12:17
export route53 in BINDish format
#!/bin/bash
case $1 in
--name)
shift
zonename="$1"
hostedzoneid=($(aws route53 list-hosted-zones | jq -r ".HostedZones[] | select(.Name == \"$zonename.\") | .Id" | cut -d'/' -f3))
if [ ${#hostedzoneid[@]} -eq 0 ]; then
echo >&2 "Could not find Route53 zone for \"$zonename\", exiting.."
exit 1
@anapsix
anapsix / lockcreen.md
Created February 8, 2018 15:18
lockscreen command line utility on mac

Make a lockscreen CLI utility on your Mac

ATTENTION: use at your own risk, no warranty of any kind This seems to work in High Sierra, but may break in future versions

cat > /tmp/lockscreen.c <<EOF
// lockscreen.c
extern void SACLockScreenImmediate();
int main()
{
@anapsix
anapsix / check_http.sh
Created January 9, 2018 09:20
Check URL and return timing, http code, number of redirects, and effective url
#!/usr/bin/env bash
#
# returns the following
# [curl exit code],[total request time],[http response code],[number of redirects],[effective url]
#
if [[ ${1} == '' ]]; then
echo >&2 'missing URL to check'
echo >&2 "Usage: $0 google.com"
exit 1
@anapsix
anapsix / getting_ips_in_Javascript_and_CoffeeScript.md
Created December 22, 2017 13:09
How to get interface IP in JavaScript/NodeJS and CoffeeScript

JavaScript

function getInterfaceIPv4(iface) {
  var iface_info = os.networkInterfaces()[iface];
  var addresses = [];
  //console.log(iface_info);
  for (var k in iface_info) {
    var address = iface_info[k];
    //console.log(address);
 if (address.family === 'IPv4') {
@anapsix
anapsix / kinesis_consumer.php
Created December 15, 2017 17:08
Kinesis Consumer in PHP with AWS SDK
<?php
// if running in Alpine, install the following
// apk -U add php7 php7-mbstring php7-simplexml php7-json php7-phar php7-openssl curl
// curl -sS https://getcomposer.org/installer | php
// php composer.phar require aws/aws-sdk-php
//
// export AWS_ACCESS_KEY_ID=...
// export AWS_SECRET_ACCESS_KEY=...
if (getenv('KINESIS_STREAM')) {
$streamName = getenv('KINESIS_STREAM');
@anapsix
anapsix / aws_metadata_proxy.md
Created December 13, 2017 16:47
How to proxy EC2 metadata

How to proxy to EC2 Metadata

Sometimes, you need to use your EC2 instance's credentials to access the AWS resources, for testing, development, etc.. This is how you do it.

Step 1

create 169.254.169.254 on loopback interface

linux

sudo ip a add 169.254.169.254 dev lo

Keybase proof

I hereby claim:

  • I am anapsix on github.
  • I am anapsix (https://keybase.io/anapsix) on keybase.
  • I have a public key ASAqGKWc6Gg5in_d1Fd22gENDnm8vWd5zrPo758smzTpxAo

To claim this, I am signing this object:

@anapsix
anapsix / get_elb_logs.sh
Last active January 30, 2017 18:45
Getting ELB logs from S3 via SQS queue at maximum warp
#!/usr/bin/env bash
#================================================================
# DESCRIPTION
# Script retrieves files from S3 via SQS at maximum warp.
#================================================================
# AUTHOR Anastas Dancha (@anapsix)
# COPYRIGHT Copyright (c) Anastas Dancha (@anapsix)
# LICENCE GNU General Public License
#================================================================
@anapsix
anapsix / eventbrite_tickets_count.md
Last active October 7, 2015 18:21
eventbrite tickets count

remaining tickets count from Eventbrite, without API key